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 charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      60 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      145 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      161 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      97 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      283 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X