Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategies Started on Chart vs Strategy Tab

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

    Strategies Started on Chart vs Strategy Tab

    I found a very subtle but killer bug for me. This one was driving me crazy. It is associated with iterating the StrategyBase.

    What I found was related to the "SystemPerformance.AllTrades" and associated "Trades". When a strategy is added & started on a Chart, there are not problems, but if you add & start a strategy on the strategy tab of the central control, all the Trades (in the StrategyBase iteration) are lost and not updated. The strategy added to the chart works fine if you disable and enable on the strategy tab, this doesn't break the "Trades".

    I have enclosed a sample strategy. It includes the following block of code:
    Code:
     [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnBarUpdate[/COLOR]()
     {
     [COLOR=#0000ff]int[/COLOR] [COLOR=#080808]modeselect[/COLOR]=([COLOR=#080808]CurrentBar[/COLOR]/[COLOR=#ff8c00]10[/COLOR])%[COLOR=#ff8c00]2[/COLOR];
     
     [COLOR=#0000ff]if[/COLOR] (([COLOR=#080808]Position[/COLOR].[COLOR=#080808]MarketPosition[/COLOR]!=[COLOR=#080808]MarketPosition[/COLOR].[COLOR=#080808]Long[/COLOR]) && ([COLOR=#080808]modeselect[/COLOR]==[COLOR=#ff8c00]0[/COLOR]))
     [COLOR=#080808]EnterLong[/COLOR]();
     
     [COLOR=#0000ff]if[/COLOR] (([COLOR=#080808]Position[/COLOR].[COLOR=#080808]MarketPosition[/COLOR]!=[COLOR=#080808]MarketPosition[/COLOR].[COLOR=#080808]Short[/COLOR]) && ([COLOR=#080808]modeselect[/COLOR]==[COLOR=#ff8c00]1[/COLOR]))
     [COLOR=#080808]EnterLong[/COLOR](); 
     
     [COLOR=#080808]NinjaTrader[/COLOR].[COLOR=#080808]Code[/COLOR].[COLOR=#080808]Output[/COLOR].[COLOR=#080808]Process[/COLOR]([COLOR=#080808]CurrentBar[/COLOR]+[COLOR=#b22222]" OnBarUpdate(): Trades="[/COLOR]+[COLOR=#080808]SystemPerformance[/COLOR].[COLOR=#080808]AllTrades[/COLOR].[COLOR=#080808]Count[/COLOR]+[COLOR=#b22222]" vs TradeCount="[/COLOR]+
     +[COLOR=#080808]SystemPerformance[/COLOR].[COLOR=#080808]AllTrades[/COLOR].[COLOR=#080808]TradesCount[/COLOR]+[COLOR=#b22222]" Name="[/COLOR]+[COLOR=#080808]Name[/COLOR]+[COLOR=#b22222]" strategyID="[/COLOR]+[COLOR=#080808]Id[/COLOR],[COLOR=#080808]PrintTo[/COLOR].[COLOR=#080808]OutputTab1[/COLOR]);
     [COLOR=#0000ff]foreach[/COLOR] ([COLOR=#080808]StrategyBase[/COLOR] [COLOR=#080808]sb[/COLOR] [COLOR=#0000ff]in[/COLOR] [COLOR=#080808]StrategyBase[/COLOR].[COLOR=#080808]Strategies[/COLOR])
     {
     [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]sb[/COLOR]!=[COLOR=#0000ff]null[/COLOR])
     {
     [COLOR=#080808]NinjaTrader[/COLOR].[COLOR=#080808]Code[/COLOR].[COLOR=#080808]Output[/COLOR].[COLOR=#080808]Process[/COLOR]([COLOR=#080808]CurrentBar[/COLOR]+[COLOR=#b22222]" OnBarUpdate(StrategyBase Method): Trades="[/COLOR]+[COLOR=#080808]sb[/COLOR].[COLOR=#080808]SystemPerformance[/COLOR].[COLOR=#080808]AllTrades[/COLOR].[COLOR=#080808]Count[/COLOR]+[COLOR=#b22222]" vs TradeCount="[/COLOR]+
     +[COLOR=#080808]sb[/COLOR].[COLOR=#080808]SystemPerformance[/COLOR].[COLOR=#080808]AllTrades[/COLOR].[COLOR=#080808]TradesCount[/COLOR]+[COLOR=#b22222]" sb.Name="[/COLOR]+[COLOR=#080808]sb[/COLOR].[COLOR=#080808]Name[/COLOR]+[COLOR=#b22222]" sb.strategyID="[/COLOR]+[COLOR=#080808]sb[/COLOR].[COLOR=#080808]Id[/COLOR],[COLOR=#080808]PrintTo[/COLOR].[COLOR=#080808]OutputTab2[/COLOR]); 
     }
     }
     }
    It will print all the "Counts" for the Strategy thread in Output 1 and the Iterated list in Output 2. Simply add one copy of the strategy to a 6E 1 Range Chart, and manually add the same directly through the Strategy Tab. Run the strategy and it will populate those output window tabs. You will see something like this:

    Tab1:
    8500 OnBarUpdate(): Trades=2 vs TradeCount=2 Name=TestStrategyBaseAccess strategyID=47593721
    8501 OnBarUpdate(): Trades=2 vs TradeCount=2 Name=TestStrategyBaseAccess strategyID=47593721
    8502 OnBarUpdate(): Trades=2 vs TradeCount=2 Name=TestStrategyBaseAccess strategyID=47593721
    8503 OnBarUpdate(): Trades=2 vs TradeCount=2 Name=TestStrategyBaseAccess strategyID=47593721
    8504 OnBarUpdate(): Trades=2 vs TradeCount=2 Name=TestStrategyBaseAccess strategyID=47593721
    Here Count==TradeCount as expected and there is Trades in the collection.

    And Tab2:
    8500 OnBarUpdate(StrategyBase Method): Trades=0 vs TradeCount=4 sb.Name=TestStrategyBaseAccess sb.strategyID=47593720
    8500 OnBarUpdate(StrategyBase Method): Trades=2 vs TradeCount=2 sb.Name=TestStrategyBaseAccess sb.strategyID=47593721
    8501 OnBarUpdate(StrategyBase Method): Trades=0 vs TradeCount=4 sb.Name=TestStrategyBaseAccess sb.strategyID=47593720
    8501 OnBarUpdate(StrategyBase Method): Trades=2 vs TradeCount=2 sb.Name=TestStrategyBaseAccess sb.strategyID=47593721
    8502 OnBarUpdate(StrategyBase Method): Trades=0 vs TradeCount=4 sb.Name=TestStrategyBaseAccess sb.strategyID=47593720
    8502 OnBarUpdate(StrategyBase Method): Trades=2 vs TradeCount=2 sb.Name=TestStrategyBaseAccess sb.strategyID=47593721
    8503 OnBarUpdate(StrategyBase Method): Trades=0 vs TradeCount=4 sb.Name=TestStrategyBaseAccess sb.strategyID=47593720
    8503 OnBarUpdate(StrategyBase Method): Trades=2 vs TradeCount=2 sb.Name=TestStrategyBaseAccess sb.strategyID=47593721
    8504 OnBarUpdate(StrategyBase Method): Trades=0 vs TradeCount=4 sb.Name=TestStrategyBaseAccess sb.strategyID=47593720
    8504 OnBarUpdate(StrategyBase Method): Trades=2 vs TradeCount=2 sb.Name=TestStrategyBaseAccess sb.strategyID=47593721
    You will see in Tab2, the Count==0, but the TradeCount!=Count and there are 0 trades in the collection. It is like the StrategyBase is not connected to the actual strategy, maybe a strategy local variable is covering this StrategyBase.

    Attached Files

    #2
    Thanks for your report - we're looking into this NTEIGHT-8483

    Were you running in 32-bit or 64-bit install?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Matt,

      It is the 64 Bit version.

      Comment


        #4
        Add this in State.Configure:

        IncludeTradeHistoryInBacktest = true;

        This will resolve your issue in the SA grid. I'm looking into with development now on the default setting of this and making it consistent between the chart and the strategies grid. As currently the SA grid defaults to false and the chart true.

        #8483

        Note: I'll look to add more documentation on the setting. Since setting it to true makes your backtests run slower. Setting it to false improves performance and still maintains a large majority of the functionality of the SystemPerformance (All calculations still run, etc.)

        Comment


          #5
          Thanks Brett,

          That did fix the problem. Consistency would be great here as I didn't expect a different result by starting the strategy in the Tab vs the Chart. To me they are the same. Certainly for the Analyzer and other tools it would be nice to be able to disable (maybe within the tool, to control this flag).

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          2 views
          0 likes
          Last Post AveryFlynn  
          Started by RubenCazorla, 08-30-2022, 06:36 AM
          3 responses
          77 views
          0 likes
          Last Post PaulMohn  
          Started by f.saeidi, Yesterday, 12:14 PM
          9 responses
          23 views
          0 likes
          Last Post f.saeidi  
          Started by Tim-c, Today, 03:54 AM
          0 responses
          3 views
          0 likes
          Last Post Tim-c
          by Tim-c
           
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          5 views
          0 likes
          Last Post FrancisMorro  
          Working...
          X