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.

    #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

      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);

          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)
            {

            }*/

            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"); } } }

              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

                  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 NullPointStrategies, Yesterday, 05:17 AM
                      0 responses
                      62 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      134 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      75 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
                      50 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X