Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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 bortz, 11-06-2023, 08:04 AM
      47 responses
      1,603 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      12 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X