Repaints ZigZag High Low with Supply & Demand Zones for ThinkorSwim

Repaints
This doesn't seem to work correctly, at least for what I'm looking for. I want to see what the retracement %s plot lines are, for the current Zig Zag, projected into the future bars (or I'd settle for it to be plotted on the current "zag").

The idea is to always know what the 25% and 50% retracement levels are for a rally or pullback/dip.

it's like having a measuring stick on the current "zag" at all times, so you know where it could retrace to.
 
@tomsk Can anyone confirm the reverse engineered code below for a Swing High that I attempted to translate from Tomsk original script above? Someone asked in another thread about the Swing High scanner...I don't want to respond and give incorrect script... @XeoNoX you're very good at the scanners that you've helped me out with before...does this look right to you? Not sure if I need to change the length to + 1 from -1

Code:
input length = 10;

def bn = BarNumber();
def lastBar = LowestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);

def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);

def highPointOneBarNumber = LowestAll(if swingHigh then bn else 0);

plot scan = bn == highPointOneBarNumber;
 
Last edited:
I came over this zigzag% indicator.

https://www.tradingview.com/script/ONcYoFCP-zigzag/

I wonder, if anybody could convert it to TOS.

0SYz2vf.png
 
Whats going on, I copied the supply and demand zone portion of this code to create a mtf zone indicator. However when I rewrote the code for mtf it doesnt show the large time frame zones on a smaller time frame. I dont know why and would like some help :)

Code:
input timeframe = aggregationperiod.fifTEEN_MIN;
input bubbleoffset = .0005;
input percentamount = .01;
input revAmount = .15;
input atrreversal = 1.0;
input atrlength = 5;
def zz = ZigZagHighLow("price h" = high(period=timeframe), "price l" = low(period=timeframe), "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount        = if (close(period=timeframe) * percentamount / 100) > Max(revAmount < atrreversal * atrlength, revAmount) then (close(period=timeframe) * percentamount / 100) else if revAmount < atrreversal * atrlength then atrreversal * atrlength else revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high(period=timeframe) then high(period=timeframe) else low(period=timeframe)) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
def zzL = if !IsNaN(zz) and !isUp then low(period=timeframe) else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high(period=timeframe) else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or low(period=timeframe)==zzl[1] and low(period=timeframe)==zzsave then 1 else if zzH != zzH[1] or high(period=timeframe)==zzh[1] and high(period=timeframe)==zzsave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and low(period=timeframe) > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high(period=timeframe) < zzH then if signal[1] >= 0 then -1 else signal[1]    else signal[1], 0);

rec data1 = CompoundValue(1, if (zzSave == high(period=timeframe) or zzSave == low(period=timeframe)) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
input numbersuppdemandtoshow = 2;
input showSupplyDemand = {default Pivot, Arrow, None};
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if signal crosses 0 {
    rLow = low(period=timeframe)[idx];
    rHigh = high(period=timeframe)[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
plot HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close(period=timeframe)) and rHigh != 0 then rHigh else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

plot LowLine = if datacount1 <= numbersuppdemandtoshow and  showSupplyDemand != showSupplyDemand.None and !IsNaN(close(period=timeframe)) and rLow != 0 then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

input showsupplydemandcloud = yes;
AddCloud(if showsupplydemandcloud then hlUp else Double.NaN, LowLine, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showsupplydemandcloud then hlDn else Double.NaN, LowLine, Color.LIGHT_RED, Color.LIGHT_RED);
 
@aceboogie_11 The following seems to work by using a global : "def high = high(period=timeframe); def low = low(period=timeframe); " rather than changing each instance of those as you did. Your modifications normally works with most indicators.

Code:
input timeframe = AggregationPeriod.FIFTEEN_MIN;

def high = high(period = timeframe);
def low  = low(period = timeframe);

input bubbleoffset = .0005;
input percentamount = .01;
input revAmount = .15;
input atrreversal = 1.0;
input atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount        = if (close * percentamount / 100) > Max(revAmount < atrreversal * atrlength, revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * atrlength then atrreversal * atrlength else revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
def zzL = if !IsNaN(zz) and !isUp then low else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or low == zzL[1] and low == zzSave then 1 else if zzH != zzH[1] or high == zzH[1] and high == zzSave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and low > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high < zzH then if signal[1] >= 0 then -1 else signal[1]    else signal[1], 0);

def data1 = CompoundValue(1, if (zzSave == high or zzSave == low) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
input numbersuppdemandtoshow = 2;
input showSupplyDemand = {default Pivot, Arrow, None};
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if signal crosses 0 {
    rLow = low[idx];
    rHigh = high[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
plot HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

plot LowLine = if datacount1 <= numbersuppdemandtoshow and  showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

input showsupplydemandcloud = yes;
AddCloud(if showsupplydemandcloud then hlUp else Double.NaN, LowLine, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showsupplydemandcloud then hlDn else Double.NaN, LowLine, Color.LIGHT_RED, Color.LIGHT_RED);
 
I found this code on the forum. It gives an entry-line. I have been very pleased with the results and was wondering if it is possible to make a scan from this script? I realize that it would return a large amount of results, but I would use it as a cross filter of other results and use an alarm to notify me of perfect entry opportunities. Any help would be appreciated.

Code:
#ZIG ZAG WITH REVERSL OF 0.001 THAT WAS REQUESTED BY BRAUM AND CODED BY ZZZ. THIS FORMAT OF  LARRY'S IS DIFFERENT THAN THE ORIGINAL ONE. THIS FORMAT IS MUCH MORE DETAIL, AND SPECIFIC. ONE MUST FOLLOW THE COLORE CODING AS THE POINT OF LONG, SHORT OR EXITS.

input reversalAmount = 0.001;
input length  = 1;
input length1 = 4;#4
input bar_plus =.5;
input avg     = AverageType.exponential;#Wilders
input avg1    = AverageType.exponential;#Wilders
input price   = HL2;
input  bar2_plus = .5;
def avgprice = MovingAverage(averagetype = avg, (price), length);
Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);
plot "ZZ$" = reference ZigZagHighLow(avgprice, avgprice, 0, reversalAmount, 1, 0)+ bar_plus ;
def zzSave = if !IsNaN("ZZ$") then avgprice else GetValue(zzSave, 1);
def chg = avgprice - GetValue(zzSave, 1);
def isUp = if chg >= 0 then 1 else 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));
"ZZ$".EnableApproximation();
"ZZ$".AssignValueColor(if isUp then Color.blue else Color.white);

def avgprice1 = MovingAverage(averagetype = avg1, (price), length1);
plot "ZZ1$" = reference ZigZagHighLow(avgprice1, avgprice1, 0, reversalAmount, 1, 0) + bar2_plus;

def zzSave1 = if !IsNaN("ZZ1$") then avgprice1 else GetValue(zzSave1, 1);
def chg1 = avgprice1 - GetValue(zzSave1, 1);
def isUp1 = if chg1 >= 0 then 1 else 0;
def isConf1 = AbsValue(chg1) >= reversalAmount or (IsNaN(GetValue("ZZ1$", 1)) and GetValue(isConf1, 1));
"ZZ1$".EnableApproximation();
"ZZ1$".AssignValueColor(if isUp1 then Color.GREEN else Color.GRAY);

input showlabel = no;
AddLabel(showlabel, "ZDir" + length, if isUp then Color.GREEN else Color.RED);
AddLabel(showlabel, "ZPr"  + length, if close > zzSave then Color.GREEN else Color.RED);
AddLabel(showlabel, "ZDir" + length1, if isUp1 then Color.GREEN else Color.RED);
AddLabel(showlabel, "ZPr"  + length1, if close > zzSave1 then Color.GREEN else Color.RED);

input n = 3;
def n1 = n + 1;
input showbubbles = no;
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]), close[n1] , "Z" + length,  if isUp[n1] then Color.GREEN else Color.RED, no);
AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]),  close[n1] , "Z" + length1,  if isUp1[n1] then Color.GREEN else Color.RED, no);
AddChartBubble(showbubbles and !IsNaN(close[n1 + 6]) and IsNaN(close[n + 6]), close[n1 + 6] , length,  if close[n1 + 6] > zzSave[n1 + 6] then Color.GREEN else Color.RED, no);
AddChartBubble(showbubbles and !IsNaN(close[n1 + 6]) and IsNaN(close[n + 6]),  close[n1 + 6] , length1,  if close[n1 + 6] > zzSave1[n1 + 6] then Color.GREEN else Color.RED, no);



input pricecolor = yes;
#AssignPriceColor(if pricecolor then if isUp and isUp then Color.GREEN else if isUp == 0 and isUp == 0 then Color.RED else if open>close then color.yellow else Color.WHITE else Color.CURRENT);
AssignPriceColor(if pricecolor then if isUp and isUp1 then Color.GREEN else if isUp == 0 and isUp1 == 0 then Color.DARK_RED  else Color.CURRENT else Color.CURRENT);

#EntryPrice
input showentrystoploss = yes;
def ep = if  isup and isup1 then 1 else if  isup==0 and isup1==0 then -1 else 0;
#plot e=ep;
#e.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
def eprice = if ep[1]!=1 and ep==1 then open[-1] else if ep!=-1 then eprice[1] else if ep[1]!=-1 and ep==-1 then open[-1] else if ep!=1 then eprice[1] else 0;
#plot ep1=eprice;
#ep1.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
input r = 22;
def  r1 = r + 1;
AddChartBubble(showentrystoploss and !IsNaN(close[r1]) and IsNaN(close[r]), if ep[r1]==1 then eprice[r1] else eprice[r1], "Entry" + "\n   $" + Round(eprice[r1],2), if ep[r1]==1 then Color.GREEN else if ep[r1]==-1 then Color.RED else color.white, if ep[r1]==1 then no else yes);

input offset = 0;
input lengtheprice = 10;
def sma = SimpleMovingAvg(eprice, 1, lengtheprice);
def line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline = if showentrystoploss and IsNaN(sma) then line else Double.NaN;
priceline.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
priceline.SetLineWeight(1);
priceline.setdefaultColor(color.white);

#Price Change between zigzags
def xxhigh = if zzSave == avgprice then avgprice else xxhigh[1];
def chghigh = avgprice - xxhigh[1];
def zzsave4 = if !IsNaN(zzSave) then zzSave else zzsave4[1];
rec zz1 = if zzSave1  != zzsave4[1]  then zzsave4[1]  else zz1[1];
rec zz2 = if zz1 != zz1[1] then zz1[1] else zz2[1];
rec zz3 = if zz2 != zz2[1] then zz2[1] else zz3[1];

#Higher/Lower Highs/Lows
input bubbleoffset = .00075;
input showBubblehhll = no;
plot x = if showBubblehhll and !IsNaN("ZZ$") and BarNumber() != 1 then  if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset) else Double.NaN;
x.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
x.AssignValueColor( if isUp and xxhigh - zz2 > 0 then Color.GREEN else if isUp and xxhigh - zz2 < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and xxhigh - zz2 > 0 then Color.GREEN else if !isUp and xxhigh - zz2 < 0 then Color.RED else Color.YELLOW);
x.SetLineWeight(2);
 
@Chuck I don't think that script can be converted to a scan due to the fact that it utilizes the ZigZagHighLow study, just as the Trend_Reversal_Indicator_With_Signals study can't be used for the same reason...
 
rad14733, thanks for the reply. I tried to load it as a study "as is", and it said it was to complex . ... I have a few other scripts that find highs and lows. I might try to remix the scripts together and give it a try. I am starting to learn a bit. Thanks for letting me know about the zig zag issue.
 
@Akotic That image looks very similar to the DarvasBox Study that comes with Thinkorswim... There may be others that plot similarly here in these forums... I would implore you to exhaust all efforts to insure that we have no viable alternatives here or in TOS... I, personally, don't know MT5 scripting language so any conversion on my part would be quite laborious because I'd need to learn yet another scripting language, and one that isn't as self-documenting like Thinkscript is... It's more programming language based than scripting language based... All that being said, I may edit out all of the Russian comments at some point to see what it does just out of curiosity... But I have other coding to do beforehand...
 
@Akotic That image looks very similar to the DarvasBox Study that comes with Thinkorswim... There may be others that plot similarly here in these forums... I would implore you to exhaust all efforts to insure that we have no viable alternatives here or in TOS... I, personally, don't know MT5 scripting language so any conversion on my part would be quite laborious because I'd need to learn yet another scripting language, and one that isn't as self-documenting like Thinkscript is... It's more programming language based than scripting language based... All that being said, I may edit out all of the Russian comments at some point to see what it does just out of curiosity... But I have other coding to do beforehand...
Thanks for the assistance! I currently have alternatives, but none as nice as the one I'd like converted. I'll check out Darvas for sure
 
@rad14733 This is the Mt5 code

