"Help me add more levels to this indicator."

 

The indicator below draws 5 horizontal lines (the number of pips between them defined by the user) both below and above the price level at a specific time. Help me add more horizontal lines, which should be user-defined.

#property copyright "Mystic"
#property link      "Mystic"



#property indicator_chart_window
#property indicator_buffers 12
#property indicator_color1 DarkOrchid
#property indicator_color2 DimGray
#property indicator_style1 0
#property indicator_width1 2
#property indicator_color3 DimGray
#property indicator_color4 DimGray
#property indicator_color5 DimGray
#property indicator_color6 DimGray
#property indicator_color7 DimGray
#property indicator_color8 DimGray
#property indicator_color9 DimGray
#property indicator_color10 DimGray
#property indicator_style2 0
#property indicator_width2 0
#property indicator_style3 0
#property indicator_width3 0
#property indicator_style4 0
#property indicator_width4 0
#property indicator_style5 0
#property indicator_width5 0
#property indicator_style6 0
#property indicator_width6 0
#property indicator_style7 0
#property indicator_width7 0
#property indicator_style8 0
#property indicator_width8 0
#property indicator_style9 0
#property indicator_width9 0
#property indicator_style10 0
#property indicator_width10 0

double TodayOpenBuffer[];
double AboveOpenBuffer1[];
double AboveOpenBuffer2[];
double AboveOpenBuffer3[];
double AboveOpenBuffer4[];
double AboveOpenBuffer5[];
double BelowOpenBuffer1[];
double BelowOpenBuffer2[];
double BelowOpenBuffer3[];
double BelowOpenBuffer4[];
double BelowOpenBuffer5[];

extern int Hour_ = 9;
extern int Minutes = 30;
extern int PipsAboveOpen = 10;
extern int NumOfLines = 5;


int init()
{
   if (Hour_ > 23)
   {
      Alert("Please enter a value lower than 24 hours");
      return(0);
   }

   if (Minutes > 59)
   {
      Alert("Please enter a value lower than 60 minutes");
      return (0);
   }

   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, TodayOpenBuffer);
   SetIndexLabel(0, "Open");
   SetIndexEmptyValue(0, 0.0);

   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, AboveOpenBuffer1);
   SetIndexLabel(1, "Above Open 1");
   SetIndexEmptyValue(1, 0.0);

   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, AboveOpenBuffer2);
   SetIndexLabel(2, "Above Open 2");
   SetIndexEmptyValue(2, 0.0);

   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, AboveOpenBuffer3);
   SetIndexLabel(3, "Above Open 3");
   SetIndexEmptyValue(3, 0.0);

   SetIndexStyle(4, DRAW_LINE);
   SetIndexBuffer(4, AboveOpenBuffer4);
   SetIndexLabel(4, "Above Open 4");
   SetIndexEmptyValue(4, 0.0);

   SetIndexStyle(5, DRAW_LINE);
   SetIndexBuffer(5, AboveOpenBuffer5);
   SetIndexLabel(5, "Above Open 5");
   SetIndexEmptyValue(5, 0.0);
   
   SetIndexStyle(6, DRAW_LINE);
   SetIndexBuffer(6, BelowOpenBuffer1);
   SetIndexLabel(6, "Below Open 6");
   SetIndexEmptyValue(6, 0.0);
   
   SetIndexStyle(7, DRAW_LINE);
   SetIndexBuffer(7, BelowOpenBuffer2);
   SetIndexLabel(7, "Below Open 7");
   SetIndexEmptyValue(7, 0.0);
   
   SetIndexStyle(8, DRAW_LINE);
   SetIndexBuffer(8, BelowOpenBuffer3);
   SetIndexLabel(8, "Below Open 8");
   SetIndexEmptyValue(8, 0.0);
   
   SetIndexStyle(9, DRAW_LINE);
   SetIndexBuffer(9, BelowOpenBuffer4);
   SetIndexLabel(9, "Below Open 9");
   SetIndexEmptyValue(9, 0.0);
   
   SetIndexStyle(10, DRAW_LINE);
   SetIndexBuffer(10, BelowOpenBuffer5);
   SetIndexLabel(10, "Below Open 10");
   SetIndexEmptyValue(10, 0.0);

   return (0);
}

int deinit()
{
   return(0);
}

int start()
{
   int lastbar;
   int counted_bars = IndicatorCounted();

   if (counted_bars > 0) counted_bars--;
   lastbar = Bars - counted_bars;
   DailyOpen(0, lastbar);

   return (0);
}

int DailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec = (Hour_ * 3600) + (Minutes * 60);
   double barsper30 = 1.0 * PERIOD_M30 / Period();
   bool ShowDailyOpenLevel = True;

   lastbar = MathMin(Bars - 20 * barsper30 - 1, lastbar);

   for (shift = lastbar; shift >= offset; shift--)
   {
      TodayOpenBuffer[shift] = 0;
      AboveOpenBuffer1[shift] = 0;
      AboveOpenBuffer2[shift] = 0;
      AboveOpenBuffer3[shift] = 0;
      AboveOpenBuffer4[shift] = 0;
      AboveOpenBuffer5[shift] = 0;
      BelowOpenBuffer1[shift] = 0;
      BelowOpenBuffer2[shift] = 0;
      BelowOpenBuffer3[shift] = 0;
      BelowOpenBuffer4[shift] = 0;
      BelowOpenBuffer5[shift] = 0;


      if (ShowDailyOpenLevel)
      {
         if (TimeDay(Time[shift] - tzdiffsec) != TimeDay(Time[shift + 1] - tzdiffsec))
         { // day change
            TodayOpenBuffer[shift] = Open[shift];
            AboveOpenBuffer1[shift] = Open[shift] + PipsAboveOpen * Point;
            AboveOpenBuffer2[shift] = Open[shift] + 2 * PipsAboveOpen * Point;
            AboveOpenBuffer3[shift] = Open[shift] + 3 * PipsAboveOpen * Point;
            AboveOpenBuffer4[shift] = Open[shift] + 4 * PipsAboveOpen * Point;
            AboveOpenBuffer5[shift] = Open[shift] + 5 * PipsAboveOpen * Point;
            BelowOpenBuffer1[shift] = Open[shift] - PipsAboveOpen * Point;
            BelowOpenBuffer2[shift] = Open[shift] - 2 * PipsAboveOpen * Point;
            BelowOpenBuffer3[shift] = Open[shift] - 3 * PipsAboveOpen * Point;
            BelowOpenBuffer4[shift] = Open[shift] - 4 * PipsAboveOpen * Point;
            BelowOpenBuffer5[shift] = Open[shift] - 5 * PipsAboveOpen * Point;

            TodayOpenBuffer[shift + 1] = 0; // avoid stairs in the line
            AboveOpenBuffer1[shift + 1] = 0;
            AboveOpenBuffer2[shift + 1] = 0;
            AboveOpenBuffer3[shift + 1] = 0;
            AboveOpenBuffer4[shift + 1] = 0;
            AboveOpenBuffer5[shift + 1] = 0;
            BelowOpenBuffer1[shift + 1] = 0;
            BelowOpenBuffer2[shift + 1] = 0;
            BelowOpenBuffer3[shift + 1] = 0;
            BelowOpenBuffer4[shift + 1] = 0;
            BelowOpenBuffer5[shift + 1] = 0;
         }
         else
         {
            TodayOpenBuffer[shift] = TodayOpenBuffer[shift + 1];
            AboveOpenBuffer1[shift] = AboveOpenBuffer1[shift + 1];
            AboveOpenBuffer2[shift] = AboveOpenBuffer2[shift + 1];
            AboveOpenBuffer3[shift] = AboveOpenBuffer3[shift + 1];
            AboveOpenBuffer4[shift] = AboveOpenBuffer4[shift + 1];
            AboveOpenBuffer5[shift] = AboveOpenBuffer5[shift + 1];
            BelowOpenBuffer1[shift] = BelowOpenBuffer1[shift + 1];
            BelowOpenBuffer2[shift] = BelowOpenBuffer2[shift + 1]; 
            BelowOpenBuffer3[shift] = BelowOpenBuffer3[shift + 1]; 
            BelowOpenBuffer4[shift] = BelowOpenBuffer4[shift + 1];
            BelowOpenBuffer5[shift] = BelowOpenBuffer5[shift + 1];
         }
      }
   }

   return (0);
}
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
  • Usually people who can't code don't receive free help on this forum.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community. Use the CODE button (Alt-S) when inserting code.
  • To learn MQL programming, you can research the many available Articles on the subject, or examples in the Codebase, as well as reference the online Documentation.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free). However, recommendations or suggestions for Market products are not allowed on the forum, so you will have to do your own research.
  • Finally, you also have the option to hire a programmer in the Freelance section.