Tuesday, June 11, 2024

Tradingview | A complete script to set a trade to set stop loss based on cross point of MA - moving averages

Chinese article is here. Using Google chrome translate English product feature, the article in English CAN easily be translated to English. 

Order tradingview.com here

Monthly $49/ month premium version - Pine script can be easily written and then buy and sell stocks can be processed automatically by script. 


//@version=5strategy("Take profits & stop losses", overlay=true)
// Create Indicator'sshortSMA = ta.sma(close, 10)longSMA = ta.sma(close, 30)rsi = ta.rsi(close, 14)atr = ta.atr(14)
// Specify crossover conditionslongCondition = ta.crossover(shortSMA, longSMA)shortCondition = ta.crossunder(shortSMA, longSMA)
// Execute trade if condition is Trueif (longCondition) stopLoss = low - atr * 2 takeProfit = high + atr * 2 strategy.entry("long", strategy.long, 100, when = rsi > 50) strategy.exit("exit", "long", stop=stopLoss, limit=takeProfit)
if (shortCondition) stopLoss = high + atr * 2 takeProfit = low - atr * 2 strategy.entry("short", strategy.short, 100, when = rsi < 50) strategy.exit("exit", "short", stop=stopLoss, limit=takeProfit)
// Plot Moving Average's to chartplot(shortSMA)plot(longSMA, color=color.black)

No comments:

Post a Comment