Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"global" stop loss

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

    "global" stop loss

    I want to set up a stop loss like this:
    I have 10 strategies running same time, in case, any time of the day, the sum of losses were above X (current trades and cumulative losses, for that day) , all strategies positions would be closed and the system will not trade same day.
    Is it possible? how?

    #2
    Hello dafonseca,

    This is not supported by NinjaTrader.

    You may be able to accomplish this by looping through the accounts and using logic to find the information you need.

    Below is a small sample of code to get you started.
    Code:
    foreach (Account acct in Cbi.Globals.Accounts)
    {
    if (acct.Positions != null)
    {
    // print information about each position
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice);
    }
    // print information about each order
    OrderCollection orders = acct.Orders;
    foreach (Order ord in orders)
    {
    Print(ord.ToString());
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      You mean, each strategy would check all positions and send a order, in case.
      this part of code would be inside onBarUpdate(), right?

      Comment


        #4
        dafonseca, no this would need to come from one monitoring script then. It would be easier if you trade with one MultiSeries script probably that would implement your signals across markets, then the script would have access to the positions and you would not need to find a way to potentially cross communicate across instances.

        Comment


          #5
          So, today I ve traded 5 different assets using 5 different strategies, You are saying tht working with one multiseries strategies would be a better approach. A bigger code which would control everything including my global stop loss policy, Am I rught?

          Just for me to understand, in case I do not need to use a global stop loss ike this, would the multi series strategy approach a better solution for me? why would be that?

          Comment


            #6
            dafonseca, the MultiSeries script will mean you are working in one script only and thus have access to all strategy positions. That's the advantage of trying to implement a global stop loss using undocumented means. The 'downside' is you're working with one larger code base then.

            Comment


              #7
              I have a question regarding multiSeries script. What about instrument[0].. How would we trade nasdaq and sp500 ?? which chart would we run the strategy?
              I am confused.

              Comment


                #8
                The primary instrument would always be the one you have selected to run the script on, either from the chart or the strategies tab. The next slots would be determined by your Add() bars objects in the script's Initialize().

                For an example you could check into the SampleMultiInstrument script directly installed per default with NT (for the full detailed docs, please check into this online resource https://www.ninjatrader.com/support/...nstruments.htm)

                Comment


                  #9
                  I am trying to develope the multistrategy script.. I have a question:

                  I used to control my P&L like this:
                  if (Position.MarketPosition == MarketPosition.Long)
                  But now, having several positions on different assets how can I recognize an specificposition on AAPL for instance?

                  Where can I get information o total P7L control,?
                  Regards,

                  Comment


                    #10
                    Hello dafonseca,

                    You will need to check the position of each separate instrument. (If an instrument is already added to the chart, the positions will reflect the first instance of Positions where this instrument is used)

                    For example:
                    Print(Positions[1].MarketPosition.ToString());

                    This would print the position of the second added price data series.

                    http://www.ninjatrader.com/support/h.../positions.htm
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Let me check if I got it right

                      Add("GOOG", PeriodType.Minute,1); //1

                      Add("AMZN",PeriodType.Minute,1); //3

                      Running a script like that on AAPL,,
                      position[0] will all ways be aapl,
                      position[1] -> goog
                      position[2] --> amzn

                      Am i right?

                      Comment


                        #12
                        I have used the position[number] as you said.
                        But my script is showing this error:

                        CANNOT APLY IDEXING WITH [] TO AN EXPRESSION OF A TYPE NINJA TRADER CBI.POSITION..
                        What should I do?

                        Do I have to insert any line ant INITISTE??? in order to use it..

                        Comment


                          #13
                          Hello dafonseca,

                          What is the line of code you are using?

                          Is it something like:
                          if (Positions[1].MarketPosition == MarketPosition.Flat)

                          No initiation is needed as the Positions variable is created by the NinjaTrader core and is updated when OnPositionUpdate is run.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            I am using this:

                            if (BarsInProgress == 0)
                            {

                            if (Position[0].MarketPosition != MarketPosition.Long)
                            {
                            EnterLong(0,positionTakenAapl3,"LongAapl3");
                            }

                            }
                            But the error is there!

                            Comment


                              #15
                              Hello dafonseca,

                              You are using Position. I am suggesting you use Positions.

                              Position - http://www.ninjatrader.com/support/h...7/position.htm

                              Positions - http://www.ninjatrader.com/support/h.../positions.htm

                              This is also the difference between Close[0] and Closes[0][0].
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              571 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              330 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              548 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              549 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X