【问题标题】:pine scritp for loop strange outcome循环奇怪结果的松树脚本
【发布时间】:2021-08-02 09:23:41
【问题描述】:

我正在尝试通过资本指标创建一个累加器,但不知道为什么,无法正常工作。 我认为是 for 循环,但无法解决。 错误是当我增加累积过程的百分比差异时,它会产生奇怪的步骤:

代码:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © manolo_alm

study("ACUMULACIÓN", overlay = true)

//****************DEFINICIÓN DE VARIABLES**************************

vol_neg = 0.0 // función propia de TV pero lo renombramos
precio = 0.0 // precio medio de la vela high + low +center hlc3
//capital = vol_neg * precio// esto en principio sino lo resetamos puede calcular desde el origen de los tiempos o para cada vela
porcent_acu = input ( 0.1, title = "% precio altura banda AC" , step = 0.01)// variable para seleccionar la anchura óptima nos valdrá para estudiar cada producto
cap_neg_min = input (1, title ="M de Capital negociado ($)", step=500)// no olvidar multiplicar *10^6 
cap_neg_max = input (13300, title ="M de Capital negociado ($)", step=500)// no olvidar multiplicar *10^6
var acu_capital= 0.0 // va a ser un acumulador del capital negociado en un rango predefinido por sus condiciones de contorno de precio, decimal empieza en 0.0
var nvelas_acu = 0// número de velas en el rango de acumulación
inicio_acumulacion = input (defval=0, title="Velas inicio acumulación")
fin_acumulacion = input (defval=100, title="Velas máx acumulación")

//****************SET UP INICIAL**********************************
//
//****************ETIQUETAS************************************
// Crea las etiquetas para poder marcar los puntos tomados para generar las rectas

var etiq_cap = label.new(bar_index[0], high, text = "CAPITAL:" + tostring (acu_capital), style=label.style_square, textcolor=color.yellow, tooltip="Capital Negociado", size=size.normal )

//**************** PROGRAMA***************************************

//sólo debe acumular sí horizontalmente está en un rango de precios y a partir de un capital determinado no vale que lo etiquete si es poco importe
   

// ********************ACUMULADOR DE CAPITAL*****************************

// si la diferencia de altura de velas (por arriba o por abajo)  es < que la establecida por porcent_acu empieza a acumular

for i = inicio_acumulacion to fin_acumulacion// empezamos analizando grupos de 100 velas, ya vemos si hacen falta más vamos a ponerlo en una etiqueta el número
    if (high[i+1]/low[0]) < porcent_acu and (low[i+1]/low[0])< porcent_acu        
        capital = hlc3 [i] * volume[i]
        acu_capital := (acu_capital + capital)
        nvelas_acu := i

// Dibujar el etiqueta
label.set_x (etiq_cap, bar_index[nvelas_acu])
label.set_y (etiq_cap, high[nvelas_acu] )
label.set_text(etiq_cap, tostring (nvelas_acu) + "CAPITAL:" + tostring (acu_capital))

感谢您的帮助。

【问题讨论】:

    标签: loops for-loop pine-script indicator tradingview-api


    【解决方案1】:

    这条线的条件几乎永远不会为真,所以你的循环没有做任何事情:

            if (high[i+1]/low[0]) < porcent_acu and (low[i+1]/low[0])< porcent_acu        
    

    high/low 比率通常围绕 1 旋转,而您的条件要求它小于 0.1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 2016-05-26
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多