Restrict strategy entry to third bar after market open


Category:
0
0

Good Evening,

I have spent countless hours looking for how to set time parameters for my strategy and I just cannot seem to locate what I need.  I want my strategy to only look at candles starting with the open of the trading day.  As of now my strategy will look at candles from the end of the previous day as a continuation, which I do not want.  Its really a 3 candle strategy and I only want the first 3 -30min candles of the day to be evaluated in the strategy..

Thanks so much

DB

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on March 9, 2020 2:46 pm
80 views
0
Private answer

Can't do anything without your code.

Edit: Now that the author of the post has provided their code we can provide a solution. The original title of the question has also been updated to more accurately reflect the context of the question. "Time Parameters" did not explain things in sufficient detail.

Not only was that title not sufficient, it really did not explain the goal. Using time to control the signals on a chart strategy adds a degree of complexity that should be avoided unless absolutely required. And in this case it is certainly not required. We can do this much more simply without having to reference a specific time.

Here is your code, with a few lines added to ensure the entry signal will only be triggered on the third bar after the market opens. The exit is left as is, so I can be triggered on any bar after the entry signal:

input tradeSize = 100;
def newDay = GetDay() <> GetDay()[1];
def filterSignal = newDay[2];
def signal = open is greater than high from 2 bars ago and open is greater than high from 1 bars ago;
AddOrder(OrderType.BUY_TO_OPEN, filterSignal and signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
def exit = close is less than low from 2 bars ago or close crosses below Ichimoku()."Span A";
AddOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);

Final note. This solution requires that the chart be set to NOT display extended hours session. The variable named "filterSignal" is constructed so that it is true only on the third bar after the market opens.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 9, 2020 4:37 pm
0
input tradeSize = 100; def signal = open is greater than high from 2 bars ago and open is greater than high from 1 bars ago; addOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN); def exit = close is less than low from 2 bars ago or close crosses below Ichimoku()."Span A"; addOrder(OrderType.SELL_TO_CLOSE, exit,open[-1], tradesize, Color.MAGENTA, Color.MAGENTA);
( at March 9, 2020 5:44 pm)
0
I have updated my answer to include the solution you requested.
( at March 9, 2020 6:50 pm)