Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can for Loop have variable Increment/Decrement??

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

    Can for Loop have variable Increment/Decrement??

    #region Variables

    private int TQ = 10; // Total Quantity
    private int SOQ = 1; // Single Order Quantity

    OnOrderUpdate()

    for(int i = TQ - Position.Quantity; i>0 ; i--)
    {
    entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLongAgain"+i);

    }
    Question:
    Instead of i-- in the Loop construct i want to use SOQ, the variable. Is that possible, How?
    Reason is: In India we have to put Lot Sizes as Quantity & Not No. of Lots while trading.
    So i might well be using(example):
    TQ = 10000
    SOQ = 1000

    #2
    Hello piyushc,

    Thank you for your post.

    This would not be possible with a for loop. I would not base order entry on the Position.Quantity in OnOrderUpdate() as the order could just be updating from pending submit to working and the quantity of the position would till be the same as previous. This would result in unnecessary orders submitted.

    I would recommend using the OnPositionUpdate() method to begin updating the orders and not use a for loop for the additional orders. You could do something like the following:
    Code:
    			int total = 100;
    			int increment = 10;
    			if(Position.Quantity < total)
    			{
    				if(Position.Quantity < 20)
    					// enter 1 order for your increment
    				else if(Position.Quantity < 30)
    					// enter 1 order for your increment
    				// etc...
    			}

    Comment


      #3
      i really could not understand this.
      pls elaborate, including the order entry.
      Thanks

      Comment


        #4
        Hi piyushc, to further clarify, a loop could have a custom increment as well, you would not be limited to one. i.e. consider this snippet stepping through in increments of 100 -

        Code:
        for (int index = 0; index < 1000; index += 100) 
        {
        Print(index);
        }
        For the OnOrderUpdate() you would need to be mindful for which state you trigger your action, which would hold true though for all event based handling. When do you want to scale in again? When the initial one has filled?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        630 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        566 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X