How to make a indicator that is always drawn to the end of its current Time Frame?

 

Hi everyone! 
I have this standard open indicator and I would like the line to be always drawn to the end of its current Time Frame. How can I do that?


#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color3 RoyalBlue

//----

#property indicator_width3 2

#property indicator_style1 2

#property indicator_style2 2

//----

extern string  TimeFrame="15";

extern int     Shift  =0;

extern int     AjShift=0;

extern string TimeFrames="1,5,15,30;H1(60);H4;D1;W1;MN";

//----

double OpenBuffer[];

int TF;

string error="Wrong TimeFrame!";

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int init()

  {

   string short_name;

//IndicatorBuffers(1);

   SetIndexStyle(2,DRAW_LINE);

   SetIndexBuffer(2,OpenBuffer);

   SetIndexLabel(2,"Open");

   SetIndexDrawBegin(2,0);

//

   short_name="Open_v1("+TimeFrame+")";

   IndicatorShortName(short_name);

//----

   if(TimeFrame=="M1" || TimeFrame=="1") TF=PERIOD_M1;

   else

      if(TimeFrame=="M5" || TimeFrame=="5") TF=PERIOD_M5;

   else

      if(TimeFrame=="M15" || TimeFrame=="15")TF=PERIOD_M15;

   else

      if(TimeFrame=="M30" || TimeFrame=="30")TF=PERIOD_M30;

   else

      if(TimeFrame=="H1" || TimeFrame=="60") TF=PERIOD_H1;

   else

      if(TimeFrame=="H4" || TimeFrame=="240") TF=PERIOD_H4;

   else

      if(TimeFrame=="D1" || TimeFrame=="1440") TF=PERIOD_D1;

   else

      if(TimeFrame=="W1" || TimeFrame=="10080") TF=PERIOD_W1;

   else

      if(TimeFrame=="MN" || TimeFrame=="43200") TF=PERIOD_MN1;

   else

      if(TimeFrame=="0") TF=Period();

   else {Comment(error); TF=Period(); return(0);}

//----

   SetIndexShift(2,AjShift);

//----

   return(0);

  }

//+------------------------------------------------------------------+

int start()

  {

   datetime TimeArray[];

   int i=0,y=0,prevy=0;

   double OpenArray[];

//----

   if(TF<Period())

     {

      //SetIndexDrawBegin(0,Bars);

      //SetIndexDrawBegin(1,Bars);

      Comment("Incorrect TimeFrame");

      return(0);

     }

   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);

   if(counted_bars>0) counted_bars--;

   int limit=Bars-counted_bars;

   if(counted_bars==0) limit-=1+TF/Period();;

//----

   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TF);

   ArrayCopySeries(OpenArray,MODE_OPEN,Symbol(),TF);

//----

   for(i=0,y=0;i<limit;i++)

     {

      prevy=y;

      if(y<ArraySize(TimeArray)) {if(Time[i]<TimeArray[y]) y++;}

      if(y<ArraySize(OpenArray)) OpenBuffer[i]=OpenArray[y];

        }

   return(0);

  }
 

It would look something like this:



 
https://www.mql5.com/en/job
Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • www.mql5.com
good day...i need a custom indicator,this indicator should be able to send out all kinds of alerts the indicator should never repaint the indicator should also have filters such as moving averages ...thank you I have a super simple pine script script that I want to be able to run on MT4 and MT5. Pretty sure I just need it turned into MQL5. ...