Profile Picture

Trying to restrict trades to specific times or periods during day in strategy.

Posted By xpistos 2 Years Ago

Trying to restrict trades to specific times or periods during day in...

Message
ExclamationMark Posted Thursday May 07 2015
Simple way triggering trades only at specific periods of the day.  I can write code from scratch but I am sure there is simple builtin method.
Almost all my strategies are intraday so this is critical for me.
                                                                                 Thanks
Posted Thursday May 07 2015
Possible solution though not elegant...nor efficient..  Since you have hourInt, minuteInt and ampmStr you can combine into all minutes,  For 24 hour..  1 to 1440 minutes,
Time parameters can be passed  as integers and optimized.

String hourStr= "00";      int hourInt=0;
String minuteStr="00";   int minuteInt=0;
String ampmStr="00";

hourStr=Bars.Current.BarStartTime.ToString("hh");
minuteStr=Bars.Current.BarStartTime.ToString("mm");
ampmStr=Bars.Current.BarStartTime.ToString("tt");

  hourInt= Convert.ToInt32(hourStr);
minuteInt= Convert.ToInt32(minuteStr);

 OutputMessage("New hour string bar: " + hourStr);
OutputMessage("New hour integer bar: " + hourInt);
OutputMessage("New minute string bar: " + minuteStr);
OutputMessage("New minute integer bar: " + minuteInt);
OutputMessage("New AM or PM string bar: " + ampmStr);
Posted Thursday May 14 2015
Here's a simpler way of checking whether the time is within a given range:

TimeSpan timeOfDay = Bars.Current.BarStartTime.TimeOfDay;
if (timeOfDay.TotalHours > 9.5 && timeOfDay.TotalHours < 16)
{
    //Time is between 9:30 am and 4:00 pm
}


Is this what you're looking for?

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems