Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Waxavi, Today, 02:10 AM
    0 responses
    3 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    9 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    4 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by gentlebenthebear, Today, 01:30 AM
    0 responses
    4 views
    0 likes
    Last Post gentlebenthebear  
    Working...
    X