Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop trail and take profit

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

    stop trail and take profit

    hi
    i use simple script and if rsi >60
    give me signal and work atm automatically but when i start playback after some minute i got below error.
    what is problem?

    #2
    Hello f.saeidi,

    That message shows that the stop price being used was above market so it was rejected. That can happen if the stop price being used is too close to the current market price and there is a fast movement in price which allows for a stop to be submitted with an invalid price. As a first step you can try increasing the stop distance to see if that resolves the rejection.

    As a side note when using ATM's from a NinjaScript strategy in Playback you should only use 1X speed like you would have in a realtime use case. ATM's are not like a normal NinjaScript strategy which submits its own orders, the strategy is just managing the live ATM. Because of that fast forwarding will not allow the strategies ATM handling logic to work correctly.

    Comment


      #3
      thnx for notes.
      in below code i want if 1,5,15,30,60 min in up trend when (rsi > 60 in 30 second time ) give me buy position.
      when i apply 1,5,15,30 min its work fine
      but when i apply 60 min its not give me signal.
      what is problem with 60 minute?


      region Using declarations
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.ComponentModel.DataAnnotations;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Windows;
      using System.Windows.Input;
      using System.Windows.Media;
      using System.Xml.Serialization;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui;
      using NinjaTrader.Gui.Chart;
      using NinjaTrader.Gui.SuperDom;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.Core.FloatingPoint;
      using NinjaTrader.NinjaScript.Indicators;
      using NinjaTrader.NinjaScript.DrawingTools;
      #endregion

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class FinalStrategy : Strategy
      {

      double ThirtySecOpen;
      double ThirtySecClose;
      double ThirtySecBid;




      double oneMinOpen;
      double oneMinClose;
      double oneMinBid;

      double fiveMinOpen;
      double fiveMinClose;
      double fiveMinBid;

      double fifteenMinOpen;
      double fifteenMinClose;
      double fifteenMinBid;


      double thirtyMinOpen;
      double thirtyMinClose;
      double thirtyMinBid;


      double sixtyMinOpen;
      double sixtyMinClose;
      double sixtyMinBid;


      double twohundredMinOpen;
      double twohundredMinClose;
      double twohundredMinBid;


      double dailyMinOpen;
      double dailyMinClose;
      double dailyMinBid;


      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Strategy here.";
      Name = "FinalStrategy";
      Calculate = Calculate.OnBarClose;
      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 =5;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Qty = 1;
      Sl = 6;
      }
      else if (State == State.Configure)
      {
      SetTrailStop(@"long", CalculationMode.Ticks, Sl, false);
      SetTrailStop(@"short", CalculationMode.Ticks, Sl, false);

      AddDataSeries(null, BarsPeriodType.Second,30);
      AddDataSeries(null,BarsPeriodType.Minute,1);
      AddDataSeries(null,BarsPeriodType.Minute,5);
      AddDataSeries(null,BarsPeriodType.Minute,15);
      AddDataSeries(null,BarsPeriodType.Minute,30);
      AddDataSeries(null,BarsPeriodType.Minute,60);
      AddDataSeries(null,BarsPeriodType.Minute,240);
      AddDataSeries(null, BarsPeriodType.Day,1);

      }
      }

      protected override void OnBarUpdate()
      {

      if (CurrentBars[0] < 5|| CurrentBars[1] < 5 || CurrentBars[2] < 5 ||
      CurrentBars[3] < 5 || CurrentBars[4] < 5 || CurrentBars[5] < 5 || CurrentBars[6] < 5)

      return;


      if (BarsInProgress ==1) // multi time 30 sec


      {
      ThirtySecOpen= Open[0];
      ThirtySecClose = Close[0];
      ThirtySecBid= GetCurrentBid();




      }





      if (BarsInProgress ==2) //multi time 1 min
      {
      oneMinOpen = Open[0];
      oneMinClose = Close[0];
      oneMinBid = GetCurrentBid();
      }


      if (BarsInProgress ==3) //multi time 5 min
      {

      fiveMinOpen = Open[0];
      fiveMinClose = Close[0];
      fiveMinBid = GetCurrentBid();
      }


      if (BarsInProgress ==4) //multi time 15 min
      {

      fifteenMinOpen = Open[0];
      fifteenMinClose = Close[0];
      fifteenMinBid = GetCurrentBid();
      }


      if (BarsInProgress ==5) //multi time 30 min
      {

      thirtyMinOpen = Open[0];
      thirtyMinClose = Close[0];
      thirtyMinBid = GetCurrentBid();
      }


      if (BarsInProgress ==6) //multi time 60 min
      {

      sixtyMinOpen = Open[0];
      sixtyMinClose = Close[0];
      sixtyMinBid = GetCurrentBid();
      }




      if( (oneMinBid > oneMinOpen ) & (fiveMinBid > fiveMinOpen) & (fifteenMinBid > fifteenMinOpen ) & (thirtyMinBid > thirtyMinOpen) & (sixtyMinBid > sixtyMinOpen ) & CrossAbove(RSI(25,3),60,1) )
      {
      EnterLong(Convert.ToInt32(Qty), @"long");
      }












      }

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

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

      }
      }

      Comment


        #4
        Hello

        In this case you would need to use a print before your condition to see why changing the timeframe makes the condition false.

        Code:
        Print(Time[0] + $"{oneMinBid} > {oneMinOpen} && {fiveMinBid} > {fiveMinOpen}"); // you could add each of the variables to the print to see all of them
        
        if( (oneMinBid > oneMinOpen ) & (fiveMinBid > fiveMinOpen) & (fifteenMinBid > fifteenMinOpen ) & (thirtyMinBid > thirtyMinOpen) & (sixtyMinBid > sixtyMinOpen ) & CrossAbove(RSI(25,3),60,1) )
        Another problem is that you are using single & which is doing a bitwise operation and is not doing a normal AND operation. Those should be &&

        Code:
        if( (oneMinBid > oneMinOpen ) && (fiveMinBid > fiveMinOpen) && (fifteenMinBid > fifteenMinOpen ) && (thirtyMinBid > thirtyMinOpen) && (sixtyMinBid > sixtyMinOpen ) && CrossAbove(RSI(25,3),60,1) )

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X