Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit/Loss since trade entered

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

    Profit/Loss since trade entered

    Hi - I'd be very grateful if you could indicate how I can find a way to calculate the profit or loss realized, at every range bar occurring during a trade in progress, since the current trade was entered.

    (I'd like to be able to manipulate this mathematically in Ninjascript so I can construct a trailing stop that varies according to profit/loss levels, i.e. one that is not static.)

    Thanks in advance for your help.

    #2
    Please check into our GetProfitLoss() in NinjaScript for this task - http://www.ninjatrader.com/support/h...profitloss.htm

    Comment


      #3
      Dear Bertrand,

      Is there any possibility to calculate the REALIZED profit and loss of a single trade immediately after the trade was closed? (e.g. by refering to the execution.ExecutionId or execution.Order.OrderId). I assume GetProfitLoss() is not the right function as this function displays the UNREALIZED profit and loss of a position according to the ninjascript tutorial.

      Many thanks.

      Robert

      Comment


        #4
        Store GetProfitLoss() into a variable if in position, and readout this variable after trade is closed ?

        Comment


          #5
          Originally posted by Robertp75 View Post
          Dear Bertrand,

          Is there any possibility to calculate the REALIZED profit and loss of a single trade immediately after the trade was closed? (e.g. by refering to the execution.ExecutionId or execution.Order.OrderId). I assume GetProfitLoss() is not the right function as this function displays the UNREALIZED profit and loss of a position according to the ninjascript tutorial.

          Many thanks.

          Robert
          You can directly work with the NinjaScript Performance class for this task - http://www.ninjatrader.com/support/h.../nt7/trade.htm

          Comment


            #6
            Originally posted by marcow View Post
            Store GetProfitLoss() into a variable if in position, and readout this variable after trade is closed ?
            Hi marcow,

            Many thanks for your reply!
            According to the conversion at this link:


            I cannot believe that your advise works as NinjaTrader_Joydeep wrotes:
            "Position.GetProfitLoss will return the unrealized PnL of the strategy position.

            If your strategy is flat then it will return 0 (zero). If your strategy is Long or Short then it will return the unrealized PnL.


            If you are getting any other result then please upload a NinjaScript code replicating it."

            Cheers!

            Rob

            Comment


              #7
              Code:
               
              [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Wizard generated variables[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ProfitLoss_LastTrade = 0[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][/SIZE][/FONT]
              [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// User defined variables (add any user defined variables below)[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] This method is used to configure the strategy and is called once before any strategy method is called.[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
              [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
              [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
               
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( Position.MarketPosition != MarketPosition.Flat ) [/SIZE][/FONT]
              [SIZE=2][FONT=Courier New]ProfitLoss_LastTrade = Position.GetProfitLoss(Close[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], PerformanceUnit.Currency) ;[/SIZE][/FONT]
               
               
              [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
              [/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

              ProfitLoss_LastTrade will now hold the latest unrealizedPnL of each closed position.
              Assuming that the last unrealizedPnL of an open position becomes realizedPnL once that position is closed.


              Marco
              Last edited by marcow; 08-05-2012, 03:16 PM.

              Comment


                #8
                Originally posted by marcow View Post
                Code:
                 
                [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Wizard generated variables[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ProfitLoss_LastTrade = 0[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]; [/SIZE][/FONT][/SIZE][/FONT]
                [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// User defined variables (add any user defined variables below)[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] This method is used to configure the strategy and is called once before any strategy method is called.[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] Called on each bar update event (incoming tick)[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
                [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                 
                [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ( Position.MarketPosition != MarketPosition.Flat ) [/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]ProfitLoss_LastTrade = Position.GetProfitLoss(Close[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], PerformanceUnit.Currency) ;[/SIZE][/FONT]
                 
                 
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                ProfitLoss_LastTrade will now hold the latest unrealizedPnL of each closed position.
                Assuming that the last unrealizedPnL of an open position becomes realizedPnL once that position is closed.


                Marco
                Hi Marco,

                Many thanks for that hint!
                Let me check how that works.
                I will get back to you for reporting results.

                Best,

                Rob

                Comment


                  #9
                  hello Rob,

                  after looking through the thread you posted the link for : http://www.ninjatrader.com/support/f...ad.php?t=49774

                  I realized Joydeep M. came with a very good solution in post#14, which is way better then the one I posted above. It involves using the trades colection class.
                  please find below a strategy which demonstrates the use of this trade collection class.

                  Code:
                   
                  #region Variables
                  // Wizard generated variables
                  private double ProfitLoss_LastTrade = 0;   // holds profit/loss of last trade
                  private int temp = 0;                                // temp value 
                  // User defined variables (add any user defined variables below)
                  #endregion
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                  CalculateOnBarClose = true;
                  }
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                   
                  // simple EMA crossovers to generate some trades 
                  if( CrossAbove(EMA(8), EMA(14), 1) )
                  EnterLong(DefaultQuantity, "");
                   
                  if( CrossBelow(EMA(8), EMA(14), 1) )
                  EnterShort(DefaultQuantity, "");
                   
                   
                   
                  if(       Performance.AllTrades.Count >= 1       // wait for first trade
                      && Performance.AllTrades.Count > temp   // only execute if there was a new trade 
                  ) 
                   {   Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
                       ProfitLoss_LastTrade = lastTrade.ProfitCurrency; 
                   
                    [FONT=Courier New][FONT=Courier New][FONT=Arial]   PrintWithTimeStamp[/FONT][/FONT][/FONT]("The last trade profit is " + ProfitLoss_LastTrade);
                       temp = Performance.AllTrades.Count;
                  }
                   
                  }
                  please let me know if this works for you or if you have any questions,

                  Marco

                  Comment


                    #10
                    Originally posted by marcow View Post
                    hello Rob,

                    after looking through the thread you posted the link for : http://www.ninjatrader.com/support/f...ad.php?t=49774

                    I realized Joydeep M. came with a very good solution in post#14, which is way better then the one I posted above. It involves using the trades colection class.
                    please find below a strategy which demonstrates the use of this trade collection class.

                    Code:
                     
                    #region Variables
                    // Wizard generated variables
                    private double ProfitLoss_LastTrade = 0;   // holds profit/loss of last trade
                    private int temp = 0;                                // temp value 
                    // User defined variables (add any user defined variables below)
                    #endregion
                    /// <summary>
                    /// This method is used to configure the strategy and is called once before any strategy method is called.
                    /// </summary>
                    protected override void Initialize()
                    {
                    CalculateOnBarClose = true;
                    }
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                     
                    // simple EMA crossovers to generate some trades 
                    if( CrossAbove(EMA(8), EMA(14), 1) )
                    EnterLong(DefaultQuantity, "");
                     
                    if( CrossBelow(EMA(8), EMA(14), 1) )
                    EnterShort(DefaultQuantity, "");
                     
                     
                     
                    if(       Performance.AllTrades.Count >= 1       // wait for first trade
                        && Performance.AllTrades.Count > temp   // only execute if there was a new trade 
                    ) 
                     {   Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
                         ProfitLoss_LastTrade = lastTrade.ProfitCurrency; 
                     
                      [FONT=Courier New][FONT=Courier New][FONT=Arial]   PrintWithTimeStamp[/FONT][/FONT][/FONT]("The last trade profit is " + ProfitLoss_LastTrade);
                         temp = Performance.AllTrades.Count;
                    }
                     
                    }
                    please let me know if this works for you or if you have any questions,

                    Marco
                    Hi Marco,

                    Many thanks! I will check this out and let you know the results.

                    Best,

                    Rob

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by argusthome, Yesterday, 10:06 AM
                    0 responses
                    18 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    17 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post TheRealMorford  
                    Started by Mindset, 02-28-2026, 06:16 AM
                    0 responses
                    38 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X