CandleCountDown / Period() - TimeFrame M15

Back to topics list To post a new topic, please log in or register
avatar
37
Max-Enrik 2016.04.13 21: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
avatar
13001
WHRoeder 2016.04.13 22:19 #
 
avatar
106
4x_Gypsy 2016.04.14 00: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.
avatar
37
Max-Enrik 2016.04.14 08:20 #
 

Thanks for your replies.

I tried like this.

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

 It does not shows correct Countdown.

Best,

Max 

avatar
37
Max-Enrik 2016.04.14 13: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 

avatar
13001
WHRoeder 2016.04.14 14: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)

avatar
37
Max-Enrik 2016.04.14 15: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. 

avatar
37
Max-Enrik 2016.04.14 16: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] );

 

avatar
Moderator
3418
GumRai 2016.04.14 23: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

avatar
106
4x_Gypsy 2016.04.15 00: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
avatar
37
Max-Enrik 2016.04.17 23:21 #
 

Thanks for all yours replies.

I will try it soon.

 

Best,

Max 

Back to topics list  

To add comments, please log in or register