Code:
//+------------------------------------------------------------------+
//|                                    ZigZagOnParabolic_channel.mq5 |
//|                                      Copyright © 2009, EarnForex |
//|                                        [URL]http://www.earnforex.com/[/URL] |
//+------------------------------------------------------------------+
//---- авторство индикатора
#property copyright "Copyright © 2009, EarnForex"
//---- ссылка на сайт автора
#property link      "[URL]http://www.earnforex.com[/URL]"
//---- номер версии индикатора
#property version   "1.00"
#property description "ZigZag on Parabolic в виде канала"
//---- отрисовка индикатора в главном окне
#property indicator_chart_window
//---- для расчёта и отрисовки индикатора использовано восемь буферов
#property indicator_buffers 8
//---- использовано всего пять графических построений
#property indicator_plots   5
//+----------------------------------------------+
//|  Параметры отрисовки индикатора облака       |
//+----------------------------------------------+
//---- отрисовка индикатора в виде цветного облака
#property indicator_type1   DRAW_FILLING
//---- в качестве цвета облака использован
#property indicator_color1  clrLavender
//---- отображение метки индикатора
#property indicator_label1  "ZigZagOnParabolic_channel Cloud"
//+----------------------------------------------+
//|  Параметры отрисовки верхнего индикатора     |
//+----------------------------------------------+
//---- отрисовка индикатора 2 в виде многоцветной линии
#property indicator_type2   DRAW_COLOR_LINE
//---- в качестве цвета индикатора использованы
#property indicator_color2  clrTeal,clrPurple
//---- толщина линии индикатора 2 равна 2
#property indicator_width2  2
//---- отображение бычей метки индикатора
#property indicator_label2  "Up ZigZagOnParabolic_channel"
//+----------------------------------------------+
//|  Параметры отрисовки нижнего индикатора      |
//+----------------------------------------------+
//---- отрисовка индикатора 3 в виде многоцветной линии
#property indicator_type3   DRAW_COLOR_LINE
//---- в качестве цвета индикатора использованы
#property indicator_color3  clrTeal,clrPurple
//---- толщина линии индикатора 3 равна 2
#property indicator_width3  2
//---- отображение медвежьей метки индикатора
#property indicator_label3 "Down ZigZagOnParabolic_channel"
//+----------------------------------------------+
//|  Параметры отрисовки верхнего индикатора     |
//+----------------------------------------------+
//---- отрисовка индикатора 4 в виде символа
#property indicator_type4   DRAW_ARROW
//---- в качестве цвета индикатора использован DodgerBlue
#property indicator_color4  clrDodgerBlue
//---- толщина линии индикатора 4 равна 1
#property indicator_width4  1
//---- отображение бычей метки индикатора
#property indicator_label4  "Up ZigZagOnParabolic_Arrows"
//+----------------------------------------------+
//|  Параметры отрисовки нижнего индикатора      |
//+----------------------------------------------+
//---- отрисовка индикатора 5 в виде символа
#property indicator_type5   DRAW_ARROW
//---- в качестве цвета индикатора использован DeepPink
#property indicator_color5  clrDeepPink
//---- толщина линии индикатора 5 равна 1
#property indicator_width5  1
//---- отображение медвежьей метки индикатора
#property indicator_label5 "Down ZigZagOnParabolic_Arrows"
//+----------------------------------------------+
//| Входные параметры индикатора                 |
//+----------------------------------------------+
input double Step=0.02; //SAR шаг
input double Maximum=0.2; //SAR максимум
input bool ExtremumsShift=true; //флаг сдвига вершины
input uint  UpLable=163;//лейба верхнего фрактала
input uint  DnLable=163;//лейба нижнего фрактала
//+----------------------------------------------+
//---- объявление динамических массивов, которые будут в дальнейшем использованы в качестве индикаторных буферов
double UpBuffer[],DnBuffer[];
double UpperBuffer[],LowerBuffer[];
double ColorUpperBuffer[],ColorLowerBuffer[];
double LowestBuffer[],HighestBuffer[];
//---- Объявление целых переменных
int EShift;
//---- Объявление целых переменных начала отсчёта данных
int min_rates_total;
//---- Объявление целых переменных для хендлов индикаторов
int SAR_Handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---- Инициализация переменных начала отсчёта данных
   min_rates_total=1;
//---- Инициализация констант
   if(ExtremumsShift) EShift=1;
   else               EShift=0;

//---- получение хендла индикатора SAR
   SAR_Handle=iSAR(NULL,0,Step,Maximum);
   if(SAR_Handle==INVALID_HANDLE)
     {
      Print(" Не удалось получить хендл индикатора SAR");
      return(INIT_FAILED);
     }

//---- превращение динамических массивов в индикаторные буферы
   SetIndexBuffer(0,UpBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,DnBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,UpperBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ColorUpperBuffer,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,LowerBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,ColorLowerBuffer,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(6,HighestBuffer,INDICATOR_DATA);
   SetIndexBuffer(7,LowestBuffer,INDICATOR_DATA);
//---- запрет на отрисовку индикатором пустых значений
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,NULL);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,NULL);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,NULL);
   PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,NULL);
   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,NULL);
//---- индексация элементов в буферах как в таймсериях
   ArraySetAsSeries(UpBuffer,true);
   ArraySetAsSeries(DnBuffer,true);
   ArraySetAsSeries(UpperBuffer,true);
   ArraySetAsSeries(LowerBuffer,true);
   ArraySetAsSeries(ColorUpperBuffer,true);
   ArraySetAsSeries(ColorLowerBuffer,true);
   ArraySetAsSeries(LowestBuffer,true);
   ArraySetAsSeries(HighestBuffer,true);
//---- установка позиции, с которой начинается отрисовка
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,min_rates_total);
   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,min_rates_total);
//---- символы для индикатора
   PlotIndexSetInteger(3,PLOT_ARROW,DnLable);
   PlotIndexSetInteger(4,PLOT_ARROW,UpLable);
//---- Установка формата точности отображения индикатора
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- имя для окон данных и лэйба для субъокон
   IndicatorSetString(INDICATOR_SHORTNAME,"ZigZagOnParabolic_channel");
//--- завершение инициализации
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---- проверка количества баров на достаточность для расчёта
   if(BarsCalculated(SAR_Handle)<rates_total || rates_total<min_rates_total)return(0);

//---- объявления локальных переменных
   static int j_,lastcolor_;
   static bool dir_;
   static double h_,l_;
   int j,limit,climit,to_copy,bar,shift,NewBar,lastcolor;
   int barHH,barLL,barHH1,barLL1;
   double h,l,mid0,mid1,SAR[],HH,LL,HH1,LL1;
   bool dir;

//---- расчёт стартового номера limit для цикла пересчёта баров и стартовая инициализация переменных
   if(prev_calculated>rates_total || prev_calculated<=0)// проверка на первый старт расчёта индикатора
     {
      limit=rates_total-1-min_rates_total; // стартовый номер для расчёта всех баров

      h_=0.0;
      l_=999999999;
      dir_=false;
      j_=0;
      lastcolor_=0;

      for(int index=rates_total-1; index>=limit && !IsStopped(); index--)
        {
         UpBuffer[index]=NULL;
         UpperBuffer[index]=NULL;
         HighestBuffer[index]=NULL;

         DnBuffer[index]=NULL;
         LowerBuffer[index]=NULL;
         LowestBuffer[index]=NULL;
        }
     }
   else
     {
      limit=rates_total-prev_calculated; // стартовый номер для расчёта новых баров
     }

   climit=limit; // стартовый номер для раскраски индикатора

   to_copy=limit+2;
   if(limit==0) NewBar=1;
   else         NewBar=0;

//---- индексация элементов в массивах как в таймсериях
   ArraySetAsSeries(SAR,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);

//---- копируем вновь появившиеся данные в массив
   if(CopyBuffer(SAR_Handle,0,0,to_copy,SAR)<=0) return(0);

//---- восстанавливаем значения переменных
   j=j_;
   dir=dir_;
   h=h_;
   l=l_;
   lastcolor=lastcolor_;

//---- Первый большой цикл расчёта индикатора
   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      //---- запоминаем значения переменных перед прогонами на текущем баре
      if(rates_total!=prev_calculated && bar==0)
        {
         j_=j;
         dir_=dir;
         h_=h;
         l_=l;
        }

      mid0=(high[bar]+low[bar])/2;
      mid1=(high[bar+1]+low[bar+1])/2;

      HighestBuffer[bar]=0.0;
      LowestBuffer[bar]=0.0;

      if(bar>0) j++;

      if(dir)
        {
         if(h<high[bar])
           {
            h=high[bar];
            j=NewBar;
           }
         if(SAR[bar+1]<=mid1 && SAR[bar]>mid0)
           {
            shift=bar+EShift *(j+NewBar);
            if(shift>rates_total-1) shift=rates_total-1;
            HighestBuffer[shift]=h;
            dir=false;
            l=low[bar];
            j=0;
            if(shift>climit) climit=shift;
           }
        }
      else
        {
         if(l>low[bar])
           {
            l=low[bar];
            j=NewBar;
           }
         if(SAR[bar+1]>=mid1 && SAR[bar]<mid0)
           {
            shift=bar+EShift *(j+NewBar);
            if(shift>rates_total-1) shift=rates_total-1;
            LowestBuffer[shift]=l;
            dir=true;
            h=high[bar];
            j=0;
            if(shift>climit) climit=shift;
           }
        }
     }

