brimos
Pine Script Scholar
Pine Script Scholar
Posts: 4
Joined: March 26th, 2023

Entering trade on same bar as condition check

Good morning. I have a strategy that I am working on for a 5minute chart timeframe and I would like to enter the on the same unconfirmed bar that I am checking conditions on. Not sure if pinescript will allow entering on the same bar as conditions or not

I am trying to do something like this:

Did the low of the current bar drop below the close of the prior candle by 50 cents?
If yes, then did the high of the current bar exceed the high of the prior bar?
If yes to both enter long immediately on same candle.

I am trying to code it

PriceActionFilter=false

if low < close[0]-.5 //Did price of the current unconfirmed bar drop at least 50 cents below the close of the prior bar?
if high > high[0]+.1 //if yes to above, did price of the current unconfirmed bar exceed the high of the prior bar by 20 cents?
PriceActionFilter :=true //if yes to both above conditions, make my price action filter true.

Not sure if I am referencing the low and high of the current bar correctly in the code above and the larger question is can I enter on the same bar assuming the PriceActionFilter is satisfied or true?

Thanks for you help.

Steve Burman
Moderator
Moderator
Posts: 109
Joined: January 13th, 2023

Re: Entering trade on same bar as condition check

Unfortunately, Pine Script does not support placing trades on the current real-time bar in the built-in strategy backtesting environment. The strategy will always execute trades on the next bar's open.

The main reason for this limitation is that the built-in backtesting environment is designed to emulate historical trading situations, and in a historical context, you wouldn't have access to information about the current bar's closing price until the bar has closed.

However, you could setup an alert to alert you to certain conditions being met before the real-time bar has yet to close and then manually enter a trade based on the alert.

Return to “Pine Script Q&A”