Hello everyone! I am coding a simple indicator that plots the slope of the moving average with given period. The code compiles without any errors and warnings. However it does not plot anything on the window. Can you point out my mistakes?
//+------------------------------------------------------------------+//| Slope of Moving Average.mq5 |//| Miraç Baver Öztürk |//| mirac.baver.ozturk@gmail.com |//+------------------------------------------------------------------+#property copyright"Miraç Baver Öztürk"#property link"mirac.baver.ozturk@gmail.com"#property version"1.00"#property description"This indicator calculates the slope of Moving Average with given periods"#property indicator_separate_window#property indicator_buffers3#property indicator_plots1//input parametersinputint MA_Period = 14;//period of the moving average//plot color histogram#property indicator_label1"SMA"//Slope of Moving Average#property indicator_type1DRAW_COLOR_HISTOGRAM#property indicator_color1clrGreen, clrRed#property indicator_style1STYLE_SOLID#property indicator_width12//buffersdouble SMA_Buffer[];
double SMA_Colors_Buffer[];
double MA_Buffer[];
color colors[] = {clrGreen, clrRed};
int MA_Handle;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
MA_Handle = iMA(_Symbol, _Period, MA_Period, 0, MODE_SMA, PRICE_MEDIAN);
SetIndexBuffer(0, SMA_Buffer, INDICATOR_DATA);
SetIndexBuffer(1, SMA_Colors_Buffer, INDICATOR_COLOR_INDEX);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
IndicatorRelease(MA_Handle);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &spread[])
{
ArraySetAsSeries(MA_Buffer, true);
int start = 0;
if(prev_calculated > 0)start = prev_calculated - 1;
for(int i=start;i<rates_total;i++)
{
CopyBuffer(MA_Handle, 2, i, 3, MA_Buffer);
SMA_Buffer[i] = (MA_Buffer[i] - MA_Buffer[i+1]) / 2;
if(SMA_Buffer[i]>0)SMA_Colors_Buffer[i] = 0;//greenelse SMA_Colors_Buffer[i] = 1;//red
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
Hello everyone! I am coding a simple indicator that plots the slope of the moving average with given period. The code compiles without any errors and warnings. However it does not plot anything on the window. Can you point out my mistakes?