• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy behavior

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

    Strategy behavior

    Our add an supports risk management,
    the strategy allows you to monitor our own risk parameters. As Trader you can set a daily risk limit, along with daily profit / target.
    if target or stop achieved our add on close open position of all instruments and delete all working orders. This is running well.

    Our problem if the closing and deleting process complete all strategy's automatically
    deactivated.

    In this case, traders can simply continue trading because the strategy disabled .
    Is there any way to hold the strategy alway activated.

    Thanks in advance
    Last edited by Aylin; 01-16-2018, 08:15 AM.
    Aylin
    NinjaTrader Ecosystem Vendor - RealTime Trading Global

    #2
    Hello Aylin,

    Thank you for your note.

    Please advise if an error or message is seen on the Log tab when this occurs.

    Do you have Log and Trace files of such an occurrence?

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      RTG Named User: NINJADEMO2
      Initializing hub...
      CloudStatus: True
      Enabling NinjaScript strategy 'RTGRiskManager/114346452' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=By strategy position ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
      OnStateChange Realtime
      XTHandler_RaiseConnectionStateUpdateEvent Open
      Authentication done
      Autorisk license available
      Report license available
      AddEventListeners
      RTG Named User: NINJADEMO2
      Initializing hub...
      Flatten
      OnStateChange Terminated
      Dispose rtg service
      RemoveEventListeners
      Shutdown complete...
      Disabling NinjaScript strategy 'RTGRiskManager/114346452'
      Flattern done
      Flatten
      Flattern done
      Flatten
      Flattern done
      OnAccountItemUpdate authState = False
      Flatten
      Flattern done
      Flatten
      Flattern done
      Flatten
      Flattern done
      Flatten
      Aylin
      NinjaTrader Ecosystem Vendor - RealTime Trading Global

      Comment


        #4
        Hello Aylin,

        Thank you for your response.

        What function are you calling in NinjaScript that is de-activating the strategies?

        I look forward to your response.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Account.Flatten(InstrumentsToCancel);
          Aylin
          NinjaTrader Ecosystem Vendor - RealTime Trading Global

          Comment


            #6
            Account.Flatten(InstrumentsToCancel);
            Print("Flattern done");
            // Thread.Sleep(2000);
            /*Print("Positions: " + MonitorAccount.Positions.Count);
            foreach (Position position in MonitorAccount.Positions)
            {
            //if (!InstrumentsToCancel.Contains(position.Instrument )){
            InstrumentsToCancel.Add(position.Instrument);
            Print("Quantity: " + Position.Quantity);
            Print("MarketPosition: " + Position.MarketPosition);
            Print("FullName: " + Position.Instrument.FullName);
            if (Position.MarketPosition == MarketPosition.Long)
            {
            Print("ExitLong");
            ExitLong();
            }
            else if (Position.MarketPosition == MarketPosition.Short)
            {
            Print("ExitShort");
            ExitShort();
            }
            //}

            }*/

            /*Print("Orders: " + MonitorAccount.Orders.Count);
            foreach (Order order in MonitorAccount.Orders)
            {

            }*/
            Aylin
            NinjaTrader Ecosystem Vendor - RealTime Trading Global

            Comment


              #7
              Hi Patrick
              I thing the account flattern ist the reason why the stragie disabled.
              I would be grait if you can provide us code snippet which close and delete all position from each instrument

              Or you can see our alternative code may you have some improcments


              private void AutoFlattern(){ //Account.Flatten(InstrumentList); foreach (Position position in MonitorAccount.Positions){ Print("AUTOFLATTERN : " + position.Instrument.FullName); if(position.MarketPosition== MarketPosition.Long){ Print("ExitLong: " + position.Quantity); //EnterShort(position.Quantity, "RTG"); ExitLong(); } else if(position.MarketPosition== MarketPosition.Short){ Print("ExitShort: " + position.Quantity); //EnterLong(position.Quantity, "RTG"); ExitShort(); }else{ Print("Not supported type"); } } }
              Aylin
              NinjaTrader Ecosystem Vendor - RealTime Trading Global

              Comment


                #8
                Hello Aylin,

                Thank you for your response.

                You are correct in that Account.Flatten() will disable the strategies. You need to submit orders to close the positions and cancel the orders rather than call Flatten which also disables the strategies.

                Please visit the Account section for Add Ons in the Help Guide for other functions such as Cancel, Change, and Submit: https://ninjatrader.com/support/help...ount_class.htm

                Please let me know if you have any questions.
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  What do you thing about this code

                  #region Flatten_All()
                  void Flatten_All()
                  {
                  lock (Account.Positions)
                  {
                  // Print("");
                  // Print("-------------- Flatten report ----------------");

                  var positions = Account.Positions.Where( x => x.Instrument == Instrument );
                  if( positions.Count() != 0 )
                  {
                  Print( Name +", "+ Instrument.FullName +", "+ BarsArray[0].BarsPeriod +": обнаружено открытых позиций: " + positions.Count().ToString() );
                  Account.Flatten( new [] { Instrument } );
                  return;
                  }
                  }

                  var orders = Account.Orders.Where( x => x.Instrument == Instrument && !Order.IsTerminalState( x.OrderState) );
                  if( orders.Count() != 0 )
                  {
                  Print( Name +", "+ Instrument.FullName +", "+ BarsArray[0].BarsPeriod +": обнаружено активных ордеров: " + orders.Count().ToString() );
                  Account.Cancel( orders );
                  }
                  Print("");
                  }



                  Thanks
                  Aylin
                  NinjaTrader Ecosystem Vendor - RealTime Trading Global

                  Comment


                    #10
                    Hello Aylin,

                    Thank you for your response.

                    Account.Flatten() would still disable any strategy on the instrument.

                    Please let me know if you have any questions.
                    Patrick H.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Aylin,

                      Thank you for your patience.

                      I recommend you use CancelAllOrders to cancel the remaining orders. For example:
                      Code:
                      Account.CancelAllOrders(Instrument)
                      You need to refer to the details at the following link for more information: https://ninjatrader.com/support/help...lallorders.htm

                      You also need to check the current positions of the instruments and then submit orders to close those positions. Utilizing Positions and the Account.PositionUpdate you will check the position. Please refer to the following link for an example: https://ninjatrader.com/support/help...tionupdate.htm

                      To submit an order you need to use CreateOrder and Submit:
                      CreateOrder: https://ninjatrader.com/support/help...reateorder.htm
                      Submit: https://ninjatrader.com/support/help...-us/submit.htm

                      Please let me know if you need further examples on this matter.
                      Patrick H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by alfonso, Today, 10:21 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post alfonso
                      by alfonso
                       
                      Started by saeed, Today, 10:20 AM
                      1 response
                      3 views
                      0 likes
                      Last Post saeed
                      by saeed
                       
                      Started by ntbone, Yesterday, 05:21 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by ntbone, Yesterday, 04:05 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by tonynt, Today, 09:35 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_ChrisL  
                      Working...
                      X