我是TradingView上的pinescript的新手,并且所有工作都在基于renko的策略上进行,但是我想知道如何在满足我条件的第二根柱上创建买入信号。我的代码段位于下方,它将在EMA上方的空位上方的每个小节上打印“买入”信号。
我的问题是我只希望打印一个“购买”,并且不太确定如何计算真实条件,因此“购买”仅绘制一次。我正在努力找出方法,例如通过数组计数器或类似方法保存值。
我的另一个问题是,我可以控制价格样式的印刷变化吗,如松木和蜡烛中的renko,即当我选择理想的使用策略时,我不想单击价格样式等。
// Plot Buy and Sell Signals
renko_buy = renko_low > emaFast
renko_sell = renko_high < emaFast
// only want to plot this shape if meet this condition twice i.e. after
// second bar only that meets this condition of being above the EMA
plotshape(renko_buy, color=lime, style=shape.arrowup, text="Buy")
// only want tom plot this shape if meet this conditention twice i.e.
// after second bar only that meets this condition of being under the EMA
plotshape(renko_sell, color=red, style=shape.arrowdown, text="Sell")
答案 0 :(得分:0)
这是一个例子
//@version=3
study("Buy on second trigger")
myCondition = close > open
conditionMetTimes = 0
conditionMetTimes := nz(conditionMetTimes[1])
if myCondition
conditionMetTimes := conditionMetTimes + 1
BUY = 0
if myCondition and conditionMetTimes >= 2
conditionMetTimes := 0
BUY := 1
plot(BUY)
答案 1 :(得分:0)
由于条件为真,barssince函数计算条数。 barsince(条件)→系列[整数]
https://www.tradingview.com/pine-script-reference/v4/#fun_barssince