Supertrend indicator not plotting lines but no errors when compiling

 

The supertrend indicator is supposed to plot lines certain points/pips above and below the supertrend signal.

Working Supertrend  indicator and Daily Open (Indicator that plots lines certain points/pips above and below the daily open.) indicator files attached.

I was hoping to apply the line plotting function to supertrend signal instead of daily open.


#property indicator_chart_window

#property indicator_color1  clrBisque, clrPaleGreen

#property indicator_label2  "SuperTrend"

#property indicator_type1   DRAW_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_color2  clrGreen, clrRed

#property indicator_buffers 11

#property indicator_plots   11

input int    Periode=10;

input double Multiplier=3;

input int    AboveLine=0;

input int    BelowLine=0;

input bool   Show_Filling=false; // Show as DRAW_FILLING

double Filled_a[];

double Filled_b[];

double SuperTrend[];

double ColorBuffer[];

double Atr[];

double Up[];

double Down[];

double Middle[];

double trend[];

double AboveLineBuffer[];

double BelowLineBuffer[];

double ST_UpBuffer[];

double ST_DownBuffer[];

int atrHandle;

int OnInit()

{

   SetIndexBuffer(0, Filled_a, INDICATOR_DATA);

   SetIndexBuffer(1, Filled_b, INDICATOR_DATA);

   SetIndexBuffer(2, SuperTrend, INDICATOR_DATA);

   SetIndexBuffer(3, ColorBuffer, INDICATOR_COLOR_INDEX);

   SetIndexBuffer(4, Atr, INDICATOR_CALCULATIONS);

   SetIndexBuffer(5, Up, INDICATOR_CALCULATIONS);

   SetIndexBuffer(6, Down, INDICATOR_CALCULATIONS);

   SetIndexBuffer(7, Middle, INDICATOR_CALCULATIONS);

   SetIndexBuffer(8, trend, INDICATOR_CALCULATIONS);

   SetIndexBuffer(9, AboveLineBuffer, INDICATOR_DATA);

   SetIndexBuffer(10, BelowLineBuffer, INDICATOR_DATA);

   atrHandle = iATR(_Symbol, _Period, Periode);

   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_LINE);

   PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_COLOR_LINE);

   IndicatorSetInteger(INDICATOR_DIGITS, _Digits);

   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 (rates_total <= 0)

      return 0;

   ArrayResize(Atr, rates_total);

   ArrayResize(SuperTrend, rates_total);

   ArrayResize(ColorBuffer, rates_total);

   ArrayResize(Up, rates_total);

   ArrayResize(Down, rates_total);

   ArrayResize(Middle, rates_total);

   ArrayResize(trend, rates_total);

   ArrayResize(AboveLineBuffer, rates_total);

   ArrayResize(BelowLineBuffer, rates_total);

   int to_copy = (prev_calculated > rates_total || prev_calculated < 0) ? rates_total : rates_total - prev_calculated;

   if (IsStopped()) return 0;

   if (CopyBuffer(atrHandle, 0, 0, rates_total, Atr) <= 0)

   {

      Print("Getting ATR failed! Error", GetLastError());

      return 0;

   }

   int first = (prev_calculated > rates_total || prev_calculated <= 0) ? Periode : prev_calculated;

   for (int i = first; i < rates_total; i++)

   {

      if (IsStopped()) break;

      if (i < Periode) continue; // Prevent access before enough data

      Middle[i] = (high[i] + low[i]) / 2;

      Up[i]  = Middle[i] + (Multiplier * Atr[i]);

      Down[i] = Middle[i] - (Multiplier * Atr[i]);

      if (i > 0)

      {

         if (close[i] > Up[i - 1])

            trend[i] = 1;

         else if (close[i] < Down[i - 1])

            trend[i] = -1;

         else

            trend[i] = trend[i - 1];

      }

      else

      {

         trend[i] = 1;

      }

      if (trend[i] > 0 && Down[i] < Down[i - 1])

         Down[i] = Down[i - 1];

      if (trend[i] < 0 && Up[i] > Up[i - 1])

         Up[i] = Up[i - 1];

      SuperTrend[i] = (trend[i] > 0) ? Down[i] : Up[i];

      ColorBuffer[i] = (trend[i] > 0) ? 0.0 : 1.0;

      double pointValue = _Point;

      AboveLineBuffer[i] = SuperTrend[i] + (AboveLine * pointValue);

      BelowLineBuffer[i] = SuperTrend[i] - (BelowLine * pointValue);

   }

   ChartRedraw();

   return rates_total;

}


Working Supertrend and Daily Open indicators attached.

Files:
 

Your properties at the top are confused and other properties missing. Buffers for indicator calculations should always come last after plotting buffer types.

