Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Number of trades executed

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

    Number of trades executed

    hello,

    I would like to set a limit on a the number of trades to be executed during a particular period. For example upon condition X perform action Y but then if this action performs a number of times Z within a day stop trading.

    Is there a way to do this in Algo development module?

    Thanks

    #2
    Hello space_trader,

    Thank you for your post.

    Yes, you could use a counter variable that you increment each time the action is taken, and check in the conditions for that action whether or not the counter is greater than the number of times you wish to execute the action. You can then reset the counter on the first bar of a new session to have it start doing the action again.

    I'm attaching a very simple example script.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      hello Kate,

      Can this be done in Strategy Builder? Without writing any code.

      Comment


        #4
        Hello space_trader,

        Thank you for your reply.

        Yes, but due to limitations of the Strategy Builder you'll need to use a custom series to hold your count and move the count forward by assigning the previous bar's value to it in the first set, then resetting the most recent value to 0 if it's the first bar of the session, then adding to the series count when an order is placed. Please see the example Strategy Builder script below.

        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment


          #5
          Hello. I unlocked my working strategy and added the code above to allow only one trade per day. Unfortunately, it didn't work as expected. I spent some time trying to figure it out myself but there comes a point where you have to accept defeat! Could you have a look and let me know where the error is? Also, in the code, is 1 trade 'in and out' of the position or just the entry, so for one in and out trade, the trade count would need to be set to '2' ?

          Thanks
          Attached Files

          Comment


            #6
            hello,

            Same here. I am trying to build a simple strategy where a Long or Short order is placed when Price is higher or lower than the open price (first bar of session) but didn't work. I am not C# expert so the mistake could be just a minor adjustment.

            Your input is greatly appreciated.
            Attached Files

            Comment


              #7
              Hello michaelc6,

              Thank you for your note.

              Your issue is that you're not containing the entry logic within curly brackets from the if(myCount < TradesPerDay) so this isn't checked for both sets.

              You have this:

              Code:
              if (myCount < TradesPerDay)
              // Set 1
              if ((CrossAbove(Close, AuSuperTrendU111.StopDot, 1))
              && (Times[0][0].TimeOfDay > new TimeSpan(8, 30, 0))
              && (Times[0][0].TimeOfDay <= new TimeSpan(12, 0, 0)))
              {
              EnterLong(Convert.ToInt32(DefaultQuantity), "");
              myCount = myCount + 1;
              }
              // Set 2
              if ((CrossBelow(Close, AuSuperTrendU111.StopDot, 1))
              && (Times[0][0].TimeOfDay > new TimeSpan(8, 30, 0))
              && (Times[0][0].TimeOfDay <= new TimeSpan(12, 0, 0)))
              {
              EnterShort(Convert.ToInt32(DefaultQuantity), "");
              myCount = myCount + 1;
              }
              and you should have this:

              Code:
              if (myCount < TradesPerDay)
              [B]{[/B]
              // Set 1
              if ((CrossAbove(Close, AuSuperTrendU111.StopDot, 1))
              && (Times[0][0].TimeOfDay > new TimeSpan(8, 30, 0))
              && (Times[0][0].TimeOfDay <= new TimeSpan(12, 0, 0)))
              {
              EnterLong(Convert.ToInt32(DefaultQuantity), "");
              myCount = myCount + 1;
              }
              // Set 2
              if ((CrossBelow(Close, AuSuperTrendU111.StopDot, 1))
              && (Times[0][0].TimeOfDay > new TimeSpan(8, 30, 0))
              && (Times[0][0].TimeOfDay <= new TimeSpan(12, 0, 0)))
              {
              EnterShort(Convert.ToInt32(DefaultQuantity), "");
              myCount = myCount + 1;
              }
              [B]}[/B]
              I've bolded the missing curly brackets in the second set of code.

              Please let us know if we may be of further assistance to you.

              Comment


                #8
                Hello space_trader,

                Thank you for your reply.

                Your script isn't looking at the opening price of the bar, you've got it set to look at the median price of the opening bar which would be (High + Low) / 2. The open of the first bar of session would be Open[0].

                You're also not comparing the price of what you're saving as the open to the current price, you're comparing to the Median price again. Current Price would be Close[0].

                Please let us know if we may be of further assistance to you.

                Comment


                  #9
                  hello Kate,

                  Thanks but I am aware. The problem is that when I use the strategy analyzer, I see that the strategy trades multi times per day, not just one.

                  Comment


                    #10
                    Hello space_trader,

                    Thank you for your note.

                    You're not bringing the prior myCount value to the current bar so that's going to be 0. Try this:

                    Code:
                    myCount[0] = myCount[1];
                    
                    // Set 1
                    if (Bars.IsFirstBarOfSession == true)
                    {
                    Open_Price = Median[0];
                    myCount[0] = 0;
                    Print(@"Resetting to 0 at " + Convert.ToString(Times[0][0].TimeOfDay));
                    }
                    
                    // Set 2
                    if (Open_Price <= (Median[0] + (-10 * TickSize)) )
                    {
                    
                    if ((myCount[0] < TradesPerDay)
                    && (Close[0] > Open[0])
                    && (Position.MarketPosition == MarketPosition.Flat))
                    {
                    EnterShort(Convert.ToInt32(DefaultQuantity), "");
                    if (myCount[0] == 0)
                    {
                    myCount[0] = 1;
                    }
                    else
                    {
                    myCount[0] = Convert.ToInt32((myCount[1] + 1));
                    }
                    Print(Convert.ToString(myCount[0]));
                    }
                    }
                    
                    // Set 3
                    if (Open_Price >= (Median[0] + (10 * TickSize)) )
                    {
                    if ((myCount[0] < TradesPerDay)
                    && (Close[0] > Open[0])
                    && (Position.MarketPosition == MarketPosition.Flat))
                    {
                    EnterLong(Convert.ToInt32(DefaultQuantity), "");
                    if (myCount[0] == 0)
                    {
                    myCount[0] = 1;
                    }
                    else
                    {
                    myCount[0] = Convert.ToInt32((myCount[1] + 1));
                    }
                    Print(Convert.ToString("Count: " + myCount[0]));
                    }
                    }
                    Please let us know if we may be of further assistance to you.

                    Comment


                      #11
                      Hi Space_Trader,

                      I'm sorry. I know I'm late to the party.

                      I was able to create something in Strategy Builder to limit (1) trade per day, at least, it worked in Strategy Analyzer. I'm not sure if I ever tried it Live. It may trade more than once if your PnL is in between -1 and 5 dollars. If you set the 5 to a 2, the commission should take care of that. This was set to apply to all and each set that was associated with an entry order.

                      Click image for larger version

Name:	One Trade.jpg
Views:	116
Size:	15.6 KB
ID:	1309563

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      116 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      61 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      40 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      43 views
                      0 likes
                      Last Post TheRealMorford  
                      Started by Mindset, 02-28-2026, 06:16 AM
                      0 responses
                      82 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Working...
                      X