error codigo linea tendencia

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #230565 quote
    dagilo1975
    Participant
    New

    Buenos dias, alguien podria revisarme el codigo. No consigo que la linea de tendencia modifique el punto de la derecha para que se grafique correctamente

    defparam drawonlastbaronly = true

    numerobarraderechalt0=0
    numerobarraizquierdalt0=barindex
    preciobarraderechalt0 = log(low[numerobarraderechalt0])
    preciobarraizquierdalt0 = log(low[numerobarraizquierdalt0])

    //determina el valor minimo para el punto de la izquierda de la linea de tendencia
    for ilt0=numerobarraizquierdalt0 downto numerobarraderechalt0 do
    if log(low[ilt0])<preciobarraizquierdalt0 then
    preciobarraizquierdalt0 = log(low[ilt0])
    numerobarraizquierdalt0 = ilt0
    endif
    next

    //Desplaza el punto de la derecha desde el punto de la izquierda hacia la ultima barra en los minimos que sean inferiores al valor de la recta para cada barra
    for ilt0= numerobarraizquierdalt0-1 downto numerobarraderechalt0 do
    valorrecta=((10* EXP((((log(low[numerobarraderechalt0])-log(low[numerobarraizquierdalt0]))/(barindex[numerobarraderechalt0]-barindex[numerobarraizquierdalt0]))*(barindex-barindex[numerobarraderechalt0]))+log(low[numerobarraderechalt0])))/10)
    if log(low[ilt0])< valorrecta[ilt0] then
    preciobarraderechalt0 = log(low[ilt0])
    numerobarraderechalt0 = ilt0
    endif
    next

    //grafica linea de tendencia y valores de las mismas
    DRAWLINE(barindex[numerobarraizquierdalt0], low[numerobarraizquierdalt0], barindex[numerobarraderechalt0], low[numerobarraderechalt0])
    DRAWPOINT(barindex[numerobarraizquierdalt0], low[numerobarraizquierdalt0], 3)
    DRAWPOINT(barindex[numerobarraderechalt0], low[numerobarraderechalt0], 2)
    valorrecta=((10* EXP((((log(low[numerobarraderechalt0])-log(low[numerobarraizquierdalt0]))/(barindex[numerobarraderechalt0]-barindex[numerobarraizquierdalt0]))*(barindex-barindex[numerobarraderechalt0]))+log(low[numerobarraderechalt0])))/10)

    return valorrecta as “valorrecta”

    #230596 quote
    druby
    Participant
    New

    Hello… Use the ‘Insert PRT Code’ function to add code to the post or the language translation will replace your variables with different names and won’t be consistent in doing so, then the code won’t run. I had to change it just to make it work and understand a little bit. I made it work, I don’t know if it’s right. druby

    defparam drawonlastbaronly = true
    
    rightbarnumberlt0 = 0
    leftbarnumberlt0 = barindex
    
    rightbarlt0 = log(low[rightbarnumberlt0])
    leftbarpricelt0 = log(low[leftbarnumberlt0])  
    
    //Determine the minimum value for the point on the left of the trendline
    for i = leftbarnumberlt0 downto rightbarnumberlt0 do
    if log(low[i]) < leftbarpricelt0 then  // if this true
    leftbarpricelt0 = log(low[i])       // update value
    leftbarnumberlt0 = i                // update bar
    endif
    next
    
    
    //Move the point on the right from the point on the left to the last bar at the minimum that is lower than the value of the line for each bar
    for i = leftbarnumberlt0-1 downto rightbarnumberlt0 do
    
    A = low[rightbarnumberlt0]
    B = low[leftbarnumberlt0]
    C = barindex[rightbarnumberlt0]
    D = barindex[leftbarnumberlt0]
    E = barindex-barindex[rightbarnumberlt0]
    
    rightbar = ( 10 * EXP( ( ( (log(A)-log(B) ) / (C-D) ) * (E) ) )     + log(A) ) / 10
    
    
    if log(low[i] )< rightbar[i] then////////////////////
    rightbarpricelt0 = log(low[i])
    rightbarnumberlt0 = i
    endif
    
    next
    //trend line chart and values of the same
    
    x1 = leftbarnumberlt0
    x2 = rightbarnumberlt0
    
    DRAWLINE(barindex[x1], low[x1], barindex[x2], low[x2])
    DRAWPOINT(barindex[x1], low[x1], 3)
    DRAWPOINT(barindex[x2], low[x2], 2)
    
    A = low[x2]
    B = low[x1]
    C = barindex[x2]
    D = barindex[x1]
    E = barindex-barindex[x2]
    
    r =   ( 10 * EXP( ( ( (log(A)-log(B) ) / (C-D) ) * (E) ) )     + log(A) ) / 10 
    
    return low//,valorrecta as "valorrecta"
    #230656 quote
    dagilo1975
    Participant
    New

    Druby Muchas gracias por la contestación, pero el código no actúa como tengo en mente. voy a intentar hacer una explicación de lo que pretendía con mi código.

     

    1º el punto de la izquierda busca el low mas bajo (teniendo ahora una recta entre el low mas bajo (punto de la izquierda) y el low de la ultima barra (punto de la derecha))

    2º ahora preguntamos ¿hay algún low por debajo de la linea de tendencia que genera el punto de la izquierda y el punto de la derecha?

    a)   Si, ahora desplazamos el punto de la derecha hacia el punto de la izquierda, siendo nuevo punto de la izquierda el el low que ha marcado que era inferior (repitiendo el punto 2 hasta que la condicion sea NO)

    b)   No, fin del bucle

    Atentamente, David

    #230998 quote
    druby
    Participant
    New

    Hello..

    I’ve been looking at this over the weekend. I couldn’t determine if the errors were related to math, algorithm logic, or the way PRT executes code.

    I decided to start from scratch and try to make something work even if it’s not exactly what is required. However, it may be easier to understand/modify the code from a working position.

    I couldn’t fully understand the version of the logarithmic/linear equation you used, so I used a linear/linear equation for the calculation, which is much simpler and could be replaced later if needed.

    The logic of the program took a while, but it got easier, with the math under control. But there were also some execution issues to overcome.

    Looking at the indicator’s movement, I can see that there are more things to do on the logical side, as usual! Under various conditions, the line changes abruptly. The movement of the points on a new breakout of the trendline may require “some” delay when the points end very close together.

    Also, all this numerical calculation will slow down the program, but the parts could be optimized. For example, if the trendline point of the next new bar is known before the next bar arrives, then it would be a simple calculation to determine if it would break the trendline, therefore it would not require a loop of point movement etc., just the next point for the verification of the next bar.

    Just speculating on more modifications!

    This version is generalized so that it can be used for low or high trend lines using two instances of the indicator and setting the ‘switch’ variable to ‘1 or 0’ and adjusting the colour of the High/Low line via the settings menu if it is a standalone indicator, or hidden, if it is added to the price panel.

    Take a look around and see what fits, etc.

    druby

    zzzz-pic-1.png zzzz-pic-1.png julb-trend-line-V1.12.itf
    #231430 quote
    dagilo1975
    Participant
    New

    muchas gracias por tu ayuda, finalmente he encontrado la errata, No habia indicado la posicion dentro de la linea de tendencia

    valorrecta=((10* EXP((((log(low[numerobarraderechalt0])-log(low[numerobarraizquierdalt0]))/(barindex[numerobarraderechalt0]-barindex[numerobarraizquierdalt0]))*(barindex[ilt0]-barindex[numerobarraderechalt0]))+log(low[numerobarraderechalt0])))/10)

     

    Atentamente, David

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

error codigo linea tendencia


ProBuilder: Indicadores y Herramientas

New Reply
Author
author-avatar
dagilo1975 @dagilo1975 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by dagilo1975
1 year, 11 months ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 03/27/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...