Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy taking all orders at once

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

    Strategy taking all orders at once

    My strategy has up to 8 different entries and in backtesting these entries all seem to work as expected, but when experimenting with market replay data the strategy takes all the orders at once rather than one by one at the end of each bar when conditions are met.

    Why is this entering all the positions at once?

    Here are some of the entries and exits - I have a total of 8:

    Code:
    //----------------------SHORT ENTRIES----------------------------------------
    			 // SE1 ENTRY
    			if ((Position.MarketPosition == MarketPosition.Flat)
    				 && (RSI1.Default[0] > RSIOnHigherTF)
    				 && (RSI2.Default[0] > RSIOnLowerTF)
    				 && (Close[0] > High[1])
    				 && (Close[0] > Swing1.SwingHigh[0])
    				 && (MACD1.Diff[0] > 0))
    			{
    				EnterShort(Convert.ToInt32(100), @"SE1");
    			}
    			
    			 // SE1 EXIT
    			if ((Position.MarketPosition == MarketPosition.Short)
    				 && (Position.Quantity == 100)
    				 && (Close[0] < Swing1.SwingLow[0]))
    			{
    				Print("LE1 Entry time is:");
    				Print(Time[0]);
    				ExitShort(Convert.ToInt32(100), @"SExit1", @"SE1");
    			}
    			
    			 // SE2 ENTRY
    			if ((Position.Quantity == 100)
    				 && (Close[0] > High[1])
    				 && (Close[0] > Swing1.SwingHigh[0])
    				 && (Close[0] > Position.AveragePrice - .002)
    				 && (Close[0] > MAX1[1])
    				 && (MACD1.Diff[0] > 0))
    			{
    				Print("LE2 Entry time is:");
    				Print(Time[0]);
    				EnterShort(Convert.ToInt32(200), @"SE2");
    			}
    			
    			 // SE2 EXIT
    			if ((Position.Quantity == 300)
    				 && (Close[0] < Swing1.SwingLow[0]))
    			{
    				ExitShort(Convert.ToInt32(200), @"SExit2", @"SE2");
    			}
    Attached Files
    Last edited by ShruggedAtlas; 06-04-2018, 12:07 PM.

    #2
    Hello ShruggedAtlas,

    Thank you for the post.

    While I couldn't say what specifically may be happening in your two tests based on this information, you can certainly test this on your end to find out why. Based on the image, it would appear you have used CalculateOnBarClose = false which could allow the conditions to all occur in one bar. In Historical testing, CalculateOnBarClose is always true so this could be one difference. https://ninjatrader.com/support/help...lightsub=discr

    Because Historical tests are processed differently than Realtime, you are likely seeing something happening differently in your logic. I see you have some prints but they are inside of the condition which is not as helpful for seeing how the logic executes overall.

    I would suggest that you add prints outside of your conditions, and then run the script in both historical and realtime to compare how the logic is executing.

    for example:

    Code:
    Print(Time[0] + " Position.MarketPosition: " + Position.MarketPosition + " Position.Quantity: " + Position.Quantity); //etc for all of the variables used
    This type of print would output on every bar with a timestamp. It would also be helpful to remove all other prints to compare one segment of logic at a time between the two modes.



    I look forward to being of further assistance.

    Comment


      #3
      The code and the strategy settings both are confirmed as calculating on the close of the bar. It's interesting to note that when I change the time frame from the hourly bar, which is what it is supposed to be to 30 second bar the entries occur properly as they are supposed to. (I did this because i needed a way to see the conditions happen quickly) I also didn't want to mess with market replay. Strange.

      I will change how I use the print statements and see if I can't get a better picture of what is happening here.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      64 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      139 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X