Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"global" stop loss

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

    #16
    Wow,, now it works..
    And what if I want to close all positions at a specific time?

    I used to close each position like this, but I think we need to change..
    if (ToTime(Time[0]) >= closeTrades)
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    ExitLong();
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShort();
    }
    }

    Comment


      #17
      Hello dafonseca,

      You can check the position in each BarInProgress and submit an order to each position.

      Or you can loop through the positions and submit an exit order using the BarsInProgress Index.

      For example:

      Code:
      for (var i = 0; i < Positions.Count; i++)
      {
      	if (Positions[i].MarketPosition == MarketPosition.Long)
      		ExitLong(i, Positions[i].Quantity, "", "");
      	else if (Positions[i].MarketPosition == MarketPosition.Short)
      		ExitShort(i, Positions[i].Quantity, "", "");
      }
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        I am amost there..
        But I had the following error message when tried the loop to close positions[i]:

        "SYSTEM ARRAY" DOES NOT CONTAIN A DEFINITION FOR "COUNT" AND NO EXTENSION METHOD COUNT ACCEPTING FIRST ARGUMENT OF TYPE SYSTEM ARRAY..

        Any clue?? what I did wrong.

        Comment


          #19
          I got the error solutions. In fact the right is this: (Account,,,,)

          for (var i = 0; i < Account.Positions.Count; i++)

          Comment


            #20
            So, Now that I got my multi strategy script. Let me understand this:

            Performance.AllTrades.TradesPerformance.Currency.C umProfit

            The method above will present the values considering all instruments,,
            so, in case wed lost 10.000 in GOOG and profit 30.000 in AAPL,,
            the result of Performance.AllTrades.TradesPerformance.Currency.C umProfit will be -70.000
            Am I right?

            Comment


              #21
              Another question would be.. how to trade the specific stock..
              I am trying to trade the third stock added like this:
              if (BarsInProgress == 3)
              {
              if (Positions[3].MarketPosition != MarketPosition.Short)
              {

              EnterShort(0,positionTakenAmzn12, ("ShortAmzn12"));

              }

              }

              but the order has been generated on instrumento [0]..
              What should I do?

              Comment


                #22
                Hello dafonseca,

                Thank you for your response.
                The method above will present the values considering all instruments,,
                so, in case wed lost 10.000 in GOOG and profit 30.000 in AAPL,,
                the result of Performance.AllTrades.TradesPerformance.Currency.C umProfit will be -70.000
                Am I right?
                You are correct that it is all instruments the strategy is trading.
                Another question would be.. how to trade the specific stock..
                I am trying to trade the third stock added like this:
                if (BarsInProgress == 3)
                {
                if (Positions[3].MarketPosition != MarketPosition.Short)
                {

                EnterShort(0,positionTakenAmzn12, ("ShortAmzn12"));

                }

                }

                but the order has been generated on instrumento [0]..
                What should I do?
                You need to change the barsInProgress Index to 3 in the EnterShort() method, like the following:
                Code:
                EnterShort(3,positionTakenAmzn12, ("ShortAmzn12"));

                Comment


                  #23
                  Originally posted by dafonseca View Post
                  Another question would be.. how to trade the specific stock..
                  I am trying to trade the third stock added like this:
                  if (BarsInProgress == 3)
                  {
                  if (Positions[3].MarketPosition != MarketPosition.Short)
                  {

                  EnterShort(0,positionTakenAmzn12, ("ShortAmzn12"));

                  }

                  }

                  but the order has been generated on instrumento [0]..
                  What should I do?
                  Which override of EnterShort() are you trying to use? the one that you have quoted makes little sense in the context of what you seem to be describing.

                  Comment


                    #24
                    A last question would be this:
                    Considering that I just want to open a new position (from all strategies on my multi strategy script) in case the total result (on current open positions) is not lower than -1000.00,
                    what would be the best way to set it up??

                    I tried this way below, but it is sayng the operator '<' can nt be used.

                    if (Performance.RealtimeTrades.TradesPerformance.Curr ency > stopThreshold);
                    {
                    if (BarsInProgress == 0)
                    {
                    EnterLong(0,positionTakenAapl3,"LongAapl3");

                    }
                    }

                    Comment


                      #25
                      I think I forget .CumProfit .....Now it is:

                      if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit > stopThreshold);

                      Comment


                        #26
                        Regarding the management of the positions,, How can I see my onpened orders?

                        I as seeing, there is no positions even o chart of instrument [0].
                        I d like to follow allpositions opened by the multi strategy script in real time..
                        Can I do it using charts? or there is another way to do so.

                        Comment


                          #27
                          I am confused,, What is the differencebetween RealTimeTrades and AllTrades???
                          I just want to get P&L for the opened poditions (not the positions which was closed for that day).
                          Is there any way to get this value??

                          Comment


                            #28
                            Hi dafonseca,

                            In my post #17 I had an error.

                            for (var i = 0; i < Positions.Count; i++)

                            Should be

                            for (var i = 0; i < Positions.Length; i++)


                            To find an open position, you will need to check the market position of the position.

                            For example:

                            if (Positions[0].MarketPosition == MarketPosition.Long)
                            {
                            // the position is long
                            }


                            Unrealized PnL is the profit or loss from all open trades. This is a trade with an entry but no exit.

                            Realized PnL is the profit or loss from all closed trades. These are trades with an entry and an exit.

                            Attached is a script that demonstrates how to exit a trade after a certain amount of realized + unrealized loss is hit.

                            Code similar to this will be needed for your script.


                            You can see any working orders and open positions on a separate chart with Chart Trader open and that instrument selected or from the SuperDOM with that instrument selected.
                            Attached Files
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Hi Chelsea,
                              I am confused here. First it seems that the script you sent works but not for multi strategy scripts.. As I see,
                              protected override void OnPositionUpdate(IPosition position)
                              {
                              if (Position.MarketPosition == MarketPosition.Flat && Performance.AllTrades.Count > 0)
                              {
                              Print (Performance.AllTrades[Performance.AllTrades.Count-1].ProfitCurrency);
                              currentPnL += Performance.AllTrades[Performance.AllTrades.Count-1].ProfitCurrency;

                              }
                              }
                              this code will not work for me since my position will barely be flat as I have many assets trading same time. Should I use an IF for each Positions[]???
                              Another question woulb be,, Performance.AllTrades[Performance.AllTrades.Count-1].ProfitCurrency seems to be in point per share. How can I get the money lost?
                              Posiyion.Quantity did not work for me.
                              Let me know.

                              Comment


                                #30
                                "You can see any working orders and open positions on a separate chart with Chart Trader open and that instrument selected or from the SuperDOM with that instrument selected."

                                Regarding your answer above. You mean, if I open AAPL chart (which isinstrument 0) ans run my multi strategy script there..
                                In case I have AMZN chart open (instrument [3]) I will see the position there? (i ve tried and I didnot see but..I will try again)..

                                What about P&L?? When we run the strategy there must be all assets traded with P&L showed.. (I mean on control center).
                                Is it possoble tocontrol it from control center ?(an instrument not [0]).

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                578 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                334 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
                                553 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                551 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X