Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntryExecution() for Exit Trigger

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

    BarsSinceEntryExecution() for Exit Trigger

    Hi,
    I am working on a strategy where I want my positions to close after certain bars elapsed since entry. Works fine until I set the entries per direction to a number greater than 1. In this case the positions are closed out together after the last entry was X bars ago. Is there a method I can use in Strategy Builder that handles the entries as unique ones and exits each separately after they were entered X bars ago? Tried few methods but with no success so far.
    Thanks!


    #2
    Hello Balage0922,

    Thank you for your post.

    I'd say the best way to deal with this would be to use Signal Names with your orders. There is an overload for BarsSinceEntryExecution() that takes a signal name and will check how many bars it's been since that particular entry executed. I'd set up a couple of these for your different orders and then if it's been more than X bars close that specific entry by using it's Signal Name as the FromEntrySignal of the exit. Let's assume we have 2 long entries called myEntry1 and myEntry2:

    Code:
    if (BarsSinceEntryExecution("myEntry1") > 5)
    {
        ExitLong("myEntry1");
    }
    if (BarsSinceEntryExecution("myEntry2") > 5)
    {
        ExitLong("myEntry2");
    }
    Here's a link to our help guide where it mentions this overload:



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

    Comment


      #3
      Thanks Kate, will check this!

      Comment


        #4
        Kate, I filled out the unique signal names and changed entries per direction to 2/unique entries. The results are the same, did I miss something?
        Attached Files

        Comment


          #5
          Hello Balage0922,

          Thank you for your post.

          You need to have different signal names for each of the two entries, and two exits, one for each entry. Have you named the entries the same thing?

          Thanks in advance; I look forward to assisting you further.

          Comment


            #6
            Hi Kate,
            yes, I named them Nr.1 & Nr.2, forgot to mention.

            Comment


              #7
              Hello Balage0922,

              Thank you for your reply.

              Could you provide a code snippet showing the conditions for your exits and the exits themselves?

              Thanks in advance; I look forward to assisting you further.

              Comment


                #8
                Sure, here it comes:
                // Set 1
                if (CrossBelow(PCRISlow1.SlowFisherTransform, PCRI_Trigger, 1))
                {
                EnterLong(Convert.ToInt32(DefaultQuantity), @"Nr.1");
                }

                // Set 2
                if (BarsSinceEntryExecution(0, @"Nr.1", 0) >= Exit_Bars)
                {
                ExitLong(Convert.ToInt32(DefaultQuantity), @"", @"Nr.1");
                }

                // Set 3
                if (CrossBelow(PCRISlow1.SlowFisherTransform, PCRI_Trigger, 1))
                {
                EnterLong(Convert.ToInt32(DefaultQuantity), @"Nr.2");
                }

                // Set 4
                if (BarsSinceEntryExecution(0, @"Nr.2", 0) >= Exit_Bars)
                {
                ExitLong(Convert.ToInt32(DefaultQuantity), @"", @"Nr.2");
                }

                }

                Comment


                  #9
                  Hello Balage0922,

                  Thank you for your reply.

                  I had to change this up a little to test since I don't know what your PCRISlow indicator is or your value for PCRI_Trigger, but in my testing this is working as expected - it's just a little hard to see from your screenshot that they actually are exiting on different bars.

                  Here's what I got in my testing:

                  Click image for larger version

Name:	2020-02-10_1208.png
Views:	360
Size:	58.5 KB
ID:	1086834​​​​​​​

                  Thanks in advance; I look forward to assisting you further.

                  Comment


                    #10
                    Thanks Kate for checking, what are the order handling settings you used?

                    Comment


                      #11
                      Hello Balage0922,

                      Thank you for your reply.

                      I used this:

                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.UniqueEntries;

                      But it also works the same with this:

                      EntriesPerDirection = 2;
                      EntryHandling = EntryHandling.AllEntries;

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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Today, 05:17 AM
                      0 responses
                      50 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      126 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      69 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      42 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      46 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X