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 DJ888, Yesterday, 10:57 PM
    0 responses
    6 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Yesterday, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    151 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Working...
    X