• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EntriesPerDirection not updated in compiled code

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

    EntriesPerDirection not updated in compiled code

    Hi, I wrote a simple strategy for testing:

    Code:
    protected override void OnBarUpdate()
    {
    	var sma1 = SMA(this.SMA1_Val);
    	var sma2 = SMA(this.SMA2_Val);
    	/* Enter a long position if 10 SMA crosses above 20 SMA within the last bar */
    	if (CrossAbove(sma1, sma2, 1)) {
    		nOrderNum++;
    		string sOrderStr = "myEntryOrder" + nOrderNum.ToString();
    		Print(string.Format(sOrderStr));			
    		EnterLong(sOrderStr);
    	}
    }
    In addition, I've also set EntriesPerDirection = 1. When I ran the Strategy Analyzer, this is what I observed in the Output window:

    Code:
    myEntryOrder1
    Strategy 'TestStrategy/-1': An order placed at '19/1/2017 5:00:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
    myEntryOrder2
    myEntryOrder2 is Submitted
    myEntryOrder2 is Accepted
    myEntryOrder2 is Working
    myEntryOrder2 is Filled
    myEntryOrder3
    myEntryOrder4
    myEntryOrder5
    myEntryOrder6
    myEntryOrder7
    myEntryOrder8
    myEntryOrder9
    myEntryOrder10
    Exit on session close is Submitted
    Exit on session close is Accepted
    Exit on session close is Working
    Exit on session close is Filled
    Only one order was submitted, which is what I expected since EntriesPerDirection = 1.

    Next I changed sOrderStr variable in OnBarUpdate() from "myEntryOrder..." to "testingEntryOrder..." and I also changed EntriesPerDirection = 3. This is what I observed in the Output window:

    Code:
    testingEntryOrder1
    Strategy 'TestStrategy/-1': An order placed at '19/1/2017 5:00:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
    testingEntryOrder2
    testingEntryOrder2 is Submitted
    testingEntryOrder2 is Accepted
    testingEntryOrder2 is Working
    testingEntryOrder2 is Filled
    testingEntryOrder3
    testingEntryOrder4
    testingEntryOrder5
    testingEntryOrder6
    testingEntryOrder7
    testingEntryOrder8
    testingEntryOrder9
    testingEntryOrder10
    Exit on session close is Submitted
    Exit on session close is Accepted
    Exit on session close is Working
    Exit on session close is Filled
    Based on the output, it seems that only sOrderStr variable has been updated (as it is now printing "testingEntryOrder...") however EntriesPerDirection has not been updated (as only one order was submitted). What's even more strange is that in order to update EntriesPerDirection I had to select another strategy from the Strategy dropdown list in Strategy Analyzer, select back my strategy again from the dropdown list and then run my strategy - when I did this, the Output showed 3 orders submitted:

    Code:
    testingEntryOrder1
    Strategy 'TestStrategy/-1': An order placed at '19/1/2017 5:00:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.
    testingEntryOrder2
    testingEntryOrder2 is Submitted
    testingEntryOrder2 is Accepted
    testingEntryOrder2 is Working
    testingEntryOrder2 is Filled
    testingEntryOrder3
    testingEntryOrder3 is Submitted
    testingEntryOrder3 is Accepted
    testingEntryOrder3 is Working
    testingEntryOrder3 is Filled
    testingEntryOrder4
    testingEntryOrder4 is Submitted
    testingEntryOrder4 is Accepted
    testingEntryOrder4 is Working
    testingEntryOrder4 is Filled
    testingEntryOrder5
    testingEntryOrder6
    testingEntryOrder7
    testingEntryOrder8
    testingEntryOrder9
    testingEntryOrder10
    Exit on session close is Submitted
    Exit on session close is Accepted
    Exit on session close is Working
    Exit on session close is Filled
    Are both of these bugs?
    1) In my newly compiled code, why is EntriesPerDirection not updated, yet the sOrderStr variable was?
    2) Do I need to select a new strategy and re-select back my strategy in Strategy Analyzer to refresh, before my newly compiled code will run?

    #2
    Hello Vypre,

    Are you setting EntriesPerDirection in State.SetDefaults or State.Configure?

    State.SetDefaults is only run when the defaults are pulled. This would be when a strategy is first being selected in the drop-down menu of the Strategy Analyzer, or when a new instance of the strategy is added to a chart or to the Strategies tab of the Control Center.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok I see, yes I was setting EntriesPerDirection in State.SetDefaults.

      I've set it in State.Configure, and it's working now. Thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mohdhm, Today, 04:09 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by BGWTEX, Today, 03:30 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by marekflys, Today, 03:07 PM
      0 responses
      8 views
      0 likes
      Last Post marekflys  
      Started by GregoryBaskin, Today, 02:51 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Tyler  
      Started by swcooke, Today, 12:33 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X