为什么这个策略代码没有进入任何交易?

问题描述 投票:0回答:0

我正在尝试编写我的第一个策略代码,但我不明白我哪里出错了。代码中似乎没有任何错误,但代码没有生成任何条目。你能帮我理解我哪里出错了吗?

//@version=5
strategy("calcolo ingresso 4", overlay=true)

VAR1A = (close[1]<open[1] and close>open and close>high[1]) 
plotshape(VAR1A,  title = "VAR1A", location=location.belowbar, color=color.rgb(23, 159, 180), style=shape.triangleup, text="VAR1A") 

var float my_close = na
if VAR1A
    my_close := high[0]

var float my_open = na
if VAR1A
    my_open := low[1]

var float entry_level = (my_close-((my_close - my_open)/2))


//VERIFICA CONDIZIONI INGRESSO LONG
long_condition = false
first_cross_index = ta.valuewhen(ta.crossover(close, entry_level), bar_index, 0)
last_cross_index = ta.valuewhen(ta.crossover(close, entry_level), bar_index, 4)
if last_cross_index > first_cross_index
    long_condition := true

// Inserisci l'ordine di ingresso long
if long_condition and VAR1A
    strategy.entry("buy",strategy.long,qty=5000)

// Chiudi l'operazione long se il prezzo chiude sotto entry_level
close_condition = false
close_cross_index = ta.valuewhen(ta.crossunder(close, entry_level), bar_index, 0)
if strategy.position_size > 0 and close_cross_index > 0 and close[close_cross_index] >    entry_level
    close_condition := true

if strategy.position_size > 0 and close_condition
    strategy.close("buy")

从代码来看,我希望它在满足 VAR1A 条件时简单地模拟多头入场,并且价格恰好达到当前蜡烛的高值和触发 VAR1A 条件的前一根蜡烛的低值之间的价格水平.它可以尝试进入接下来的 4 根蜡烛。

pine-script long-integer pine-script-v5 trading pine-script-v4
© www.soinside.com 2019 - 2024. All rights reserved.