Bots PinScript/TradingView:设置最大棱锥(相同方向的多个堆叠条目),但大于1

Bots PinScript/TradingView:设置最大棱锥(相同方向的多个堆叠条目),但大于1,bots,pine-script,algorithmic-trading,trading,Bots,Pine Script,Algorithmic Trading,Trading,我正在写一份研究报告(不是一个策略),在较低的5分钟TF上发出警报,允许同一方向的多个条目(和一次关闭)。理想情况下,收盘前最多3个多头或3个空头,或者继续等待对方进场或收盘。(注意,我不是在寻找一次只能进入/退出1个的代码)。这是我迄今为止所做的与web研究所建议的不同之处,但由于某种原因,它似乎不起作用(在我的图表中,图表显示得非常少)——我认为我已经根据更高的TF数据将其精确定位到security()函数条件。当单独隔离金字塔时,它看起来很好。当隔离安全功能以检查是否传入数据时,它会很好地

我正在写一份研究报告(不是一个策略),在较低的5分钟TF上发出警报,允许同一方向的多个条目(和一次关闭)。理想情况下,收盘前最多3个多头或3个空头,或者继续等待对方进场或收盘。(注意,我不是在寻找一次只能进入/退出1个的代码)。这是我迄今为止所做的与web研究所建议的不同之处,但由于某种原因,它似乎不起作用(在我的图表中,图表显示得非常少)——我认为我已经根据更高的TF数据将其精确定位到security()函数条件。当单独隔离金字塔时,它看起来很好。当隔离安全功能以检查是否传入数据时,它会很好地打印。请让我知道是否有一个替代的最大金字塔逻辑或如何让它与更高的TF数据工作。提前谢谢,谢谢你的帮助

// == ORDER CONDITIONS ==
longCond = security(tickerid,'60',someHFCond1)
shortCond = security(tickerid,'60',someHFCond2)

// Count your long short conditions for more control with Pyramiding

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])

sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if longCond
    sectionLongs := sectionLongs + 1
    sectionShorts := 0

if shortCond
    sectionLongs := 0
    sectionShorts := sectionShorts + 1

// Pyramiding
pyrl = input(3,title="Max Pyramiding (stackable entries, default=3)",minval=1)
longCondition = longCond and sectionLongs <= pyrl 
shortCondition = shortCond and sectionShorts <= pyrl 

// Get the price of the last opened long or short
last_open_longCondition = na
last_open_shortCondition = na
last_open_longCondition := longCondition ? close : nz(last_open_longCondition[1])
last_open_shortCondition := shortCondition ? close : nz(last_open_shortCondition[1])

// Check if your last position was a long or a short
last_longCondition = na
last_shortCondition = na
last_longCondition := longCondition ? time : nz(last_longCondition[1])
last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])

in_longCondition = last_longCondition > last_shortCondition
in_shortCondition = last_shortCondition > last_longCondition

// Take profit
Ltakeprofit = last_open_longCondition * (1+profittarget)
Stakeprofit = last_open_shortCondition * (1-profittarget)
long_tp = high[1] > Ltakeprofit and longCondition == 0 and in_longCondition  == 1 and not longCondition[1]
short_tp = low[1] < Stakeprofit and shortCondition == 0 and in_shortCondition == 1 and not shortCondition[1]

// Create a single close for all the different closing conditions.
long_close = long_tp or long_sl ? 1 : 0
short_close = short_tp or short_sl ? 1 : 0

// Get the time of the last close
last_long_close = na
last_long_close := long_close ? time : nz(last_long_close[1])
last_short_close = na
last_short_close := short_close ? time : nz(last_short_close[1])

// Alerts & Signals
bton(b) => b ? 1 : 0
plotshape(longCondition , title="buy alert", color=green, textcolor=green, transp=0, 
          style=shape.triangleup, location=location.belowbar, size=size.small,text="LONG",offset=0)
plotshape(shortCondition, title="sell alert", color=red, textcolor=red, transp=0, 
          style=shape.triangledown, location=location.abovebar, size=size.small,text="SHORT",offset=0)
plotshape(long_tp and last_longCondition > nz(last_long_close[1]), text ="Close", title="Take Profit Long", style=shape.triangledown, 
   location=location.abovebar, color = green, size=size.tiny, editable = false, transp = 0,offset=0) 
plotshape(short_tp and last_shortCondition > nz(last_short_close[1]) , text ="Cover", title="Take Profit Short", style=shape.triangleup, 
   location=location.belowbar, color = red, size=size.tiny, editable = false, transp = 0,offset=0)
