简体   繁体   English

在许多条柱满足条件后如何编写买入或卖出触发器,在我的情况下是高于某个 EMA 的 2 个 renko 柱

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

I am new to pinescript on TradingView and have everything working on a renko based strategy, however I would like to know how I create a buy signal on the second bar that meets my condition.我是 TradingView 上 pinescript 的新手,并且一切都在基于 renko 的策略上工作,但是我想知道如何在满足我条件的第二个柱上创建买入信号。 My code snippet is below and it will print the "buy" signal on every bar above the EMA where the open is above it.我的代码片段在下面,它将在 EMA 上方的每个柱上打印“买入”信号,其中开盘价在其上方。

My issue is I want only one "buy" printed and not quite sure how to count the conditions being true so that the "buy" is painted only once.我的问题是我只想打印一个“购买”,并且不太确定如何计算条件为真,以便“购买”只绘制一次。 I'm struggling to work out how to do this ie saving values via an array counter or something similar.我正在努力解决如何做到这一点,即通过数组计数器或类似的东西保存值。

My other question is can I control the changing of the printing of price styles as renko in pinescript versus candles ie when I choose my strategy for use ideally I don't want to click on price style etc.我的另一个问题是,我可以控制价格样式的打印变化,如 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")

Here's an example这是一个例子

//@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)

The barssince function counts a number of bars since a condition was true.由于条件为真,barssince 函数计算柱数。 barssince(condition) → series[integer] barsince(condition) → series[整数]

https://www.tradingview.com/pine-script-reference/v4/#fun_barssince https://www.tradingview.com/pine-script-reference/v4/#fun_barssince

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM