How can I set up my strategy to only trade at certain times? I set these times in the Condition Builder but no trades happen in the backtesting. I know this must not be right from programming point of view because the strategy produces trades without these time limitations. I must have to separate them out into diff sets 3 and 4 for example but I seem to be having a hard time with it. Can anybody help? Is there an example strategy with time limitation to put on trades I could view? If I was coding this by hand I would nest if statements with the time limitations in the outer if's and the entry signal inside...ie if (time between 8:00 and 10:45) { do this stuff if( ...)} but I am trying out the condition builder to make my life easier and to code faster ( I'm no pro).
Also a second question....I am using the ROC of HMA because I could not figure out how to use the rising and falling methods. Any help on how to set this up in the Condition Builder too would be wonderful.
Many many Thanks in advance.
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(ROC(HMA(21), 1), 0, 1)
&& ToTime(Time[0]) >= ToTime(8, 0, 0)
&& ToTime(Time[0]) <= ToTime(10, 45, 0)
&& ToTime(Time[0]) >= ToTime(12, 45, 0)
&& ToTime(Time[0]) <= ToTime(14, 45, 0))
{
DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + 1 * TickSize, Color.Lime);
EnterLong(DefaultQuantity, "Enter Long at market");
}
// Condition set 2
if (CrossBelow(ROC(HMA(21), 1), 0, 1)
&& ToTime(Time[0]) >= ToTime(8, 0, 0)
&& ToTime(Time[0]) <= ToTime(10, 45, 0)
&& ToTime(Time[0]) >= ToTime(12, 45, 0)
&& ToTime(Time[0]) <= ToTime(14, 45, 0))
{
DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
EnterShort(DefaultQuantity, "Enter Short at market");

Comment