我希望在5分钟的时间范围内一天的第一根和第二根蜡烛的OHLC数据。也就是说,第一个5分钟蜡烛的OHLC和第二个5分钟蜡烛的OHLC。我尝试了以下方法。
is_newbar(res) =>
t = time(res)
change(t) != 0 ? 1 : 0
is_newbar1(res) =>
t = time(res)
change(t[1]) != 0 ? 1 : 0
newbar = is_newbar("D")
newbar1 = is_newbar1("D")
var float s1 = na
var float s2 = na
var float s3 = na
var float s4 = na
if newbar
s1 := low
s2 := high
s3 := close
s4 := open
var float s11 = na
var float s12 = na
var float s13 = na
var float s14 = na
if newbar1
s11 := low
s12 := high
s13 := close
s14 := open
获得这些值后,我将为范围突破编码,例如s13> s3然后执行一些操作。问题在于,它不仅实时获取两个蜡烛值中的第一个,而且考虑每个蜡烛OHLC并尝试每次都匹配if条件。我希望它执行一次并显示结果。请帮帮我。
答案 0 :(得分:0)
@Prasanna Kumar S R,您好,
不要使用if和将值保存到变量中,而是尝试使用“ valuewhen”。 我一直在制定一项策略,在此策略中我必须将第一个手柄保存得很高。我用下面的代码 当我绘制“ d”的常数直到一天结束时,'''d = valuewhen((is_first),high,0)'''。
答案 1 :(得分:0)
这是我通常在特定时间用于买卖的内容。我使用此脚本回测了BTST策略。由于您想在特定时间触发购买/出售操作,因此实际上可以在脚本中提供小时和分钟。您需要确保的是在您想要的点有一个闭合点,基本上,将分辨率保持在5分钟以内,并且可以每隔5分钟点一支蜡烛。 (在您的情况下,是1分钟和5分钟的蜡烛)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SaiyadRasikh
//@version=4
strategy("Stackoverflow_Answer", overlay = true)
// Allowing only Long entries
strategy.risk.allow_entry_in(strategy.direction.long)
//Considering Nifty as the Index
var s_close = 0.0
if (hour(time) == 09 and minute(time) == 20)
s_close := close
buy = s_close > s_close[1] //Condition where second candleis close is higher than first candle close, Then enter the trade
sell = s_close < s_close[1]
strategy.entry("Long", strategy.long, when = buy,comment="Buy")
strategy.entry("Short", strategy.short, when = sell,comment="Sell")