//---- Третий большой цикл расчёта индикатора
   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      barHH=FindFirstExtremum(bar,rates_total,HighestBuffer,HH);
      barHH1=FindFirstExtremum(barHH+1,rates_total,HighestBuffer,HH1);

      if(barHH>=0 && barHH1>=0)
        {
         for(int index=barHH1-1; index>barHH && !IsStopped(); index--)
           {
            UpBuffer[index]=HH1;
            UpperBuffer[index]=HH1;
            ColorUpperBuffer[index]=ColorUpperBuffer[index+1];
           }

         for(int index=barHH; index>=bar && !IsStopped(); index--)
           {
            UpBuffer[index]=HH;
            UpperBuffer[index]=HH;
            if(HH>HH1) ColorUpperBuffer[index]=0;
            else if(HH<HH1) ColorUpperBuffer[index]=1;
            else ColorUpperBuffer[index]=ColorUpperBuffer[index+1];
           }
        }

      barLL=FindFirstExtremum(bar,rates_total,LowestBuffer,LL);
      barLL1=FindFirstExtremum(barLL+1,rates_total,LowestBuffer,LL1);

      if(barLL>=0 && barLL1>=0)
        {
         for(int index=barLL1-1; index>barLL && !IsStopped(); index--)
           {
            DnBuffer[index]=LL1;
            LowerBuffer[index]=LL1;
            ColorLowerBuffer[index]=ColorLowerBuffer[index+1];
           }

         for(int index=barLL; index>=bar && !IsStopped(); index--)
           {
            DnBuffer[index]=LL;
            LowerBuffer[index]=LL;
            if(LL>LL1) ColorLowerBuffer[index]=0;
            else if(LL<LL1) ColorLowerBuffer[index]=1;
            else ColorLowerBuffer[index]=ColorLowerBuffer[index+1];
           }
        }
     }
//---- 
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Поиск самой первой вершины Зигзага в буферах таймсериях          |
//+------------------------------------------------------------------+ 
int FindFirstExtremum(int StartPos,int Rates_total,double &Array[],double &Extremum)
  {
//----
   for(int bar=StartPos; bar<Rates_total; bar++)
     {
      if(Array[bar] && Array[bar]!=EMPTY_VALUE)
        {
         Extremum=Array[bar];
         return(bar);
         break;
        }
     }
//----
   Extremum=NULL;
   return(-1);
  }
//+------------------------------------------------------------------+


To answer your questions,

Yes, I've seen and used this indicator on the Mt5 plartform.

Yes I've messed around with the indicators that are here as well as those that come with the platform. I use this for visual and go by previous points to look for trade entries (using stoch and price action) since ZigZag repaints.

I've usually coded things myself or pay people on upwork or freelancer for any coding needs and would be more then willing to pay a fee for the conversion

Thanks for the welcome!

ZigZnip.png

I just saw your request. Perhaps this may be useful. It is an adaption of the zigzag script that I added at the bottom, code to draw the lines similar to those in your request.
Code:
# ZigZag High Low Supply Demand
# ZigZag High Low modified in part by Linus' and Lar's code
# ZZZ, with modifications by tomsk
# 1.12.2020

# https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/page-2#post-13790

# V1.0 - 10.09.2016 - ZZZ   - Initial release of ZigZag High Low Supply Demand
# V1.1 - 06.28.2017 - tomsk - Sectionalized code, and rearranged flow of some ZZ Logic
# V1.2 - 01.12.2020 - tomsk - Removed Fibonacci related code per user request

input showBubblesChange = no;  # Price Change between Zigzags
input showBubblesPrice = no;    # Price at Zigzag High/Low
input showBubblesBarCount = no; # Bar Count between Zigzags
input showBubblesVolume = no;   # Volume at Zigzag Reversals

input showArrows = no;
input useAlerts = no;
input numberSuppDemandToShow = 2;
input showSupplyDemand = {default Pivot, Arrow, None};
input showSupplyDemandCloud = yes;

input BubbleOffset = .0005;
input PercentAmount = .01;
input RevAmount = .15;
input ATRreversal = 1.0;
input ATRlength = 5;

def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = PercentAmount,
"absolute reversal" = RevAmount, "atr length" = ATRlength, "atr reversal" = ATRreversal);

def ReversalAmount = if (close * PercentAmount / 100) > Max(RevAmount < ATRreversal * ATRlength, RevAmount)
                     then (close * PercentAmount / 100)
                     else if RevAmount < ATRreversal * ATRlength
                          then ATRreversal * ATRlength
                          else RevAmount;
# Zig Zag Specific Data

def zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= ReversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));

# Price Change Between ZigZags

def xxHigh = if zzSave == high then high else xxHigh[1];
def chgHigh = high - xxHigh[1];
def xxLow = if zzSave == low then low else xxLow[1];
def chgLow = low - xxLow[1];

# Bar Count Between ZigZags

def zzCount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzCount[1] + 1 else 0;
def zzCountHiLo = if zzCountHiLo[1] == 0 and (zzSave == high or zzSave == low) then 1
                  else if zzSave == high or zzSave == low then zzCountHiLo[1] + 1
                  else zzCountHiLo[1];
def zzHiLo = if zzSave == high or zzSave == low then zzCountHiLo else zzCountHiLo + 1;
def zzCountHigh = if zzSave == high then zzCount[1] else Double.NaN;
def zzCountLow  = if zzSave == low then zzCount[1] else Double.NaN;

# Volume at Reversals

def vol = if BarNumber() == 0 then 0 else volume + vol[1];
def vol1 = if BarNumber() == 1 then volume else vol1[1];
def xxVol = if zzSave == high or zzSave == low then TotalSum(volume) else xxVol[1];
def chgVol =  if xxVol - xxVol[1] + vol1 == vol then vol else xxVol - xxVol[1];

# Label for Confirmed/Unconfirmed Status of Current Zigzag

AddLabel(BarNumber() != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg,
    if !isConf then Color.Dark_Orange else if isUp then Color.Green else Color.Red);

# Zig Zag Plot

plot zzp = if isUp <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if isUp then Color.Green else if !isUp then Color.Red else Color.Dark_Orange);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();

plot zzdot = if isUp <= 1 then zz else Double.NaN;
zzdot.setpaintingStrategy(paintingStrategy.POINTS);
zzdot.setlineWeight(5);
zzdot.assignvalueColor(if zzsave==high then color.yellow else color.blue);

# Bubbles

# Price Change between Zigzags

AddChartBubble(showBubblesChange and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), "$" + chg, if isUp and chgHigh > 0 then Color.Green else if isUp and chgHigh < 0 then Color.Red else if isUp then Color.Yellow else if !isUp and chgLow > 0 then Color.Green else if !isUp and chgLow < 0 then Color.Red else Color.Yellow, isUp);

# Price at Zigzag High/Low

AddChartBubble(showBubblesPrice and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), if isUp then "$" + high else "$" + low , if isUp and chgHigh > 0 then Color.Green else if isUp and chgHigh < 0 then Color.Red else if isUp then Color.Yellow else if !isUp and chgLow > 0 then Color.Green else if !isUp and chgLow < 0 then Color.Red else Color.Yellow, isUp);

# Bar Count between Zigzags

