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 MiCe1999, Today, 07:19 AM
    0 responses
    3 views
    0 likes
    Last Post MiCe1999  
    Started by Mindset, Today, 06:09 AM
    0 responses
    6 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by reynoldsn, 02-28-2025, 06:44 PM
    6 responses
    65 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by MamaKB, 02-14-2025, 03:38 PM
    9 responses
    69 views
    0 likes
    Last Post charlesthomas  
    Started by llanqui, 03-05-2025, 06:03 AM
    17 responses
    115 views
    0 likes
    Last Post bltdavid  
    Working...
    X