我的ESMA基于动力战略的文字如下:除利润和停止损失出境令外,还算好。 我有洞察力,以使其能够/处置,如果能够停止损失,就不收取利润。 我确信,这与评估离职条件的顺序有关,但我根本无法正确执行。 如果有人能够看一看,我会非常赞赏。
请参看以下文字:
//@version=5
strategy("Momentum Wolf v3", overlay=true)
// Input parameters
length = input.int(14, title="Length")
adxSmoothing = input.int(14, title="ADX Smoothing")
threshold = input.float(25, title="Threshold")
stopLossEnabled = input.bool(true, title="Enable Stop Loss")
takeProfitEnabled = input.bool(true, title="Enable Take Profit")
stopLossValue = input.float(50, title="Stop Loss Value", minval=0, step=0.1)
takeProfitValue = input.float(100, title="Take Profit Value", minval=0, step=0.1)
allowedSessionStartHour = input.int(9, title="Allowed Trading Session Start Hour", minval=0, maxval=23)
allowedSessionStartMinute = input.int(30, title="Allowed Trading Session Start Minute", minval=0, maxval=59)
allowedSessionEndHour = input.int(16, title="Allowed Trading Session End Hour", minval=0, maxval=23)
allowedSessionEndMinute = input.int(0, title="Allowed Trading Session End Minute", minval=0, maxval=59)
onlyPositiveDMI = input.bool(true, title="Take Longs only when DMI is Positive")
onlyNegativeDMI = input.bool(true, title="Take Shorts only when DMI is Negative")
// Custom function to check if the current time is within the allowed trading session
isAllowedSession() =>
currentHour = hour(time)
currentMinute = minute(time)
sessionStartHour = allowedSessionStartHour
sessionStartMinute = allowedSessionStartMinute
sessionEndHour = allowedSessionEndHour
sessionEndMinute = allowedSessionEndMinute
// Check if the current time is within the allowed session
(currentHour > sessionStartHour or (currentHour == sessionStartHour and currentMinute >= sessionStartMinute)) and (currentHour < sessionEndHour or (currentHour == sessionEndHour and currentMinute <= sessionEndMinute))
// Custom function to check if the current time is beyond the allowed session end time
isSessionEnded() =>
currentHour = hour(time)
currentMinute = minute(time)
sessionEndHour = allowedSessionEndHour
sessionEndMinute = allowedSessionEndMinute
// Check if the current time is beyond the allowed session end time
currentHour > sessionEndHour or (currentHour == sessionEndHour and currentMinute > sessionEndMinute)
// Calculate moving averages
baseMA = ta.ema(close, 3)
fastMA = ta.ema(close, 20)
mediumMA = ta.ema(close, 100)
slowMA = ta.ema(close, 200)
// Calculate DMI components
[di_plus, di_minus, adx] = ta.dmi(length, adxSmoothing)
// Detect crossover and crossunder
crossover = ta.crossover(di_plus, di_minus)
crossunder = ta.crossunder(di_plus, di_minus)
// Enter long positions
if ta.crossover(baseMA, fastMA) and fastMA > mediumMA and fastMA > slowMA and (onlyPositiveDMI ? di_plus > di_minus : true) and isAllowedSession()
strategy.entry("buy 1", strategy.long)
strategy.close("sell 1")
strategy.close("sell 2")
strategy.close("sell 3")
if ta.crossover(baseMA, mediumMA) and mediumMA > fastMA and mediumMA > slowMA and (onlyPositiveDMI ? di_plus > di_minus : true) and isAllowedSession()
strategy.entry("buy 2", strategy.long)
strategy.close("sell 1")
strategy.close("sell 2")
strategy.close("sell 3")
if ta.crossover(baseMA, slowMA) and slowMA > fastMA and slowMA > mediumMA and (onlyPositiveDMI ? di_plus > di_minus : true) and isAllowedSession()
strategy.entry("buy 3", strategy.long)
strategy.close("sell 1")
strategy.close("sell 2")
strategy.close("sell 3")
// Enter short positions
if ta.crossunder(baseMA, fastMA) and fastMA < mediumMA and fastMA < slowMA and (onlyNegativeDMI ? di_minus > di_plus : true) and isAllowedSession()
strategy.entry("sell 1", strategy.short)
strategy.close("buy 1")
strategy.close("buy 2")
strategy.close("buy 3")
if ta.crossunder(baseMA, mediumMA) and mediumMA < fastMA and mediumMA < slowMA and (onlyNegativeDMI ? di_minus > di_plus : true) and isAllowedSession()
strategy.entry("sell 2", strategy.short)
strategy.close("buy 1")
strategy.close("buy 2")
strategy.close("buy 3")
if ta.crossunder(baseMA, slowMA) and slowMA < fastMA and slowMA < mediumMA and (onlyNegativeDMI ? di_minus > di_plus : true) and isAllowedSession()
strategy.entry("sell 3", strategy.short)
strategy.close("buy 1")
strategy.close("buy 2")
strategy.close("buy 3")
// Exit orders
if ta.crossunder(di_plus, di_minus) or isSessionEnded()
strategy.close("buy 1")
strategy.close("buy 2")
strategy.close("buy 3")
if stopLossEnabled
strategy.exit("sell SL", "sell 1", loss=stopLossValue)
strategy.exit("sell SL", "sell 2", loss=stopLossValue)
strategy.exit("sell SL", "sell 3", loss=stopLossValue)
if takeProfitEnabled
strategy.exit("sell TP", "sell 1", profit=takeProfitValue)
strategy.exit("sell TP", "sell 2", profit=takeProfitValue)
strategy.exit("sell TP", "sell 3", profit=takeProfitValue)
if ta.crossover(di_plus, di_minus) or isSessionEnded()
strategy.close("sell 1")
strategy.close("sell 2")
strategy.close("sell 3")
if stopLossEnabled
strategy.exit("buy SL", "buy 1", loss=stopLossValue)
strategy.exit("buy SL", "buy 2", loss=stopLossValue)
strategy.exit("buy SL", "buy 3", loss=stopLossValue)
if takeProfitEnabled
strategy.exit("buy TP", "buy 1", profit=takeProfitValue)
strategy.exit("buy TP", "buy 2", profit=takeProfitValue)
strategy.exit("buy TP", "buy 3", profit=takeProfitValue)
// Plot moving averages
plot(baseMA, "Base MA", color.white)
plot(fastMA, "Fast MA", color.yellow)
plot(mediumMA, "Medium MA", color.orange)
plot(slowMA, "Slow MA", color.red)
// Plot signals
plotshape(strategy.opentrades != 0 ? crossover : na, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="DMI Crossover")
plotshape(strategy.opentrades != 0 ? crossunder : na, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="DMI Crossunder")
我尝试了各种秩序结构,以确保停机损失和获利后订单都得到评估。 不工作......