[英]how to write a buy or sell trigger after a number of bars meet condition which in my case is 2 renko bars above a certain EMA
我是 TradingView 上 pinescript 的新手,并且一切都在基于 renko 的策略上工作,但是我想知道如何在满足我条件的第二个柱上创建买入信号。 我的代码片段在下面,它将在 EMA 上方的每个柱上打印“买入”信号,其中开盘价在其上方。
我的问题是我只想打印一个“购买”,并且不太确定如何计算条件为真,以便“购买”只绘制一次。 我正在努力解决如何做到这一点,即通过数组计数器或类似的东西保存值。
我的另一个问题是,我可以控制价格样式的打印变化,如 pinescript 与蜡烛中的 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")
这是一个例子
//@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)
由于条件为真,barssince 函数计算柱数。 barsince(condition) → series[整数]
https://www.tradingview.com/pine-script-reference/v4/#fun_barssince
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.