try this:

#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots 3

#property indicator_label1  "SuperTrend"
#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1  clrGreen, clrRed
#property indicator_width1  3

#property indicator_label2  "Above line"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrSkyBlue
#property indicator_style2  STYLE_DOT
#property indicator_width2  1

#property indicator_label3  "Below line"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrYellow
#property indicator_style3  STYLE_DOT
#property indicator_width3  1

input int    Periode=10;

input double Multiplier=3;

input int    AboveLine=100;

input int    BelowLine=100;

input bool   Show_Filling=false; // Show as DRAW_FILLING

double Filled_a[];

double Filled_b[];

double SuperTrend[];

double ColorBuffer[];

double Atr[];

double Up[];

double Down[];

double Middle[];

double trend[];

double AboveLineBuffer[];

double BelowLineBuffer[];

double ST_UpBuffer[];

double ST_DownBuffer[];

int atrHandle;

int OnInit()

{
   SetIndexBuffer(0, SuperTrend, INDICATOR_DATA);

   SetIndexBuffer(1, ColorBuffer, INDICATOR_COLOR_INDEX);
   
   SetIndexBuffer(2, AboveLineBuffer, INDICATOR_DATA);

   SetIndexBuffer(3, BelowLineBuffer, INDICATOR_DATA);
   
   SetIndexBuffer(4, Atr, INDICATOR_CALCULATIONS);

   SetIndexBuffer(5, Up, INDICATOR_CALCULATIONS);

   SetIndexBuffer(6, Down, INDICATOR_CALCULATIONS);

   SetIndexBuffer(7, Middle, INDICATOR_CALCULATIONS);

   SetIndexBuffer(8, trend, INDICATOR_CALCULATIONS);

   atrHandle = iATR(_Symbol, _Period, Periode);

   IndicatorSetInteger(INDICATOR_DIGITS, _Digits);

   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 (rates_total <= 0)

      return 0;


   int to_copy = (prev_calculated > rates_total || prev_calculated < 0) ? rates_total : rates_total - prev_calculated + 1;

   if (IsStopped()) return 0;

   if (CopyBuffer(atrHandle, 0, 0, to_copy, Atr) <= 0)

   {

      Print("Getting ATR failed! Error", GetLastError());

      return 0;

   }

   int first = (prev_calculated == 0) ? Periode : prev_calculated - 1;

   for (int i = first; i < rates_total; i++)

   {

      if (IsStopped()) break;

      if (i < Periode) continue; // Prevent access before enough data

      Middle[i] = (high[i] + low[i]) / 2;

      Up[i]  = Middle[i] + (Multiplier * Atr[i]);

      Down[i] = Middle[i] - (Multiplier * Atr[i]);

      if (i > 0)

      {

         if (close[i] > Up[i - 1])

            trend[i] = 1;

         else if (close[i] < Down[i - 1])

            trend[i] = -1;

         else

            trend[i] = trend[i - 1];

      }

      else

      {

         trend[i] = 1;

      }

      if (trend[i] > 0 && Down[i] < Down[i - 1])

         Down[i] = Down[i - 1];

      if (trend[i] < 0 && Up[i] > Up[i - 1])

         Up[i] = Up[i - 1];

      SuperTrend[i] = (trend[i] > 0) ? Down[i] : Up[i];

      ColorBuffer[i] = (trend[i] > 0) ? 0.0 : 1.0;

      double pointValue = _Point;

      AboveLineBuffer[i] = SuperTrend[i] + (AboveLine * pointValue);

      BelowLineBuffer[i] = SuperTrend[i] - (BelowLine * pointValue);

   }

   ChartRedraw();

   return rates_total;

}
 

this accounts for 2 buffers and 1 plot:

SetIndexBuffer(0, SuperTrend, INDICATOR_DATA);
SetIndexBuffer(1, ColorBuffer, INDICATOR_COLOR_INDEX);

this accounts for 1 buffer and 1 plot:

SetIndexBuffer(2, AboveLineBuffer, INDICATOR_DATA);

this accounts for 1 buffer and 1 plot:

SetIndexBuffer(3, BelowLineBuffer, INDICATOR_DATA);

this adds 5 more buffers:

SetIndexBuffer(4, Atr, INDICATOR_CALCULATIONS);

SetIndexBuffer(5, Up, INDICATOR_CALCULATIONS);

SetIndexBuffer(6, Down, INDICATOR_CALCULATIONS);

SetIndexBuffer(7, Middle, INDICATOR_CALCULATIONS);

SetIndexBuffer(8, trend, INDICATOR_CALCULATIONS);

so you have 9 buffers and 3 plots in total