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

Porting StrategyDesk Programming Code to NT

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

    Porting StrategyDesk Programming Code to NT

    I’m looking at porting the algorithms I’m using with StrategyDesk (TD AMERITRADE's automated trading platform) to NT. My trading system strategy uses multiple timeframes (5, 60, D) and is quite deep in logic.

    StrategyDesk’s programming language supports multiple timeframes nicely and the function library is pretty good.. All of StrategyDesk’s indicators are supported by NT, so rewriting the Boolean logic with NT functions is not a problem.

    I looked at the NT examples for multiple timeframes for setting up Add(PeriodType) object data series for each timeframe and using IF( BarsInProgress = x) and the IF (entry/exit Boolean logic) statements for each timeframe in C#.. Pretty simple but I’m not too sure how to make this work in my case..

    Here’s an example of my entry condition’s Boolean logic complexity (in pseudocode)… My entry logic is about 100 lines while the exit is about 75 lines.

    Code:
    (
      (
        TAIndicator1[Close,D,0,$COMPX] < TAIndicator[Close,D,1,$COMPX]
        AND
        TAIndicator1[Close,D,0,$COMPX] <= 0
        AND
        TAIndicator1[Close,D,0,$COMPX] > 0
      )
      OR
      TAIndicator1[Close,D,0,$COMPX] <= 0
    )
    AND
    (
      (
        (
          TAIndicator2[Close,D,0,$COMPX] >= TAIndicator2[Close,D,5,$COMPX]
          OR
          TAIndicator2[Close,D,0,$COMPX] >= TAIndicator2[Close,D,1,$COMPX]
        )
        AND
        TAIndicator2[Close,60,1,$COMPX] >= 80
      )
      OR
      (
        TAIndicator3[Close,D,0,$COMPX] < TAIndicator3[Close,D,1,$COMPX]
        AND
        TAIndicator3[Close,D,0,$COMPX] < TAIndicator3[Close,D,5,$COMPX]
        AND
        TAIndicator3[Close,60,1,$COMPX] >= 80
        AND
        TAIndicator3[Close,5,1,$COMPX] >= TAIndicator3[Close,5,1,$COMPX]
      )
    )
    AND
    (
      (
        TAIndicator4[Close,5,1,$COMPX] >= 80
        AND
        TAIndicator4[Close,5,1,$COMPX] >= 80
        AND
        (
          (
            TAIndicator5[Close,D,0,$COMPX] >= 0
            AND
            TAIndicator5[Close,5,1,$COMPX] >= 80
            AND
            (
              (
                TAIndicator6[Close,5,2,$COMPX] <= 0
              )
              OR
              (
                TAIndicator6[Close,5,1,$COMPX] >= 80
              )
            )
          ) 
          OR
          (
            TAIndicator7[Close,D,0,$COMPX] < 0
            AND
            TAIndicator7[Close,5,1,$COMPX] >= 80
            AND
            (
              (
                TAIndicator7[Close,5,3,$COMPX] <= 0
              )
              OR
              (
                TAIndicator7[Close,5,1,$COMPX] >= 80
              )
            ) 
          )
        )
      )
      OR
    .
    .
    .
    ..... 50 more lines of similar boolean logic buy strategy .....
    Problem is my logic seems too complex for the IF conditional test. Is there a better way to move the logic outside the IF statement for each timeframe?

    I’m just looking for an approach and maybe some pseudocode. Thanks

    #2
    Hello,

    I'm not totally sure what is going on in your sample code but you can call different timeframes like this in NT using BarsArray:

    and:


    This is pretty advanced programming though.
    DenNinjaTrader Customer Service

    Comment


      #3
      Thank Ben,

      Let me restate my question in a different way.

      From NT reference samples, I see how to write simple trade trigger logic in multiple timeframes, as in this example...

      Code:
       
      protected override void Initialize() 
      { 
      Add(PeriodType.Minute, 5); 
      } 
       
      protected override void OnBarUpdate() 
      { 
      if (BarsInProgress == 1) 
      return; 
       
      if (SMA(20)[0] > SMA(BarsArray[1], 20)[0]) 
      EnterLong(); 
      }

      where the trade trigger logic is in the conditional statement of the second IF statement. However, my trade trigger logic is quite complex.

      Alternatively, I could create boolean variables for each of the many indicator conditional tests, and then use these variables in the second IF statement's conditional statement. This would shorten the IF's conditional test, but not really simplify things. So there must be a better way.

      Are there any examples of how to use OOP (class, objects, methods) to simplify the trade trigger logic?

      Comment


        #4
        Hi borland, unfortunately we don't have any OOP examples available.

        The method you mentioned with bool flags would work for sure though.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        23 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        45 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        21 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X