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

resets my pnl

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

    resets my pnl

    if (Bars.IsFirstBarOfSession)
    PnlDiario = 0;


    if (DetenerEstrategia)
    return;

    //Condicion Perdida Maxima Diaria
    PnlDiario = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit - PnlAcumulado;
    if (ActivarPerdida && (PnlDiario + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0])) <= -MaxPerdidaDiaria)
    {
    // Se llamará a un método personalizado diseñado para cerrar todas las posiciones abiertas y cancelar todas las órdenes de trabajo.
    StopStrategy();
    }

    using if (Bars.IsFirstBarOfSession) resets my pnl at the start of a new day. The problem comes because when starting the strategy, the NLP is located in the virtual NLP. If the strategy had been working all the time since the beginning of the day, then I need to reset my NLP at the time of starting the strategy.

    And how can I start a strategy without showing me the operations that he was able to do in the past?​

    #2
    Hello franatas,

    Thanks for your post.

    There are no supported methods or properties to check if a strategy is enabled within a NinjaScript strategy.

    If you want to set a variable to 0, you could consider setting it to 0 in OnStateChange() when the State == State.Configure.

    OnStateChange(): https://ninjatrader.com/support/help...ightsub=States

    If you want to skip the historical processing of data when enabling the script so the strategy does not calculate historical (virtual) trades when it is enabled, you could add if (State == State.Historical) return; to the top of your OnBarUpdate() logic.

    For example:

    Code:
    protected override void OnBarUpdate()
    ​{
        if (State == State.Historical)
            return;
    
        //rest of your OnBarUpdate() logic.
    }
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by TraderKnG, Today, 01:30 AM
    0 responses
    5 views
    0 likes
    Last Post TraderKnG  
    Started by morrnel, 05-12-2024, 06:07 PM
    8 responses
    147 views
    1 like
    Last Post nobchi
    by nobchi
     
    Started by nobchi, Today, 01:05 AM
    0 responses
    2 views
    0 likes
    Last Post nobchi
    by nobchi
     
    Started by Skifree, 06-17-2024, 06:35 PM
    3 responses
    18 views
    0 likes
    Last Post Skifree
    by Skifree
     
    Started by sy2023, 09-15-2023, 08:51 PM
    2 responses
    238 views
    0 likes
    Last Post Crusade12  
    Working...
    X