Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy in function of the last trade

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

    Strategy in function of the last trade

    Hi everybody,

    I'm trying to create a strategy who change the quantity in function of the last trade :

    If the last trade is a profit, then new quantity is "900".

    I try this, but it doesn't work :
    If (Performance.AllTrades.Count - 1 > 0)
    EnterLong(900, "");

    May you help me into this ?

    Thank you in advance.

    #2
    Hello Chris128,

    Thank you for your post.

    You could use something simliar to the following:
    Code:
            #region Variables		
            private int orderQty = 1; // set your initial quantity here
    		private double prevPnL = 0;
    		private double currentPnL = 0;
            #endregion
    
            
            protected override void Initialize()
            {
               	
            }
    		
    		protected override void OnBarUpdate()
    		{
    			if(currentPnL > prevPnL)
    			{
    				orderQty = 900;
    			}
    		}
    		protected override void OnPositionUpdate(IPosition position)
    		{
    			if(position.MarketPosition != MarketPosition.Flat)
    			{
    				prevPnL = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
    			}
    			
    			if(position.MarketPosition == MarketPosition.Flat)
    			{
    				currentPnL = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
    			}
    		}
    For information on CumProfit please visit the following link: http://www.ninjatrader.com/support/h.../cumprofit.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Thank you very much Patrick, I will try it tomorrow.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      672 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      379 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      111 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      577 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      582 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X