Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Repeating EnterLongLimit in Realtime

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

    #16
    Originally posted by NinjaTrader_Jesse View Post
    Hello dibDab,

    I don't understand what you are referring to here, you will need to provide more information such as images describing what you are seeing.
    when I enterlonglimit, it should exit after 5 bars, but it doesn't?

    in helpguide ExitLong is ignored if not long but I''ll try again with this

    protected override void OnBarUpdate()
    {
    double limitPrice = 3877;

    if (IsFirstTickOfBar)
    ++elapsedBars;

    if (Count - 2 == CurrentBar && entryCnt == 0)
    {
    ++entryCnt;
    elapsedBars = 0;
    EnterLongLimit(0, true, 1, limitPrice, "Long Limit");
    }

    if (elapsedBars == 5 && Position.MarketPosition == MarketPosition.long)
    ExitLong("Long Limit");
    }​


    Last edited by dibDab; 10-26-2022, 09:20 AM.

    Comment


      #17
      Hello dibDab,

      Please see post 14, your logic allows for that to happen

      Comment


        #18
        trying again with this ...

        protected override void OnBarUpdate()
        {
        double limitPrice = 3889;

        if (IsFirstTickOfBar)
        ++elapsedBars;

        if (Count - 2 == CurrentBar && entryCnt == 0)
        {
        ++entryCnt;
        elapsedBars = 0;
        EnterLongLimit(0, true, 1, limitPrice, "Long Limit");
        }

        if (elapsedBars >= 5 && Position.MarketPosition == MarketPosition.Long)
        ExitLong("Long Limit");
        }​

        Comment


          #19
          Hello dibDab,

          That wont work because you are not waiting for the entry to fill before starting the count. Please see the link in post 14 for a way to do that. The logic you made is not valid, the 5 count can happen before the entry even fills which means the exit would be on the same bar as your entry fill.

          Comment


            #20
            doing it again, is my code incorrect?

            Click image for larger version

Name:	chart5.png
Views:	72
Size:	7.6 KB
ID:	1221014

            Comment


              #21
              Hello dibDab,

              Yes that code is not valid, please see my previous replies.

              Comment


                #22
                does this look ok?

                protected override void OnBarUpdate()
                {
                double limitPrice = 3889;

                if (Count - 2 == CurrentBar && entryCnt == 0)
                {
                ++entryCnt;
                EnterLongLimit(0, true, 1, limitPrice, "Long Limit");
                }

                if ((BarsSinceEntryExecution() > 5 || BarsSinceEntryExecution() == -1))
                ExitLong("Long Limit Exit");
                }​

                Comment


                  #23
                  Hello dibDab,

                  Yes that is how the help guide sample shows to use that method. You need to wait for the entry to actually fill before being able to count bars since an entry. Your other logic allows for the 5 count to happen before your entry had filled.

                  You can remove the || BarsSinceEntryExecution() == -1 because you are specifically waiting for an entry to have filled before doing an exit. -1 is when no entry had happened so the exit will be called immediately which is not what you want.

                  Comment


                    #24
                    same thing happening again, confused

                    Click image for larger version  Name:	chart6.png Views:	0 Size:	6.8 KB ID:	1221029

                    Comment


                      #25

                      I don't understand why the entry triangle is displayed in an area where the bar price isn't?


                      Click image for larger version

Name:	chart8.png
Views:	74
Size:	7.5 KB
ID:	1221038
                      Last edited by dibDab; 10-26-2022, 09:56 AM.

                      Comment


                        #26
                        Hello dibDab,

                        The image you provided was not attached, please try again

                        Comment


                          #27
                          Originally posted by NinjaTrader_Jesse View Post
                          Hello dibDab,

                          The image you provided was not attached, please try again
                          is that ok?

                          Comment


                            #28
                            Hello dibDab,

                            That may be related to the bars type being used, PC clock being out of sync or also possibly the data provider being used. I would suggest that you sync the PC clock and then also enable the tick filter to prevent off market ticks.



                            Before doing that ensure that you have modified the code to actually exit 5 bars after the entry, the image you provided is still within the same bar so your conditions are not working correctly still.

                            Comment


                              #29
                              I'm using kinetick with UK time

                              Calculate.OnEachTick

                              bar type: Volume 400

                              code is:

                              protected override void OnBarUpdate()
                              {
                              double limitPrice = 3892;

                              if (Count - 2 == CurrentBar && entryCnt == 0)
                              {
                              //only 1 entry allowed
                              ++entryCnt;
                              EnterLongLimit(0, true, 1, limitPrice, "Long Limit");
                              }

                              if (BarsSinceEntryExecution() > 5)
                              ExitLong("Long Limit");
                              }​

                              Comment


                                #30
                                Hello dibDab,

                                The code you provided shouldn't be happening within the same bar, have you compiled the changes and re applied the strategy? The ExitLong shouldn't be happening unless it has been 5 bars since the last entry.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                64 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                139 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                75 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X