Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

BarsSinceEntryExecution

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

    BarsSinceEntryExecution

    Hello,

    I have a strategy that enters long trade with signal name "LEn1". I would like to exit this trade after 10 bars since entry using BarsSinceEntryExecution(0, "LEn1", 0) > 10.

    However, my strategy can open another trade under the name signal name "LEn1". Would BarsSinceEntryExecution exit both trades once the first Enter hits 10 bars even if the second trades did not?

    I allow up to 3 entries per unique entry name.

    Thanks,
    Tom
    Last edited by eleven; 05-18-2022, 04:09 PM.

    #2
    My idea would be to save CurrentBar, when entry is executed, like:

    [Within OnBarUpdate]
    Code:
    if (BarsSinceEntryExecution(0, "LEn1", 0) == 0) // Entry bar
    {
    int EntryBar1 = CurrentBar;
    }
    And if you'd like to have a system for 3 entries, i'd go like this:
    Code:
    if (BarsSinceEntryExecution(0, "LEn1", 0) == 0 && EntryBar1 == 0 && EntryBar2 == 0 && EntryBar3 == 0) // Entry bar, EntryBar1 is not set, EntryBar2 is not set, EntryBar3 is not set,
    {
    int EntryBar1 = CurrentBar;
    }
    if (BarsSinceEntryExecution(0, "LEn1", 0) == 0 && EntryBar1 != 0 && EntryBar2 == 0 && EntryBar3 == 0) // Entry bar, EntryBar1 is set, EntryBar2 is not set, EntryBar3 is not set,
    {
    int EntryBar2 = CurrentBar;
    }
    if (BarsSinceEntryExecution(0, "LEn1", 0) == 0 && EntryBar1 != 0 && EntryBar2 != 0 && EntryBar3 == 0) // Entry bar, EntryBar1 is set, EntryBar2 is set, EntryBar3 is not set,
    {
    int EntryBar3 = CurrentBar;
    }
    Then, for exit, I'd go like:
    Code:
     if (CurrentBar - EntryBar1 == 10) // Check whether Current bar minus bar number saved on EntryBar1 is equal to 10
    {
    ExitLong(); // THERE YOU HAVE TO SPECIFY YOUR ENTRY1 NAME IN ORDER TO GET CORRECT TRADE EXITED.
    EntryBar1 = 0; // Reset to 0
    }
    if (CurrentBar - EntryBar2 == 10) // Check whether Current bar minus bar number saved on EntryBar2 is equal to 10
    {
    ExitLong(); // THERE YOU HAVE TO SPECIFY YOUR ENTRY2 NAME IN ORDER TO GET CORRECT TRADE EXITED.
    EntryBar2 = 0; // Reset to 0
    }
    if (CurrentBar - EntryBar3 == 10) // Check whether Current bar minus bar number saved on EntryBar3 is equal to 10
    {
    ExitLong(); // THERE YOU HAVE TO SPECIFY YOUR ENTRY3 NAME IN ORDER TO GET CORRECT TRADE EXITED.
    EntryBar3 = 0; // Reset to 0
    }
    So mind ExitLong() command and adjust it to your entry names and you should be ok.

    Comment


      #3
      Hello eleven,

      Thank you for your post.

      BarsSinceEntryExecution(0, "LEn1", 0) > 10 would return true if it's been 10 bars since the most recent LEn1 entry. The quantity exited would depend on what quantity is specified in the exit order.

      So, if you have entered a LEn1 entry, and 5 bars elapse and a second LEn1 entry is submitted, the exit would not be triggered until at least 10 bars after the second entry.

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

      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the reply's. UltraNIX, thanks for your idea. I think I can make something like that work.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jonafare, 12-06-2012, 03:48 PM
        5 responses
        3,986 views
        0 likes
        Last Post rene69851  
        Started by Fitspressorest, Today, 01:38 PM
        0 responses
        2 views
        0 likes
        Last Post Fitspressorest  
        Started by Jonker, Today, 01:19 PM
        0 responses
        2 views
        0 likes
        Last Post Jonker
        by Jonker
         
        Started by futtrader, Today, 01:16 PM
        0 responses
        8 views
        0 likes
        Last Post futtrader  
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,792 views
        0 likes
        Last Post aligator  
        Working...
        X