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 argusthome, 03-08-2026, 10:06 AM
        0 responses
        80 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        46 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        66 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X