#include <MovingAverages.mqh>
#property indicator_separate_window#property indicator_buffers2#property indicator_plots1#property indicator_type1DRAW_LINE#property indicator_color1 Blue
#property indicator_label1"Diference"
//--- global variablesint InpMAPeriod=20;
int ExtPlotBegin=0;
//---- indicator bufferdouble ExtdiferenceBuffer[];
double ExtMABuffer[];
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0,ExtdiferenceBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtMABuffer,INDICATOR_CALCULATIONS);
//--- set accuracyIndicatorSetInteger(INDICATOR_DIGITS,2);
//--- sets first bar from what index will be drawn
ExtPlotBegin=InpMAPeriod-1;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);
//---- line shifts when drawingPlotIndexSetInteger(0,PLOT_SHIFT,0);
//--- name for DataWindowIndicatorSetString(INDICATOR_SHORTNAME,"Diference: ");
//--- set index labelsPlotIndexSetString(0,PLOT_LABEL,"Diference");
//---- sets drawing line empty value--PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//---- initialization donereturn(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constint begin,
constdouble &price[])
{
//--- variablesint pos;
//--- indexes draw begin settings, when we've recieved previous beginif(ExtPlotBegin!=InpMAPeriod+begin)
{
ExtPlotBegin=InpMAPeriod+begin;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
}
//--- check for bars countif(rates_total<ExtPlotBegin) return(0);
//--- starting calculationif(prev_calculated>1) pos=prev_calculated-1;
else pos=0;
//--- main cyclefor(int i=pos;i<rates_total && !IsStopped();i++)
{
//---SMA
ExtMABuffer[i]=SimpleMA(i,InpMAPeriod,price);
//---Diferencedouble diference = fabs(ExtMABuffer[i-6]-ExtMABuffer[i-1]);
ExtdiferenceBuffer[i] = diference;
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
Hello guys,
I'm learning about indicators and wanna do a simple one, but i'm having problems in the loop logic. I know it is wrong but can't fix it.
Here is the indicator's ideia: He calculates a simple moving average of close price then returns the value of SMA[6]-SMA[1]. The plot will be the result of SMA[6]-SMA[1] only.
I've already tried to do 2 diferent plots with a shift of 6 and 1, but the shift is only visual the return value is the same for both, resulting in SMA[6]-SMA[1] = 0
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello guys,
I'm learning about indicators and wanna do a simple one, but i'm having problems in the loop logic. I know it is wrong but can't fix it.
Here is the indicator's ideia: He calculates a simple moving average of close price then returns the value of SMA[6]-SMA[1]. The plot will be the result of SMA[6]-SMA[1] only.
I've already tried to do 2 diferent plots with a shift of 6 and 1, but the shift is only visual the return value is the same for both, resulting in SMA[6]-SMA[1] = 0
Any ideias how to do the correct loop?
Sorry for the bad english :)