Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

two calculations in one

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    two calculations in one

    I have a flag that needs to calculate OnBarClose and OnEachTick for two different processes, The problem is that if calculate = OnEachTick in the OnBarClose process when using IsFirstTickOfBar, low and High [0] give the desired value, it is different than if calculate = OnBarClose; It is possible to have both calculations in the same code. foreach (var kvp in lineasDiccionario)
    {
    string claveLinea = kvp.Key;
    FranatasNivelesAtrapados linea = kvp.Value;

    // Resta uno de DistanciaFinal
    linea.DistanciaInicial++;
    linea.PrecioTocado = false;
    linea.DistanciaFinal = -1;

    // Verifica si el precio ha tocado la línea y agrega la clave a la lista de eliminación
    if ((linea.Color == ColorCompras && !linea.PrecioTocado && Low[0] <= linea.PrecioLinea) ||
    (linea.Color == ColorVentas && !linea.PrecioTocado && High[0] >= linea.PrecioLinea))
    {
    linea.Toque = CurrentBar;
    linea.PrecioTocado = true;

    linea.DistanciaFinal = CurrentBar - linea.Toque;
    lineasAEliminar.Add(claveLinea);
    }

    // Actualiza la línea en el gráfico
    Draw.Line(this, claveLinea, linea.DistanciaInicial, linea.PrecioLinea, linea.DistanciaFinal, linea.PrecioLinea, linea.Color);
    }, if ((linea.Color == ColorCompras && !linea.PrecioTocado && Low[0] <= linea.PrecioLinea) ||
    (linea.Color == ColorVentas && !linea.PrecioTocado && High[0] >= linea.PrecioLinea))​
    this is the part that calculates different low and high if calculate = OnBarClose or calculate = OnEachTick withIsFirstTickOfBar​
    Last edited by franatas; 03-10-2024, 11:42 PM.

    #2
    Hello franatas,

    Thank you for your post.

    When using Calculate.OnBarClose, in live/replay data, [0] is the latest just closed bar, your script will run once at the end of the bar, the script does not know of the currently forming bar until it closes and the index [0] shifts to the just closed bar, the previously closed bar would now be [1]. The Low and High values of the bar are already known. Your code would execute exactly the same as it does historically.

    When using Calculate.OnEachTick, in live/replay data, Close[0] is the current price of the currently forming bar, the Close, High and Low values change as the price changes in the currently forming bar until it closes. Note: In this mode your code will execute on each incoming tick which may be exactly the same price as the previous tick(s). Like OnPriceChange, the currently forming bar prices of Close, High, Low will change until the bar closes. The bar index of [1] is the just closed bar.

    https://ninjatrader.com/support/help.../calculate.htm

    This sample script demonstrates separating logic to calculate once on bar close or on every tick:



    Please let me know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    599 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    345 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    558 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X