Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy only to trade at certain times

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

    Strategy only to trade at certain times

    Hi
    How can I set up my strategy to only trade at certain times? I set these times in the Condition Builder but no trades happen in the backtesting. I know this must not be right from programming point of view because the strategy produces trades without these time limitations. I must have to separate them out into diff sets 3 and 4 for example but I seem to be having a hard time with it. Can anybody help? Is there an example strategy with time limitation to put on trades I could view? If I was coding this by hand I would nest if statements with the time limitations in the outer if's and the entry signal inside...ie if (time between 8:00 and 10:45) { do this stuff if( ...)} but I am trying out the condition builder to make my life easier and to code faster ( I'm no pro).

    Also a second question....I am using the ROC of HMA because I could not figure out how to use the rising and falling methods. Any help on how to set this up in the Condition Builder too would be wonderful.

    Many many Thanks in advance.

    HTML Code:
     protected override void OnBarUpdate()
            {
                // Condition set 1
                if (CrossAbove(ROC(HMA(21), 1), 0, 1)
                    && ToTime(Time[0]) >= ToTime(8, 0, 0)
                    && ToTime(Time[0]) <= ToTime(10, 45, 0)
                    && ToTime(Time[0]) >= ToTime(12, 45, 0)
                    && ToTime(Time[0]) <= ToTime(14, 45, 0))
                {
                    DrawArrowUp("My up arrow" + CurrentBar, false, 0, Low[0] + 1 * TickSize, Color.Lime);
                    EnterLong(DefaultQuantity, "Enter Long at market");
                }
    
                // Condition set 2
                if (CrossBelow(ROC(HMA(21), 1), 0, 1)
                    && ToTime(Time[0]) >= ToTime(8, 0, 0)
                    && ToTime(Time[0]) <= ToTime(10, 45, 0)
                    && ToTime(Time[0]) >= ToTime(12, 45, 0)
                    && ToTime(Time[0]) <= ToTime(14, 45, 0))
                {
                    DrawArrowDown("My down arrow" + CurrentBar, false, 0, High[0] + 1 * TickSize, Color.Red);
                    EnterShort(DefaultQuantity, "Enter Short at market");

    #2
    Blash, you should separate those AM and PM trades out into more than 2 sets as otherwise the time conditions all combined with the && are too hard to trigger anything - the result you currenly see.

    For a coded strategy example with time filters please see this one here - http://www.ninjatrader.com/support/f...ead.php?t=3226

    You would pass the HMA series into the Rising / Falling methods on the left side of the condition builder and then check for it being equal to true on the right hand side for your signal for example.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    574 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X