AddChartBubble(showBubblesBarCount and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), if zzSave == high then zzCountHigh else zzCountLow, if isUp and chgHigh > 0 then Color.Green else if isUp and chgHigh < 0 then Color.Red else if isUp then Color.Yellow else if !isUp and chgLow > 0 then Color.Green else if !isUp and chgLow < 0 then Color.Red else Color.Yellow, if isUp then yes else no );

# Volume at Zigzag Reversals

AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset) else low * (1 - bubbleoffset), chgVol,if isUp and chghigh > 0 then Color.Green else if isUp and chghigh < 0 then Color.Red else if isUp then Color.Yellow else if !isUp and chglow > 0 then Color.Green else if !isUp and chglow < 0 then Color.Red else Color.Yellow, if isUp then yes else no );

# Arrows

def zzL = if !IsNaN(zz) and !isUp then low else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high else GetValue(zzH, 1);

def dir = CompoundValue(1, if zzL != zzL[1] or low == zzL[1] and low == zzSave then 1
                           else if zzH != zzH[1] or high == zzH[1] and high == zzSave then -1
                           else dir[1], 0);

def signal = CompoundValue(1, if dir > 0 and low > zzL
                              then if signal[1] <= 0 then 1 else signal[1]
                              else if dir < 0 and high < zzH
                                   then if signal[1] >= 0 then -1 else signal[1]
                                   else signal[1], 0);

plot U1 = showArrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.Green);
U1.SetLineWeight(4);

plot D1 = showArrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.Red);
D1.SetLineWeight(4);

# Alerts

Alert(useAlerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(useAlerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);

# Supply Demand Areas

def data1 = CompoundValue(1, if (zzSave == high or zzSave == low) then data1[1] + 1 else data1[1], 0);
def dataCount1 = (HighestAll(data1) - data1[1]);
def idx = showSupplyDemand == showSupplyDemand.Pivot;

def rLow;
def rHigh;
if signal crosses 0 {
    rLow = low[idx];
    rHigh = high[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}

plot HighLine = if dataCount1 <= numberSuppDemandToShow and
                   showSupplyDemand != showSupplyDemand.None and
                   !isNaN(close) and
                   rHigh != 0
                then rHigh
                else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.Green else Color.Red);

plot LowLine = if dataCount1 <= numberSuppDemandToShow and
                  showSupplyDemand != showSupplyDemand.None and
                  !isNaN(close) and
                  rLow != 0
               then rLow
               else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.Green else Color.Red);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

AddCloud(if showSupplyDemandCloud then hlUp else Double.NaN, LowLine, Color.Light_Green, Color.Light_Green);
AddCloud(if showSupplyDemandCloud then hlDn else Double.NaN, LowLine, Color.Light_Red, Color.Light_Red);


#Moification per Usethinkscript request to draw lines form one zzlow to another and the same for zzhigh to another zzhigh  
def shsl_low = if zzsave==low then zz else shsl_low[1];
plot swinglow = shsl_low;
swinglow.enableApproximation();
def slcolor = if swinglow != swinglow[1] and swinglow > swinglow[1]
              then 1
              else if slcolor[1] == 1 and swinglow == swinglow[1]
              then 1
              else 0;
swinglow.assignvalueColor(if slcolor == 1 then color.green else color.red);
swinglow.setlineWeight(3);

def shsl_high = if zzsave==high then zz else shsl_high[1];
plot swinghigh = shsl_high;
swinghigh.enableApproximation();
swinghigh.setlineWeight(3);

def shcolor = if swinghigh != swinghigh[1] and swinghigh > swinghigh[1]
              then 1
              else if slcolor[1] == 1 and swinghigh == swinghigh[1]
              then 1
              else 0;
swinghigh.assignvalueColor(if shcolor == 1 then color.green else color.red);

# End ZigZag High Low Supply Demand

Capture.jpg
 
made few edits to scripts from RobertPayne. Thank you for your script

Supply Demand Zones on various timeframes

# define swing low points
input length = 10;
input inRange = 1;

def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if swingLow then Color.LIME else if swingHigh then Color.red else Color.GRAY);

def atrRange = atr(length, AverageType.wEIGHTED);

# using a single plot to show the swing low points
def demandLow = if swingLow then low else demandLow[1];
plot PdemandLow = demandLow;
PdemandLow.SetDefaultColor(Color.RED);
PdemandLow.SetPaintingStrategy(12);

def demandHigh = if swingLow then high else demandHigh[1];
plot PdemandHigh = demandHigh;
PdemandHigh.SetDefaultColor(Color.GREEN);
PdemandHigh.SetPaintingStrategy(12);

def demandMid = if swingLow then (demandLow+demandHigh)/2 else demandMid[1];
plot PdemandMid = demandMid;
PdemandMid.SetDefaultColor(Color.cyan);
PdemandMid.SetPaintingStrategy(12);

AddCloud(PdemandMid, PdemandLow, Color.green, Color.green);

# using a single plot to show the swing High points
def SupplyLow = if swingHigh then low else SupplyLow[1];
plot PSupplyLow = SupplyLow;
PSupplyLow.SetDefaultColor(Color.RED);
PSupplyLow.SetPaintingStrategy(12);

def SupplyHigh = if swingHigh then high else SupplyHigh[1];
plot PSupplyHigh = SupplyHigh;
PSupplyHigh.SetDefaultColor(Color.GREEN);
PSupplyHigh.SetPaintingStrategy(12);

def SupplyMid = if swingHigh then (SupplyLow + SupplyHigh) / 2 else SupplyMid[1];
plot PSupplyMid = SupplyMid;
PSupplyMid.SetDefaultColor(Color.CYAN);
PSupplyMid.SetPaintingStrategy(12);
PSupplyMid.setLineWeight(2);


AddCloud(PSupplyMid , PSupplyHigh, Color.PINK, Color.PINK);

#def ht1 = if swingLow then c1+ ( c1*inRange ) / 100 else ht1[1];
#plot highTgt1 = ht1;
#highTgt1.SetDefaultColor(Color.green);
#highTgt1.SetPaintingStrategy(12);

#def lt1 = if swingLow then c1- ( c1*inRange ) / 100 else lt1[1];
#plot lowTgt1 = lt1;
#lowTgt1.SetDefaultColor(Color.red);
#lowTgt1.SetPaintingStrategy(12);

#def htAtr1 = if swingLow then c1+ ( c1*atrRange ) / 100 else htAtr1[1];
#plot highAtr11 = htAtr1;
#highAtr11.SetDefaultColor(Color.dark_green);
#highAtr11.SetPaintingStrategy(12);

#def ltAtr1 = if swingLow then c1- ( c1*atrRange ) / 100 else ltAtr1[1];
#plot lowAtr11 = ltAtr1;
#lowAtr11.SetDefaultColor(Color.white);
#lowAtr11.SetPaintingStrategy(12);
 
made few edits to scripts from RobertPayne. Thank you for your script

Supply Demand Zones on various timeframes
FEJ13aLWUAkPRhF?format=png&name=4096x4096.png

# define swing low points
input length = 10;
input inRange = 1;

def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if swingLow then Color.LIME else if swingHigh then Color.red else Color.GRAY);

def atrRange = atr(length, AverageType.wEIGHTED);

# using a single plot to show the swing low points
def demandLow = if swingLow then low else demandLow[1];
plot PdemandLow = demandLow;
PdemandLow.SetDefaultColor(Color.RED);
PdemandLow.SetPaintingStrategy(12);

def demandHigh = if swingLow then high else demandHigh[1];
plot PdemandHigh = demandHigh;
PdemandHigh.SetDefaultColor(Color.GREEN);
PdemandHigh.SetPaintingStrategy(12);

