ThinkorSwim Higher High Lower Low Indicator

Steve2286

New member
2019 Donor
Is there a way to turn Mobius's TTM Scalper into a watchlist column that would indicate when a higher high or lower low is formed on chart?

Code:
# Mobius

# Mobius on My Trade

# TTM Scalper Replica or High_Low_Pivots

# V001.06.2012

# jpwel added alerts 06/26/2015



input n = 8;

input ShowLines = yes;

input SoundAlerts = yes;



def h = high;

def l = low;

def Firstbar = BarNumber();

def Highest = fold i = 1

             to n + 1

             with p = 1

             while p

             do h > GetValue(h, -i);

def A = if (Firstbar > n

            and h == Highest(h, n)

            and Highest)

            then h

            else Double.NaN;

def Lowest = fold j = 1

            to n + 1

            with q = 1

            while q

            do l < GetValue(l, -j);

def B = if (Firstbar > n

            and l == Lowest(l, n)

            and Lowest)

            then l

            else Double.NaN;

rec Al = if !IsNaN(A)

             then A

             else Al[1];

rec Bl = if !IsNaN(B)

             then B

             else Bl[1];



plot ph = Round(A, 2);

ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);



plot hL = if Al > 0

                       then Al

                       else Double.NaN;

hL.SetHiding(!ShowLines);

hL.SetPaintingStrategy(PaintingStrategy.DASHES);

hL.SetDefaultColor(Color.GREEN);



plot pl = Round(B, 2);

pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);



plot ll = if Bl > 0

                      then Bl

                      else Double.NaN;

ll.SetHiding(!ShowLines);

ll.SetPaintingStrategy(PaintingStrategy.DASHES);

ll.SetDefaultColor(Color.RED);



# Alerts

Alert(SoundAlerts and h > al , "Up", Alert.BAR, Sound.Bell);

Alert(SoundAlerts and l < bl, "Down", Alert.BAR, Sound.Ding);
 

adarty73

New member
I need to build a Scanner that find stocks at the opening creates a new High, 1 min candle, but cannot create another high , it creates a lower High, the price starts to change direction to the downside. creating a lower high

thanks you I appreciate any help
 

tomsk

Well-known member
VIP
@2sureshk from your description seems like you're looking for an inside bar transition from the previous bar to the current bar. That by definition is what a lower high and and a higher low is. Here is your requested scan. I have assumed that the size of the bar excludes the wicks. Here then is your requested scan. Make sure you run this on a daily aggregation on the scanner. I obtained 93 hits on a daily scan of the S&P 500.

Code:
# START
def barSize = AbsValue(open-close);
plot scan = high < high[1] and low > low[1] and barsize - barSize[1] < 0.6;
# END
 

tabs999

Member
Is there a higher high lower low indicator vice versa script out there floating around for ToS?

This is what I was able to find.

TtykLa4.png


Bars until the next higher high _DMonkey

Code:
#I am unclear as to what you where trying to accomplish, but the here is an example of a forward loop...it starts with a simple condition to define a peak, then from there it loops forward and stops when the condition is meet. it checks to see if a high breaks above the peak.Again, I dont know what your goal was, but the fault usually lays in the logic....you should be able to figure out what your after from here. It displays how many bars after the peak it takes to make a break of that condition in your selected length.if it does not happen in your determined length no criteria is recorded.
input n = 13;
def h = high;
def bar = barnumber();
def peak = if sum(h > h[1],2)>=2 && h[-1] < h
         then bar
         else peak[1];
def hh2 = if bar == peak
          then h
          else hh2[1];
plot NextHigh = if bar == peak
                then
                    fold i = 0 to n + 1
                    with price = Double.NaN
                    while IsNaN(price)
                    do if getValue(h, -i,( -n - 1)) > getvalue(hh2,-i,(-n - 1))
                    then i
                    else double.nan
                else double.nan;

nexthigh.setpaintingStrategy(PaintingStrategy.VALUES_ABOVE);
 

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.

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

EupfafQ.png


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
 

XeoNoX

Well-known member
VIP
Does anyone have an indicator that colors the candles when they close higher than the previous candle?

@MColb

Colors the candle Blue if the Close is greater than the previous Candle

Code:
#By XeoNoX via usethinkscript.com
def scan = close>high[1];
AssignPriceColor(if scan then color.BLUE else color.white);
 

TOS Rookie

