Pinescript Code Modification
Budget: $10 – $30 AUD
I need an expert in PineScript to modify code for a strategy, so that the Recalculate "After Order is Filled" parameter works correctly.
This example strategy will indicate what I am trying to achieve:
- Whilst 20 EMA > 50 EMA, continually enter Long Positions on each candle, with 2% Take Profit Target, and 4% Stop Loss Target
- If the Take Profit or Stop Loss is hit on the SAME CANDLE that the Long Position was entered, then the position must exit on that candle where it was hit. This is why the Recalculate "After Order is Filled" parameter is crucial for this strategy
I've found that if you simply just turn on the "After Order is Filled" parameter, TradingView behaves strangely and creates entry orders at the highs and lows of the candles (see screenshot 1 and the associated code attached).
I've tried modifying this to restrict long entries, however as you will see this only works for every second candle (see screenshot 2 and the associated code attached)
To reclarify exactly what I need, is for every candle where the long condition is met (ema 20 > ema 50), it must enter a long position, and set the TP / SL. If those targets are hit on the same candle where the position was entered, then the position must exit on that candle where those targets were hit
This example strategy will indicate what I am trying to achieve:
- Whilst 20 EMA > 50 EMA, continually enter Long Positions on each candle, with 2% Take Profit Target, and 4% Stop Loss Target
- If the Take Profit or Stop Loss is hit on the SAME CANDLE that the Long Position was entered, then the position must exit on that candle where it was hit. This is why the Recalculate "After Order is Filled" parameter is crucial for this strategy
I've found that if you simply just turn on the "After Order is Filled" parameter, TradingView behaves strangely and creates entry orders at the highs and lows of the candles (see screenshot 1 and the associated code attached).
I've tried modifying this to restrict long entries, however as you will see this only works for every second candle (see screenshot 2 and the associated code attached)
To reclarify exactly what I need, is for every candle where the long condition is met (ema 20 > ema 50), it must enter a long position, and set the TP / SL. If those targets are hit on the same candle where the position was entered, then the position must exit on that candle where those targets were hit