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

Tick replay and update on every tick indicators

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

    Tick replay and update on every tick indicators

    I have a couple of indicators that require tick replay = true

    The problem is that another indicator now only works on those charts with calculate on bar close. If it's set to update on every tick (with tick replay) it produces rubbish.

    I apologize if this is something really basic. I'm new to coding.



    Code:
       public class Locations : Indicator
    
        {
            private int Zero;
    
            private Brush Brush1;
            private Brush Brush2;
            private Brush Brush3;
            private Brush Brush4;
            private Brush Brush5;
            private Brush Brush6;
            private EMA EMA1;
            private EMA EMA2;
            private MABandsFixed MABandsFixed1;
            private NinjaTrader.NinjaScript.Indicators.GomPro.GomCD GomCD1;
            private EMA EMA3;
            private MABandsFixed MABandsFixed2;
    
            protected override void OnStateChange()
    
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionSMA;
                    Name                        = "Locations";
                    IsOverlay                    = false;
                    IsSuspendedWhileInactive    = false;
                    Zero                        = 0;
    
                }
                else if (State == State.Configure)
                {
                    Brush1 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF3D0603"));
                    Brush1.Freeze();
                    Brush2 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF1F3954"));
                    Brush2.Freeze();
                    Brush3 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF3D0603"));
                    Brush3.Freeze();
                    Brush4 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF1F3954"));
                    Brush4.Freeze();
                    Brush5 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF1F3954"));
                    Brush5.Freeze();
                    Brush6 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF3D0603"));
                    Brush6.Freeze();
                }
                else if (State == State.DataLoaded)
                {                
                    EMA1                = EMA(Close, 20);
                    EMA2                = EMA(Close, 60);
                    MABandsFixed1 = MABandsFixed(Close, 1.5, 1, 20);
                    GomCD1             = GomCD(Close, Gom.DeltaLib.DeltaCalcType.BidAsk, true, -1, 0, Gom.CumulativeDelta.ChartType.CumulativeChart, false);
                    EMA3                 = EMA(GomCD1.DeltaClose, 20);
                    MABandsFixed2  = MABandsFixed(Close, 1.5, 1, 60);
                }
            }
            protected override void OnBarUpdate()
            {
    
            {
                    if (BarsInProgress != 0) 
                    return;
    
    
    
                 // Set 1
                if ((Close[0] < EMA1[0])
                     && (Close[0] < Open[0])
                     && (Close[0] < EMA2[0]))
                {
                    BackBrushAll = Brush1;
                }
    
    
                // Set 2
                if ((Close[0] > EMA1[0])
                     && (Close[0] > Open[0])
                     && (Close[0] > EMA2[0]))
                {
                    BackBrushAll = Brush2;
                }
    
                 //Set 3
                if ((Close[0] > MABandsFixed1.Upper[0])
                     && (Close[0] < Open[0])
                     && (GomCD1.DeltaClose[0] < EMA3[0]))
                {
                    BackBrushAll = Brush3;
                }
    
                 //Set 4
                if ((Close[0] < MABandsFixed1.Lower[0])
                     && (Close[0] > Open[0])
                     && (GomCD1.DeltaClose[0] > EMA3[0]))
                {
                    BackBrushAll = Brush4;
                }
    
                  //Set 5
                if ((Close[0] > Open[0])
                     && (Close[0] < MABandsFixed2.Lower[0])
                     && (Close[0] > EMA1[0]))
                {
                    BackBrushAll = Brush5;
                }
    
                 //Set 6
                if ((Close[0] > MABandsFixed2.Upper[0])
                     && (Close[0] < Open[0])
                     && (Close[0] < EMA1[0]))
                {
                    BackBrushAll = Brush6;
                }
    
    
    
                }











    #2
    Hello Sparkyboy,

    If the indicator was not programmed with using TickReplay in mind you would likely need to modify it to work as you wanted.

    If you need it to work OnBarClose, you could try to instead use IsFirstTickOfBar to simulate that when using OnEachTick. https://ninjatrader.com/support/help...FirstTickOfBar

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    26 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, Yesterday, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    191 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,230 views
    0 likes
    Last Post xiinteractive  
    Working...
    X