Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Potential Trade collection issue

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

    Potential Trade collection issue

    hi

    I just noticed the below code gives me the opposite results:

    I am counting long trades and short trades under OnPositionUpdate.

    The count for long trades equals short trades and the count for short trades equals long trades in the actual execution.

    Code:
    		protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
    		{
    				
        	if (position.MarketPosition == MarketPosition.Flat)
        	{
    		++strategy_trade_counts;
    			
    		Trade a = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];		
    		tradename1 = a.Exit.Name;
    		instrument_name = a.Exit.Instrument.MasterInstrument.Name;
    			
    			if(a.Exit.Instrument.MasterInstrument.Name == "AUDUSD" && a.Exit.MarketPosition ==MarketPosition.Long)
    			{
    				++aud_long_count;
    			}
    			
    }
    Actual trade count =

    long trades = 15; Short trades = 12

    however, the above code gives me:

    long trades = 12; short trades = 15

    can you confirm if you're seeing the same on your end?

    thanks

    #2
    Hello staycool3_a,

    Thank you for the post.

    I wanted to check, is the overall goal here to count how many long and short entries have occurred?

    In contrast to what you have provided, I would be unsure why the two values are reversed with this sample as I cannot see the full details of your test or run it. I would likely need to see a more complete example including your Prints along with being able to step through the logic to see why that may be happening. This is also something you can do on your end, or add more prints into the various parts of your logic displayed to see how it is evaluating in that situation.

    If the goal is to count the trades, I would also suggest using OnExecutionUpdate for that purpose rather than OnPositionUpdate. OnExecutionUpdate would not require the use of the TradesCollection, you would simply monitor the execution names and accumulate if that execution was one that should cause accumulation. This would, of course, depend on your overall logic so this is simply another item you can review to see if that fits your purpose.

    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello staycool3_a,

      Thank you for the post.

      I wanted to check, is the overall goal here to count how many long and short entries have occurred?

      In contrast to what you have provided, I would be unsure why the two values are reversed with this sample as I cannot see the full details of your test or run it. I would likely need to see a more complete example including your Prints along with being able to step through the logic to see why that may be happening. This is also something you can do on your end, or add more prints into the various parts of your logic displayed to see how it is evaluating in that situation.

      If the goal is to count the trades, I would also suggest using OnExecutionUpdate for that purpose rather than OnPositionUpdate. OnExecutionUpdate would not require the use of the TradesCollection, you would simply monitor the execution names and accumulate if that execution was one that should cause accumulation. This would, of course, depend on your overall logic so this is simply another item you can review to see if that fits your purpose.

      I look forward to being of further assistance.
      Yea my goal was to count my long and short trades and the overall trades in the strategy and by instrument. I need to do it under OnPositionUpdate for other reasons.

      I'll have to put together a sample for you when I have some time but I seriously think the TradeCollection for Long.Trades.count and short.trades.count is reversed. I have 10 different instruments in the strategy and it's reversing the values for all of them, so for my purposes, for now.. i just reversed the values.. short.count=long.count and long.count=short.count.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      45 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      31 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X