0
votes

I'm new to pine script and I need a help with a strategy I'm trying to create without success. The rule is as follows:

Entry - RSI(2) < 50

Exit - OpenCandlePrice > EMA(3) or CloseCandlePrice >= EMA(3)

The entries are not occurring at the closing of the candle and the exits are also not occurring at the opening or closing of the candle. Could someone help me figure out what I'm doing wrong? When I use "process_orders_on_close" the entries occur correctly in the closing of candle, but the exits remain wrong.

CODE

//@version=4
strategy("IFR2", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

//RSI

vrsi = rsi(close, 2)

//Moving Averages

shortema = ema(close,3)

//Strategy

`if (strategy.position_size == 0)`

`if (vrsi<50)`

`strategy.entry(id="EL", long=true, stop=close, comment="Open")`

`else if (strategy.position_size > 0)`

`if (open>shortema)`

`strategy.exit(id="ES", stop=open, comment="Close")`

`if (close>=shortema)`

`strategy.exit(id="ES", stop=close, comment="Close")`

enter image description here

1

1 Answers

0
votes

Try using process_orders_on_close=true in the first line of the strategy function. You can take reference of this link Help needed with strategy - Entry is off by 2 candles. Even if problem not resolved then the possible solution is to make the exact same strategy in study.