Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Running a strategy during specific hours

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

    Running a strategy during specific hours

    I'm currently building a strategy with the Strategy Builder to run during specific times, it is a simple MA crossover.
    The hours are 7:00am until 7:45am, and then 10:00am until 1:45pm.
    There is no stop/target as I am letting it run the trade until the MAs cross over.
    My issue is that if it enters a trade just before the "break" between 7:45am and 10:00am, it won't complete the trade at the crossover, as demonstrated in this screenshot.
    Click image for larger version

Name:	image.png
Views:	123
Size:	61.2 KB
ID:	1309569
    Sorry, it is difficult to see the fast MA, it is a dark blue. As per the chart, the script went long, however the MAs crossed over roughly around 7:50am and I would have wanted the trade to close, but of course, the conditions only last until 7:45am.
    Is it possible to ask the script to complete the trade with the MA crossover, then not trade again until 10:00am?
    Thank you in advance.

    #2
    Hello amichalska,

    Thank you for your post.

    You would need to add additional logic in the script that allows for exiting the trade during the break.

    The condition would check if the crossover occurred during those hours and if you are currently in an open position, exit the position. You could add a bool as an additional exit condition for the break, require the bool to be true to allow you to exit during those hours, and set the bool for false once you have exited the position.

    Please let us know if you have any further questions.

    Comment


      #3
      Hi Gaby, thanks so much for the response. Could you guide me on what I need to put in the bool?

      Comment


        #4
        Hello amichalska,

        A bool just holds a true or false value. Just as an example, a condition to close an open long position during the break could look something like this:

        Code:
        // at the class level 
        private bool myBool = true; 
        
        //in OnBarUpdate()
        if (<your time condition for the break here> && <your crossover condition> && MarketPosition == MarketPosition.Long && myBool) 
        {
        ExitLong();
        myBool = false;
        }
        Please let us know if you have any further questions.

        Comment


          #5
          Hi Gaby, apologies, as mentioned earlier, I am using Strategy Builder - could you guide me with what to do there?

          Comment


            #6
            Hello amichalska,

            You can create the bool variable in the Inputs and Variables screen. Set the default value to true.

            Then, in one of your sets (from the Conditions and Actions screen) you would have your time filter condition for the break, your crossover condition, and the additional checks for Market Position and the bool.

            Attached is a screenshot that you can use to model your logic after. Please note this is just an example and you'll need to adjust it to fit your specific logic requirements for the crossover / your desired conditions to exit during the break.
            Attached Files

            Comment


              #7
              Hi Gaby, if it's alright, I will add some screenshots for your review as I'm not sure I'm doing this correctly. Is this correct in the Inputs and Variables or am I missing something from MyBool?
              Click image for larger version

Name:	var.png
Views:	96
Size:	26.0 KB
ID:	1309638

              These are my current sets:
              ​​ Click image for larger version

Name:	set1.png
Views:	96
Size:	30.0 KB
ID:	1309639 Click image for larger version

Name:	set2.png
Views:	99
Size:	30.5 KB
ID:	1309640 Click image for larger version

Name:	set3.png
Views:	99
Size:	30.3 KB
ID:	1309641 Click image for larger version

Name:	set4.png
Views:	96
Size:	29.9 KB
ID:	1309642

              Do I need to create new Sets to add the conditions from your screenshot, or are they added to the current 4 sets? Please advise, thank you so much.

              Comment


                #8
                Hello,

                You would need to add a new set, since this set will only have logic for what to do during the "break" you specified in your original post.

                Please let us know if you have any further questions.

                Comment


                  #9
                  Gaby, thank you for replying.

                  Could you let me know if the MyBool is set up correctly under Inputs and Variables?
                  Also, where do I find this to add it to my set?
                  Click image for larger version

Name:	bool.png
Views:	94
Size:	6.4 KB
ID:	1309648
                  Here is what I see when I open the "add" under "Do the following":
                  Click image for larger version

Name:	add.png
Views:	92
Size:	276.3 KB
ID:	1309649

                  Comment


                    #10
                    Hello,

                    MyBool should be a variable, not an input. That way you can set it under the conditions and actions.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    119 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    62 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
                    44 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