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 affilife, 02-17-2024, 09:53 AM
    7 responses
    127 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by lucyb, 06-23-2024, 08:33 AM
    10 responses
    36 views
    0 likes
    Last Post lucyb
    by lucyb
     
    Started by gabrielrodrigues, 06-21-2024, 07:38 AM
    11 responses
    56 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Dan_TUK, Today, 08:59 AM
    6 responses
    18 views
    0 likes
    Last Post Dan_TUK
    by Dan_TUK
     
    Started by RISKYBUSINEZZ, Today, 10:43 AM
    3 responses
    13 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Working...
    X