Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stops NOT Working

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

    Stops NOT Working

    Ninja Nation - need help. I cannot get my stops to work. Stops are +/- 1 tick from previous high or low. Although you'll see it not working...something in code?

    (also trail stop not working but I'm assuming its probably related). Thanks!


    Click image for larger version

Name:	Wallpaper 2.JPG
Views:	304
Size:	131.1 KB
ID:	1096557Click image for larger version

Name:	Wallpaper.jpg
Views:	313
Size:	138.0 KB
ID:	1096556

    #2
    Too little context to your code.
    Is this OnBarUpdate?


    Comment


      #3
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "X";
      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.ByStrategyPosition;
      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      LT1 = 1;
      LT2 = 1;
      LT3 = 5;
      ST1 = 1;
      ST2 = 1;
      ST3 = 5;
      Stop = 1;
      }
      else if (State == State.Configure)
      {
      AddDataSeries("GC 06-20", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
      }
      else if (State == State.DataLoaded)
      {
      SMA1 = SMA(Close, 50);
      SMA1.Plots[0].Brush = Brushes.Goldenrod;
      AddChartIndicator(SMA1);
      SetProfitTarget("", CalculationMode.Ticks, LT1);
      SetProfitTarget("", CalculationMode.Ticks, LT2);
      SetProfitTarget("", CalculationMode.Ticks, ST1);
      SetProfitTarget("", CalculationMode.Ticks, ST2);
      SetStopLoss("", CalculationMode.Price, Stop, false);


      }
      }
      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 3)
      return;

      // LONG ENTER
      if ("hidden code" && Position.MarketPosition == MarketPosition.Flat)
      {

      EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE1");
      EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE2");
      EnterLongStopMarket(High[1] + (1 * TickSize),"R3 LE3");
      }

      // LONG EXIT
      if (Position.MarketPosition == MarketPosition.Long)

      {
      //ExitLong(Convert.ToInt32(DefaultQuantity), @"Lx1", "");
      SetProfitTarget("R3 LE1",CalculationMode.Ticks,LT1);
      SetProfitTarget("R3 LE2",CalculationMode.Ticks,LT2);
      SetProfitTarget("R3 LE3",CalculationMode.Ticks,LT3);
      SetStopLoss("R3 LE1", CalculationMode.Price,Low[1]-1*TickSize,false);
      SetStopLoss("R3 LE2", CalculationMode.Price,Low[1]-1*TickSize,false);
      SetStopLoss("R3 LE3", CalculationMode.Price,Low[1]-1*TickSize,false);
      // SetTrailStop("R3 LE1",CalculationMode.Ticks,Stop,false);
      // SetTrailStop("R3 LE2",CalculationMode.Ticks,Stop,false);
      // SetTrailStop("R3 LE3",CalculationMode.Ticks,Stop,false);

      }
      // SHORT ENTER
      if ("hidden code" && Position.MarketPosition == MarketPosition.Flat)
      {
      EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE1");
      EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE2");
      EnterShortStopMarket(Low[1] - (1 * TickSize),"R3 SE3");
      }

      // SHORT EXIT
      if (Position.MarketPosition == MarketPosition.Short)

      {
      SetProfitTarget("R3 SE1",CalculationMode.Ticks,ST1);
      SetProfitTarget("R3 SE2",CalculationMode.Ticks,ST2);
      SetProfitTarget("R3 SE3",CalculationMode.Ticks,ST3);
      SetStopLoss("R3 SE1", CalculationMode.Price,High[1]+1*TickSize,false);
      SetStopLoss("R3 SE2", CalculationMode.Price,High[1]+1*TickSize,false);
      SetStopLoss("R3 SE3", CalculationMode.Price,High[1]+1*TickSize,false);
      // SetTrailStop("R3 SE1",CalculationMode.Ticks,Stop,false);
      // SetTrailStop("R3 SE2",CalculationMode.Ticks,Stop,false);
      // SetTrailStop("R3 SE3",CalculationMode.Ticks,Stop,false);
      }

      }

      #region Properties
      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="LT1", Order=1, GroupName="Parameters")]
      public int LT1
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="LT2", Order=2, GroupName="Parameters")]
      public int LT2
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="LT3", Order=3, GroupName="Parameters")]
      public int LT3
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="ST1", Order=4, GroupName="Parameters")]
      public int ST1
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="ST2", Order=5, GroupName="Parameters")]
      public int ST2
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="ST3", Order=6, GroupName="Parameters")]
      public int ST3
      { get; set; }

      [NinjaScriptProperty]
      [Range(1, int.MaxValue)]
      [Display(Name="Stop", Order=7, GroupName="Parameters")]
      public int Stop
      { get; set; }
      #endregion

      }
      }

      Comment


        #4
        sorry I was trying to hide actual logic. Above is the code minus Entry logic

        Comment


          #5
          Hi elcowen,
          I only had a quick glance. The first thing to consider here is entry handling: EntryHandling.UniqueEntries.
          NT-Roland

          Comment


            #6
            Hi elcowen, thanks for your question.

            Regrettably, the support team is not allowed to debug custom code. We have a guide here on working out bugs in your scripts:



            Kind regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Understood. I'm not trying to get free work from you guys. However, I think I narrowed down the issue and if you could steer me in the right direction I would appreciate that.

              Here's the Error I keep getting across several strategies. However I have no idea how it got this number (which isnt even close to the market)??

              Is this an entry, exit, order management issue?? thank you


              Click image for larger version

Name:	Wallpaper 2.JPG
Views:	289
Size:	197.5 KB
ID:	1096628


              Comment


                #8
                This happens across all strategies. I read it might be a OCO unique identifier issue? Does that sound right. Below is the strategy's OCO column where Entry & Exit have same OCO ID.... Does this like a OCO unique ID issue? If so, is there a template I can use to update my script? Thank you!


                Click image for larger version

Name:	Wallpaper.jpg
Views:	311
Size:	130.7 KB
ID:	1096635

                Comment


                  #9
                  Hello elcowen,

                  Thanks for your reply.

                  The error message in your post #7 is advising that your strategy code tried place a sell stop (market) or sell stop limit order above the current price and the message identifies the specific order at sell stop market at 1761.6. You will need to debug your strategy to find out why it is placing the order incorrectly. It may be a matter of checking the current price before placing the order to ensure it is appropriate.

                  The OCO column shows what orders are tied together. If you expand out the name colum, the two orders (in each example) are the Profit Target and Stop loss which should be OCO tied and would be expected to have the same number.

                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  16 responses
                  3,281 views
                  0 likes
                  Last Post Leafcutter  
                  Started by WHICKED, Today, 12:45 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post WHICKED
                  by WHICKED
                   
                  Started by Tim-c, Today, 02:10 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Taddypole, Today, 02:47 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post Taddypole  
                  Started by chbruno, 04-24-2024, 04:10 PM
                  4 responses
                  53 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Working...
                  X