Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Update Net Liquidation Variable

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

    Update Net Liquidation Variable

    I'm trying to modify the Position Display Indicator of NinjaTrader_Jim but I couldn't get what I needed.
    Instead of the cashValue I used the NetLiquidation which is what I intend to use. That I was able to do. Now, what I need is to Add in the indicator the Highest NetLiquidation. I know I need to create a new variable for that. I have named it private double MaxNetLiquidation;

    BUT I don't get it updated with the Highest NetLiquidation Value that I require.

    Lastly, I need to show that up in the indicator as well.


    Hope you can help me.

    #2
    Hello jhudas88,

    Thanks for your post.

    To accomplish your goal you would need to create a double variable named something like highestNetLiqVal. In the OnAccountItemUpdate method, you would assign the NetLiquidation value of the account to a variable, such as netLiquidation.

    After assigning the NetLiquidation value of the account to a netLiquidation variable, you would check if the netLiquidation value is not null and if the netLiquidation value is greater than highestNetLiqValue and assign netLiquidation to the highestNetLiqVal variable.

    See the code below for an example of what this may look like.

    Code:
    //Class level variables
    private double netLiquidation;
    private double highestNetLiqVal;
    
    else if (State == State.DataLoaded)
    {
        netLiquidation = account.Get(AccountItem.NetLiquidation, Currency.UsDollar);
    }
    
    private void OnAccountItemUpdate(object sender, AccountItemEventArgs e)
    {
        if (e.AccountItem == AccountItem.NetLiquidation)
            netLiquidation = e.Value;
    
        if (netLiquidation != null && netLiquidation > highestNetLiqVal)
            highestNetLiqVal = netLiquidation;
    }
    Let us know if we may further assist.
    <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


      #3
      This is exactly what i need NinjaTrader_BrandonH. Thank you! <3

      Comment


        #4
        Good day Sir! NinjaTrader_BrandonH . I was able to get what I desired but I noticed whenever I press F5 to refresh the indicator, my highestNetLiqVal resets to my NetLiquidation.
        How do I Keep its value?

        here is my Code on render

        Code:
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
        base.OnRender(chartControl, chartScale);
        if (position != null)
        unRealizedPnL = position.GetUnrealizedProfitLoss(PerformanceUnit, Close.GetValueAt(CurrentBar));
        else
        unRealizedPnL = 0;
        
        string label = "UnRealized PnL" +"\n\n"+ "Realized PnL" +"\n\n"+ "Net Liquidation" +"\n\n"+ "highestNetLiqVal" +"\n";
        string realizedPnLstring = "\n" + "\n" + "\n" + realizedPnL.ToString("N2");
        string NetLiquidationstring = "\n" + "\n" + "\n" + "\n" + "\n" + NetLiquidation.ToString("N2");
        string unRealizedPnLstring;
        string highestNetLiqValstring = "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + highestNetLiqVal.ToString("N2");
        
        if (PerformanceUnit == PerformanceUnit.Percent)
        unRealizedPnLstring = "\n" + unRealizedPnL.ToString("P");
        else
        unRealizedPnLstring = "\n" + unRealizedPnL.ToString("N2");
        
        DrawTextBox(RenderTarget, ChartPanel, label, Font, labelTextBrush, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, areaBrush, borderBrush);
        
        DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, unRealizedPnLstring, Font, unRealizedPnL < 0 ? negativeBrush : positiveBrush);
        DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, realizedPnLstring, Font, realizedPnL < 0 ? negativeBrush : positiveBrush);
        DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, NetLiquidationstring, Font, NetLiquidation < 0 ? negativeBrush : positiveBrush);
        DrawTextLayout(RenderTarget, ChartPanel, ChartPanel.X + HorizontalOffset, ChartPanel.Y + VerticalOffset, highestNetLiqValstring, Font, highestNetLiqVal < 0 ? negativeBrush : positiveBrush);
        }

        Comment


          #5
          Hello jhudas88,

          Thanks for your note.

          Pressing 'F5' will reload the NinjaScript and reset the values in the script.

          Something you could consider is saving the value to a file using a StreamWriter before pressing F5. The script could then check if the file exists in OnStateChange when the State == State.Configure and reload the value from the file.

          See the help guide documentation below.
          StreamWriter: https://ninjatrader.com/support/help...o_write_to.htm
          StreamReader: https://ninjatrader.com/support/help...o_read_fro.htm

          Let us know if we may assist further.
          <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
          579 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X