these bad boys here are empty ,so you probably run into "array out of range issues" ,you can confirm that in the "Experts tab
if you cant see the Experts Tab , hit Ctrl+T ,and click on "Experts"
You want to weigh by volume yeah ?
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor - If you had looking in the experts tab, you would see the array exceeded message.
int start(){ ⋮ double WROC[]; double ROC[]; ⋮ ROC[j] = …
Try this , i think you did not want volume weighting eventually
Its not as complex as it looks , the averaging function at the bottom is what interests you .
#property copyright "Forum.Thread" #property link "https://www.mql5.com/en/forum/351677" #property version "1.00" #property description "Telegram : https://t.me/lorentzor\nInstagram : @rlorentzo\nTwitter : @lorentzo_r\nLinkedIn : https://www.linkedin.com/in/lorentzor\nYoutube : https://www.youtube.com/channel/UCM0Lj06cAJagFWvSpb9N5zA\nFacebook : @LorentzoR" /* ways to connect .> : Telegram : https://t.me/lorentzor Instagram : https://www.instagram.com/rlorentzo /OR/ @rlorentzo Twitter : https://twitter.com/lorentzo_r /OR/ @lorentzo_r LinkedIn : https://www.linkedin.com/in/lorentzor Youtube : https://www.youtube.com/channel/UCM0Lj06cAJagFWvSpb9N5zA Facebook : https://www.facebook.com/LorentzoR /OR/ @LorentzoR Mql5.com : https://www.mql5.com/en/users/lorio */ #property strict #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot ROC #property indicator_label1 "ROC" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLimeGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot avgROC #property indicator_label2 "avgROC" #property indicator_type2 DRAW_LINE #property indicator_color2 clrWhite #property indicator_style2 STYLE_SOLID #property indicator_width2 1 input int ROCPeriod=14;//Period input bool W_Recency=false;//Weight by recency input bool W_Volume=false;//Weight by volume //--- indicator buffers double AvgROC[],ROC[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ROC); SetIndexBuffer(1,AvgROC); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- //basic indicator loop ignore int nuevo=rates_total-prev_calculated; int i_from=rates_total-2,i_to=0;//if as series if(nuevo<i_from){i_from=nuevo;} //loop for(int i=i_from;i>=0;i--) { int j=rates_total-i-1;//mt5 adress - ignore //basic indicator loop ends here ---- your code follows //>>> //raw roc for this bar using your unWeighted formula -> current close - prev_close / prev close ROC[i]=(Close[i]-Close[i+1])/Close[i+1]; //weighted average AvgROC[i]=RecencyAndVolumeWeightedAverage(ROC,i,ROCPeriod,W_Recency,W_Volume,volume); //<<< } //loop ends here //--- return value of prev_calculated for next call return(rates_total); } //for series +1 is in the past -1 is in the future double RecencyAndVolumeWeightedAverage(double &series[], int i_from, int period, bool weight_by_recency, bool weight_by_volume, const long &vol[]){ double rovwa=0; //recency weight double reweight=0; //volume weight double volweight=0; //sum double sum=0; //divider double div=0; //start int i_sta=i_from+period-1;//we include the from bar in the calculation if(i_sta>(ArraySize(series)-1)){i_sta=ArraySize(series)-1;} //loop for(int i=i_sta;i>=i_from;i--) { //this weight double this_weight=1; //by recency if(weight_by_recency) { reweight++; this_weight*=reweight; } //by volume if(weight_by_volume&&i<ArraySize(vol)) { volweight=((double)vol[i]/1000); this_weight*=volweight; } sum+=series[i]*this_weight; div+=this_weight; } if(div>0){rovwa=sum/div;} //loop return(rovwa); }
-
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
Messages Editor - If you had looking in the experts tab, you would see the array exceeded message.
Try this , i think you did not want volume weighting eventually
Its not as complex as it looks , the averaging function at the bottom is what interests you .
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear All,
Why my indicator can not show anything? I want to design a indicator for weighted rate of change with formula as below
#property indicator_separate_window
#property indicator_buffers 1