Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

enterlong cummulatively

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

    enterlong cummulatively

    i have a code that allow adding position progressively.

    like

    int shares = 0;
    protected override void OnBarUpdate()
    {
    if(A){
    enterlong(1, "initial");
    shares = 1;
    }
    if(B){
    enterlong(1,"add");
    shares = shares +1
    }

    if(C){
    entershort(shares , "exit");
    shares = 0;
    }
    }



    The problem is when i do backtesting, it has me "initial 1 @0.9095". And the next trade is exit 4 @0.9100, Close position 1 @0.9100. There should be another 3 "add 1 @***". Actually, the "add" trades never show up in the whole backtesting period even though I am very confident that the if(B) statement is triggered a lot (otherwise, exit won't sell more than 1).

    Cam some one tell me why it does not add position?

    #2
    Hi Sunjoke,

    Thank you for posting and welcome to the forums!

    Are you using Unique Entries for your backtest parameters?

    What is your Entries Per Direction set to?

    I would suggest adding a DrawDot() to the IF condition B to see if indeed this is being met.
    Additionally, add TraceOrders to the Initialize section of the code so that you can see if orders are getting ignored and why.
    TraceOrders
    DrawObjects

    Thank you
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hi Sunjoke,

      Thank you for posting and welcome to the forums!

      Are you using Unique Entries for your backtest parameters?

      What is your Entries Per Direction set to?

      I would suggest adding a DrawDot() to the IF condition B to see if indeed this is being met.
      Additionally, add TraceOrders to the Initialize section of the code so that you can see if orders are getting ignored and why.
      TraceOrders
      DrawObjects

      Thank you
      The reason was that I did not set entry per direction. After setting that, it is resolved. thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      65 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      41 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      23 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      26 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      52 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X