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

SetStopLoss in Strategy not submitted in Market Replay Modus

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

    SetStopLoss in Strategy not submitted in Market Replay Modus

    I try to test a strategy in Replay Modus, but the SetStopLoss doesn't work.
    It does in Realtime Connection:
    Is this "the state of the art" will say this is not possible in the release of NT 7?

    Is it possible to unable a strategy within a strategy?
    Thank you.
    Last edited by RolfTheus; 11-23-2013, 02:09 PM.

    #2
    Hello RolfTheus,

    Thank you for your post.

    The SetStopLoss() will work the same in Market Replay as it would in real-time. Likely there is an error reported for this order when it is attempted to be submitted in Market Replay. do you see any errors reported in the Log tab of the NinjaTrader Control Center when the SetStopLoss() should be submitted? If so, what does this error or errors report?

    If you enable TraceOrders, do you see any information in the Output Window (Tools > Output Window) in regards to this order?

    Information on TraceOrders can be found at the following link: http://www.ninjatrader.com/support/h...raceorders.htm

    To disable a strategy within itself you can use Disable(), but this cannot be used to disable other strategies: http://www.ninjatrader.com/support/h...t7/disable.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hallo Patrick,

      The disable function works fine.


      In Market Replay the SetStopLoss doesn't work although it works in realtime Modus.
      This is the output of the outputwindow with TraceOrders set to true:

      *******************************
      **NT** Enabling NinjaScript strategy 'MyTestStopper/86a4b4ec0e4c4327b8c456b49a900e91' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=UniqueEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes
      MyTestStopper: changed multiplier:1,3
      MyTestStopper: changed deviationValue:0,15
      FDAX

      Trendsterne: 1
      Trend: 9
      mar****rderLong True
      mar****rderShort False
      limitPrice 0
      stopPrice 0
      targetPrice 0

      setSystemStoppInTicks True
      initialStoppInTicks 40
      initialStoppAsPrice 0
      trailingStoppAt 0,5
      breakEvenAt 1

      posSize 10
      risc 5000

      Strategie fortsetzen?
      11.11.2013 11:35:00 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long' Mode=Ticks Value=40 Currency=0 Simulated=True
      11.11.2013 11:35:00 Entered internal PlaceOrder() method at 11.11.2013 11:35:00: BarsInProgress=0 Action=Buy OrderType=Market Quantity=10 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''

      *******************************

      but i don't see a stopporder in the chart or in the orders tag of the cc.

      this i my code before i open a postion per EnterShort(posSize,"Short"); for short i.e.:


      SetStopLoss("Short",CalculationMode.Price,initialS toppAsPrice,true);
      EnterShort(posSize,"Short");


      Is it possible, when starting a strategy in chartwindow to display the orders and stops and targets after enabling the strategy in the chart?

      Thank You

      Rolf
      Last edited by RolfTheus; 11-26-2013, 03:42 AM.

      Comment


        #4
        Hello Rolf,

        Thank you for your response.

        This is possible by opening another chart and enabling the Chart Trader (right click > Properties > Show Chart Trader = True > OK) to see the orders. The Chart Trader and strategies cannot be ran on the same chart.

        Please let me know if you do not see the Stop Loss plotted on the chart.

        Comment


          #5
          Hallo Patrick,

          Thank you, I know, but wouldn't it be nicer, if you only need one chart:
          The chart where the strategy is started and when the Position is opened you can see all the other Orders: targets, Trailingstops,
          with the loaded Indicators which determine the open of the position, the trailing of the stops, the own graphical Objects. (My strategy can read horizontal lines (specified by different colors) in the chart which detemine the Entry, Stop and Target)

          When I need to open another chart, i have to reorganize all this again (at least the graphical Objects) a second time.

          May be a feature in the next release ? I would like it.


          Thanks

          Rolf
          Last edited by RolfTheus; 11-26-2013, 11:30 AM.

          Comment


            #6
            Hello Rolf,

            Thank you for your response.

            I have forwarded your request to our development team. However, the Chart Trader can close the orders from the strategy and thus disable the strategy. You can use Draw() method to have custom drawing objects displaying your orders on the chart, for information on the Draw() methods please visit the following link: http://www.ninjatrader.com/support/h...t7/drawing.htm

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

            Comment


              #7
              Hallo Patrick,

              Thank you for the answer,

              I have still another problem:


              I have tried to use SetStopLoss("Long",CalculationMode.Price,initialSt oppAsPrice,true); with the last parameter to true for all Contracts opened by EnterLong(posSize,"Long");
              But then i cannot identify the stopprice in the OnOrderUpdate because it is always: order.StopPrice=0;
              Where can i identify the stoppPrice in which callback?


              When i use
              for (int i=1; i<=posSize; i++)
              SetStopLoss("Long",CalculationMode.Ticks,initialSt oppInTicks,false);
              then i get a stopprice by OnOrderUpdate but the initial stopporders are sometimes different by one tick when posSize > 1.



              Thanks

              Rolf

              Comment


                #8
                Hello Rolf,

                Thank you for your response.

                The StopPrice is never true for the order that is simulated as it is never truly a Stop Market order, when it's price is reached it is submitted as a Market order. The price here is not technically a StopPrice as there is no Stop Market order price. You can calculate the price based on where you submitted it for the double value of the SetStopLoss() when it was submitted if it is submitted within the OnBarUpdate() method. For example:
                Code:
                			if(Position.MarketPosition == MarketPosition.Long)
                			{
                				SetStopLoss(CalculationMode.Price, Instrument.MasterInstrument.Round2TickSize(EMA(20)[0]));
                				Print(EMA(20)[0]);
                			}
                Please let me know if you have any questions.

                Comment


                  #9
                  Hallo Patrick,
                  Thank you for the quick answer. I have much more to understand and i could integrate your advice very good.Thank you very much.

                  What is about the problem with the Market Replay?

                  Thank You

                  Rolf

                  Comment


                    #10
                    Hello Rolf,

                    Thank you for your response.
                    11.11.2013 11:35:00 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Long' Mode=Ticks Value=40 Currency=0 Simulated=True
                    Thank you for providing this information from the TraceOrders in the Output window, this is helpful as I tested this on my end and the SetStopLoss() set to simulated = true does not visualize in Market Replay on the Chart Trader on another chart. I will follow up here when I have additional information on this item.

                    Please let me know if you have any questions.

                    Comment


                      #11
                      Hello Rolf,

                      Thank you for your suggestion on how we can improve our product to display the orders on the chart the strategy is enabled on. It has been inserted into our tracking system with the unique ID # 62.

                      Comment


                        #12
                        Hallo Patric,

                        is it possible to change the quantity of a stop- and target-order during the lifetime of a position in a strategy?


                        my code and the log:
                        bool scaleOut(bool l)
                        {

                        int quantity = (int)(posSize*scaleOutFraction);

                        if(l)ExitLong(quantity, "ScaleOutLong", "Long");
                        else
                        ExitShort(quantity, "ScaleOutShort", "Short");


                        posSize=posSize-quantity;

                        if( Position.MarketPosition == MarketPosition.Long )
                        {

                        if(stopOrder != null) CancelOrder(stopOrder);
                        stopOrder = ExitLongStop(posSize, lastLongStop, "stop", "Long");


                        if(targetOrder != null) CancelOrder(targetOrder);
                        if(targetOrder != null)targetOrder = ExitLongLimit(posSize, targets[0], "target", "Long");

                        }
                        else if( Position.MarketPosition == MarketPosition.Short )
                        {

                        if(stopOrder != null) CancelOrder(stopOrder);
                        stopOrder = ExitShortStop(posSize, lastShortStop, "stop", "Short");


                        if(targetOrder != null) CancelOrder(targetOrder);
                        if(targetOrder != null)targetOrder = ExitShortLimit(posSize, targets[0], "target", "Short");

                        }

                        return true;

                        }

                        The method works but after a few seconds i get this:
                        My new Stop- and Targetorder are canceled.


                        23.12.2013 21:04:56 Cancelled expired order: BarsInProgress=0: Order='4a909543404c4f7ea3eb918c12b6669e/Sim101' Name='stop' State=Accepted Instrument='CL 02-14' Action=Sell Limit price=0 Stop price=98,47 Quantity=3 Strategy='MTS' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4a909543404c4f7ea3eb918c12b6669e' Gtd='01.12.2099 00:00:00'
                        23.12.2013 21:04:56 Cancelled expired order: BarsInProgress=0: Order='67e97f0951f743579ab49d63fea9f3ad/Sim101' Name='target' State=Working Instrument='CL 02-14' Action=Sell Limit price=99,22 Stop price=0 Quantity=3 Strategy='MTS' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='67e97f0951f743579ab49d63fea9f3ad' Gtd='01.12.2099 00:00:00'

                        Thank You


                        Rolf Theus
                        Last edited by RolfTheus; 12-23-2013, 02:09 PM.

                        Comment


                          #13
                          RolfTheus,

                          You have the correct logic for adjusting your Exit Orders. However, all those logs are telling you is that the condition for the exit was not true on the next Bar Update and thus they were cancelled. You would need to include a Live until Cancelled property to the orders -
                          http://www.ninjatrader.com/support/h...r_handling.htm
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hallo Patrick,

                            Thank you, works fine,

                            Rolf

                            Comment


                              #15
                              Strategie MySampleMACrossOver

                              Hallo,

                              what is wrong with this code:
                              I have modified the SampleMACrossOver and have run it under Replay data:

                              See te errormessages at the end
                              Thank You
                              Rolf Theus


                              namespace NinjaTrader.Strategy
                              {
                              /// <summary>
                              /// Simple moving average cross over strategy.
                              /// </summary>
                              [Description("Simple moving average cross over strategy.")]
                              public class MySampleMACrossOver : Strategy
                              {
                              #region Variables
                              private int fast = 10;
                              private int slow = 25;
                              private IOrder entryOrder = null;
                              private int internPosSize=1;
                              #endregion

                              /// <summary>
                              /// This method is used to configure the strategy and is called once before any strategy method is called.
                              /// </summary>
                              protected override void Initialize()
                              {
                              SMA(Fast).Plots[0].Pen.Color = Color.Orange;
                              SMA(Slow).Plots[0].Pen.Color = Color.Green;

                              Add(SMA(Fast));
                              Add(SMA(Slow));

                              CalculateOnBarClose = true;
                              }

                              protected override void OnExecution(IExecution execution)
                              {
                              Print("OnExecution entryOrder: " + entryOrder +" execution.Order: " + execution.Order);
                              if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                              {
                              Print("OnExecution 2 execution.Order.Filled:" + execution.Order.Filled +
                              " execution.Order.OrderState : " + execution.Order.OrderState +
                              " OrderState.Filled: " + OrderState.Filled +
                              " OrderState.PartFilled: " + OrderState.PartFilled );

                              }
                              }
                              /// <summary>
                              /// Called on each bar update event (incoming tick).
                              /// </summary>
                              protected override void OnBarUpdate()
                              {
                              if (CrossAbove(SMA(Fast), SMA(Slow), 1))
                              entryOrder=EnterLong(internPosSize,"Long");
                              else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
                              entryOrder=EnterShort(internPosSize,"Long");
                              }

                              #region Properties
                              /// <summary>
                              /// </summary>
                              [Description("Period for fast MA")]
                              [GridCategory("Parameters")]
                              public int Fast
                              {
                              get { return fast; }
                              set { fast = Math.Max(1, value); }
                              }

                              /// <summary>
                              /// </summary>
                              [Description("Period for slow MA")]
                              [GridCategory("Parameters")]
                              public int Slow
                              {
                              get { return slow; }
                              set { slow = Math.Max(1, value); }
                              }
                              #endregion
                              }
                              }


                              ***********************
                              **NT** Enabling NinjaScript strategy 'MySampleMACrossOver/6dc5b53172494f85a53dd1b43d1e3d5d' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=True CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
                              OnExecution entryOrder: Order='NT-00000/Replay101' Name='Long' State=Filled Instrument='FDAX 03-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='MySampleMACrossOver' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=9636,5 Token='49ed0865c78b49338e76e8de0b70ebe5' Gtd='01.12.2099 00:00:00' execution.Order: Order='NT-00000/Replay101' Name='Long' State=Filled Instrument='FDAX 03-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='MySampleMACrossOver' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=9636,5 Token='49ed0865c78b49338e76e8de0b70ebe5' Gtd='01.12.2099 00:00:00'
                              OnExecution 2 execution.Order.Filled:1 execution.Order.OrderState : Filled OrderState.Filled: Filled OrderState.PartFilled: PartFilled
                              OnExecution 2 execution.Order.Filled:1 execution.Order.OrderState : Filled OrderState.Filled: Filled OrderState.PartFilled: PartFilled
                              OnExecution entryOrder: Order='NT-00002/Replay101' Name='Long' State=Working Instrument='FDAX 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='MySampleMACrossOver' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='33e9649987344455936969a768569f7d' Gtd='01.12.2099 00:00:00' execution.Order:
                              **NT** Error on calling 'OnExecution' method for strategy 'MySampleMACrossOver/6dc5b53172494f85a53dd1b43d1e3d5d': Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by FishTrade, Yesterday, 11:11 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post FishTrade  
                              Started by Graci117, Today, 09:02 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by ETFVoyageur, Today, 07:55 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by janio973, Today, 07:24 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by aligator, 01-06-2022, 12:14 PM
                              4 responses
                              250 views
                              0 likes
                              Last Post john_44573  
                              Working...
                              X