def demandMid = if swingLow then (demandLow+demandHigh)/2 else demandMid[1];
plot PdemandMid = demandMid;
PdemandMid.SetDefaultColor(Color.cyan);
PdemandMid.SetPaintingStrategy(12);

AddCloud(PdemandMid, PdemandLow, Color.green, Color.green);

# using a single plot to show the swing High points
def SupplyLow = if swingHigh then low else SupplyLow[1];
plot PSupplyLow = SupplyLow;
PSupplyLow.SetDefaultColor(Color.RED);
PSupplyLow.SetPaintingStrategy(12);

def SupplyHigh = if swingHigh then high else SupplyHigh[1];
plot PSupplyHigh = SupplyHigh;
PSupplyHigh.SetDefaultColor(Color.GREEN);
PSupplyHigh.SetPaintingStrategy(12);

def SupplyMid = if swingHigh then (SupplyLow + SupplyHigh) / 2 else SupplyMid[1];
plot PSupplyMid = SupplyMid;
PSupplyMid.SetDefaultColor(Color.CYAN);
PSupplyMid.SetPaintingStrategy(12);
PSupplyMid.setLineWeight(2);


AddCloud(PSupplyMid , PSupplyHigh, Color.PINK, Color.PINK);

#def ht1 = if swingLow then c1+ ( c1*inRange ) / 100 else ht1[1];
#plot highTgt1 = ht1;
#highTgt1.SetDefaultColor(Color.green);
#highTgt1.SetPaintingStrategy(12);

#def lt1 = if swingLow then c1- ( c1*inRange ) / 100 else lt1[1];
#plot lowTgt1 = lt1;
#lowTgt1.SetDefaultColor(Color.red);
#lowTgt1.SetPaintingStrategy(12);

#def htAtr1 = if swingLow then c1+ ( c1*atrRange ) / 100 else htAtr1[1];
#plot highAtr11 = htAtr1;
#highAtr11.SetDefaultColor(Color.dark_green);
#highAtr11.SetPaintingStrategy(12);

#def ltAtr1 = if swingLow then c1- ( c1*atrRange ) / 100 else ltAtr1[1];
#plot lowAtr11 = ltAtr1;
#lowAtr11.SetDefaultColor(Color.white);
#lowAtr11.SetPaintingStrategy(12);

Charts
 
Correct. A plot is just a variable that displays its value on the screen. A variable can only hold ONE value at a time. That's why when you try to do it with a single plot, the line stops when a new swing point is identified. That is, you can have the variable remember the old swing point's value, but when a new swing point is encountered, the old value is discarded and the new value is remembered.

Ruby:
# define swing low points
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
# change candle colors just to make it easier to see what we are working with
AssignPriceColor(if swingLow then Color.LIME else Color.DARK_GRAY);

# using a single plot to show the swing low points
def l1 = if swingLow then low else l1[1];
plot low1 = l1;
low1.SetDefaultColor(Color.RED);
low1.SetPaintingStrategy(12);

sJuJ2Fu.png


In order to have two lines overlapping (both lines extending to the right of the chart) requires TWO plot lines because two different values must be displayed simultaneously---the new swing point and the old swing point.
Is there a way to only show levels during pre-market time period?
 
Is there a way to only show levels during pre-market time period?

The following will limit the levels to only show if these occur during the premarket. You can then have the option to limit the plot of the horizontal lines to within the premarket.

The image is with the input set to limit the plot within the premarket.
Capture.jpg
Ruby:
# define swing low points
input length = 10;
def bn       = BarNumber();
def lastBar  = HighestAll(if IsNaN(close) then 0 else bn);
def offset   = Min(length - 1, lastBar - bn);

def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);

# change candle colors just to make it easier to see what we are working with

input pricecolor = yes;
AssignPriceColor(if !pricecolor
                 then Color.CURRENT               
                 else if swingLow
                 then Color.LIME
                 else Color.DARK_GRAY);

# using a single plot to show the swing low points

input limit_horizontal_line_plot_to_premarket = yes;
def premarket = if GetTime() crosses above RegularTradingEnd(GetYYYYMMDD()[1])
                then 1
                else if  GetTime() <= RegularTradingStart(GetYYYYMMDD())
                then 1
                else 0;


def l1        = if premarket and swingLow
                then low
                else l1[1];
plot low1     = if limit_horizontal_line_plot_to_premarket and !premarket
                then Double.NaN
                else l1;
low1.SetDefaultColor(Color.RED);
low1.SetPaintingStrategy(12);
 
Hi, I've fiddled with all the settings in the shared supply/demand indicator, but can't get the supply/demand zones to show. Can anyone tell me which input I have to adjust to show them? Thanks in advance.
 
Here is the ZigZag High Low indicator with Supply and Demand Zones. In addition to that, we also have Fibonacci extension, alerts, reversal signals, and price change shown in bubbles style. You can adjust these features to your liking after adding the indicator.

eXpGylF.png


thinkScript Code

Rich (BB code):
# Archive Name: ZigZag High Low with Supply DemandIndex and Fibs_Linus_Lar
# Archive Section: Scripts
# Suggested Tos Name: ZigZagHighLow_SupplyDemand_FibExtensions_LinusLar
# Archive Date:
# Archive Notes:

#TOS version ZigZagHighLow modified in part by Linus' and Lar's code
input bubbleoffset = .0005;
input percentamount = .01;
input revAmount = .15;
input atrreversal = 1.0;
input atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = percentAmount, "absolute reversal" = revAmount, "atr length" =atrlength, "atr reversal" = atrreversal);
def reversalAmount        = if (close * percentamount / 100) > Max(revAmount < atrreversal * atrlength, revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * atrlength then atrreversal * atrlength else revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
plot zzp = if zzd <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if zzd == 1 then Color.GREEN else if zzd == 0 then Color.RED else Color.DARK_ORANGE);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();

#Price Change between zigzags
def xxhigh = if zzSave == high then  high else xxhigh[1];
def chghigh = high - xxhigh[1];
def xxlow = if zzSave == low then low else xxlow[1];
def chglow = low - xxlow[1];
input showBubbleschange = yes;
AddChartBubble(showBubbleschange and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , "$" + chg , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);

#Price at High/Low
input showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , if isUp then "$" + high else "$" + low , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);

#Label for Confirmed/Unconfirmed Status of Current Zigzag
AddLabel(BarNumber() != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then Color.DARK_ORANGE else if isUp then Color.GREEN else Color.RED);

#Bar Count between zigzags
rec zzcount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzcount[1] + 1 else 0;
def zzcounthilo   =  if zzcounthilo[1] == 0 and (zzSave == high or zzSave == low) then 1 else if zzSave == high or zzSave == low then zzcounthilo[1] + 1 else zzcounthilo[1];
def zzhilo = if zzSave == high or zzSave == low then zzcounthilo else zzcounthilo + 1;
def zzcounthigh = if zzSave == high then zzcount[1] else Double.NaN;
def zzcountlow =  if zzSave == low then zzcount[1] else Double.NaN;
input showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , if zzSave == high then zzcounthigh else zzcountlow, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );

#Arrows
def zzL = if !IsNaN(zz) and !isUp then low else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or low==zzl[1] and low==zzsave then 1 else if zzH != zzH[1] or high==zzh[1] and high==zzsave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and low > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high < zzH then if signal[1] >= 0 then -1 else signal[1]    else signal[1], 0);
input showarrows = no;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);

