嗨,我想要一个修改的松木编辑器脚本的RSI战略指示,我想设置的入口和斯多普洛斯的百分比从入口价格。例如购买进入price=100,那么sl应该是进入价格(100)的-1%,目标应该是入口价格(100)的+5%。类似于短线price=100,那么sl应该是入口价格(100)的+1%,而tagert应该是入口价格(100)的-5%。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yashp1334
//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yashp1334
//@version=4
strategy("RSI Strategy", overlay=false)
length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
rsi = rsi(price, length)
band1 = hline(overSold, "overSold", color=#C0C0C0)
band0 = hline(overBought, "overBought", color=#C0C0C0)
plot(rsi, "RSI", color=color.red)
fill(band1, band0, color=color.black, transp=90, title="Background")
buysignal = crossover(rsi, overSold)
sellsignal = crossunder(rsi, overBought)
//time conditions
//INTRADAY
s=input(title="INTRA DAY TRADE SESSION",type=input.session,defval="0915-1450")
st=time(timeframe.period,s)
e=input(title="END SESSION",type=input.session,defval="1515-1520")
et=time(timeframe.period,e)
symbol=syminfo.ticker
//trading custom quantities
quant=input(title="Trade Quantity",defval=1)
lxse="TYPE: LX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
sxle="TYPE: SX" + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant) + " :TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
le="TYPE:LE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
lx="TYPE:LX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
se="TYPE:SE " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
sx="TYPE:SX " + " :SYMBOL: " + syminfo.ticker + " :QTY: " + tostring(quant)
if (not na(rsi))
if(buysignal and st and strategy.position_size==0)
strategy.entry("BUY",strategy.long,comment=le)
if(sellsignal and st and strategy.position_size==0)
strategy.entry("SELL",strategy.short,comment=se)
if(buysignal and st and strategy.position_size!=0)
strategy.entry("BUY",strategy.long,comment=sxle)
if(sellsignal and st and strategy.position_size!=0)
strategy.entry("SELL",strategy.short,comment=lxse)
//adding stoploss and target option
ut=input(defval=false,title="USE TARGET")
us=input(defval=false,title="USE STOPLOSS")
tar=input(defval=10.0,title="TARGET IN RS")
stop=input(defval=7.0,title="STOP LOSS IN RS")
tar:=tar/syminfo.mintick
stop:=stop/syminfo.mintick
if(ut==true and us==false)
strategy.exit(id="LX",from_entry="BUY",profit=tar,comment=lx)
strategy.exit(id="SX",from_entry="SELL",profit=tar,comment=sx)
if(us==true and ut==false)
strategy.exit(id="LX",from_entry="BUY",loss=stop,comment=lx)
strategy.exit(id="SX",from_entry="SELL",loss=stop,comment=sx)
if(ut==true and us==true)
strategy.exit(id="LX",from_entry="BUY",profit=tar,loss=stop,comment=lx)
strategy.exit(id="SX",from_entry="SELL",profit=tar,loss=stop,comment=sx)
strategy.close(id="BUY",when=et,comment=lx)
strategy.close(id="SELL",when=et,comment=sx)发布于 2022-11-28 13:13:24
你必须记录你的入场价:
var entryprice = 0.0
entryprice := close
strategy.entry("BUY",strategy.long,comment=le, limit= entryprice)然后,对于您的SL (以-1%的价格),您应该使用:
strategy.exit(id="LX",from_entry="BUY", limit = entryprice*0.99 ,comment=lx)https://stackoverflow.com/questions/74596784
复制相似问题