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

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.

    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.

        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.

                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.

                    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.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by chbruno, Today, 04:10 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Started by josh18955, 03-25-2023, 11:16 AM
                      6 responses
                      436 views
                      0 likes
                      Last Post Delerium  
                      Started by FAQtrader, Today, 03:35 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post FAQtrader  
                      Started by rocketman7, Today, 09:41 AM
                      5 responses
                      19 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by frslvr, 04-11-2024, 07:26 AM
                      9 responses
                      127 views
                      1 like
                      Last Post caryc123  
                      Working...
                      X