#Alerts
input usealerts = no;
Alert(usealerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(usealerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);

#Supply Demand Areas
rec data1 = CompoundValue(1, if (zzSave == high or zzSave == low) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
input numbersuppdemandtoshow = 2;
input showSupplyDemand = {default Pivot, Arrow, None};
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if signal crosses 0 {
    rLow = low[idx];
    rHigh = high[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
plot HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !isNaN(close) and rHigh != 0 then rHigh else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

plot LowLine = if datacount1 <= numbersuppdemandtoshow and  showSupplyDemand != showSupplyDemand.None and !isNaN(close) and rLow != 0 then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

input showsupplydemandcloud = yes;
AddCloud(if showsupplydemandcloud then hlUp else double.nan, LowLine, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showsupplydemandcloud then hlDn else double.nan, LowLine, Color.LIGHT_RED, Color.LIGHT_RED);

#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2  != zzsave2[1]  then zzsave2[1]  else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (zzSave == high or zzSave == low) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
input numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
input showFibExtLines = yes;
input showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) * 1
else extfib1[1];
plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
extfib100.HideBubble();
def extfib1a = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a[1];
plot extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
extfib382.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382.SetDefaultColor(Color.RED);
extfib382.SetLineWeight(1);
extfib382.HideBubble();
def extfib2 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2[1];
plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0  then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
extfib618.HideBubble();
def extfib3 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3[1];
plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and  !IsNaN(extfib3) and dir < 0  and cpo != 0  then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
extfib1618.HideBubble();
def extfib3a = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a[1];
plot extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and  !IsNaN(extfib3a) and dir < 0  and cpo != 0  then extfib3a[1] else Double.NaN;
extfib2000.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000.SetDefaultColor(Color.RED);
extfib2000.SetLineWeight(1);
extfib2000.HideBubble();
def extfib4 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4[1];
plot extfib2618 = if  datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0  and cpo != 0  then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
extfib2618.HideBubble();
def extfib5 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5[1];
plot extfib3618 = if  datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0  and cpo != 0  then extfib5[1] else Double.NaN;
extfib3618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618.SetDefaultColor(Color.RED);
extfib3618.SetLineWeight(1);
extfib3618.HideBubble();
def extfib1_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) * 1
else extfib1_[1];
plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
extfib100_.HideBubble();
def extfib1a_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a_[1];
plot extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
extfib382_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382_.SetDefaultColor(Color.GREEN);
extfib382_.SetLineWeight(1);
extfib382_.HideBubble();
def extfib2_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2_[1];
plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0  and cpo != 0  then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
extfib618_.HideBubble();
def extfib3_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3_[1];
plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0  and cpo != 0  then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
extfib1618_.HideBubble();
def extfib3a_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a_[1];
plot extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0  and cpo != 0  then extfib3a_[1] else Double.NaN;
extfib2000_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000_.SetDefaultColor(Color.GREEN);
extfib2000_.SetLineWeight(1);
extfib2000_.HideBubble();
def extfib4_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4_[1];
plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0  and cpo != 0  then extfib4_[1]  else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);
extfib2618_.HideBubble();
def extfib5_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5_[1];
plot extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0  and cpo != 0  then extfib5_[1]  else Double.NaN;
extfib3618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618_.SetDefaultColor(Color.GREEN);
extfib3618_.SetLineWeight(1);
extfib3618_.HideBubble();
input fibextbubblespacesinexpansion = 8;
def b = fibextbubblespacesinexpansion;
def direction = if !isUp then 1 else 0;
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1[b + 2], "100%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1a[b + 2], "38.2%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib2[b + 2], "61.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3[b + 2], "161.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3a[b + 2], "200%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib4[b + 2], "261.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib5[b + 2], "361.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1_[b + 2], "100%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib1a_[b + 2], "38.2%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib2_[b + 2], "61.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3_[b + 2], "161.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib3a_[b + 2], "200%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib4_[b + 2], "261.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close), extfib5_[b + 2], "361.8%", Color.GREEN, yes);

#Volume at Reversals
def vol = if BarNumber() == 0 then 0 else volume + vol[1];
def vol1 = if BarNumber() == 1 then volume else vol1[1];
def xxvol = if zzSave == high or zzSave == low then TotalSum(volume) else xxvol[1];
def chgvol =  if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
input showBubblesVolume = no;
AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset), chgvol,if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );

Shareable Link

https://tos.mx/ZbuQDX
Hi BenTen, Can you please provide the code for the image shown above? the link https://tos.mx/ZbuQDX does not show the same image as shown above. and the codes above is not same as what's being shown.Thanks,
 
Hi BenTen, Can you please provide the code for the image shown above? the link https://tos.mx/ZbuQDX does not show the same image as shown above. and the codes above is not same as what's being shown.Thanks,

It looks like the indicator code you are referencing is the code used in the image in post #1. The main code difference is input atrreversal = 1.0; Change that to 5.0. Otherwise, the image appears to be set with extended hours turned off. I was able to match the image in Ondemand. There is some problem with the bubble code displaying multiple fib bubbles in the BenTen version though.

{Edit- I fixed the bubbles]

Ruby:
# Archive Name: ZigZag High Low with Supply DemandIndex and Fibs_Linus_Lar
# Archive Section: Scripts
# Suggested Tos Name: ZigZagHighLow_SupplyDemand_FibExtensions_LinusLar
# Archive Date:
# Archive Notes:

#TOS version ZigZagHighLow modified in part by Linus' and Lar's code
input bubbleoffset = .0005;
input percentamount = .01;
input revAmount = .15;
input atrreversal = 1.0;
input atrlength = 5;
def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = percentAmount, "absolute reversal" = revAmount, "atr length" =atrlength, "atr reversal" = atrreversal);
def reversalAmount        = if (close * percentamount / 100) > Max(revAmount < atrreversal * atrlength, revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * atrlength then atrreversal * atrlength else revAmount;
rec zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1));
def zzd = if isUp then 1 else 0;
plot zzp = if zzd <= 1 then zz else Double.NaN;
zzp.AssignValueColor(if zzd == 1 then Color.GREEN else if zzd == 0 then Color.RED else Color.DARK_ORANGE);
zzp.SetStyle(Curve.FIRM);
zzp.EnableApproximation();

#Price Change between zigzags
def xxhigh = if zzSave == high then  high else xxhigh[1];
def chghigh = high - xxhigh[1];
def xxlow = if zzSave == low then low else xxlow[1];
def chglow = low - xxlow[1];
input showBubbleschange = yes;
AddChartBubble(showBubbleschange and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , "$" + chg , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);

#Price at High/Low
input showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)   , if isUp then "$" + high else "$" + low , if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, isUp);

#Label for Confirmed/Unconfirmed Status of Current Zigzag
AddLabel(BarNumber() != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg, if !isConf then Color.DARK_ORANGE else if isUp then Color.GREEN else Color.RED);

#Bar Count between zigzags
rec zzcount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzcount[1] + 1 else 0;
def zzcounthilo   =  if zzcounthilo[1] == 0 and (zzSave == high or zzSave == low) then 1 else if zzSave == high or zzSave == low then zzcounthilo[1] + 1 else zzcounthilo[1];
def zzhilo = if zzSave == high or zzSave == low then zzcounthilo else zzcounthilo + 1;
def zzcounthigh = if zzSave == high then zzcount[1] else Double.NaN;
def zzcountlow =  if zzSave == low then zzcount[1] else Double.NaN;
input showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset)  , if zzSave == high then zzcounthigh else zzcountlow, if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );

