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

Calculate = OnPriceChange / OnEachTick Error!

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

    Calculate = OnPriceChange / OnEachTick Error!

    Hi NT,
    I am getting absurd results using the below code with Renko Bars NinjaTrader.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class MyCustomStrategy : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "MyCustomStrategy";
                    Calculate                                    = Calculate.OnPriceChange;
    
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
    
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(IsFirstTickOfBar && CurrentBar > 0)
                {
                    if(Close[1] >= Open[1])
                    {
                        Print("Bullish" + " " + Time[1] + " " + CurrentBar);
                    }
                    else
                    {
                        Print("Bearish" + " " + Time[1] + " " + CurrentBar);
                    }
                }
            }
        }
    }
    I am getting wrong result which is duplicate bars. Need Help!

    #2
    Hello dastaan,

    Thank you for your post.

    This would be expected when trying to use IsFirstTickOfBar with bar types that remove the last bar, such as renko bars.



    Since renko bars redraw the open of the bar, IsFirstTickOfBar will return true several times per bar as that open is adjusted.

    If you only want this logic to run once per bar, you should run this OnBarClose instead, as it would then have the full, redrawn bar to refer to.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by helpwanted, Today, 03:06 AM
    1 response
    10 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    9 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X