usmanwalana
usmanwalana

Reputation: 1062

pinescript reference previous bar in Heikin Ashi candles and strategy testing

I am trying to get values of previous bar in a Heikin Ashi chart on 15m time frame. As the script will execute after every 15m. I want to check if previous bar was closed high than its open. If it was I am opening a new entry in strategy. It is working but the long position are not opening as it is supposed to be.

enter image description here

I want the strategy to open trade on candles where its yellow color. I am using the following code

long = close[1] > open[1]
short = close[1] < open[1]

strategy.entry("Long", strategy.long, when = long)
strategy.close("Long", when = short)

Upvotes: 0

Views: 295

Answers (1)

vitruvius
vitruvius

Reputation: 21219

By default, it will open positions on the open of the next candle. If you want to enter a position when a candle is closed, you should use process_orders_on_close=true in your strategy() call.

Upvotes: 1

Related Questions