#Arrows
def zzL = if !IsNaN(zz) and !isUp then low else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or low==zzl[1] and low==zzsave then 1 else if zzH != zzH[1] or high==zzh[1] and high==zzsave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and low > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high < zzH then if signal[1] >= 0 then -1 else signal[1]    else signal[1], 0);
input showarrows = no;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);

#Alerts
input usealerts = no;
Alert(usealerts and U1, "ZIG-UP", Alert.BAR, Sound.Bell);
Alert(usealerts and D1, "ZAG-DOWN", Alert.BAR, Sound.Chimes);

#Supply Demand Areas
rec data1 = CompoundValue(1, if (zzSave == high or zzSave == low) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
input numbersuppdemandtoshow = 2;
input showSupplyDemand = {default Pivot, Arrow, None};
def idx = if showSupplyDemand == showSupplyDemand.Pivot then 1 else 0;
def rLow;
def rHigh;
if signal crosses 0 {
    rLow = low[idx];
    rHigh = high[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
plot HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !isNaN(close) and rHigh != 0 then rHigh else Double.NaN;
HighLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HighLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

plot LowLine = if datacount1 <= numbersuppdemandtoshow and  showSupplyDemand != showSupplyDemand.None and !isNaN(close) and rLow != 0 then rLow else Double.NaN;
LowLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LowLine.AssignValueColor(if signal > 0 then Color.GREEN else Color.RED);

def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;

input showsupplydemandcloud = yes;
AddCloud(if showsupplydemandcloud then hlUp else double.nan, LowLine, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(if showsupplydemandcloud then hlDn else double.nan, LowLine, Color.LIGHT_RED, Color.LIGHT_RED);

#Store Previous Data
def zzsave1 = if !IsNaN(zzSave) then zzSave else zzsave1[1];
def zzsave2 = zzsave1;
rec priorzz1 = if zzsave2  != zzsave2[1]  then zzsave2[1]  else priorzz1[1];
rec priorzz2 = if priorzz1 != priorzz1[1] then priorzz1[1] else priorzz2[1];
rec priorzz3 = if priorzz2 != priorzz2[1] then priorzz2[1] else priorzz3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (zzSave == high or zzSave == low) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
input numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
input showFibExtLines = yes;
input showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) * 1
else extfib1[1];
plot extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
extfib100.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100.SetDefaultColor(Color.RED);
extfib100.SetLineWeight(1);
extfib100.HideBubble();
def extfib1a = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a[1];
plot extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
extfib382.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382.SetDefaultColor(Color.RED);
extfib382.SetLineWeight(1);
extfib382.HideBubble();
def extfib2 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2[1];
plot extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0  then extfib2[1] else Double.NaN;
extfib618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618.SetDefaultColor(Color.RED);
extfib618.SetLineWeight(1);
extfib618.HideBubble();
def extfib3 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3[1];
plot extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and  !IsNaN(extfib3) and dir < 0  and cpo != 0  then extfib3[1] else Double.NaN;
extfib1618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618.SetDefaultColor(Color.RED);
extfib1618.SetLineWeight(1);
extfib1618.HideBubble();
def extfib3a = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a[1];
plot extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and  !IsNaN(extfib3a) and dir < 0  and cpo != 0  then extfib3a[1] else Double.NaN;
extfib2000.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000.SetDefaultColor(Color.RED);
extfib2000.SetLineWeight(1);
extfib2000.HideBubble();
def extfib4 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4[1];
plot extfib2618 = if  datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0  and cpo != 0  then extfib4[1] else Double.NaN;
extfib2618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618.SetDefaultColor(Color.RED);
extfib2618.SetLineWeight(1);
extfib2618.HideBubble();
def extfib5 = if zzSave == high then high - AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5[1];
plot extfib3618 = if  datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0  and cpo != 0  then extfib5[1] else Double.NaN;
extfib3618.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618.SetDefaultColor(Color.RED);
extfib3618.SetLineWeight(1);
extfib3618.HideBubble();
def extfib1_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) * 1
else extfib1_[1];
plot extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
extfib100_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib100_.SetDefaultColor(Color.GREEN);
extfib100_.SetLineWeight(1);
extfib100_.HideBubble();
def extfib1a_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) * 0.382
else extfib1a_[1];
plot extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
extfib382_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib382_.SetDefaultColor(Color.GREEN);
extfib382_.SetLineWeight(1);
extfib382_.HideBubble();
def extfib2_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
0.618 else extfib2_[1];
plot extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0  and cpo != 0  then extfib2_[1] else Double.NaN;
extfib618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib618_.SetDefaultColor(Color.GREEN);
extfib618_.SetLineWeight(1);
extfib618_.HideBubble();
def extfib3_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
1.618 else extfib3_[1];
plot extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0  and cpo != 0  then extfib3_[1] else Double.NaN;
extfib1618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib1618_.SetDefaultColor(Color.GREEN);
extfib1618_.SetLineWeight(1);
extfib1618_.HideBubble();
def extfib3a_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
2.000 else extfib3a_[1];
plot extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0  and cpo != 0  then extfib3a_[1] else Double.NaN;
extfib2000_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2000_.SetDefaultColor(Color.GREEN);
extfib2000_.SetLineWeight(1);
extfib2000_.HideBubble();
def extfib4_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
2.618 else extfib4_[1];
plot extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0  and cpo != 0  then extfib4_[1]  else Double.NaN;
extfib2618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib2618_.SetDefaultColor(Color.GREEN);
extfib2618_.SetLineWeight(1);
extfib2618_.HideBubble();
def extfib5_ = if zzSave == low then low + AbsValue(priorzz2 - priorzz1) *
3.618 else extfib5_[1];
plot extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0  and cpo != 0  then extfib5_[1]  else Double.NaN;
extfib3618_.SetPaintingStrategy(PaintingStrategy.DASHES);
extfib3618_.SetDefaultColor(Color.GREEN);
extfib3618_.SetLineWeight(1);
extfib3618_.HideBubble();
input fibextbubblespacesinexpansion = 8;
def b = fibextbubblespacesinexpansion;
def direction = if !isUp then 1 else 0;
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1[b + 2], "100%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1a[b + 2], "38.2%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2[b + 2], "61.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3[b + 2], "161.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3a[b + 2], "200%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4[b + 2], "261.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 1 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib5[b + 2], "361.8%", Color.RED, no);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1_[b + 2], "100%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib1a_[b + 2], "38.2%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib2_[b + 2], "61.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3_[b + 2], "161.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib3a_[b + 2], "200%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib4_[b + 2], "261.8%", Color.GREEN, yes);
AddChartBubble( direction[b + 1] == 0 and showFibExtLines and !IsNaN(close[b + 1]) and IsNaN(close[b]), extfib5_[b + 2], "361.8%", Color.GREEN, yes);

#Volume at Reversals
def vol = if BarNumber() == 0 then 0 else volume + vol[1];
def vol1 = if BarNumber() == 1 then volume else vol1[1];
def xxvol = if zzSave == high or zzSave == low then TotalSum(volume) else xxvol[1];
def chgvol =  if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
input showBubblesVolume = no;
AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + bubbleoffset)  else low * (1 - bubbleoffset), chgvol,if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no );
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
370 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top