Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I drag stop and target lines placed by strat?

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

    How do I drag stop and target lines placed by strat?

    I have a simple strategy that places an order, stop and target on the chart. But when I try to drag the stop to a new spot, it jumps back to the spot where the strategy originally put it. it makes sense since that value is "programmed" to a certain spot.

    But I downloaded a couple other strategies that also place trades (non ATM) and am able to move the stops and targets. But I can't find the code that is allowing that move.

    What do I need to allow dragging the stop and target?

    thanks
    Mike

    #2
    this is the code (not the final code) that I have

    PHP Code:
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "Break & Retest";
                    Calculate                                    = Calculate.OnEachTick;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
                    Risk                    = 600;
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                bool noTrades = Position.MarketPosition == MarketPosition.Flat;
                
                if (High[0] > Low[0] && noTrades)
                {
                    EnterLong(Convert.ToInt32(1), @"Long");
                    SetStopLoss(@"Long", CalculationMode.Ticks, 30, false);
                    SetProfitTarget(@"Long", CalculationMode.Ticks, 30);
    
                }
    
            }
    
            #region Properties
            [NinjaScriptProperty]
            [Range(1, int.MaxValue)]
            [Display(Name="Risk", Description="Risk per Trade in $", Order=1, GroupName="Parameters")]
            public int Risk
            { get; set; }
            #endregion
    ​ 
    

    Comment


      #3
      Hello cre8able,

      You can find a sample of that concept here:

      Comment


        #4
        got it
        thank you

        Comment


          #5
          I almost got it

          I'm using 2 buttons to place my trades

          Which order type do I use to place the stop limit order on a short? ExitShortStopLimit didn't work like ExitLongStopLimit works for a long trade

          PHP Code:
          
                  protected void Button3Click(object sender, RoutedEventArgs e)
                  {
                      if (Position.MarketPosition == MarketPosition.Flat)
                      {
                          EnterLong(orderQty, "Long");
                          ExitLongStopLimit(0, true, Position.Quantity, 0, Position.AveragePrice - 60 * TickSize, "Stop", "Long");
                          ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + 120 * TickSize, "Target", "Long");
                      }
                      
                      ForceRefresh();            
                  }
                  
                  protected void Button4Click(object sender, RoutedEventArgs e)
                  {
                      if (Position.MarketPosition == MarketPosition.Flat)
                      {
                          EnterShort(orderQty, "Short");
                          ExitShortStopLimit(0, true, Position.Quantity, 0, Position.AveragePrice + 60 * TickSize, "Stop", "Short");
                          ExitShortLimit(0, true, Position.Quantity, Position.AveragePrice - 120 * TickSize, "Target", "Short");
                      }
                      
                      ForceRefresh();
                  }
          
          ​ 
          
          Last edited by cre8able; 03-14-2025, 03:51 PM.

          Comment


            #6
            Hello cre8able,

            When submitting Exit order like you are you would need to do that once you are in a position, the orders are likely getting ignored because the position for the entry does not yet exist at that point. Those 3 lines of code are executed at the same time so the entry will not have filled or even been submitted yet. Using the SetStopLoss and SetProfitTarget can be used in that way because they wait for the order fill. You can see the following sample that shows how to wait for the entry to fill before submitting the targets.

            Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

            Comment


              #7
              that works.. thank you

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              33 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              124 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              64 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              41 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X