如果有人问了这个问题,我很抱歉(如果是的话,请引导我找到答案)我已经搜索并试图解决这个问题近两个星期了,但没有任何运气!
我正在制定一个策略,我需要我的策略在tp1和tp2分别收盘50%和50%,万一满足退出条件,它就会结束整个交易
我尝试了许多变体,但我得到了以下问题之一:
1-它会在图表上没有通知我的情况下命中红灯(有箭头警报的事情)
2-它会完全忽略止损3-它只会部分关闭一些止损
请帮助我,因为我已经尝试了我能找到的一切和我能想到的一切!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Strategy Entry//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Limit10 = input(false,title= " ? Stop Loss and Take Profit ? ")
atrLength = input(14, "Strategy ATR Length")
slMultiplier = input(4.0, "Strategy SL")
tpMultiplier = input(1.0, "Strategy TP1")
tpMultiplier2 = input(1.5, "Strategy TP2")
tpMultiplier3 = input(1.8, "Strategy TP3")
atr = atr(atrLength)
sls = (price + atr * slMultiplier)
tps = (price - atr * tpMultiplier)
sll = (price - atr * slMultiplier)
tpl = (price + atr * tpMultiplier)
// EWO Strategy
EWOenterLong = smadif > 0.01
EWOenterShort = smadif < -0.01
// Baseline Strategy
BaselineLong = close > sma(sma(src, ceil(len / 2)), floor(len / 2) + 1)
BaselineShort = sma(sma(src, ceil(len / 2)), floor(len / 2) + 1) > close
LongMA = out < close
ShortMA = out > close
// WAE Strategy
WAELong = (t1 >= 0) ? t1 : 0
WAEShort = (t1 < 0) ? (-1*t1) : 0
// Alert Entry
AlertLong = long
AlertShort = short
//KVO Exit
KVOExitLong = kvo(lenFast, lenSlow) < ShortZone
KVOExitShort = kvo(lenFast, lenSlow) > LongZone
//RVI Entry Exit
RVIBullish = current_rvi > highest(nz(current_rvi[1]), period)
RVIBeaerish = current_rvi < lowest(nz(current_rvi[1]), period)
//////////////
//Entries
enterLong = AlertLong and BaselineLong and WAELong and EWOenterLong and LongMA
enterShort = AlertShort and BaselineShort and WAEShort and EWOenterShort and ShortMA
//Exits
LongSL = price - atr * slMultiplier
ShortSL = price + atr * slMultiplier
///
if (enterLong)
sl1 = price - atr * slMultiplier
tp1 = price + atr * tpMultiplier
tp2 = price + atr * tpMultiplier2
tp3 = price + atr * tpMultiplier3
LongSL = price - atr * slMultiplier
exitLong = RVIBeaerish or KVOExitLong or LongSL? 1 : 0
strategy.entry("Long", strategy.long)
strategy.exit("Long TP1 -50%", "Long", qty_percent = 50 , limit = tp1, stop = LongSL)
strategy.exit("Long TP2 -25%", "Long", qty_percent = 25 , limit = tp2, stop = LongSL)
strategy.exit("Short TP3 -100% or SL Hit", "Short", qty_percent = 100 , limit = tp3, stop = ShortSL)
strategy.exit("Exit Long Now", "Long", qty_percent = 100 , limit = tp3 , stop = LongSL)
if (enterShort)
sl1 = price + atr * slMultiplier
tp1 = price - atr * tpMultiplier
tp2 = price - atr * tpMultiplier2
tp3 = price - atr * tpMultiplier3
ShortSL = price + atr * slMultiplier
exitShort = RVIBullish or KVOExitShort or ShortSL? 0 : 1
strategy.entry("Short", strategy.short)
strategy.exit("Short TP1 -50%", "Short", qty_percent = 50 , limit = tp1, stop = ShortSL)
strategy.exit("Short TP2 -25%", "Short", qty_percent = 25 , limit = tp2, stop = ShortSL)
strategy.exit("Short TP3 -100% or SL Hit", "Short", qty_percent = 100 , limit = tp3, stop = ShortSL)
strategy.exit("Exit Short Now", "Short", qty_percent = 100 , stop = ShortSL)提前感谢,如果我上面写的不清楚,请随时提出问题
发布于 2020-12-30 07:44:56
您的代码示例缺少组件且不可编译,因此请猜测一下。
我会将exitLong变量更改为boolean类型,而不是integer。
exitLong = RVIBeaerish or KVOExitLong or LongSL? true : false您在本地作用域中初始化tp*变量,这可能会导致问题。在全局作用域中初始化它们,并在局部作用域中重新分配(:=)值。
var float tp1 = na
var float tp2 = na
var float tp3 = na
if (enterShort)
tp1 := price - atr * tpMultiplier
tp2 := price - atr * tpMultiplier2
tp3 := price - atr * tpMultiplier3ShortSL变量声明了两次-在全局作用域中和在if (enterShort)语句中。这将产生编译错误。
https://stackoverflow.com/questions/65498208
复制相似问题