Indicator showing the range of two moving averages
I think you are overcomplicating things.
You can simply use iMA commands for initializing handles into OnInit, then copy buffers from MA indicators, and then do a simple difference between your buffers.
#property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 input int iMA1Period = 50; input int iMA2Period = 200; double ExtMA1[], ExtMA2[], ExtDelta[]; int Handle_MA1, Handle_MA2; int OnInit() { SetIndexBuffer(0,ExtDelta); SetIndexBuffer(1,ExtMA1); SetIndexBuffer(2,ExtMA2); PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE); PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrBlue); if( (Handle_MA1 = iMA(NULL,0,iMA1Period,0,MODE_EMA,PRICE_CLOSE)) == INVALID_HANDLE ) return INIT_FAILED; if( (Handle_MA2 = iMA(NULL,0,iMA2Period,0,MODE_EMA,PRICE_CLOSE)) == INVALID_HANDLE ) return INIT_FAILED; return(INIT_SUCCEEDED); } 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[]) { if( prev_calculated<1 ) { ArrayInitialize(ExtMA1,EMPTY_VALUE); ArrayInitialize(ExtMA2,EMPTY_VALUE); ArrayInitialize(ExtDelta,EMPTY_VALUE); } if( CopyBuffer(Handle_MA1,0,0,MathMin(rates_total-prev_calculated+1,rates_total-1),ExtMA1)<=0 ) return 0; if( CopyBuffer(Handle_MA2,0,0,MathMin(rates_total-prev_calculated+1,rates_total-1),ExtMA2)<=0 ) return 0; for (int i=MathMax(0,prev_calculated-1); i<rates_total && !_StopFlag; i++) ExtDelta[i] = ExtMA1[i] - ExtMA2[i]; return(rates_total); }
I think you are overcomplicating things.
You can simply use iMA commands for initializing handles into OnInit, then copy buffers from MA indicators, and then do a simple difference between your buffers.
Hello Community,
I tried building an indicator that shows the range of two moving averages.
The indicator is designed to have 3 buffers and 1 plot, with the plot being a single line showing the range data.
The goal is to be able to track proximity to the crossover. Need help please.
Below is my script, but it
seems not to be working.
I keep on getting this error code; 2024.05.07 08:39:08.450 array out of range in 'macor.mq5' (60,36)
Am just barely 3 months old to MQL5. I need help.
Would be so happy to have this script working.
At the moment I use it in it basic logic in my EA which works like this ;
But would love to have it as an indicator.