/==订单条件==
longCond=安全性(tickerid,'60',someHFCond1)
shortCond=security(tickerid,'60',someHFCond2)
//计算你的长-短条件,以便更有效地控制金字塔
截面长度=0
sectionLongs:=nz(sectionLongs[1])
截面短路=0
sectionShorts:=nz(sectionShorts[1])
如果长秒
sectionLongs:=sectionLongs+1
分段短路:=0
如果短促
截面长度:=0
分段短路:=分段短路+1
//金字塔形
pyrl=输入(3,title=“最大金字塔化(可堆叠条目,默认值=3)”,最小值=1)
longCondition=longCond和Section Longs last_longCondition
//获利
Ltakeprofit=最后一次打开的时间条件*(1+利润目标)
Stakeprofit=最后一个开放的短期条件*(1-利润目标)
long_tp=high[1]>Ltakeprofit和longCondition==0,in_longCondition==1而非longCondition[1]
short_tp=low[1]<利益相关者和短期条件==0,in_短期条件==1而非短期条件[1]
//为所有不同的关闭条件创建单个关闭。
long\u close=long\u tp还是long\u sl?1 : 0
short\u close=short\u tp或short\u sl?1 : 0
//获取最后一次关闭的时间
最后长时间关闭=不适用
最后关闭:=长关闭?时间:新西兰(最后一次关闭[1])
最后一次\u短\u关闭=不适用
最后一次短合:=短合?时间:新西兰(最后一次短时间结束[1])
//警报和信号
bton(b)=>b?1 : 0
plotshape(longCondition,title=“购买警报”,color=green,textcolor=green,transp=0,
style=shape.triangleup,location=location.belowbar,size=size.small,text=“LONG”,offset=0)
plotshape(快捷条件,title=“销售警报”,颜色=红色,文本颜色=红色,传输=0,
style=shape.triangledown,location=location.overbar,size=size.small,text=“SHORT”,offset=0)
plotshape(long\u tp和last\u longCondition>nz(last\u long\u close[1]),text=“close”,title=“Take Profit long”,style=shape.triangledown,
位置=位置.bar,颜色=绿色,大小=大小.tiny,可编辑=假,传输=0,偏移=0)
plotshape(short\u tp和last\u shortCondition>nz(last\u short\u close[1]),text=“Cover”,title=“Take Profit short”,style=shape.triangleup,
位置=位置.belowbar,颜色=红色,大小=大小.tiny,可编辑=假,传输=0,偏移=0)

这表明您的金字塔控件工作正常:

//@version=4
study("", "", true)
// == ORDER CONDITIONS ==
barUp = close > open
longCond = barUp and barUp[1]
shortCond = not barUp and not barUp[1]

// Count your long short conditions for more control with Pyramiding

sectionLongs = 0
sectionLongs := nz(sectionLongs[1])

sectionShorts = 0
sectionShorts := nz(sectionShorts[1])

if longCond
    sectionLongs := sectionLongs + 1
    sectionShorts := 0
    label.new(bar_index, low - tr, tostring(sectionLongs, "▲\n#"), xloc.bar_index, yloc.price, color.green, label.style_none, color.green, size.large)

if shortCond
    sectionLongs := 0
    sectionShorts := sectionShorts + 1
    label.new(bar_index, na, tostring(sectionShorts, "#\n▼"), xloc.bar_index, yloc.abovebar, color.maroon, label.style_none, color.maroon, size.large)

// Pyramiding
pyrl = input(3,title="Max Pyramiding (stackable entries, default=3)",minval=1)
longCondition = longCond and sectionLongs <= pyrl 
shortCondition = shortCond and sectionShorts <= pyrl 

bgcolor(longCondition ? color.lime : shortCondition ? color.red : na)
plotchar(sectionLongs, "sectionLongs", "", location.top)
plotchar(sectionShorts, "sectionShorts", "", location.top)
/@version=4
研究(“,”,真)
//==订单条件==
barUp=关闭>打开
longCond=barUp和barUp[1]
shortCond=不加增音和不加增音[1]
//计算你的长-短条件,以便更有效地控制金字塔
截面长度=0
sectionLongs:=nz(sectionLongs[1])
截面短路=0
sectionShorts:=nz(sectionShorts[1])
如果长秒
sectionLongs:=sectionLongs+1
分段短路:=0
标签。新的(条形图索引,低tr,tostring(截面长度,)▲\n#“)、xloc.bar_索引、yloc.price、color.green、label.style_无、color.green、size.large)
如果短促
截面长度:=0
分段短路:=分段短路+1
标签。新建(条形索引、na、tostring(截面短?)\n▼"), xloc.bar\u索引,yloc.overbar,color.maroon,label.style\u无,color.maroon,size.large)
//金字塔形
pyrl=输入(3,title=“最大金字塔化(可堆叠条目,默认值=3)”,最小值=1)

longCondition=longCond和sectionLongs注意:这与“security()”函数一起工作,以确保只有在更高的时间段指示器有效时才会发生长短条件。当删除更高的TF检查时,我认为金字塔是有效的。但是当删除金字塔盖时(上面的代码)让它有无限的堆叠,安全()更高的tf检查有效。所以我被卡住了。谢谢你的时间!是的,我隔离了金字塔,它工作得很好。我还隔离了更高tf数据的安全计时器,它工作得很好。但是一旦组合起来,它就不工作了。具体地说,只有当macd保持正值(50ema>200ema)时,安全条件才会很长在1h TF上,仅当macd保持为负值(50ema<200ema)时短在1h TF上。一旦安全性和金字塔元素结合在一起,绘图就无法按预期工作。有什么想法吗?在回答之前没有看到您的评论。至于更高TF的东西,没有编译的代码是很难帮助的。如果您不想或太复杂,无法在这里共享代码,请使用与pl相同的技术ot标记,它将允许您验证基本条件,然后,如果您与它们一起构建的复合条件与它们的状态相对应。