Remaining time indicator_

Author: Copyright 2019, qq:20078321
0 Views
0 Downloads
0 Favorites
Remaining time indicator_
ÿþ//+------------------------------------------------------------------+

//|                                                      ProjectName |

//|                                      Copyright 2020, CompanyName |

//|                                       http://www.companyname.net |

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

#property copyright "Copyright 2019, qq:20078321"

#property link      "www.mql5.com"



#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots  2



input color yanse= clrYellow; //

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   return(INIT_SUCCEEDED);

  }

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

//|                                                                  |

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

void OnDeinit(const int reason)

  {

//ObjectsDeleteAll(0);

   ObjectDelete(0,"time");

   Comment("");

  }

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

//| Custom indicator iteration function                              |

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

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[])

  {

   ArraySetAsSeries(close,true);

   ArraySetAsSeries(time,true);



   long m,s;

   m=time[0]+PeriodSeconds(PERIOD_CURRENT)-TimeCurrent();

//i=m/60.0;

   s=m%60;

   m=(m-m%60)/60;



   Comment((string)m + " minutes " + (string)s + " seconds left to bar end");



   if(ObjectFind(0,"time")!=-1)

      ObjectDelete(0,"time");

//---

   if(ObjectFind(0,"time") != 0)

     {

      text("time","        < "+IntegerToString(m)+":"+IntegerToString(s,2,'0'),time[0],close[0],yanse,11);

     }

   else

     {

      ObjectMove(0,"time",0,time[0],close[0]);

     }



   return(rates_total);

  }



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

//|                                                                  |

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

int IndicatorCountedMQL4()

  {

   int prev_calculated=0;

   if(prev_calculated>0)

      return(prev_calculated-1);

   if(prev_calculated==0)

      return(0);

   return(0);

  }



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

//|                                                                  |

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

void text(string name,string text,datetime time,double price,color colo=255,int fontsize=10,int sub_window=0)

  {

   if(ObjectFind(0,name)<0)

     {

      ObjectCreate(0,name,OBJ_TEXT,sub_window,time,price);

     }

   else

     {

      if(ObjectGetInteger(0,name,OBJPROP_TIME)!=time)

        {

         ObjectSetInteger(0,name,OBJPROP_TIME,time);

        }

      if(ObjectGetDouble(0,name,OBJPROP_PRICE)!=price)

        {

         ObjectSetDouble(0,name,OBJPROP_PRICE,price);

        }

     }

   if(ObjectGetInteger(0,name,OBJPROP_FONTSIZE)!=fontsize)

     {

      ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);

     }

   if(ObjectGetInteger(0,name,OBJPROP_COLOR)!=colo)

     {

      ObjectSetInteger(0,name,OBJPROP_COLOR,colo);

     }

   if(ObjectGetString(0,name,OBJPROP_TEXT)!=text)

     {

      ObjectSetString(0,name,OBJPROP_TEXT,text);

     }

  }

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

Comments