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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      64 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      35 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      59 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      62 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Working...
      X