Just playing around, learning how to write strategies. The one I'm trying right now is (pseudo-code)...
if(previousCandle == red
... AND previousCandle.high >= sma
... AND previousCandle.low <= sma
... AND currentPrice > previousCandle.high)
enter trade
What I have in Pine Script is...
redTouch = close < open and high >= ma and low <= ma
longCond = redTouch[1] and close > high[1]
strategy.entry("Long", strategy.long, when = longCond)
The redTouch candles are all identified correctly (checked previously using BG colors), but for the longCond I don't want close > high[1], because that enters the trade only on the next candle (and too late).
The following screenshot shows where the trade is currently being entered (blue line on red candle), and where I'd like it to trigger/enter (yellow line on green candle).

How do I change close > high[1] to price > high[1] or a similar intra-candle crossover trigger? Or can you only enter trades in the next candle in Pine Script?
You'll need to do a few things to get the behavior you're looking for.
process_orders_on_close=true to your strategy declaration statement to get the Strategy tester to process on the bar that triggers the condition instead of the next bar's open.high[1]+somenumberlimit=YourEntryPriceVariable to your strategy.entry statementThis will create a limit order to enter at the price you specify on the bar that it happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With