简体   繁体   中英

PineScript - Strategy.exit not responding

I have some issues with the strategy.exit. It does not work. As shown in the picture below, both exit arguments should have worked!

在此处输入图片说明

RSI Script:

// RSI parameters
var RSI = "RSI"
overBought = input(title="OverBought RSI",group=RSI, defval=75)
overSold = input(title="OverSold RSI",group=RSI, defval=20)
rsi50 = input(50,title="RSI average",group=RSI)
rsi14exit = input(title="RSI 14 OverSold Exit Strategy", group=RSI, defval=70)

// RSI Short/Long
rsiLong = rsi(close,6) <= overSold
rsiShort = rsi(close,6) >= overBought
rsiBelowAverage = rsi(close,6) <= rsi50
rsi14_exit = rsi(close,14) >= rsi14exit

// Calculating
MACD Script:
fast_ma = sma_source == "SMA" ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source == "SMA" ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? sma(macd, signal_length) : ema(macd, signal_length)
hist = macd - signal

// MACD Long/Short
Macd_long = macd >= signal
Macd_short = macd < signal

// Strategy close
strategy.exit("LongA Closed","LongA", loss=longStop, when= Macd_short or rsi14_exit)

You actually want to close a trade, so use strategy.close() instead.

strategy.close(id="LongA", when= Macd_short or rsi14_exit)

You can add your stop loss parameter to your strategy.entry call. It has a stop parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM