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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      474 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      315 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      253 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      340 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      305 views
      0 likes
      Last Post CarlTrading  
      Working...
      X