Announcement

Collapse
No announcement yet.

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.
    }
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    597 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 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
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    555 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X