Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry()

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

    BarsSinceEntry()

    Alright i looked through a lot of past threads and i cannot find a solution to what seems to be a simple problem.

    I have Broken the code down to as simple as possible

    " protected override void OnBarUpdate()
    {
    if (Close[0] > Close[5])
    {
    EnterLong();

    }
    if (BarsSinceEntry() > 5 )
    {
    ExitLong();
    }

    }"

    Why does the code not exit after 5 bars every time? Its erratic at best, sometimes 1 bar, sometimes 3, sometimes 5, sometimes more. I dont understand what is wrong here or if am mis interpreting how this function works. In MC it was simple, if BSE > 2 bars, an exit would happen 2 bars later every time.

    #2
    Hello neb1998, you would need to include proper signal names -

    protected override void OnBarUpdate()
    {
    if (Close[0] > Close[5])
    {
    EnterLong(DefaultQuantity, "");
    }

    if (BarsSinceEntry() > 2)
    {
    ExitLong("", "");
    }
    }
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Ok i had tried this before but i went ahead and added them and its still not working. Random exiting.

      protected override void OnBarUpdate()
      {
      if (Close[0] > Close[5])
      {
      EnterLong(DefaultQuantity,"LE1");

      }
      if (BarsSinceEntry() > 2 )
      {
      ExitLong("LE1","LE1");
      }

      }

      Comment


        #4
        Picture of results

        See Previous Post, i couldnt insert a pic from a reply for some reason.
        Attached Files

        Comment


          #5
          Hello neb1998,

          Is there any improvement when passing in the name of the entry in your BarsSinceEntry() condition?

          if (BarsSinceEntry("LE1") > 2 )
          {
          ExitLong("LE1","LE1");
          }

          It looks like every exit takes place 4 bars after the entry. This is consistent with your code.
          The condition only evaluates true on the third bar after entry, and the order is submitted on the bar following this.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ok this might be working, thanks! It looks good for now, i have to implement this into my actual strategy but looks good! Thanks.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            3 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X