Download MetaTrader 5
To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
Max Enrik
474
Max Enrik 2016.04.13 19:47 
Hello,

I would like to write some code for Indicator "Candle CountDown" but I need some help.
I know Period() - Returns timeframe of the current chart.
But I would like to use "Period()" like "PERIOD_M15" in the M1 TimeFrame Chart.

CandleCountDown = ( Period() * 60 ) - ( TimeCurrent() - Time[0] );


Best,
Max
whroeder1
13596
whroeder1 2016.04.13 20:19  
Donald Gibson
482
Donald Gibson 2016.04.13 22:54  
Max-Enrik:
Hello,

I would like to write some code for Indicator "Candle CountDown" but I need some help.
I know Period() - Returns timeframe of the current chart.
But I would like to use "Period()" like "PERIOD_M15" in the M1 TimeFrame Chart.



Best,
Max
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  //EventSetTimer(1); <---Place in OnInt
//Clock
   int thisbarminutes=Period();
   double thisbarseconds=thisbarminutes*60;
   double seconds=thisbarseconds -(TimeCurrent()-Time[0]); // seconds left in bar 

   double minutes= MathFloor(seconds/60);
   double hours  = MathFloor(seconds/3600);

   minutes = minutes -  hours*60;
   seconds = seconds - minutes*60 - hours*3600;


   string sText=DoubleToStr(seconds,0);
   if(StringLen(sText)<2) sText="0"+sText;
   string mText=DoubleToStr(minutes,0);
   if(StringLen(mText)<2) mText="0"+mText;
   string hText=DoubleToStr(hours,0);
   if(StringLen(hText)<2) hText="0"+hText;

   ObjectCreate("Time_Remaining",OBJ_LABEL,0,0,0);
   if(Period()<240) ObjectSetText("Time_Remaining","Time Remaining = "+mText+":"+sText,8,"Ariel",clrDarkGray);
   else ObjectSetText("Time_Remaining","Time Remaining = "+hText+":"+mText+":"+sText,8,"Ariel",clrDarkGray);
   ObjectSet("Time_Remaining",OBJPROP_CORNER,1);
   ObjectSet("Time_Remaining",OBJPROP_XDISTANCE,0);
   ObjectSet("Time_Remaining",OBJPROP_YDISTANCE,70);
   ObjectSet("Time_Remaining",OBJPROP_BACK,False);
  }
This is what I use.
Max Enrik
474
Max Enrik 2016.04.14 06:20  

Thanks for your replies.

I tried like this.

CandleCountDown = ( PERIOD_M15 * 60 ) - ( TimeCurrent() - Time[0] );

 It does not shows correct Countdown.

Best,

Max 

Max Enrik
474
Max Enrik 2016.04.14 11:31  
4x_Gypsy:
This is what I use.

Where may I download that indicator what you use?

Because I tried I cannot make right code what I want.

 

Best,

Max 

whroeder1
13596
whroeder1 2016.04.14 12:51  

Max-Enrik:

I tried like this.

It does not shows correct Countdown.

Of course it doesn't and I told you how to correct it. (#2)
Max Enrik
474
Max Enrik 2016.04.14 13:01  
WHRoeder:

Max-Enrik:

I tried like this.

It does not shows correct Countdown.

Of course it doesn't and I told you how to correct it. (#2)

Thanks once again @WHRoeder

 

There is only problem with my English.

I will try it I hope I can do that. 

Max Enrik
474
Max Enrik 2016.04.14 14:27  

I tried like below but it does not show anything also I have not any error message.

I do not know what is wrong at the there. 

datetime CandleCountDown = iTime ( Symbol(), PERIOD_M15, 0);
CandleCountDown = ( PERIOD_M15 * 60 ) - ( TimeCurrent() - Time[0] );
Keith Watford
Moderator
7887
Keith Watford 2016.04.14 21:50  
Max-Enrik:

I tried like below but it does not show anything also I have not any error message.

I do not know what is wrong at the there. 

datetime CandleCountDown = iTime ( Symbol(), PERIOD_M15, 0);
CandleCountDown = ( PERIOD_M15 * 60 ) - ( TimeCurrent() - Time[0] );

 

What do you expect it to do?

You set a value for CandleCountDown, do nothing with that value and then immediately  assign another value to the variable

datetime CandleCountDown = iTime ( Symbol(), PERIOD_M15, 0);

gives you the time that the candle opened, you need the time that the candle will close

so add PERIOD_M15*60 to get candle close time

candle close time - TimeCurrent() is the number of seconds remaining until the M15 candle closes

Donald Gibson
482
Donald Gibson 2016.04.14 22:55  
Max-Enrik:

Where may I download that indicator what you use?

Because I tried I cannot make right code what I want.

 

Best,

Max 

The code is a function that i have added to several of my indicators.

I use it on at least 10 different indicators and it works flawlessly.  

copy n paste into  OnInit()

  //EventSetTimer(1); <---Place in OnInt
Max Enrik
474
Max Enrik 2016.04.17 21:21  

Thanks for all yours replies.

I will try it soon.

 

Best,

Max 

/ /12
To add comments, please log in or register