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 judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    59 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    36 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    7 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    21 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post cre8able  
    Working...
    X