Counting 4 green bars when you have red bar with higher high

S

supercool

New member
I am trying to do a sequence indicator for al brooks price action. The setup I looking for is when I see a red bar which has a higher high I would like to count 4 green bars with higher high and label them as 1, 2,3,4 and draw a support line on 4th bar. I am stuck.. Any help appreciated. Additionally if there is a new higher high or lower low I would like to reset count.

 
S

supercool

New member
I have the code ready in ninjascript but having a horrid time with thinkscript. Any help appreciated.

 
BenTen

BenTen

Administrative
Staff
VIP
@supercool Post the code fro Ninjatrader, maybe someone can help you convert it.
 
S

supercool

New member
Here is the ninja script code.

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.DrawingTools;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
    public class JohnsFourBar : Indicator
    {

        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                                    = @"Enter the description for your new custom Indicator here.";
                Name                                        = "JohnsFourBar";
                Calculate                                    = Calculate.OnBarClose;
                IsOverlay                                    = true;
                DisplayInDataBox                            = false;
                DrawOnPricePanel                            = true;
                DrawHorizontalGridLines                        = true;
                DrawVerticalGridLines                        = true;
                PaintPriceMarkers                            = true;
                BarsBack                                    =4;
                ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                //See Help Guide for additional information.
                IsSuspendedWhileInactive                    = true;
                AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.TriangleDown, "HiHiRed");
                AddPlot(new Stroke(Brushes.Lime, 2), PlotStyle.TriangleUp, "LoLoGreen");
            }
            else if (State == State.Configure)
            {
            }
        }
       
        protected bool detectXSignal() {
            // Dectecting a X Signal
            if (( Low[1] <= Low[2] && High[0] > High[1]) ||
                (Low[1] >= Low[2] && High[1] <= High[2] && High[0] > High[1]) ) {
                return true;
            }
            return false;
        }
       

        protected bool detectYSignal() {
            // Dectecting a X Signal
            if ( (High[1] > High[2] && Open[1] > Close[1]))
                return true;
            return false;
        }
       
        protected bool findFourGreensBack() {
            int gccount=0;
            double llow=Low[1];
            int[] a = new int[BarsBack];
            for ( int i =1 ; i < 10+BarsBack && gccount < BarsBack && llow >= Low; i++ ) {
                if (llow > Low)
                    llow = Low;
                if ( Open < Close && 
                     High > High[i+1]) 
                    a[gccount++]=i;
            }
            if ( gccount == BarsBack) {
                for (int j =0; j < BarsBack; j++)
                    Draw.Text(this,@"GBar"+CurrentBar+a[j],(j+1).ToString(),a[j],High[a[j]]+1, Brushes.Green);
                Draw.Line(this,"GrnSupport"+CurrentBar,a[gccount-1],Low[a[gccount-1]],-30,Low[a[gccount-1]],Brushes.Green);
                return true;
            }
            return false;
        }
        
        protected bool findFourRedsBack() {
            int rccount=0; 
            double hhigh=High[1];
            int[] a = new int[BarsBack];
            for ( int i =1 ; i < 10+BarsBack && rccount < BarsBack && hhigh <= High; i++ ) {
                if (hhigh < High)
                    hhigh = High;
                if ( Open > Close && 
                     High < High[i+1]) {
                    a[rccount++]=i;
                }
            }
            if ( rccount == BarsBack) {
                for (int j =0; j < BarsBack; j++)
                    Draw.Text(this,@"RBar"+CurrentBar+a[j],(j+1).ToString(),a[j],Low[a[j]]-1, Brushes.Red);
                Draw.Line(this,"RedSupport"+CurrentBar,a[rccount-1],High[a[rccount-1]],-30,High[a[rccount-1]],Brushes.Green);
                return true;
            }
            return false;
        }

        protected int invokeFourBar()
        {
            if(CurrentBar < 15 ) {
                return 0;
            }
            //Draw.Text(this,@"CBar"+CurrentBar,CurrentBar.ToString(),0,Low[0]-4, Brushes.Red);
            if ( detectYSignal() ) {
                if ( findFourGreensBack()) 
                    Values[0][1] = High[1]+1;
            }
            if ( detectXSignal() ) {
                if ( findFourRedsBack() )
                    Values[1][1] = Low[1]-1;
            }
            return 0;
        }
        
        protected override void OnBarUpdate()
        {
            //Add your custom indicator logic here.
            invokeFourBar();
            
        }

        
        
        #region Properties

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> HiHiRed
        {
            get { return Values[0]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> LoLoGreen
        {
            get { return Values[1]; }
        }
        #endregion

        //[NinjaScriptProperty]
        [Range(1, 8)]
        [Display(Name="BarsBack", Order=1, GroupName="Parameters")]
        public int BarsBack
        { get; set; }

        
    }
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
        private JohnsFourBar[] cacheJohnsFourBar;
        public JohnsFourBar JohnsFourBar()
        {
            return JohnsFourBar(Input);
        }

        public JohnsFourBar JohnsFourBar(ISeries<double> input)
        {
            if (cacheJohnsFourBar != null)
                for (int idx = 0; idx < cacheJohnsFourBar.Length; idx++)
                    if (cacheJohnsFourBar[idx] != null &&  cacheJohnsFourBar[idx].EqualsInput(input))
                        return cacheJohnsFourBar[idx];
            return CacheIndicator<JohnsFourBar>(new JohnsFourBar(), input, ref cacheJohnsFourBar);
        }
    }
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
        public Indicators.JohnsFourBar JohnsFourBar()
        {
            return indicator.JohnsFourBar(Input);
        }

        public Indicators.JohnsFourBar JohnsFourBar(ISeries<double> input )
        {
            return indicator.JohnsFourBar(input);
        }
    }
}

namespace NinjaTrader.NinjaScript.Strategies
{
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
        public Indicators.JohnsFourBar JohnsFourBar()
        {
            return indicator.JohnsFourBar(Input);
        }

        public Indicators.JohnsFourBar JohnsFourBar(ISeries<double> input )
        {
            return indicator.JohnsFourBar(input);
        }
    }
}

#endregion
 

Similar threads

Top