Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Auto trail only sometimes working

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

    Auto trail only sometimes working

    Hi Guys

    I have a very perplexing situation! I wonder if you could kindly try to sort me out.

    I have two similar but not identical strategies, call them A and B. The trades are entered perfectly in both (and I can see this with arrows and back colors).

    In both A and B, the Initialize() sections are 100% identical as follows (the instrument is ^DJIA with 1000 range bars):

    SetTrailStop("Longtrade", CalculationMode.Ticks, 1500, true);
    SetTrailStop("Shorttrade", CalculationMode.Ticks, 1500, true);
    SetProfitTarget("Longtrade", CalculationMode.Ticks, 3000);
    SetProfitTarget("Shorttrade", CalculationMode.Ticks, 3000);

    The trades are entered on both identically as follows:

    EnterLong(1, "Longtrade"); and

    EnterShort(1, "Shorttrade");

    Please see the 2 attachments. When I put them thru the Analyzer, in A the auto trail works perfectly but in B, it hardly works at all. In both, the trail distance is set at 1500. This is correctly interpreted in A but not in B as you'll see.

    Click image for larger version

Name:	Strategy A working.jpg
Views:	1
Size:	152.2 KB
ID:	898498

    Click image for larger version

Name:	Strategy B not working.jpg
Views:	1
Size:	154.6 KB
ID:	898499

    Thanks very much in advance for your advice.

    #2
    Hello,

    From the code you provided, it should be giving you similar results.

    Is the Initialize() method the only place you used SetAutoTrail?

    Are you using SetStopLoss() anywhere in the OnBarUpdate() method?

    Please provide us with any other relevant pieces of code that might be different between the two scripts.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks very much for your reply, Matthew.

      1) Yes, Initialize() method is the only place where I use SetAutoTrail.

      2) There's no SetStopLoss() anywhere in the OnBarUpdate() method.

      Well, that's strange. The 'problem' strategy always seems to have compiled well before - no errors were ever flagged up - and you saw the image I sent you of the problem.

      Anyway, I've just compiled it again - and it now seems to work fine in the Analyzer! It must have been a temporary glitch somewhere which disappeared when I didn't use the program for about an hour. How this happened, I don't know.

      It's working now - and that's what's important. Thanks, again, Matthew, for your assistance.

      Comment


        #4
        I'm glad to hear it is working now. Please let me know if this pops up again.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Well, Matthew, I was too optimistic! It worked once and then failed again as before.

          I can only think of one thing: this strategy (which I had 'saved as' from another one) must have developed some kind of programming/compiling anomaly. The coding is not too complex. What I'll do is start again from scratch using the Wizard and hopefully the problem won't recur.

          One simple question re using the Wizard: is it possible to code else if using the Wizard alone?

          Thanks for letting me know.

          Comment


            #6
            Hello,

            Unfortunately you would only be able to use If statements in the Strategy Wizard alone.
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            673 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            577 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X