Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Too Many Entries

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

    Too Many Entries

    I have a strategy that "can't" buy more than one contract at a time and "can't" buy more than one contract per bar and "can't" reenter a bar that it just exited. It does all three things (see Pic1). The bars are one minute bars in this instance.

    The position starts flat entering the 10:06 bar. It buys one contract then another, sells one then sells the other. Then it proceeds to do it all over again, all in the 10:06 candle. A chart visual of this is in Pic2.

    I might add an EntriesPerDirection instruction to control this, but I should have wrapped the code in enough layers to prevent it from over ordering. What I'm doing isn't working. I don't have a clue why.

    Here's a code summary:

    if (FirstTickOfBar)
    {
    currentbar = CurrentBar;

    ....... stop and exit logic

    }

    // These statements are part of the OnBarUpdate method
    if (Position.MarketPosition == MarketPosition.Long)
    if ((Close[0] - Position.AvgPrice) >= targetprofit) //Hit Max Profit
    {


    ExitLong();
    ....
    exit_bar = currentbar;
    ....

    }

    }

    if (FirstTickOfBar)
    {


    //Trying to enter an UP trade
    if (enteronbar < currentbar) //redundant
    // This statement keeps it from reentering on the same bar if it has entered then exited in the same bar
    if (Position.MarketPosition == MarketPosition.Flat)
    // This statement keeps it from entering on the next bar if not flat
    if (currentbar > exit_bar)
    // This statement keeps it from exiting then renetering on the same bar if the exit bar is not the entry bar

    ....more logic......
    enteronbar = currentbar;

    SetStopLoss(CalculationMode.Price, (Close[0] - initial_stop));
    EnterLong();

    }

    So, with all that "don't-trade" logic, it trades like crazy.
    Any ideas?

    Thanks,

    Larry

    Attached Files
    Last edited by epcompany; 04-01-2009, 09:21 PM.

    #2
    Hi Larry, are you sure you are synched up properly before starting the strategy live? If not, this can create confusion along the waym -



    Have you checked with Print() statements that your 'don't trade' logic works and covers the needed cases?

    It might be easier to work with EntriesPerDirection to limit entries programmatically.

    Also since you use FirstTickOfBar I assume you work this on CalculateOnBarClose = false? Maybe your conditions still trigger intrabar outside of this statement and thus create additional entries.

    Comment


      #3
      Hi, Bertrand. Thanks for the response!

      Yes. I make sure I don't start the strategy if it can have an entry when it hits the live trades. Also

      if (Position.MarketPosition == MarketPosition.Flat)

      is supposed to make sure that the strategy can't initiate a trade unless the position is flat.

      I hadn't considered using the output window to trace this, but I don't understand why it traded 48 seconds into the bar inside of FirstTickOfBar. It's hard to imaging zero ticks coming until the 48th second. So, I can use Print to let me see when the ticks come by printing the time at FirstTickOfBar and the time when it trades. They'd better be the same.

      But, of course, they won't be as the example I gave traded 4 times in one minute.

      EntriesPerDirection would only solve part of it and it should work as it stands. I'm trying to trade at the beginning of a bar and not trade again if I exit during the same bar. I also don't want to reenter a bar if I just exited it until the next bar. NT seems to ignore the statements.

      Yes, I use
      protectedoverridevoid Initialize()
      {
      ClearOutputWindow();
      CalculateOnBarClose =
      false;
      }

      I'm assuming when I trace this that it will confirm that it's trading outside of FirstTickOfBar when I've told it to only trade inside of FirstTickOfBar. I still won't understand why. So, suggestions are most welcome.

      Thanks again!

      Larry

      Comment


        #4
        Hi Larry, I would need to take a look through your full code to further advise, if you don't want to post it on the forum, please contact me at support at ninjatrader dot com Attn Bertrand - Thanks!

        Comment


          #5
          Bertrand,
          Thank you very much! You're the Doctor for my illness. I'll send it so please look for it shortly. I'll write up a short description to tell you how it is supposed to work.

          Thanks again!

          Larry

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X