Este guión de Pine se muestra normalmente en la televisión y puede tener operaciones abiertas, también hay resultados de retrospección, no hay respuesta, no hay informes de errores, pero tampoco hay transacciones.
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SpeculatioEMA + ADX Strategy with Partial Take Profit$0nLab
//@version=5
strategy("分仓止盈 ADX+Vegas", pyramiding=5)
//--------------------------------------------------5EMA settings----------------------------------------------------
//设置用户设定(set user input)
group1 = "EMA1"
group2 = "EMA2"
group3 = "EMA3"
group4 = "EMA4"
group5 = "EMA5"
enableEMA1 = input.bool(false, "Disable EMA1", tooltip="禁用此条EMA", group=group1)
enableEMA2 = input.bool(false, "Disable EMA2", tooltip="禁用此条EMA", group=group2)
enableEMA3 = input.bool(false, "Disable EMA3", tooltip="禁用此条EMA", group=group3)
enableEMA4 = input.bool(false, "Disable EMA4", tooltip="禁用此条EMA", group=group4)
enableEMA5 = input.bool(false, "Disable EMA5", tooltip="禁用此条EMA", group=group5)
Length1 = input.int(12, "EMA Length 1", tooltip="请输入恰当的EMA长度", group=group1)
Length2 = input.int(144, "EMA Length 2", tooltip="请输入恰当的EMA长度", group=group2)
Length3 = input.int(169, "EMA Length 3", tooltip="请输入恰当的EMA长度", group=group3)
Length4 = input.int(576, "EMA Length 4", tooltip="请输入恰当的EMA长度", group=group4)
Length5 = input.int(676, "EMA Length 5", tooltip="请输入恰当的EMA长度", group=group5)
//计算ema值(get ema values)
emaValue1 = ta.ema(close, Length1)
if enableEMA1
emaValue1 := na
emaValue2 = ta.ema(close, Length2)
if enableEMA2
emaValue2 := na
emaValue3 = ta.ema(close, Length3)
if enableEMA3
emaValue3 := na
emaValue4 = ta.ema(close, Length4)
if enableEMA4
emaValue4 := na
emaValue5 = ta.ema(close, Length5)
if enableEMA5
emaValue5 := na
//绘出(draw onto the chart)
plot(emaValue1, "EMA1", color=color.yellow, force_overlay=true)
plot(emaValue2, "EMA2", color=color.white, force_overlay=true)
plot(emaValue3, "EMA3", color=color.white, force_overlay=true)
plot(emaValue4, "EMA4", color=#fb406c, force_overlay=true)
plot(emaValue5, "EMA5", color=#fb406c, force_overlay=true)
//-----------------------------------------------------------adx settings----------------------------------------------------
len = input(14, "Length")
th = input(30, "Threshold")
TrueRange = math.max(math.max(high - low, math.abs(high - nz(close[1]))), math.abs(low - nz(close[1])))
high_change = ta.change(high)
low_change = ta.change(low)
DirectionalMovementPlus = high_change > low_change ? math.max(high_change, 0) : 0
DirectionalMovementMinus = low_change > high_change ? math.max(-low_change, 0) : 0
var SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - (nz(SmoothedTrueRange[1]) / len) + TrueRange
var SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - (nz(SmoothedDirectionalMovementPlus[1]) / len) + DirectionalMovementPlus
var SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - (nz(SmoothedDirectionalMovementMinus[1]) / len) + DirectionalMovementMinus
DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = math.abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX = ta.sma(DX, len)
plot(ADX, color=color.aqua, title="ADX")
hline(th, "Threshold", color=color.white)
//----------------------------------------------------------STRATEGY settings---------------------------------------------------------
//vegas过滤器
vegasLong = math.min(emaValue2, emaValue3) > math.max(emaValue4, emaValue5)
vegasShort = math.max(emaValue2, emaValue3) < math.min(emaValue4, emaValue5)
//蜡烛过滤器
lowDis = math.abs(low - math.max(emaValue2, emaValue3))
highDis = math.abs(math.min(emaValue2, emaValue3) - high)
baseDis = math.abs(emaValue2 - emaValue3)
longCandle = lowDis <= baseDis
shortCandle = highDis <= baseDis
//设置储存变量
var float t_target1 = na
var float t_target3 = na
var float t_stop = na
var longTrade = 0
var shortTrade = 0
//设置买入卖出信号
longSignal = vegasLong and longCandle and longTrade <= 1 and not longCandle[1] and ADX > th
shortSignal = vegasShort and shortCandle and shortTrade <= 1 and not shortCandle[1] and ADX > th
//设置止损点位
rr1 = input.float(1, "Risk Reward 1", tooltip="改变风险回报比 1")
rr2 = input.float(2, "Risk Reward 2", tooltip="改变风险回报比 2")
longStop = ta.lowest(low, 30)
shortStop = ta.highest(high, 30)
longDistance = close - longStop
shortDistance = shortStop - close
longTarget1 = close + (longDistance * rr1)
longTarget3 = close + (longDistance * rr2)
shortTarget1 = close - (shortDistance * rr1)
shortTarget3 = close - (shortDistance * rr2)
//设置入场条件
rpt = input.float(1, "Risk Per Trade%", tooltip="设定单笔交易风险(%)")
if longSignal and barstate.isconfirmed
t_stop := longStop
t_target1 := longTarget1
t_target3 := longTarget3
longTrade += 1
shortTrade := 0
positionSize = math.floor((strategy.equity * (rpt / 100)) / (close - t_stop))
strategy.entry(id="Long", direction=strategy.long, qty=positionSize)
if shortSignal and barstate.isconfirmed
t_stop := shortStop
t_target1 := shortTarget1
t_target3 := shortTarget3
longTrade := 0
shortTrade += 1
positionSize = math.floor((strategy.equity * (rpt / 100)) / (t_stop - close))
strategy.entry(id="Short", direction=strategy.short, qty=positionSize)
//设置出场条件
if strategy.position_size > 0
strategy.exit("Long Exit 1", "Long", limit=t_target1, stop=t_stop, qty_percent=50)
strategy.exit("Long Exit 3", "Long", limit=t_target3, stop=t_stop)
if strategy.position_size < 0
strategy.exit("Short Exit 1", "Short", limit=t_target1, stop=t_stop, qty_percent=50)
strategy.exit("Short Exit 3", "Short", limit=t_target3, stop=t_stop)
plotshape(longSignal, "Long Signal", shape.triangleup, location.abovebar, color.green, force_overlay=true)
plotshape(shortSignal, "Short Signal", shape.triangleup, location.abovebar, color.red, force_overlay=true)
plot(strategy.position_size != 0 ? t_stop : na, style=plot.style_linebr, force_overlay=true, color=color.red)
plot(strategy.position_size != 0 ? t_target1 : na, style=plot.style_linebr, force_overlay=true, color=color.green)
plot(strategy.position_size != 0 ? t_target3 : na, style=plot.style_linebr, force_overlay=true, color=color.blue)
Los inventores cuantifican - sueños pequeñosHola, ¿puedes enviar el código de nuevo y pegarlo en el formato: ¿Por qué no lo haces? El código ¿Por qué no lo haces? No se preocupe por los símbolos No es un símbolo. De lo contrario, el código no está formateado y no puede ser probado.