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

Concise reset code needed

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

    Concise reset code needed

    Is there are more efficient to reset the “GreenCount” to zero without all the repetition?

    Any coding help will be greatly appreciated.

    Code:
    if (BarsInProgress == 0 && Position.MarketPosition == MarketPosition.Long)
    {
        if (currentTradeNumber == 1)
            {
            ExitLong(4, qtyLong1, "LX01_");
            GreenCount = 0;
            }
        else
        if (currentTradeNumber == 2)
            {
            ExitLong(4, qtyLong2, "LX02_”);
            GreenCount = 0;
            }
        else
        if (currentTradeNumber == 3)
            {
            ExitLong(4, qtyLong3, "LX03_”);
            GreenCount = 0;
            }
        else
        if (currentTradeNumber == 4)
            {
            ExitLong(4, qtyLong4, "LX04_”);
            GreenCount = 0;
            }
        else
        if (currentTradeNumber == 5)
            {
            ExitLong(4, qtyLong5, "LX05_”);
            GreenCount = 0;
            }
    }

    Thanks in advance.

    #2
    Hello ArmKnuckle,

    Thanks for your post.

    if (currentTradeNumber >= 1 && currentTradeNumber <= 5)
    {
    GreenCount = 0;
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by ArmKnuckle View Post
      Is there are more efficient to reset the “GreenCount” to zero without all the repetition?

      Any coding help will be greatly appreciated.

      Code:
      if (BarsInProgress == 0 && Position.MarketPosition == MarketPosition.Long)
      {
      if (currentTradeNumber == 1)
      {
      ExitLong(4, qtyLong1, "LX01_");
      GreenCount = 0;
      }
      else
      if (currentTradeNumber == 2)
      {
      ExitLong(4, qtyLong2, "LX02_”);
      GreenCount = 0;
      }
      else
      if (currentTradeNumber == 3)
      {
      ExitLong(4, qtyLong3, "LX03_”);
      GreenCount = 0;
      }
      else
      if (currentTradeNumber == 4)
      {
      ExitLong(4, qtyLong4, "LX04_”);
      GreenCount = 0;
      }
      else
      if (currentTradeNumber == 5)
      {
      ExitLong(4, qtyLong5, "LX05_”);
      GreenCount = 0;
      }
      }

      Thanks in advance.
      Every single branch of the code sets GreenCount = 0. You might just as well unconditionally set GreenCount = 0 once before or after the complete set of branches.
      Last edited by koganam; 11-18-2019, 10:22 AM. Reason: Added the word "once" to make the statement clearer.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Kaledus, Today, 01:29 PM
      3 responses
      9 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frankthearm, Yesterday, 09:08 AM
      14 responses
      47 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by gentlebenthebear, Today, 01:30 AM
      2 responses
      13 views
      0 likes
      Last Post gentlebenthebear  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      17 views
      0 likes
      Last Post PaulMohn  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      2 responses
      56 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Working...
      X