- Suggestion for an expert advisor, please help :)
- Questions from Beginners MQL5 MT5 MetaTrader 5
- Can Arrays be paired to run operations without the need for loops?
-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Always post all relevant code. You reference two arrays, but didn't post the definition, whether they are resized or buffers, etc.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem -
You sum your arrays. What about those elements that have no value. Did you set their empty value to zero, or are you summing EMPTY_VALUE?
-
What about bar zero changing direction? You will have both arrays set.
- www.mql5.com
-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Always post all relevant code. You reference two arrays, but didn't post the definition, whether they are resized or buffers, etc.
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problem -
You sum your arrays. What about those elements that have no value. Did you set their empty value to zero, or are you summing EMPTY_VALUE?
-
What about bar zero changing direction? You will have both arrays set.
//+------------------------------------------------------------------+ //| PRODeviation.mq4 | //| VockCap | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "VockCap" #property link "https://www.mql5.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 3 #property indicator_plots 3 extern double UpLevel=75; extern double DownLevel=25; extern int LimitsForDeviation=10; //--- plot ProDeviation #property indicator_label1 "ProDeviation" #property indicator_type1 DRAW_HISTOGRAM #property indicator_type2 DRAW_HISTOGRAM #property indicator_type3 DRAW_HISTOGRAM #property indicator_color1 clrBlue #property indicator_color2 clrGreen #property indicator_color3 clrRed #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_SOLID #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 2 //--- indicator buffers double ProDeviationBuffer[]; double SDU[]; double SDD[]; double InfoUp[]; double InfoDown[]; double MAUP[]; double MADOWN[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ProDeviationBuffer); SetIndexBuffer(1,SDU); SetIndexBuffer(2,SDD); SetIndexDrawBegin(0,0); SetIndexDrawBegin(1,0); SetIndexDrawBegin(2,0); SetIndexLabel(0,"ProDeviation"); SetIndexLabel(1,"Signal Buy"); SetIndexLabel(2,"Signal Sell"); //--- 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[]) { //--- //DemoCheck: if(TimeCurrent()>D'07.07.2023') { return(0); } //ArrayResize: ArrayResize(SDU,rates_total+LimitsForDeviation*2,10); ArrayResize(SDD,rates_total+LimitsForDeviation*2,10); ArrayResize(ProDeviationBuffer,rates_total+LimitsForDeviation*2,10); ArrayResize(InfoUp,rates_total+LimitsForDeviation*2,10); ArrayResize(InfoDown,rates_total+LimitsForDeviation*2,10); ArrayResize(MAUP,rates_total+LimitsForDeviation*2,10); ArrayResize(MADOWN,rates_total+LimitsForDeviation*2,10); //Calculating: for(int i=0; i<rates_total; i++) { //Disstribution double Different=iClose(NULL,0,i)-iClose(NULL,0,i+1); if(Different>0) { InfoUp[i]=Different; } if(Different<0) { InfoDown[i]=MathAbs(Different); } } for(int i=0; i<rates_total; i++) { double UP=0, Down=0, AverUP=0, AverDown=0, StdU=0, StDD=0; //CalculateResult&Counting for(int x=i; x<=i+LimitsForDeviation; x++) { UP=UP+InfoUp[x]; //SUM Down=Down+InfoDown[x]; //SUM } AverUP=UP/LimitsForDeviation; AverDown=Down/LimitsForDeviation; for(int ii=i; ii<=i+LimitsForDeviation; ii++) { StdU+=(InfoUp[ii]-AverUP)*(InfoUp[ii]-AverUP); StDD+=(InfoDown[ii]-AverDown)*(InfoDown[ii]-AverDown); } double trueStdU=MathSqrt(StdU/(LimitsForDeviation-1)); double trueStdD=MathSqrt(StDD/(LimitsForDeviation-1)); double Y=0; if(trueStdU!=0&&trueStdD!=0) { Y=trueStdU/trueStdD; } double RSI=100-100/(1+Y); if(RSI<DownLevel) { SDU[i]=RSI; } if(RSI>UpLevel) { SDD[i]=RSI; } ProDeviationBuffer[i]=RSI; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
Greetings!
This is all code:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use