Announcement

Collapse
No announcement yet.

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;
    }

    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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      72 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X