Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need a little help with a multi timeframe strategy I am working on

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

    Need a little help with a multi timeframe strategy I am working on

    I used the strategy builder to create a new strategy that I have been working on which includes two time frames (4mins and 240 mins) but running the strategy doesn't seem to do the right thing so something is wrong.

    The strategy is a simple crossover on an indicator I use but I want to execute the trade when Close[0] i.e closing price on my 4 min chart crosses above/below the indicator (ATRTrailingStop of the 4 min char) but also when Close[0] is > ATRTrailingStop of the 4 hour chart.

    Here is what I have in the code
    declarations
    private ATRTrailingStop ATRTrailingStop1;
    private ATRTrailingStop ATRTrailingStop2;

    in State == State.Configure
    AddDataSeries(Data.BarsPeriodType.Minute, 4);
    AddDataSeries(Data.BarsPeriodType.Minute, 240);

    in State == State.DataLoaded
    ATRTrailingStop1 = ATRTrailingStop(Close, 10, 3.03);
    ATRTrailingStop2 = ATRTrailingStop(Closes[2], 10, 3.03);

    in OnBarUpdate()

    if ((CrossAbove(Close, ATRTrailingStop1, 1))
    && (Times[0][0].TimeOfDay > new TimeSpan(6, 30, 0))
    && (Times[0][0].TimeOfDay < new TimeSpan(13, 40, 0))
    && Close[0] > ATRTrailingStop2[0])
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if ((CrossBelow(Close, ATRTrailingStop1, 1))
    && (Times[0][0].TimeOfDay > new TimeSpan(6, 30, 0))
    && (Times[0][0].TimeOfDay < new TimeSpan(13, 40, 0))
    && Close[0] < ATRTrailingStop2[0])
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    What am I missing here?
    Last edited by vpatanka; 11-28-2021, 11:01 AM.

    #2
    Hello vpatanka,

    In the Strategy Builder you can select the added series when clicking Series1 -> Input series.

    Attached is a screenshot.

    To understand the behavior of the script, it is necessary to print all values used in the condition.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior and includes a video that debugs a CrossAbove condition in the Strategy Builder.


    I am happy to assist with analyzing the output from the prints.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    41 views
    0 likes
    Last Post CarlTrading  
    Working...
    X