Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Looking for specific example: switching timeframes

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

    Looking for specific example: switching timeframes

    There's a particular technique that I'm trying to code up in NinjaScript. While I'm confident that I'll figure it out eventually, I was wondering if anybody else has seen something similar, and could point me to some sample code.

    I have several strategies that I call "Signal and Trigger" strategies. Basically: the strategy looks for certain TA criteria on a higher timeframe (say, 10 minute bars) - when those criteria are met, that's the "signal". The strategy then switches to a smaller timeframe (say, 2 minutes) to finesse the entry. When the shorter-timeframe criteria are met, the trade is executed. That's the "trigger".

    I understand multiple timeframe concepts like BarsArray, BarsInProgress, etc. What I'm looking for is some sample code for a strategy that switches timeframes during its decision-making process. Again, in general, the code is saying: "Okay, that's the setup I'm looking for. Time to trade - but first I'll switch to a shorter timeframe to improve my entry." I'd also like to know if there's any additional complications from using Tick-based bars instead of Minute-based bars.

    Note: In no way am I looking for tips, specific TA settings, timeframes, etc. I consider that to be 100% my own responsibility. I'm just looking for a little coding guidance for this multi-timeframe technique.

    #2
    It sounds like you're already familiar with this but if not I strongly recommend reading this article: http://www.ninjatrader.com/support/h...nstruments.htm

    Then in regards to your logic you would want to do something like:

    Code:
    if(BarsInProgress == 0)//assuming this is the longer time frame but you could code it either way
    {
    if(lookingForSetup)
    {
    //wait for longer time frame to be setup
    //once it's setup flip a boolean value
    }
    else
    return;
    }
    else if (BarsInProgress == 1)
    {
    if(!lookingForSetup)
    {
    //only want to process logic when we aren't looking for the setup
    //would want to flip lookingForSetup back to true after trade
    }
    else return;
    }
    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thanks, Lance. I guess I was trying to make things overly complicated. I was working on a generic solution that could support multiple timeframes (not just two), using something like a state machine. But this approach will work just fine for my immediate needs. I guess I just wanted confirmation that the key variable - that would be the boolean value "lookingForSetup" - is class-level variable, and not something that might possibly hold different values depending on which set of bars is current.

      Comment


        #4
        Yes that is correct in regards to the boolean.

        If you needed more states you could use an int instead.

        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        0 responses
        3 views
        0 likes
        Last Post helpwanted  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X