Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Haiasi, 04-25-2024, 06:53 PM
    2 responses
    17 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    5 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,786 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X