Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MarketPosition question

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

    MarketPosition question

    Hi everyone,

    What is the function to check the last closed position, if was long or short and if it was in profit or loss?
    Postion.MarketPosition == MarketPosition.Long I check actual position if it is long, if I want to check last closed position?

    Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0
    Is this correct to check if the actual position it is in gain?
    I check the total profit or the profit of actual open position only?
    I need to check if the last closed position was in profit or loss.

    Thank you

    #2
    Please take a look here: http://www.ninjatrader-support.com/v...ead.php?t=4084

    Comment


      #3
      Good example, profit and loss are monitoring during the session, but I do not understand how can I check the last closed position, if it was long or short.

      Postion.MarketPosition == MarketPosition.Long

      this is the actual condition if I have long trade open.
      Which is the expression for the previous closed trade if it was long or short?

      Comment


        #4
        You could check the Performance class, see the Help Guide on this or just hold an internal variable indicating last known position.
        RayNinjaTrader Customer Service

        Comment


          #5
          I have the same problem.

          I've read help about Performance Class but it is used to evaluate the whole trade in backtest and the trade in real time but not in the middle of the session of backtest.

          For example to evaluate a strategy in the middle of backtest I'd like to know the last trade executed if it was a long position or a short.

          What class I can check ??

          Is it possible in Ninja ??

          Tanks in advance!

          Comment


            #6
            just hold an internal variable indicating last known position.
            RayNinjaTrader Customer Service

            Comment


              #7
              It is not clear.

              Is there any example to examine this case?

              Comment


                #8
                create a variable in the variables section

                private MarketPosition lastMarketPosition = MarketPosition.Flat;
                private MarketPosition currentMarketPosition = MarketPosition.Flat;

                then in OnBarUpdate() do something like:

                if (Position.MarketPosition != MarketPosition.Flat && currentMarketPosition != MarketPosition.Flat) currentMarketPosition = Position.MarketPosition;
                else if (Position.MarketPosition == MarketPosition.Flat && currentMarketPosition != MarketPosition.Flat)
                {
                lastMarketPosition = currentMarketPosition;
                currentMarketPosition = MarketPosition.Flat;
                }

                the variable lastMarketPosition will always hold your last known market position.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Ok!

                  Now I try it in my code.

                  Tank you very much.

                  Comment


                    #10
                    As in the post above thank you for your indication but I've had a trubble to test your code.

                    The code you have suggested doesn't work fine in my strategy.

                    I have solved it improving your idea in a simple way more simple than it appears.

                    create a variable in the variables section

                    private MarketPosition lastMarketPosition = MarketPosition.Flat;
                    private MarketPosition currentMarketPosition = MarketPosition.Flat;

                    then in OnBarUpdate() do something like:

                    if (Position.MarketPosition != currentMarketPosition)
                    {
                    lastMarketPosition = currentMarketPosition;
                    currentMarketPosition = Position.MarketPosition;
                    }

                    I have tried it my simple strategy and it work fine.

                    This is for any users who have the same problem.

                    tanks for your indication

                    bye.

                    Comment


                      #11
                      Hello chkyour6,

                      your simple code works fine for me too!

                      Thanks so much.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      633 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      364 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      105 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      567 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      568 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X