Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trailstop after a certain threshold

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

    trailstop after a certain threshold

    Code:
                if (Close[0] >= Position.AvgPrice + trail) 
                {
                      SetTrailStop("", CalculationMode.Ticks, trail/.25, false);
                }
    hi how come the above is not working as scripted. i want to set a trailstop when price goes above a certain threshold. but what it's doing is setting a trailstop as soon as i enter a position.

    #2
    Hello calhawk01,

    Thank you for your post.

    Is the SetTrailStop() set in the Initialize() method? What determines the "trail" value?

    I look forward to your response.

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello calhawk01,

      Thank you for your post.

      Is the SetTrailStop() set in the Initialize() method? What determines the "trail" value?

      I look forward to your response.
      It's set in OBC

      User sets the value for trail... For example "4"

      If close > Avgprice+4.... Start the trailstop

      Comment


        #4
        Hello calhawk01,

        Thank you for your response.

        Are there any Set() methods in the Initalize() method?

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello calhawk01,

          Thank you for your response.

          Are there any Set() methods in the Initalize() method?
          nO

          Code:
                  protected override void Initialize()
                  {
          
                      CalculateOnBarClose = true;
                      TraceOrders = true;
                  }
          Code:
                  protected override void OnBarUpdate()
                  {
                      double total = profit+trigger;
                      
                      if ((Position.MarketPosition == MarketPosition.Flat)
                          &&.....................................)
                      {
                          EnterLongLimit(..................);
                            SetProfitTarget("", CalculationMode.Ticks, total/.25);
                      }
          
                      if (Close[0] >= Position.AvgPrice + trail)              {                   SetTrailStop("", CalculationMode.Ticks, trail/.25, false);             }
          
                      if (ToTime(Time[0]) == ToTime(15, 57, 0))
                      {
                          ExitLong("", "");
                      }
                  
                  }

          Comment


            #6
            Originally posted by calhawk01 View Post
            nO

            Code:
                    protected override void Initialize()
                    {
            
                        CalculateOnBarClose = true;
                        TraceOrders = true;
                    }
            Code:
                    protected override void OnBarUpdate()
                    {
                        double total = profit+trigger;
                        
                        if ((Position.MarketPosition == MarketPosition.Flat)
                            &&.....................................)
                        {
                            EnterLongLimit(..................);
                              SetProfitTarget("", CalculationMode.Ticks, total/.25);
                        }
            
                        if (Close[0] >= Position.AvgPrice + trail)              {                   SetTrailStop("", CalculationMode.Ticks, trail/.25, false);             }
            
                        if (ToTime(Time[0]) == ToTime(15, 57, 0))
                        {
                            ExitLong("", "");
                        }
                    
                    }
            That is the issue with the Set() methods. Once used, they exist for all time. That is why they need to be reset when you go flat.

            Comment


              #7
              how do i reset?

              Comment


                #8
                Hello calhawk01,

                Thank you for your response.

                An example of this is the following:
                Code:
                // Resets the stop loss to the original value when all positions are closed
                			if (Position.MarketPosition == MarketPosition.Flat)
                			{
                				SetStopLoss(CalculationMode.Ticks, stoplossticks);
                			}
                The above code was taken form the following reference sample: http://www.ninjatrader.com/support/f...ead.php?t=3222

                Please let me know if I may be of further assistance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X