Horizontal Price line On Ichimoku SpanB Flats in all time Frames

 

Hello guys

I used this code to draw a horizontal line where Ichimoku SpanB goes flat :

//--- input parameters of the script
input string          InpName="HLine";     // Line name
input int             InpPrice=25;         // Line price, %
input color           InpColor=clrRed;     // Line color
input ENUM_LINE_STYLE InpStyle=STYLE_SOLID;// Line style
input int             InpWidth=2;          // Line width
input bool            InpBack=false;       // Background line
input bool            InpSelection=false;   // Highlight to move
input bool            InpHidden=true;      // Hidden in the object list
input long            InpZOrder=0;         // Priority for mouse click
//+------------------------------------------------------------------+
//| Create the horizontal line                                       |
//+------------------------------------------------------------------+
bool HLineCreate(const long            chart_ID=0,        // chart's ID
                 const string          name="HLine",      // line name
                 const int             sub_window=0,      // subwindow index
                 double                price=0,           // line price
                 const color           clr=clrRed,        // line color
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
                 const int             width=2,           // line width
                 const bool            back=false,        // in the background
                 const bool            selection=false,   // highlight to move
                 const bool            hidden=true,       // hidden in the object list
                 const long            z_order=0)         // priority for mouse click
  {
//--- if the price is not set, set it at the current Bid price level
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
   ResetLastError();
//--- create a horizontal line
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))
     {
      Print(__FUNCTION__,
            ": failed to create a horizontal line! Error code = ",GetLastError());
      return(false);
     }
//--- set line color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Move horizontal line                                             |
//+------------------------------------------------------------------+
bool HLineMove(const long   chart_ID=0,   // chart's ID
               const string name="HLine", // line name
               double       price=0)      // line price
  {
//--- if the line price is not set, move it to the current Bid price level
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
   ResetLastError();
//--- move a horizontal line
   price = PR;
   if(!ObjectMove(chart_ID,name,0,0,price))
     {
      Print(__FUNCTION__,
            ": failed to move the horizontal line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Delete a horizontal line                                         |
//+------------------------------------------------------------------+
bool HLineDelete(const long   chart_ID=0,   // chart's ID
                 const string name="HLine") // line name
  {
//--- reset the error value
   ResetLastError();
//--- delete a horizontal line

   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete a horizontal line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }

datetime alert[4];
int      sendb,sends;
double   Spread = MarketInfo(_Symbol, MODE_SPREAD);
double   SLB,SLS,TPB,TPS;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   alert[0]= 0;
   alert[1]= 0;
   alert[2]= 0;
   alert[3]= 0;

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {

   double SenkouspanBH126 = iIchimoku(NULL,PERIOD_H1,9,26,52,MODE_SENKOUSPANB,-26);
   double SenkouspanBH125 = iIchimoku(NULL,PERIOD_H1,9,26,52,MODE_SENKOUSPANB,-25);

   if(SenkouspanBH126 == SenkouspanBH125)
     {
      PR = SenkouspanBH126;
     }
   else
     {
      PRN = SenkouspanBH126;
     }
   
//--- check correctness of the input parameters
   if(InpPrice<0 || InpPrice>100)
     {
      Print("Error! Incorrect values of input parameters!");
      return;
     }
//--- price array size
   int accuracy=1000;
//--- array for storing the price values to be used
//--- for setting and changing line anchor point's coordinates
   double price[];
//--- memory allocation
   ArrayResize(price,accuracy);
//--- fill the array of prices
//--- find the highest and lowest values of the chart
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
//--- define a change step of a price and fill the array
   double step=(max_price-min_price)/accuracy;
   for(int i=0; i<accuracy; i++)
      price[i]=min_price+i*step;
//--- define points for drawing the line
   int p=InpPrice*(accuracy-1)/100;
//--- create a horizontal line
   if(!HLineCreate(0,InpName,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
                   InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
//--- redraw the chart and wait for 1 second
   ChartRedraw();
   Sleep(1000);
//--- now, move the line
//--- loop counter
   int v_steps=accuracy/2;
//--- move the line
   for(int i=0; i<v_steps; i++)
     {
      //--- use the following value
      if(p < accuracy-1)
         p+=1;
      //--- move the point
      if(!HLineMove(0,InpName,price[p]))
         return;
      //--- check if the script's operation has been forcefully disabled
      if(IsStopped())
         return;
      //--- redraw the chart
      ChartRedraw();
     }
//--- 1 second of delay
   Sleep(1000);
//--- delete from the chart
      HLineDelete(0,InpName);
      ChartRedraw();
      //--- 1 second of delay
      Sleep(1000);
      //---

I don't know how to make it work in all time frames. I mean I need it to recognize last flats in all time frames and draw the price line that you can see all 9 lines (M1,M5,M15,M30,H1,H4,D1,W1,MN1) on every opened chart. I used :

if(SenkouspanBH126 == SenkouspanBH125)
     {
      PR = SenkouspanBH126;
     }

to determine if the SpanB is flat or not. In backtest and fastest mode, I can see that it works fine but when I change the speed to slower,the line is deleted.

Please someone help me

I am amateur.

Thanks