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 CarlTrading, Yesterday, 11:51 AM
      0 responses
      12 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, Yesterday, 11:48 AM
      0 responses
      19 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-25-2026, 09:53 PM
      0 responses
      16 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 03-25-2026, 09:51 PM
      0 responses
      13 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 03-23-2026, 11:13 AM
      0 responses
      18 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X