[英]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.