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 bmartz, 03-12-2024, 06:12 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by Aviram Y, Today, 05:29 AM
        4 responses
        13 views
        0 likes
        Last Post Aviram Y  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        28 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X