Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Insert daily time frame

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

    Insert daily time frame

    Hallo,
    i would like to calculate daily ATR in the strategy. I'm using the strategy for 60 min chart and I would like to calculate daily ATR.
    Any help would be appreciated.

    Thanks

    {
    #region Variables
    // Wizard generated variables
    private int fast = 20; // Default setting for Fast
    private int slow = 55; // Default setting for Slow
    private int indicator = 70; // Default setting for Indicator
    private int stop = 150; // Default setting for Stop
    private int atr = 20; // Default setting for Atr
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetStopLoss("LONG", CalculationMode.Ticks, Stop, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(SMA(Fast), SMA(Slow), 1)
    && ATR(14)[0] < Atr)
    {
    EnterLong(DefaultQuantity, "LONG");
    }

    // Condition set 2
    if (RSI(14, 3).Avg[0] > Indicator)
    {
    ExitLong("ExitLong", "LONG");
    }
    }

    #2
    Hello Dragan,

    Thank you for your note.

    You would need to add a Daily data series to the script to use for the ATR calculations -
    Code:
    protected override void Initialize()
    {
        SetStopLoss("LONG", CalculationMode.Ticks, Stop, false);
    
        CalculateOnBarClose = true;
        [B]Add(PeriodType.Day, 1);[/B]
    }
    
    protected override void OnBarUpdate()
    {
        // Condition set 1
        if (CrossAbove(SMA(Fast), SMA(Slow), 1)
          && [B]ATR(BarsArray[1], 14)[0][/B] < Atr)
        {
            EnterLong(DefaultQuantity, "LONG");
        }
    
        // Condition set 2
        if (RSI(14, 3).Avg[0] > Indicator)
        {
            ExitLong("ExitLong", "LONG");
        }
    }
    http://www.ninjatrader.com/support/h....html?add3.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply. It works now but I have a problem with the entries now.
      i want to have one entry per direction, and before adding barsarrey I had only one entry per direction. It doesn't work even though I have tried with Unique entry and also with All entries. Entries per direction is set to 1. Attached is a screenshot.
      Attached Files

      Comment


        #4
        Dragan,

        You will need to filter out the BarsInProgress in this case.

        Try adding -

        if(BarsInProgress == 1) return;

        to the beginning of OnBarUpdate()

        http://www.ninjatrader.com/support/h...inprogress.htm
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 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
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X