New member
I’m looking to create a counter, this is so basic, but learning.
1) Counter that only looks at red candles . After reaching a new low, each higher high Red candle (indicated by absolute highest price of the wick for day) would be counted. The first high red candle is 1, then next higher high red is 2, etc.... cycle runs forward until we terminate at a reversal in which we see lower low Red candles.
2) Now on to downside from a Peak, the first Red candle down is 1, and if the next Red candle is at least >=50% of previous candle body, then it would be counted as 2, same count continues downward until we terminate at new low.

Code:
Def Red = Close < Open;
Def HigherRed = Close < Open and  Absolute high price > Red (-1)
Def LowerRed = Close < Open and Absolute high price => 50% of Red (-1)
If HigherRed > Red, 1, else 0
Count # +1
If LowerRed < Red, 1, else 0
Count #+1

Something along these lines... and they can repaint over if a new Red Higher or Lower bar displaces the last one in value. Thanks for any guidance.
 

XeoNoX

Well-known member
VIP
I’m looking to create a counter, this is so basic, but learning.
1) Counter that only looks at red candles . After reaching a new low, each higher high Red candle (indicated by absolute highest price of the wick for day) would be counted. The first high red candle is 1, then next higher high red is 2, etc.... cycle runs forward until we terminate at a reversal in which we see lower low Red candles.
2) Now on to downside from a Peak, the first Red candle down is 1, and if the next Red candle is at least >=50% of previous candle body, then it would be counted as 2, same count continues downward until we terminate at new low.

Code:
Def Red = Close < Open;
Def HigherRed = Close < Open and  Absolute high price > Red (-1)
Def LowerRed = Close < Open and Absolute high price => 50% of Red (-1)
If HigherRed > Red, 1, else 0
Count # +1
If LowerRed < Red, 1, else 0
Count #+1

Something along these lines... and they can repaint over if a new Red Higher or Lower bar displaces the last one in value. Thanks for any guidance.

I just put that together as a concept of what I’m trying to achieve. No idea how to make it work, I’ve been studying the tutorial but maybe I’m just missing the basics here.
here goes your "concept" you requested:
Code:
def red_cande_high = if close<open then high else 0;
def higher_red_candle = red_cande_high > red_cande_high[1];
def Count_red_highs = CompoundValue(1, if higher_red_candle  then Count_red_highs[1] + 1 else 0, 0);
def Final_scan = if Count_red_highs and low>low[1] then 0 else Count_red_highs;
plot scan = Final_scan;
 

airgb

New member
Hello guys, I was told to post the question here that I am looking for someone to make me an indicator for my TOS platform. It's a simple indicator (at least it is to me) where it shows the trend, with respect to, higher highs, lower lows, inside days, outside days up, outside days down, etc., by drawing a line to each bar or candle's new high or low. I can send anyone interested a jpg of what I am wanting if needed. Anyone? Thanks
 

rad14733

Well-known member
VIP
@airgb Please post you image(s) here so we can visualize what you are referring to... It's a bit of a security risk from members to openly post their email addresses and there is no private messaging feature enabled in these forums, also for security reasons... Post you images openly for all to see and either someone will be interested or they won't... Or perhaps you'll be directed to an existing Thinkscript...
 

british43

Member
Hello,

I'm trying to plot a low line at the low of the high scalp candle. Any help is greatly appeciated.

Code:
input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();

def Highest = fold i = 1 to n + 1
              with p = 1
              while p
              do h > GetValue(h, -i);

def A = if (Firstbar > n and
            h == Highest(h, n) and
            Highest)
        then h
        else Double.NaN;

def Al = if !IsNaN(A)
         then A
         else Al[1];

plot ph = Round(A, 2);
     ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
     ph.SetDefaultColor(Color.Green);

plot hL = if Al > 0
          then Al
          else Double.NaN;
     hL.SetHiding(!ShowLines);
     hL.SetPaintingStrategy(PaintingStrategy.DASHES);
     hL.SetDefaultColor(Color.GREEN);
 

SleepyZ

Well-known member
@british43

Code:
input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();

def Highest = fold i = 1 to n + 1
with p = 1
while p
do h > GetValue(h, -i);

def A = if (Firstbar > n and
h == Highest(h, n) and
Highest)
then h
else Double.NaN;

def Al = if !IsNaN(A)
then A
else Al[1];

plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
ph.SetDefaultColor(Color.Green);

plot hL = if Al > 0
then Al
else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);

def B = if (Firstbar > n and
h == Highest(h, n) and
Highest)
then l
else Double.NaN;

def B1= if !IsNaN(A)
then B
else B1[1];

plot pl = if Al > 0
then B1
else Double.NaN;
pl.SetHiding(!ShowLines);
pl.SetPaintingStrategy(PaintingStrategy.DASHES);
pl.SetDefaultColor(Color.red);
 

Similar threads

Top