Repaints Idea for Momentum Indicator (ASMA)

Repaints

Yohannes24

New member
To whom it may concern,

My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments. I am hoping @BenTen or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

Last but not least, any notions or reactions to this potential idea is much appreciated.

Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

Note : Visual in document is simply there to communicate concept visually (not perfect). In addition, only the green/red arrows along with repainting should be present in final indicator, rest is just for transparency.

Thank you. 06/03/23






@halcyonguy

The code was written by "BenTen" an admin on this site. In short, the code attached to the PDF creates the red, green, and purple bubbles seen on the visual. However, after some use, I found that a lot of false positives were being thrown up. In this sense, I wanted to add SMA crosses as confirmation prior to these bubbles being shown.

In short, I wanted to make the existing indicator (BB) which indicates bubbles due to a set of criteria implemented in its code more accurate while factoring in general market environments. In essence, when the 20 Simple Moving Avg. is below the 200 Simple Moving Avg. (bearish) I wanted to capture the downtrends using the criteria in "Criteria A". Once the 20 SMA is above the 200 SMA I wanted the criteria in "Criteria B" to be used in order to erect a signal.

Ex. Criteria B (True at same time, no particular order)

1. The red/neutral bubble from BB indicator are erected
2. 10 SMA crosses below 20 SMA
This creates a downwards Green arrow indicating the beginning of the downtrend.
In addition every candle form here on outwards is colored red to further indicate this trend.

The Exit criteria as as follows

3. The green/neutral bubbles from BB indicator are erected
4. 10 SMA crosses above 20 SMA
This creates a upwards Red arrow indicating the end of a downtrend
This marks the end of the red candle repainting.

Criteria A is essentially the opposite, capturing uptrends.

The current code for the BB code is fully functional as is, I just wanted to make these additions if possible.

Note : All candles which do not satisfy the appropriate criteria are repainted grey.

I hope this can shed some light on the project. Any insight is much appreciated.

Thank you .
 

Attachments

  • %22BB Trend Capture Indicator%22 (BBTCI)-5.pdf
    497.8 KB · Views: 333
Last edited:
To whom it may concern,

My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments. I am hoping “BenTen” or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

Last but not least, any notions or reactions to this potential idea is much appreciated.

Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

Note : Visual in document is simply there to communicate concept visually (not perfect). In addition, only the green/red arrows along with repainting should be present in final indicator, rest is just for transparency.

Thank you. 06/03/23


comments

i am confused by your post.
what needs to be changed in your code?
...add some formulas and make the code a strategy , with buy and sell signals?


you included code...
...did you write it? why is chatgpt mentioned in the PDF?
...does the code work? ( i managed to clean it up and load it and it draws bubbles)
...i get scared when i see chatgpt, knowing that every time, code from it is crap.


what variable does this refer to? what is a BB?
...A1. First condition requirement : Most recent BB Indicator signal (red or neutral)


i didn't study all of the PDF.

--------------------

don't post code in a PDF. copying from it results in it adding carriage returns after every line. so every long comment and hint needs adjusting (appended to the line above them). formulas don't need changing, although they should be.

post code in a code window. click on </> in the header. type doesn't matter. ruby is a good color formating.

----------------------

your code , cleaned up and unaltered

Code:
# momentum_bb_pdf_code_00

#https://usethinkscript.com/threads/idea-for-momentum-indicator-asma.15812/
#Idea for Momentum Indicator (ASMA)
#Yohannes24  6/28  #1

#My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments.
# I am hoping “BenTen” or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

#Last but not least, any notions or reactions to this potential idea is much appreciated.

#Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

#Attachments
#%22BB Trend Capture Indicator%22 (BBTCI)-5.pdf
#497.8 KB · Views: 0



#"BB Trend Capture Indicator" (BBTCI)
#Visual Indicator Engineered by Issey Yohannes
#Additional Conditional Visual

#Criteria A : 20 SMA below 200 SMA (Bear - Shorting) - Indicating downtrends
#Signal : Downwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (red or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria A” are met) are red.
#Signal : Upwards Red Arrow (All conditions must be true at same time)
#3. Both conditions A1 and A2 have been met
#4. First condition requirement : BB Indicator signal (green or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria A” are met) are gray.

#Criteria B : 20 SMA above 200 SMA (Bull - Long) - Indicating uptrends
#Signal : Upwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (green or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria B” are met) are green.
#Signal : Downwards Red Arrow (All conditions must be true at same time)
#3. Both conditions B1 and B2 have been met
#4. First condition requirement : BB Indicator signal (red or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria B” are met) are gray.

#Note : No subtractions from current visuals of BB are required.
#Visual of Concept
#EX.1
#Note : This example is solely to visualize the concept, all potential signals within this graph were not highlighted in
#order to facilitate illustration with no clutter.
#BB Study Summary (ChatGPT) - Implemented in BBTCI: BB carries out technical analysis using price
#action, volume, and Fibonacci retracement levels to identify potential trend reversals. It also combines
#several indicators, including moving averages, RSI, and MACD, to accomplish the identification of these
#reversals. In addition, BB includes a custom algorithm that looks for specific price patterns and volume
#behavior. Last but not least, Fibonacci retracement levels are used to identify potential support and
#resistance levels, and the study includes a feature to display these levels on the chart.
#BBTCI Study Summary (ChatGPT) : The BBTCI combines the power of the BB indicator, SMA crosses,
#and other specific conditions to generate signals relating to potential short and long positions. Traders can
#utilize the alerts and SMS messages to monitor the market and take appropriate actions based on the
#signals received. This information can be used to purchase stock equity out right or utilize other financial
#instruments such as stock options. It is important to thoroughly test and validate the BBTCI's functionality
#before using it in real trading scenarios, as no trading strategy can guarantee success in all market
#conditions.
#BB Break Down (ChatGPT)
#1. Fib Levels: The code uses Fibonacci retracement levels to identify potential areas of support and
#resistance on the chart. The code calculates the Fibonacci levels based on the difference
#between the highest high and lowest low of the selected period. The levels that the code uses are
#0.236, 0.382, 0.500, 0.618, and 0.786.
#2. Fib Skip: The code allows the user to set a percentage difference between the Fibonacci high
#and low before a new Fibonacci grid is created. This is known as the Fib Skip. The default value
#is 1.0, but the user can manually set this value by changing the "fibskip" input.
#3. Chart Bubbles: The code displays chart bubbles that show the current Fibonacci level as a
#percentage of the distance between the Fibonacci low and high. The bubbles are color-coded
#based on whether the current price is above or below the Fibonacci low.
#4. Reversal Signals: The code generates reversal signals based on several criteria:
#● The current price must be below the Fibonacci low.
#● The current price must be above the previous low.
#● The previous low must be below the Fibonacci low.
#● The previous low must be a certain percentage (determined by the "percentagereversal"
#input) below the Fibonacci low.
#If all of these conditions are met, the code generates a bullish reversal signal. The code generates a
#bearish reversal signal if the current price is above the Fibonacci high and the previous high meets the
#above criteria.
#5. Other Inputs: The code also allows the user to customize several other inputs, including:
#● The period over which to calculate the Fibonacci levels (controlled by the "data1" input).
#● Whether to show the Fibonacci levels and bubbles (controlled by the "showfiblines" and
#"showBubblesfibratio" inputs).
#● Whether to show the current Fibonacci level as a label on the chart (controlled by the
#"showFibLabel" input).
#Overall, BB is a technical analysis tool that uses Fibonacci retracement levels to identify potential areas of
#support and resistance on the chart, and generates reversal signals based on the price's relationship to
#these levels.

#BB Indicator Code
def price = close;
def superfast_length = 9;
def fast_length = 14;
def slow_length = 21;
def displace = 0;
def mov_avg9 = ExpAverage(price[-displace], superfast_length);
def mov_avg14 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;
#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
Colorbars.Hide();
Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
Colorbars.DefineColor("Neutral", Color.PLUM);
#___________________________________________________________________________
input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
#plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
#EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);
#EnhancedLines.SetStyle(Curve.FIRM);
#EnhancedLines.EnableApproximation();
#EnhancedLines.HideBubble();
#Price Change between Enhanceds
def xxhigh = if EISave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if EISave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
def showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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
def showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , 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 Enhanced
#Bar Count between Enhanceds
rec EIcount = if EISave[1] != EISave then 1 else if EISave[1] == EISave then EIcount[1] + 1 else 0;
def EIcounthilo = if EIcounthilo[1] == 0 and (EISave == priceh or EISave == pricel) then 1 else if EISave == priceh or EISave == pricel then EIcounthilo[1] + 1 else EIcounthilo[1];
def EIhilo = if EISave == priceh or EISave == pricel then EIcounthilo else EIcounthilo + 1;
def EIcounthigh = if EISave == priceh then EIcount[1] else Double.NaN;
def EIcountlow = if EISave == pricel then EIcount[1] else Double.NaN;
def showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if EISave == priceh then EIcounthigh else EIcountlow, 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 EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
def U1 = showarrows and signal > 0 and signal[1] <= 0;
#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#U1.SetDefaultColor(Color.GREEN);
#U1.SetLineWeight(4);
def D1 = showarrows and signal < 0 and signal[1] >= 0;
#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#D1.SetDefaultColor(Color.RED);
#D1.SetLineWeight(4);
def barnumber = BarNumber()[10];
AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);
AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK,
yes);
def revLineTop;
def revLineBot;
if barnumber and D1 {
    revLineBot = Double.NaN;
    revLineTop = high[1];
} else if barnumber and U1 {
    revLineTop = Double.NaN;
    revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
    revLineBot = revLineBot[1];
    revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
    revLineTop = revLineTop[1];
    revLineBot = Double.NaN;
} else {
    revLineTop = Double.NaN;
    revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.LIGHT_GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.LIGHT_RED);
#Alerts
def usealerts = no;
#Alert(usealerts and U1, "EI-UP", Alert.BAR, Sound.Bell);
#Alert(usealerts and D1, "EI-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def numbersuppdemandtoshow = 0;
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 = pricel[idx];
    rHigh = priceh[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
def HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
def LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
def showsupplydemandcloud = no;
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 EIsave1 = if !IsNaN(EISave) then EISave else EIsave1[1];
def EIsave2 = EIsave1;
rec priorEI1 = if EIsave2 != EIsave2[1] then EIsave2[1] else priorEI1[1];
rec priorEI2 = if priorEI1 != priorEI1[1] then priorEI1[1] else priorEI2[1];
rec priorEI3 = if priorEI2 != priorEI2[1] then priorEI2[1] else priorEI3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
def showFibExtLines = no;
def showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1 else extfib1[1];
def extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
def extfib1a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a[1];
def extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
def extfib2 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2[1];
def extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
def extfib3 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3[1];
def extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
def extfib3a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a[1];
def extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
def extfib4 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4[1];
def extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
def extfib5 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5[1];
def extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
def extfib1_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1 else extfib1_[1];
def extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
def extfib1a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a_[1];
def extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
def extfib2_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2_[1];
def extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
def extfib3_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3_[1];
def extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
def extfib3a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a_[1];
def extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
def extfib4_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4_[1];
def extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
def extfib5_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5_[1];
def extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
def 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 EISave == priceh or EISave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
def showBubblesVolume = no;

AddChartBubble(showBubblesVolume and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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 );

input usemanualfibskip = no;
#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.

input fibskip = .50;
#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.

def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;

#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
#
#


--------------------------------


this is a strategy

it seems not every buy or sell is drawn... so not perfect.
but maybe a starting point for a next version...

your code , turned into a strategy
create buy/sell variables , in middle of strategy, so 2nd half of code is not used.
...based off of logic in 2 bubble functions

AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);

AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);


add warn formulas , for the purple bubbles.
add addorder functions for buying and selling

can draw vertical lines to verify buy/sell signals

Code:
# momentum_bb_pdf_code_01a

#https://usethinkscript.com/threads/idea-for-momentum-indicator-asma.15812/
#Idea for Momentum Indicator (ASMA)
#Yohannes24  6/28  #1

#My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments.
# I am hoping “BenTen” or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

#Last but not least, any notions or reactions to this potential idea is much appreciated.

#Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

#Attachments
#%22BB Trend Capture Indicator%22 (BBTCI)-5.pdf
#497.8 KB · Views: 0



#"BB Trend Capture Indicator" (BBTCI)
#Visual Indicator Engineered by Issey Yohannes
#Additional Conditional Visual

#Criteria A : 20 SMA below 200 SMA (Bear - Shorting) - Indicating downtrends
#Signal : Downwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (red or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria A” are met) are red.
#Signal : Upwards Red Arrow (All conditions must be true at same time)
#3. Both conditions A1 and A2 have been met
#4. First condition requirement : BB Indicator signal (green or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria A” are met) are gray.

#Criteria B : 20 SMA above 200 SMA (Bull - Long) - Indicating uptrends
#Signal : Upwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (green or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria B” are met) are green.
#Signal : Downwards Red Arrow (All conditions must be true at same time)
#3. Both conditions B1 and B2 have been met
#4. First condition requirement : BB Indicator signal (red or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria B” are met) are gray.

#Note : No subtractions from current visuals of BB are required.
#Visual of Concept
#EX.1
#Note : This example is solely to visualize the concept, all potential signals within this graph were not highlighted in
#order to facilitate illustration with no clutter.
#BB Study Summary (ChatGPT) - Implemented in BBTCI: BB carries out technical analysis using price
#action, volume, and Fibonacci retracement levels to identify potential trend reversals. It also combines
#several indicators, including moving averages, RSI, and MACD, to accomplish the identification of these
#reversals. In addition, BB includes a custom algorithm that looks for specific price patterns and volume
#behavior. Last but not least, Fibonacci retracement levels are used to identify potential support and
#resistance levels, and the study includes a feature to display these levels on the chart.
#BBTCI Study Summary (ChatGPT) : The BBTCI combines the power of the BB indicator, SMA crosses,
#and other specific conditions to generate signals relating to potential short and long positions. Traders can
#utilize the alerts and SMS messages to monitor the market and take appropriate actions based on the
#signals received. This information can be used to purchase stock equity out right or utilize other financial
#instruments such as stock options. It is important to thoroughly test and validate the BBTCI's functionality
#before using it in real trading scenarios, as no trading strategy can guarantee success in all market
#conditions.
#BB Break Down (ChatGPT)
#1. Fib Levels: The code uses Fibonacci retracement levels to identify potential areas of support and
#resistance on the chart. The code calculates the Fibonacci levels based on the difference
#between the highest high and lowest low of the selected period. The levels that the code uses are
#0.236, 0.382, 0.500, 0.618, and 0.786.
#2. Fib Skip: The code allows the user to set a percentage difference between the Fibonacci high
#and low before a new Fibonacci grid is created. This is known as the Fib Skip. The default value
#is 1.0, but the user can manually set this value by changing the "fibskip" input.
#3. Chart Bubbles: The code displays chart bubbles that show the current Fibonacci level as a
#percentage of the distance between the Fibonacci low and high. The bubbles are color-coded
#based on whether the current price is above or below the Fibonacci low.
#4. Reversal Signals: The code generates reversal signals based on several criteria:
#● The current price must be below the Fibonacci low.
#● The current price must be above the previous low.
#● The previous low must be below the Fibonacci low.
#● The previous low must be a certain percentage (determined by the "percentagereversal"
#input) below the Fibonacci low.
#If all of these conditions are met, the code generates a bullish reversal signal. The code generates a
#bearish reversal signal if the current price is above the Fibonacci high and the previous high meets the
#above criteria.
#5. Other Inputs: The code also allows the user to customize several other inputs, including:
#● The period over which to calculate the Fibonacci levels (controlled by the "data1" input).
#● Whether to show the Fibonacci levels and bubbles (controlled by the "showfiblines" and
#"showBubblesfibratio" inputs).
#● Whether to show the current Fibonacci level as a label on the chart (controlled by the
#"showFibLabel" input).
#Overall, BB is a technical analysis tool that uses Fibonacci retracement levels to identify potential areas of
#support and resistance on the chart, and generates reversal signals based on the price's relationship to
#these levels.

#BB Indicator Code
def price = close;
def superfast_length = 9;
def fast_length = 14;
def slow_length = 21;
def displace = 0;
def mov_avg9 = ExpAverage(price[-displace], superfast_length);
def mov_avg14 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;
#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
Colorbars.Hide();
Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
Colorbars.DefineColor("Neutral", Color.PLUM);

#___________________________________________________________________________

input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
#plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
#EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);
#EnhancedLines.SetStyle(Curve.FIRM);
#EnhancedLines.EnableApproximation();
#EnhancedLines.HideBubble();
#Price Change between Enhanceds
def xxhigh = if EISave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if EISave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
def showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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
def showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , 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 Enhanced
#Bar Count between Enhanceds
rec EIcount = if EISave[1] != EISave then 1 else if EISave[1] == EISave then EIcount[1] + 1 else 0;
def EIcounthilo = if EIcounthilo[1] == 0 and (EISave == priceh or EISave == pricel) then 1 else if EISave == priceh or EISave == pricel then EIcounthilo[1] + 1 else EIcounthilo[1];
def EIhilo = if EISave == priceh or EISave == pricel then EIcounthilo else EIcounthilo + 1;
def EIcounthigh = if EISave == priceh then EIcount[1] else Double.NaN;
def EIcountlow = if EISave == pricel then EIcount[1] else Double.NaN;
def showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if EISave == priceh then EIcounthigh else EIcountlow, 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 EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
def U1 = showarrows and signal > 0 and signal[1] <= 0;
#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#U1.SetDefaultColor(Color.GREEN);
#U1.SetLineWeight(4);
def D1 = showarrows and signal < 0 and signal[1] >= 0;
#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#D1.SetDefaultColor(Color.RED);
#D1.SetLineWeight(4);




# 126
# plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;

def barnumber = BarNumber()[10];

AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);

AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);

#--------------------

input sell_on_warn = no;
input buy_on_warn = no;


def short_warn = (U1 and isUp and signal > 0 and signal[1] <= 0 and Colorbars == 3);
def long_warn = (d1 and !isUp and signal < 0 and signal[1] >= 0 and Colorbars == 3);

#def long_buy = ((barnumber and U1) and isUp and signal > 0 and signal[1] <= 0 );
def long_buy = (U1 and isUp and signal > 0 and signal[1] <= 0 and Colorbars != 3) or (buy_on_warn and short_warn);
def short_buy = (d1 and !isUp and signal < 0 and signal[1] >= 0 and Colorbars != 3) or (buy_on_warn and long_warn);

def long_sell = short_buy or (sell_on_warn and long_warn);
def short_sell = long_buy or (sell_on_warn and short_warn);




input test_vert_lines = no;
addverticalline(test_vert_lines and long_buy, "buy", color.green);
addverticalline(test_vert_lines and short_buy, "sell", color.red);

addverticalline(test_vert_lines and long_warn, "warn", color.cyan);
addverticalline(test_vert_lines and short_warn, "warn", color.yellow);



input test2 = no;
AddChartBubble(test2, low,
barnumber + " bn\n" +
U1 + " u1\n" +
isUp + " up\n" +
signal + " s0\n" +
signal[1] + " s1\n" +
( signal > 0 and signal[1] ) + " ss\n" +
( U1 and isUp and signal > 0 and signal[1] <= 0 ) + "\n" +
Colorbars + " col\n" +
long_buy
, color.yellow, no);



#--------------------


def revLineTop;
def revLineBot;
if barnumber and D1 {
    revLineBot = Double.NaN;
    revLineTop = high[1];
} else if barnumber and U1 {
    revLineTop = Double.NaN;
    revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
    revLineBot = revLineBot[1];
    revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
    revLineTop = revLineTop[1];
    revLineBot = Double.NaN;
} else {
    revLineTop = Double.NaN;
    revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.LIGHT_GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.LIGHT_RED);
#Alerts
def usealerts = no;
#Alert(usealerts and U1, "EI-UP", Alert.BAR, Sound.Bell);
#Alert(usealerts and D1, "EI-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def numbersuppdemandtoshow = 0;
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 = pricel[idx];
    rHigh = priceh[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
def HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
def LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
def showsupplydemandcloud = no;
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 EIsave1 = if !IsNaN(EISave) then EISave else EIsave1[1];
def EIsave2 = EIsave1;
rec priorEI1 = if EIsave2 != EIsave2[1] then EIsave2[1] else priorEI1[1];
rec priorEI2 = if priorEI1 != priorEI1[1] then priorEI1[1] else priorEI2[1];
rec priorEI3 = if priorEI2 != priorEI2[1] then priorEI2[1] else priorEI3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
def showFibExtLines = no;
def showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1 else extfib1[1];
def extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
def extfib1a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a[1];
def extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
def extfib2 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2[1];
def extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
def extfib3 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3[1];
def extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
def extfib3a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a[1];
def extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
def extfib4 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4[1];
def extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
def extfib5 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5[1];
def extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
def extfib1_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1 else extfib1_[1];
def extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
def extfib1a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a_[1];
def extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
def extfib2_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2_[1];
def extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
def extfib3_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3_[1];
def extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
def extfib3a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a_[1];
def extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
def extfib4_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4_[1];
def extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
def extfib5_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5_[1];
def extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
def 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 EISave == priceh or EISave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
def showBubblesVolume = no;

AddChartBubble(showBubblesVolume and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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 );

input usemanualfibskip = no;
#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.

input fibskip = .50;
#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.

def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;

#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
#
#

#----------------------------------

def size = 1;
AddOrder(OrderType.BUY_TO_OPEN, long_buy, open[-1], size, color.green, color.green, name = "long" );
AddOrder(OrderType.SELL_TO_CLOSE, long_sell, open[-1], size, color.white, color.white, name = "-" );

AddOrder(OrderType.sell_TO_OPEN, short_buy, open[-1], size, color.red, color.red, name = "short" );
AddOrder(OrderType.buy_TO_CLOSE, short_sell, open[-1], size, color.white, color.white, name = "-" );

#
 
comments

i am confused by your post.
what needs to be changed in your code?
...add some formulas and make the code a strategy , with buy and sell signals?


you included code...
...did you write it? why is chatgpt mentioned in the PDF?
...does the code work? ( i managed to clean it up and load it and it draws bubbles)
...i get scared when i see chatgpt, knowing that every time, code from it is crap.


what variable does this refer to? what is a BB?
...A1. First condition requirement : Most recent BB Indicator signal (red or neutral)


i didn't study all of the PDF.

--------------------

don't post code in a PDF. copying from it results in it adding carriage returns after every line. so every long comment and hint needs adjusting (appended to the line above them). formulas don't need changing, although they should be.

post code in a code window. click on </> in the header. type doesn't matter. ruby is a good color formating.

----------------------

your code , cleaned up and unaltered

Code:
# momentum_bb_pdf_code_00

#https://usethinkscript.com/threads/idea-for-momentum-indicator-asma.15812/
#Idea for Momentum Indicator (ASMA)
#Yohannes24  6/28  #1

#My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments.
# I am hoping “BenTen” or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

#Last but not least, any notions or reactions to this potential idea is much appreciated.

#Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

#Attachments
#%22BB Trend Capture Indicator%22 (BBTCI)-5.pdf
#497.8 KB · Views: 0



#"BB Trend Capture Indicator" (BBTCI)
#Visual Indicator Engineered by Issey Yohannes
#Additional Conditional Visual

#Criteria A : 20 SMA below 200 SMA (Bear - Shorting) - Indicating downtrends
#Signal : Downwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (red or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria A” are met) are red.
#Signal : Upwards Red Arrow (All conditions must be true at same time)
#3. Both conditions A1 and A2 have been met
#4. First condition requirement : BB Indicator signal (green or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria A” are met) are gray.

#Criteria B : 20 SMA above 200 SMA (Bull - Long) - Indicating uptrends
#Signal : Upwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (green or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria B” are met) are green.
#Signal : Downwards Red Arrow (All conditions must be true at same time)
#3. Both conditions B1 and B2 have been met
#4. First condition requirement : BB Indicator signal (red or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria B” are met) are gray.

#Note : No subtractions from current visuals of BB are required.
#Visual of Concept
#EX.1
#Note : This example is solely to visualize the concept, all potential signals within this graph were not highlighted in
#order to facilitate illustration with no clutter.
#BB Study Summary (ChatGPT) - Implemented in BBTCI: BB carries out technical analysis using price
#action, volume, and Fibonacci retracement levels to identify potential trend reversals. It also combines
#several indicators, including moving averages, RSI, and MACD, to accomplish the identification of these
#reversals. In addition, BB includes a custom algorithm that looks for specific price patterns and volume
#behavior. Last but not least, Fibonacci retracement levels are used to identify potential support and
#resistance levels, and the study includes a feature to display these levels on the chart.
#BBTCI Study Summary (ChatGPT) : The BBTCI combines the power of the BB indicator, SMA crosses,
#and other specific conditions to generate signals relating to potential short and long positions. Traders can
#utilize the alerts and SMS messages to monitor the market and take appropriate actions based on the
#signals received. This information can be used to purchase stock equity out right or utilize other financial
#instruments such as stock options. It is important to thoroughly test and validate the BBTCI's functionality
#before using it in real trading scenarios, as no trading strategy can guarantee success in all market
#conditions.
#BB Break Down (ChatGPT)
#1. Fib Levels: The code uses Fibonacci retracement levels to identify potential areas of support and
#resistance on the chart. The code calculates the Fibonacci levels based on the difference
#between the highest high and lowest low of the selected period. The levels that the code uses are
#0.236, 0.382, 0.500, 0.618, and 0.786.
#2. Fib Skip: The code allows the user to set a percentage difference between the Fibonacci high
#and low before a new Fibonacci grid is created. This is known as the Fib Skip. The default value
#is 1.0, but the user can manually set this value by changing the "fibskip" input.
#3. Chart Bubbles: The code displays chart bubbles that show the current Fibonacci level as a
#percentage of the distance between the Fibonacci low and high. The bubbles are color-coded
#based on whether the current price is above or below the Fibonacci low.
#4. Reversal Signals: The code generates reversal signals based on several criteria:
#● The current price must be below the Fibonacci low.
#● The current price must be above the previous low.
#● The previous low must be below the Fibonacci low.
#● The previous low must be a certain percentage (determined by the "percentagereversal"
#input) below the Fibonacci low.
#If all of these conditions are met, the code generates a bullish reversal signal. The code generates a
#bearish reversal signal if the current price is above the Fibonacci high and the previous high meets the
#above criteria.
#5. Other Inputs: The code also allows the user to customize several other inputs, including:
#● The period over which to calculate the Fibonacci levels (controlled by the "data1" input).
#● Whether to show the Fibonacci levels and bubbles (controlled by the "showfiblines" and
#"showBubblesfibratio" inputs).
#● Whether to show the current Fibonacci level as a label on the chart (controlled by the
#"showFibLabel" input).
#Overall, BB is a technical analysis tool that uses Fibonacci retracement levels to identify potential areas of
#support and resistance on the chart, and generates reversal signals based on the price's relationship to
#these levels.

#BB Indicator Code
def price = close;
def superfast_length = 9;
def fast_length = 14;
def slow_length = 21;
def displace = 0;
def mov_avg9 = ExpAverage(price[-displace], superfast_length);
def mov_avg14 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;
#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
Colorbars.Hide();
Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
Colorbars.DefineColor("Neutral", Color.PLUM);
#___________________________________________________________________________
input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
#plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
#EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);
#EnhancedLines.SetStyle(Curve.FIRM);
#EnhancedLines.EnableApproximation();
#EnhancedLines.HideBubble();
#Price Change between Enhanceds
def xxhigh = if EISave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if EISave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
def showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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
def showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , 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 Enhanced
#Bar Count between Enhanceds
rec EIcount = if EISave[1] != EISave then 1 else if EISave[1] == EISave then EIcount[1] + 1 else 0;
def EIcounthilo = if EIcounthilo[1] == 0 and (EISave == priceh or EISave == pricel) then 1 else if EISave == priceh or EISave == pricel then EIcounthilo[1] + 1 else EIcounthilo[1];
def EIhilo = if EISave == priceh or EISave == pricel then EIcounthilo else EIcounthilo + 1;
def EIcounthigh = if EISave == priceh then EIcount[1] else Double.NaN;
def EIcountlow = if EISave == pricel then EIcount[1] else Double.NaN;
def showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if EISave == priceh then EIcounthigh else EIcountlow, 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 EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
def U1 = showarrows and signal > 0 and signal[1] <= 0;
#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#U1.SetDefaultColor(Color.GREEN);
#U1.SetLineWeight(4);
def D1 = showarrows and signal < 0 and signal[1] >= 0;
#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#D1.SetDefaultColor(Color.RED);
#D1.SetLineWeight(4);
def barnumber = BarNumber()[10];
AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);
AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK,
yes);
def revLineTop;
def revLineBot;
if barnumber and D1 {
    revLineBot = Double.NaN;
    revLineTop = high[1];
} else if barnumber and U1 {
    revLineTop = Double.NaN;
    revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
    revLineBot = revLineBot[1];
    revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
    revLineTop = revLineTop[1];
    revLineBot = Double.NaN;
} else {
    revLineTop = Double.NaN;
    revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.LIGHT_GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.LIGHT_RED);
#Alerts
def usealerts = no;
#Alert(usealerts and U1, "EI-UP", Alert.BAR, Sound.Bell);
#Alert(usealerts and D1, "EI-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def numbersuppdemandtoshow = 0;
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 = pricel[idx];
    rHigh = priceh[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
def HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
def LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
def showsupplydemandcloud = no;
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 EIsave1 = if !IsNaN(EISave) then EISave else EIsave1[1];
def EIsave2 = EIsave1;
rec priorEI1 = if EIsave2 != EIsave2[1] then EIsave2[1] else priorEI1[1];
rec priorEI2 = if priorEI1 != priorEI1[1] then priorEI1[1] else priorEI2[1];
rec priorEI3 = if priorEI2 != priorEI2[1] then priorEI2[1] else priorEI3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
def showFibExtLines = no;
def showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1 else extfib1[1];
def extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
def extfib1a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a[1];
def extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
def extfib2 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2[1];
def extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
def extfib3 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3[1];
def extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
def extfib3a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a[1];
def extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
def extfib4 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4[1];
def extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
def extfib5 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5[1];
def extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
def extfib1_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1 else extfib1_[1];
def extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
def extfib1a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a_[1];
def extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
def extfib2_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2_[1];
def extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
def extfib3_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3_[1];
def extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
def extfib3a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a_[1];
def extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
def extfib4_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4_[1];
def extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
def extfib5_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5_[1];
def extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
def 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 EISave == priceh or EISave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
def showBubblesVolume = no;

AddChartBubble(showBubblesVolume and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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 );

input usemanualfibskip = no;
#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.

input fibskip = .50;
#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.

def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;

#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
#
#


--------------------------------


this is a strategy

it seems not every buy or sell is drawn... so not perfect.
but maybe a starting point for a next version...

your code , turned into a strategy
create buy/sell variables , in middle of strategy, so 2nd half of code is not used.
...based off of logic in 2 bubble functions

AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);

AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);


add warn formulas , for the purple bubbles.
add addorder functions for buying and selling

can draw vertical lines to verify buy/sell signals

Code:
# momentum_bb_pdf_code_01a

#https://usethinkscript.com/threads/idea-for-momentum-indicator-asma.15812/
#Idea for Momentum Indicator (ASMA)
#Yohannes24  6/28  #1

#My name is Issey Yohannes, I am currently a student at the University of Virginia. That being said, I have been using the “Thinkorswim” platform to invest in options/fequities since 2018. After years of practice, I have engineered an idea for a momentum indicator that I would like to make a reality. I will attach a PDF with all the details. requirements, and scripts to be implemented in the indicator. As this program is created for Thinkorswim, I do not require real money orders or automatic investments.
# I am hoping “BenTen” or any other equally skilled coder on this platform can aid me in my execution of the concept. Be warned that the indicators in the program are complex (not created by me), however, the aggregate of the code is unique.

#Last but not least, any notions or reactions to this potential idea is much appreciated.

#Made a few changes/additions and updated visuals. I think this indicator would heavily shift favor of options/equities investing to the investor at hand. Though it is not always right (as all indicators aren't) I believe it could be powerful if someone has the skill/knowhow to code it as noted. Any insight is much appreciated.

#Attachments
#%22BB Trend Capture Indicator%22 (BBTCI)-5.pdf
#497.8 KB · Views: 0



#"BB Trend Capture Indicator" (BBTCI)
#Visual Indicator Engineered by Issey Yohannes
#Additional Conditional Visual

#Criteria A : 20 SMA below 200 SMA (Bear - Shorting) - Indicating downtrends
#Signal : Downwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (red or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria A” are met) are red.
#Signal : Upwards Red Arrow (All conditions must be true at same time)
#3. Both conditions A1 and A2 have been met
#4. First condition requirement : BB Indicator signal (green or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria A” are met) are gray.

#Criteria B : 20 SMA above 200 SMA (Bull - Long) - Indicating uptrends
#Signal : Upwards Green Arrow (All conditions must be true at same time)
#1. First condition requirement : Most recent BB Indicator signal (green or neutral)
#2. Second condition requirement : 10 Simple Moving Avg. Cross Above 20 Simple Moving Avg.
#Repaint : All candles beyond the green arrow (entry for “Criteria B” are met) are green.
#Signal : Downwards Red Arrow (All conditions must be true at same time)
#3. Both conditions B1 and B2 have been met
#4. First condition requirement : BB Indicator signal (red or neutral)
#5. Second condition requirement : 10 Simple Moving Avg. Cross Below 20 Simple Moving Avg.
#Repaint : All candles beyond the red arrow (exit for “Criteria B” are met) are gray.

#Note : No subtractions from current visuals of BB are required.
#Visual of Concept
#EX.1
#Note : This example is solely to visualize the concept, all potential signals within this graph were not highlighted in
#order to facilitate illustration with no clutter.
#BB Study Summary (ChatGPT) - Implemented in BBTCI: BB carries out technical analysis using price
#action, volume, and Fibonacci retracement levels to identify potential trend reversals. It also combines
#several indicators, including moving averages, RSI, and MACD, to accomplish the identification of these
#reversals. In addition, BB includes a custom algorithm that looks for specific price patterns and volume
#behavior. Last but not least, Fibonacci retracement levels are used to identify potential support and
#resistance levels, and the study includes a feature to display these levels on the chart.
#BBTCI Study Summary (ChatGPT) : The BBTCI combines the power of the BB indicator, SMA crosses,
#and other specific conditions to generate signals relating to potential short and long positions. Traders can
#utilize the alerts and SMS messages to monitor the market and take appropriate actions based on the
#signals received. This information can be used to purchase stock equity out right or utilize other financial
#instruments such as stock options. It is important to thoroughly test and validate the BBTCI's functionality
#before using it in real trading scenarios, as no trading strategy can guarantee success in all market
#conditions.
#BB Break Down (ChatGPT)
#1. Fib Levels: The code uses Fibonacci retracement levels to identify potential areas of support and
#resistance on the chart. The code calculates the Fibonacci levels based on the difference
#between the highest high and lowest low of the selected period. The levels that the code uses are
#0.236, 0.382, 0.500, 0.618, and 0.786.
#2. Fib Skip: The code allows the user to set a percentage difference between the Fibonacci high
#and low before a new Fibonacci grid is created. This is known as the Fib Skip. The default value
#is 1.0, but the user can manually set this value by changing the "fibskip" input.
#3. Chart Bubbles: The code displays chart bubbles that show the current Fibonacci level as a
#percentage of the distance between the Fibonacci low and high. The bubbles are color-coded
#based on whether the current price is above or below the Fibonacci low.
#4. Reversal Signals: The code generates reversal signals based on several criteria:
#● The current price must be below the Fibonacci low.
#● The current price must be above the previous low.
#● The previous low must be below the Fibonacci low.
#● The previous low must be a certain percentage (determined by the "percentagereversal"
#input) below the Fibonacci low.
#If all of these conditions are met, the code generates a bullish reversal signal. The code generates a
#bearish reversal signal if the current price is above the Fibonacci high and the previous high meets the
#above criteria.
#5. Other Inputs: The code also allows the user to customize several other inputs, including:
#● The period over which to calculate the Fibonacci levels (controlled by the "data1" input).
#● Whether to show the Fibonacci levels and bubbles (controlled by the "showfiblines" and
#"showBubblesfibratio" inputs).
#● Whether to show the current Fibonacci level as a label on the chart (controlled by the
#"showFibLabel" input).
#Overall, BB is a technical analysis tool that uses Fibonacci retracement levels to identify potential areas of
#support and resistance on the chart, and generates reversal signals based on the price's relationship to
#these levels.

#BB Indicator Code
def price = close;
def superfast_length = 9;
def fast_length = 14;
def slow_length = 21;
def displace = 0;
def mov_avg9 = ExpAverage(price[-displace], superfast_length);
def mov_avg14 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;
#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
Colorbars.Hide();
Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
Colorbars.DefineColor("Neutral", Color.PLUM);

#___________________________________________________________________________

input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
#plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
#EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);
#EnhancedLines.SetStyle(Curve.FIRM);
#EnhancedLines.EnableApproximation();
#EnhancedLines.HideBubble();
#Price Change between Enhanceds
def xxhigh = if EISave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if EISave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
def showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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
def showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , 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 Enhanced
#Bar Count between Enhanceds
rec EIcount = if EISave[1] != EISave then 1 else if EISave[1] == EISave then EIcount[1] + 1 else 0;
def EIcounthilo = if EIcounthilo[1] == 0 and (EISave == priceh or EISave == pricel) then 1 else if EISave == priceh or EISave == pricel then EIcounthilo[1] + 1 else EIcounthilo[1];
def EIhilo = if EISave == priceh or EISave == pricel then EIcounthilo else EIcounthilo + 1;
def EIcounthigh = if EISave == priceh then EIcount[1] else Double.NaN;
def EIcountlow = if EISave == pricel then EIcount[1] else Double.NaN;
def showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if EISave == priceh then EIcounthigh else EIcountlow, 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 EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
def U1 = showarrows and signal > 0 and signal[1] <= 0;
#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#U1.SetDefaultColor(Color.GREEN);
#U1.SetLineWeight(4);
def D1 = showarrows and signal < 0 and signal[1] >= 0;
#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#D1.SetDefaultColor(Color.RED);
#D1.SetLineWeight(4);




# 126
# plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;

def barnumber = BarNumber()[10];

AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);

AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK, yes);

#--------------------

input sell_on_warn = no;
input buy_on_warn = no;


def short_warn = (U1 and isUp and signal > 0 and signal[1] <= 0 and Colorbars == 3);
def long_warn = (d1 and !isUp and signal < 0 and signal[1] >= 0 and Colorbars == 3);

#def long_buy = ((barnumber and U1) and isUp and signal > 0 and signal[1] <= 0 );
def long_buy = (U1 and isUp and signal > 0 and signal[1] <= 0 and Colorbars != 3) or (buy_on_warn and short_warn);
def short_buy = (d1 and !isUp and signal < 0 and signal[1] >= 0 and Colorbars != 3) or (buy_on_warn and long_warn);

def long_sell = short_buy or (sell_on_warn and long_warn);
def short_sell = long_buy or (sell_on_warn and short_warn);




input test_vert_lines = no;
addverticalline(test_vert_lines and long_buy, "buy", color.green);
addverticalline(test_vert_lines and short_buy, "sell", color.red);

addverticalline(test_vert_lines and long_warn, "warn", color.cyan);
addverticalline(test_vert_lines and short_warn, "warn", color.yellow);



input test2 = no;
AddChartBubble(test2, low,
barnumber + " bn\n" +
U1 + " u1\n" +
isUp + " up\n" +
signal + " s0\n" +
signal[1] + " s1\n" +
( signal > 0 and signal[1] ) + " ss\n" +
( U1 and isUp and signal > 0 and signal[1] <= 0 ) + "\n" +
Colorbars + " col\n" +
long_buy
, color.yellow, no);



#--------------------


def revLineTop;
def revLineBot;
if barnumber and D1 {
    revLineBot = Double.NaN;
    revLineTop = high[1];
} else if barnumber and U1 {
    revLineTop = Double.NaN;
    revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
    revLineBot = revLineBot[1];
    revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
    revLineTop = revLineTop[1];
    revLineBot = Double.NaN;
} else {
    revLineTop = Double.NaN;
    revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.LIGHT_GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.LIGHT_RED);
#Alerts
def usealerts = no;
#Alert(usealerts and U1, "EI-UP", Alert.BAR, Sound.Bell);
#Alert(usealerts and D1, "EI-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def numbersuppdemandtoshow = 0;
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 = pricel[idx];
    rHigh = priceh[idx];
} else {
    rLow = rLow[1];
    rHigh = rHigh[1];
}
def HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
def LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
def showsupplydemandcloud = no;
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 EIsave1 = if !IsNaN(EISave) then EISave else EIsave1[1];
def EIsave2 = EIsave1;
rec priorEI1 = if EIsave2 != EIsave2[1] then EIsave2[1] else priorEI1[1];
rec priorEI2 = if priorEI1 != priorEI1[1] then priorEI1[1] else priorEI2[1];
rec priorEI3 = if priorEI2 != priorEI2[1] then priorEI2[1] else priorEI3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
def showFibExtLines = no;
def showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1 else extfib1[1];
def extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
def extfib1a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a[1];
def extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
def extfib2 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2[1];
def extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
def extfib3 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3[1];
def extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
def extfib3a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a[1];
def extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
def extfib4 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4[1];
def extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
def extfib5 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5[1];
def extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
def extfib1_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1 else extfib1_[1];
def extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
def extfib1a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a_[1];
def extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
def extfib2_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2_[1];
def extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
def extfib3_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3_[1];
def extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
def extfib3a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a_[1];
def extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
def extfib4_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4_[1];
def extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
def extfib5_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5_[1];
def extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
def 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 EISave == priceh or EISave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
def showBubblesVolume = no;

AddChartBubble(showBubblesVolume and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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 );

input usemanualfibskip = no;
#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.

input fibskip = .50;
#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.

def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;

#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
#
#

#----------------------------------

def size = 1;
AddOrder(OrderType.BUY_TO_OPEN, long_buy, open[-1], size, color.green, color.green, name = "long" );
AddOrder(OrderType.SELL_TO_CLOSE, long_sell, open[-1], size, color.white, color.white, name = "-" );

AddOrder(OrderType.sell_TO_OPEN, short_buy, open[-1], size, color.red, color.red, name = "short" );
AddOrder(OrderType.buy_TO_CLOSE, short_sell, open[-1], size, color.white, color.white, name = "-" );

#
Is it possible to create a scanner for this strategy? I am getting the " complex..." error? Thanks
 
This script will not work in the Scan Hacker.
"Too Complex" error that means the script cannot be used in watchlists, scans, conditional orders, or any other widget that interfaces with the condition wizard.
 
Dear friends (@BenTen , @halcyonguy, @MerryDay , @tradelex20 , @mashume , @sum ). I have been working on the issues related to this indicator (decided to name it the Daily Options Indicator (DOI)). The visuals also have been altered, it is recommended to use the default settings on a daily chart - hence the name. In addition, it is recommended to interpret the closing candle near market close to give enough time for any position changes.

Note : Color index has changed.

Red Candle = Sell Long or Short
Green Candle = Buy Long or Sell Short
White Candle = Neutral (No recommended position)

Here is the code - Please maintain the name of the indicator along with the credit which I have attributed in comments. Thank You.

-----------------------------------------------------------------------------------------------

# Daily Options Indicator (DOI) with Additional Features
# Created by Helcyonguy and Issey Yohannes
# Recommended to interpret candle near close (3:55PM EST)
# Beware of false positives
# Human interpretation required

declare upper;

input length = 9;
input length2 = 12;

# Bollinger Bands
def price = close;
def deviation = stdev(price, length);
def mov_avg = SimpleMovingAvg(price, length);
def upperband = mov_avg + deviation;
def lowerband = mov_avg - deviation;

# Exponential Moving Averages
def mov_avg9 = ExpAverage(close, length);
def mov_avg12 = ExpAverage(close, length2);

# Additional Simple Moving Averages
def mov_avg10 = SimpleMovingAvg(price, 10);
def mov_avg20 = SimpleMovingAvg(price, 20);
def mov_avg50 = SimpleMovingAvg(price, 50);
def mov_avg200 = SimpleMovingAvg(price, 200);

# Buy and Sell Signals
def buysignal = if close > mov_avg and close > upperband and mov_avg9 > mov_avg12 then 1 else 0;
def sellsignal = if close < mov_avg and close < lowerband and mov_avg9 < mov_avg12 then 1 else 0;

# Recolor candles based on SMA conditions
def green_condition = mov_avg10 > mov_avg20 and mov_avg20 > mov_avg200 and mov_avg10 > mov_avg50;
def red_condition = mov_avg10 < mov_avg20 and mov_avg20 < mov_avg200 and mov_avg10 < mov_avg50;

AssignPriceColor(if green_condition and mov_avg10 > mov_avg50 then Color.GREEN
else if green_condition and mov_avg10 < mov_avg50 then Color.WHITE
else if red_condition and mov_avg10 < mov_avg50 then Color.RED
else if red_condition and mov_avg10 > mov_avg50 then Color.WHITE
else Color.WHITE);

# Fibonacci Extensions
rec data = CompoundValue(1, if (mov_avg9 == price) or (mov_avg9 == price[1]) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);

def fib_ext_low = if datacount <= 2 then low - AbsValue(price[1] - price[2]) * 1.618 else Double.NaN;
def fib_ext_high = if datacount <= 2 then high + AbsValue(price[1] - price[2]) * 1.618 else Double.NaN;

def show_fib_ext_lines = no;
def today = GetDay() == GetLastDay();
plot FibLow = if show_fib_ext_lines and today then fib_ext_low else Double.NaN;
FibLow.SetDefaultColor(Color.GREEN);
FibLow.SetPaintingStrategy(PaintingStrategy.POINTS);
plot FibHigh = if show_fib_ext_lines and today then fib_ext_high else Double.NaN;
FibHigh.SetDefaultColor(Color.RED);
FibHigh.SetPaintingStrategy(PaintingStrategy.POINTS);

# Supply Demand Areas
rec data1 = CompoundValue(1, if (mov_avg9 == price) or (mov_avg9 == price[1]) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);

def pivot_high = if datacount1 <= 0 then high else Double.NaN;
def pivot_low = if datacount1 <= 0 then low else Double.NaN;
def show_supply_demand = no;
plot PivotHigh = if show_supply_demand then pivot_high else Double.NaN;
PivotHigh.SetDefaultColor(Color.GREEN);
PivotHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
plot PivotLow = if show_supply_demand then pivot_low else Double.NaN;
PivotLow.SetDefaultColor(Color.RED);
PivotLow.SetPaintingStrategy(PaintingStrategy.POINTS);

# Plot additional Simple Moving Averages
plot SMA10 = mov_avg10;
SMA10.SetDefaultColor(Color.CYAN);
SMA10.SetLineWeight(2);
plot SMA20 = mov_avg20;
SMA20.SetDefaultColor(Color.GRAY);
SMA20.SetLineWeight(2);

# Cloud between SMA10 and SMA20
AddCloud(SMA10, SMA20, Color.GREEN, Color.RED);

# Plot additional Simple Moving Averages
plot SMA50 = mov_avg50;
SMA50.SetDefaultColor(Color.YELLOW);
SMA50.SetLineWeight(2);
plot SMA200 = mov_avg200;
SMA200.SetDefaultColor(Color.WHITE);
SMA200.SetLineWeight(2);

# Projection Pivots
input pp_length = 21;
input show_pp_lines = yes;
input show_pp_values = no;
input show_pp_bars = no;
input pp_extension_length = 35;
input pp_upper_ext_limit = 5;
input pp_lower_ext_limit = 5;
input pp_display_label = yes;

addlabel(pp_display_label, "Projection Pivots n:" + pp_length + " ", color.WHITE);

def pp_vHigh = high;
def pp_vLow = low;
def pp_bn = BarNumber();
def pp_currentBar = HighestAll(if !IsNaN(pp_vHigh) then pp_bn else Double.NaN);

def pp_PH;
def pp_PL;

def pp_hh = fold i = 1 to pp_length + 1
with p = 1
while p
do pp_vHigh > getValue(pp_vHigh, -i);
pp_PH = if (pp_bn > pp_length and
pp_vHigh == highest(pp_vHigh, pp_length) and
pp_hh)
then pp_vHigh
else Double.NaN;

def pp_ll = fold j = 1 to pp_length + 1
with q = 1
while q
do pp_vLow < getValue(low, -j);
pp_PL = if (pp_bn > pp_length and
pp_vLow == lowest(pp_vLow, pp_length) and
pp_ll)
then pp_vLow
else Double.NaN;

def pp_PHBar = if !isNaN(pp_PH)
then pp_bn
else pp_PHBar[1];
def pp_PLBar = if !isNaN(pp_PL)
then pp_bn
else pp_PLBar[1];

def pp_PHL = if !isNaN(pp_PH)
then pp_PH
else pp_PHL[1];
def pp_priorPHBar = if pp_PHL != pp_PHL[1]
then pp_PHBar[1]
else pp_priorPHBar[1];

def pp_PLL = if !isNaN(pp_PL)
then pp_PL
else pp_PLL[1];
def pp_priorPLBar = if pp_PLL != pp_PLL[1]
then pp_PLBar[1]
else pp_priorPLBar[1];

def pp_HighPivots = pp_bn >= highestAll(pp_priorPHBar);
def pp_LowPivots = pp_bn >= highestAll(pp_priorPLBar);

def pp_FirstRpoint = if pp_HighPivots
then pp_bn - pp_PHBar
else 0;
def pp_PriorRpoint = if pp_HighPivots
then pp_bn - pp_priorPHBar
else 0;
def pp_RSlope = (getValue(pp_PH, pp_FirstRpoint) - getValue(pp_PH, pp_PriorRpoint))
/ (pp_PHBar - pp_priorPHBar);

def pp_FirstSpoint = if pp_LowPivots
then pp_bn - pp_PLBar
else 0;
def pp_PriorSpoint = if pp_LowPivots
then pp_bn - pp_priorPLBar
else 0;
def pp_SSlope = (getValue(pp_PL, pp_FirstSpoint) - getValue(pp_PL, pp_PriorSpoint))
/ (pp_PLBar - pp_priorPLBar);

def pp_RExtend = if pp_bn == highestall(pp_PHBar)
then 1
else pp_RExtend[1];
def pp_SExtend = if pp_bn == highestall(pp_PLBar)
then 1
else pp_SExtend[1];

plot pp_pivotHigh = if pp_HighPivots
then pp_PH
else Double.NaN;
pp_pivotHigh.SetDefaultColor(Color.GREEN);
pp_pivotHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotHigh.SetLineWeight(2);

plot pp_pivotLow = if pp_LowPivots
then pp_PL
else Double.NaN;
pp_pivotLow.SetDefaultColor(Color.RED);
pp_pivotLow.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotLow.SetLineWeight(2);

plot pp_pivotHighLine = if pp_PHL > 0 and
pp_HighPivots
then pp_PHL
else Double.NaN;
pp_pivotHighLine.SetDefaultColor(Color.GREEN);
pp_pivotHighLine.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotHighLine.SetLineWeight(2);

plot pp_pivotLowLine = if pp_PLL > 0 and
pp_LowPivots
then pp_PLL
else Double.NaN;
pp_pivotLowLine.SetDefaultColor(Color.RED);
pp_pivotLowLine.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotLowLine.SetLineWeight(2);

def pp_calc_ResistanceExtension = if pp_RExtend
then (pp_bn - pp_PHBar) * pp_RSlope + pp_PHL
else Double.NaN;
plot pp_line_ResistanceExtension = if pp_bn <= (pp_currentBar + pp_extension_length)
and pp_calc_ResistanceExtension[1] >= (lowestall(pp_vLow) * (1 - (pp_lower_ext_limit / 100)))
and pp_calc_ResistanceExtension[1] <= (highestall(pp_vHigh) * (1 + (pp_upper_ext_limit / 100)))
then pp_calc_ResistanceExtension else Double.NaN;
pp_line_ResistanceExtension.SetDefaultColor(Color.WHITE);
pp_line_ResistanceExtension.SetPaintingStrategy(PaintingStrategy.LINE);
pp_line_ResistanceExtension.SetLineWeight(2);

def pp_calc_SupportExtension = if pp_SExtend
then (pp_bn - pp_PLBar) * pp_SSlope + pp_PLL
else Double.NaN;
plot pp_line_SupportExtension = if pp_bn <= (pp_currentBar + pp_extension_length)
and pp_calc_SupportExtension[1] >= (lowestall(pp_vLow) * (1 - (pp_lower_ext_limit / 100)))
and pp_calc_SupportExtension[1] <= (highestall(pp_vHigh) * (1 + (pp_upper_ext_limit / 100)))
then pp_calc_SupportExtension else Double.NaN;
pp_line_SupportExtension.SetDefaultColor(Color.WHITE);
pp_line_SupportExtension.SetPaintingStrategy(PaintingStrategy.LINE);
pp_line_SupportExtension.SetLineWeight(2);

plot pp_Rline = pp_pivotHigh;
pp_Rline.enableApproximation();
pp_Rline.SetDefaultColor(Color.WHITE);
pp_Rline.SetPaintingStrategy(PaintingStrategy.LINE);
pp_Rline.SetLineWeight(2);

plot pp_supportline = pp_pivotLow;
pp_supportline.enableApproximation();
pp_supportline.SetDefaultColor(Color.WHITE);
pp_supportline.SetPaintingStrategy(PaintingStrategy.LINE);
pp_supportline.SetLineWeight(2);





plot pp_supportline = pp_pivotLow;
pp_supportline.enableApproximation();
pp_supportline.SetDefaultColor(Color.WHITE);
pp_supportline.SetPaintingStrategy(PaintingStrategy.LINE);
pp_supportline.SetLineWeight(2);
 
Last edited:
Issey Yohannes

My name is Issey Yohannes, I have spent many hours to integrate the visuals (along with all its relevant associated calculations) of the BB indicator to another one of my indicators named Trend Master. My goal is to combine without compromising on the signals both indicators create.

Note : The BB indicator was created by BenTen


# Trend Master Indicator (TMI)
# Created by Helcyonguy, and Issey Yohannes

declare upper;
input length = 9;
input length2 = 12;

# Bollinger Bands
def price = close;
def deviation = stdev(price, length);
def mov_avg = SimpleMovingAvg(price, length);
def upperband = mov_avg + deviation;
def lowerband = mov_avg - deviation;

# Exponential Moving Averages
def mov_avg9 = ExpAverage(close, length);
def mov_avg12 = ExpAverage(close, length2);

# Additional Simple Moving Averages
def mov_avg10 = SimpleMovingAvg(price, 10);
def mov_avg20 = SimpleMovingAvg(price, 20);
def mov_avg50 = SimpleMovingAvg(price, 50);
def mov_avg200 = SimpleMovingAvg(price, 200);

# Buy and Sell Signals
def buysig = if close > mov_avg and close > upperband and mov_avg9 > mov_avg12 and mov_avg10 > mov_avg50 then low else Double.NaN;
def sellsig = if close < mov_avg and close < lowerband and mov_avg9 < mov_avg12 and mov_avg10 < mov_avg50 then high else Double.NaN;

# Calculate the slope of SMA50
def slope_SMA50 = (mov_avg50 - mov_avg50[1]) / 50;

# Define a threshold for the minimum slope magnitude
input min_slope_magnitude = 0.1;

# Filter out signals based on slope
def signal_condition = buysig and slope_SMA50 > min_slope_magnitude;
def exit_condition = sellsig and slope_SMA50 < -min_slope_magnitude;

# Plot buy and sell signals only when the slope is steep enough
plot BuySignal = if signal_condition then buysig else Double.NaN;
plot SellSignal = if exit_condition then sellsig else Double.NaN;

# Adjust plot appearance
BuySignal.SetDefaultColor(Color.GREEN);
SellSignal.SetDefaultColor(Color.RED);
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# Recolor candles based on SMA cloud conditions
def sma_cloud_color = if mov_avg10 > mov_avg20 then 1 else if mov_avg10 < mov_avg20 then -1 else 0;
AssignPriceColor(if sma_cloud_color == 1 then Color.GREEN
else if sma_cloud_color == -1 then Color.RED
else Color.WHITE);

# Fibonacci Extensions
rec data = CompoundValue(1, if (mov_avg9 == price) or (mov_avg9 == price[1]) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def fib_ext_low = if datacount <= 2 then low - AbsValue(price[1] - price[2]) * 1.618 else Double.NaN;
def fib_ext_high = if datacount <= 2 then high + AbsValue(price[1] - price[2]) * 1.618 else Double.NaN;
def show_fib_ext_lines = no;
def today = GetDay() == GetLastDay();
plot FibLow = if show_fib_ext_lines and today then fib_ext_low else Double.NaN;
FibLow.SetDefaultColor(Color.GREEN);
FibLow.SetPaintingStrategy(PaintingStrategy.POINTS);
plot FibHigh = if show_fib_ext_lines and today then fib_ext_high else Double.NaN;
FibHigh.SetDefaultColor(Color.RED);
FibHigh.SetPaintingStrategy(PaintingStrategy.POINTS);

# Supply Demand Areas
rec data1 = CompoundValue(1, if (mov_avg9 == price) or (mov_avg9 == price[1]) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def pivot_high = if datacount1 <= 0 then high else Double.NaN;
def pivot_low = if datacount1 <= 0 then low else Double.NaN;
def show_supply_demand = no;
plot PivotHigh = if show_supply_demand then pivot_high else Double.NaN;
PivotHigh.SetDefaultColor(Color.GREEN);
PivotHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
plot PivotLow = if show_supply_demand then pivot_low else Double.NaN;
PivotLow.SetDefaultColor(Color.RED);
PivotLow.SetPaintingStrategy(PaintingStrategy.POINTS);

# Plot additional Simple Moving Averages
plot SMA10 = mov_avg10;
SMA10.SetDefaultColor(Color.CYAN);
SMA10.SetLineWeight(2);
plot SMA20 = mov_avg20;
SMA20.SetDefaultColor(Color.GRAY);
SMA20.SetLineWeight(2);

# Cloud between SMA10 and SMA20
AddCloud(SMA10, SMA20, Color.GREEN, Color.RED);

# Plot additional Simple Moving Averages
plot SMA50 = mov_avg50;
SMA50.SetDefaultColor(Color.YELLOW);
SMA50.SetLineWeight(2);
plot SMA200 = mov_avg200;
SMA200.SetDefaultColor(Color.WHITE);
SMA200.SetLineWeight(2);

# Projection Pivots
input pp_length = 21;
input show_pp_lines = yes;
input show_pp_values = no;
input show_pp_bars = no;
input pp_extension_length = 35;
input pp_upper_ext_limit = 5;
input pp_lower_ext_limit = 5;
input pp_display_label = yes;
addlabel(pp_display_label, "Projection Pivots n:" + pp_length + " ", color.WHITE);
def pp_vHigh = high;
def pp_vLow = low;
def pp_bn = BarNumber();
def pp_currentBar = HighestAll(if !IsNaN(pp_vHigh) then pp_bn else Double.NaN);
def pp_PH;
def pp_PL;
def pp_hh = fold i = 1 to pp_length + 1
with p = 1
while p
do pp_vHigh > getValue(pp_vHigh, -i);
pp_PH = if (pp_bn > pp_length and
pp_vHigh == highest(pp_vHigh, pp_length) and
pp_hh)
then pp_vHigh
else Double.NaN;
def pp_ll = fold j = 1 to pp_length + 1
with q = 1
while q
do pp_vLow < getValue(low, -j);
pp_PL = if (pp_bn > pp_length and
pp_vLow == lowest(pp_vLow, pp_length) and
pp_ll)
then pp_vLow
else Double.NaN;
def pp_PHBar = if !isNaN(pp_PH)
then pp_bn
else pp_PHBar[1];
def pp_PLBar = if !isNaN(pp_PL)
then pp_bn
else pp_PLBar[1];
def pp_PHL = if !isNaN(pp_PH)
then pp_PH
else pp_PHL[1];
def pp_priorPHBar = if pp_PHL != pp_PHL[1]
then pp_PHBar[1]
else pp_priorPHBar[1];
def pp_PLL = if !isNaN(pp_PL)
then pp_PL
else pp_PLL[1];
def pp_priorPLBar = if pp_PLL != pp_PLL[1]
then pp_PLBar[1]
else pp_priorPLBar[1];
def pp_HighPivots = pp_bn >= highestAll(pp_priorPHBar);
def pp_LowPivots = pp_bn >= highestAll(pp_priorPLBar);
def pp_FirstRpoint = if pp_HighPivots
then pp_bn - pp_PHBar
else 0;
def pp_PriorRpoint = if pp_HighPivots
then pp_bn - pp_priorPHBar
else 0;
def pp_RSlope = (getValue(pp_PH, pp_FirstRpoint) - getValue(pp_PH, pp_PriorRpoint))
/ (pp_PHBar - pp_priorPHBar);

def pp_FirstSpoint = if pp_LowPivots
then pp_bn - pp_PLBar
else 0;
def pp_PriorSpoint = if pp_LowPivots
then pp_bn - pp_priorPLBar
else 0;
def pp_SSlope = (getValue(pp_PL, pp_FirstSpoint) - getValue(pp_PL, pp_PriorSpoint))
/ (pp_PLBar - pp_priorPLBar);
def pp_RExtend = if pp_bn == highestall(pp_PHBar)
then 1
else pp_RExtend[1];
def pp_SExtend = if pp_bn == highestall(pp_PLBar)
then 1
else pp_SExtend[1];
plot pp_pivotHigh = if pp_HighPivots
then pp_PH
else Double.NaN;
pp_pivotHigh.SetDefaultColor(Color.GREEN);
pp_pivotHigh.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotHigh.SetLineWeight(2);

plot pp_pivotLow = if pp_LowPivots
then pp_PL
else Double.NaN;
pp_pivotLow.SetDefaultColor(Color.RED);
pp_pivotLow.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotLow.SetLineWeight(2);
plot pp_pivotHighLine = if pp_PHL > 0 and
pp_HighPivots
then pp_PHL
else Double.NaN;
pp_pivotHighLine.SetDefaultColor(Color.GREEN);
pp_pivotHighLine.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotHighLine.SetLineWeight(2);
plot pp_pivotLowLine = if pp_PLL > 0 and
pp_LowPivots
then pp_PLL
else Double.NaN;
pp_pivotLowLine.SetDefaultColor(Color.RED);
pp_pivotLowLine.SetPaintingStrategy(PaintingStrategy.POINTS);
pp_pivotLowLine.SetLineWeight(2);
def pp_calc_ResistanceExtension = if pp_RExtend
then (pp_bn - pp_PHBar) * pp_RSlope + pp_PHL
else Double.NaN;
plot pp_line_ResistanceExtension = if pp_bn <= (pp_currentBar + pp_extension_length)
and pp_calc_ResistanceExtension[1] >= (lowestall(pp_vLow) * (1 - (pp_lower_ext_limit / 100)))
and pp_calc_ResistanceExtension[1] <= (highestall(pp_vHigh) * (1 + (pp_upper_ext_limit / 100)))
then pp_calc_ResistanceExtension else Double.NaN;
pp_line_ResistanceExtension.SetDefaultColor(Color.WHITE);
pp_line_ResistanceExtension.SetPaintingStrategy(PaintingStrategy.LINE);
pp_line_ResistanceExtension.SetLineWeight(2);
def pp_calc_SupportExtension = if pp_SExtend
then (pp_bn - pp_PLBar) * pp_SSlope + pp_PLL
else Double.NaN;
plot pp_line_SupportExtension = if pp_bn <= (pp_currentBar + pp_extension_length)
and pp_calc_SupportExtension[1] >= (lowestall(pp_vLow) * (1 - (pp_lower_ext_limit / 100)))
and pp_calc_SupportExtension[1] <= (highestall(pp_vHigh) * (1 + (pp_upper_ext_limit / 100)))
then pp_calc_SupportExtension else Double.NaN;
pp_line_SupportExtension.SetDefaultColor(Color.WHITE);
pp_line_SupportExtension.SetPaintingStrategy(PaintingStrategy.LINE);
pp_line_SupportExtension.SetLineWeight(2);
plot pp_Rline = pp_pivotHigh;
pp_Rline.enableApproximation();
pp_Rline.SetDefaultColor(Color.WHITE);
pp_Rline.SetPaintingStrategy(PaintingStrategy.LINE);
pp_Rline.SetLineWeight(2);
plot pp_supportline = pp_pivotLow;
pp_supportline.enableApproximation();
pp_supportline.SetDefaultColor(Color.WHITE);
pp_supportline.SetPaintingStrategy(PaintingStrategy.LINE);
pp_supportline.SetLineWeight(2);













#BB Indicator Code
#Created by BenTen
def price = close;
def superfast_length = 9;
def fast_length = 14;
def slow_length = 21;
def displace = 0;
def mov_avg9 = ExpAverage(price[-displace], superfast_length);
def mov_avg14 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
def Superfast = mov_avg9;
def Fast = mov_avg14;
def Slow = mov_avg21;
def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;
def stopbuy = mov_avg9 <= mov_avg14;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);
def Buy_Signal = buysignal[1] == 0 and buysignal == 1;
#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

def Momentum_Down = buysignal[1] == 1 and buysignal == 0;
#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;
def stopsell = mov_avg9 >= mov_avg14;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);
def Sell_Signal = sellsignal[1] == 0 and sellsignal;
#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);
def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;
Colorbars.Hide();
Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);
Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);
Colorbars.DefineColor("Neutral", Color.PLUM);
#___________________________________________________________________________
input method = {default average, high_low};
def bubbleoffset = .0005;
def percentamount = .01;
def revAmount = .05;
def atrreversal = 2.0;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.EXPONENTIAL;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh = if method == method.high_low then pricehigh else mah;
def pricel = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;
rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);
def isUp = chg >= 0;
rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));
def EId = if isUp then 1 else 0;
#plot EnhancedLines = if EId <= 1 then EI else Double.NaN;
#EnhancedLines.AssignValueColor(if EId == 1 then Color.GREEN else if EId == 0 then Color.RED else Color.DARK_ORANGE);
#EnhancedLines.SetStyle(Curve.FIRM);
#EnhancedLines.EnableApproximation();
#EnhancedLines.HideBubble();
#Price Change between Enhanceds
def xxhigh = if EISave == priceh then priceh else xxhigh[1];
def chghigh = priceh - xxhigh[1];
def xxlow = if EISave == pricel then pricel else xxlow[1];
def chglow = pricel - xxlow[1];
def showBubbleschange = no;
AddChartBubble(showBubbleschange and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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
def showBubblesprice = no;
AddChartBubble(showBubblesprice and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then "$" + priceh else "$" + pricel , 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 Enhanced
#Bar Count between Enhanceds
rec EIcount = if EISave[1] != EISave then 1 else if EISave[1] == EISave then EIcount[1] + 1 else 0;
def EIcounthilo = if EIcounthilo[1] == 0 and (EISave == priceh or EISave == pricel) then 1 else if EISave == priceh or EISave == pricel then EIcounthilo[1] + 1 else EIcounthilo[1];
def EIhilo = if EISave == priceh or EISave == pricel then EIcounthilo else EIcounthilo + 1;
def EIcounthigh = if EISave == priceh then EIcount[1] else Double.NaN;
def EIcountlow = if EISave == pricel then EIcount[1] else Double.NaN;
def showBubblesbarcount = no;
AddChartBubble(showBubblesbarcount and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if EISave == priceh then EIcounthigh else EIcountlow, 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 EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);
def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);
def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
def showarrows = yes;
def U1 = showarrows and signal > 0 and signal[1] <= 0;
#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#U1.SetDefaultColor(Color.GREEN);
#U1.SetLineWeight(4);
def D1 = showarrows and signal < 0 and signal[1] >= 0;
#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#D1.SetDefaultColor(Color.RED);
#D1.SetLineWeight(4);
def barnumber = BarNumber()[10];
AddChartBubble((barnumber and U1), if isUp then low else high, if showarrows and signal > 0 and signal[1] <= 0 then "Reversal:" + low else "" , if Colorbars == 3 then Color.PLUM else Color.UPTICK, no);
AddChartBubble((barnumber and D1), if isUp then low else high, if showarrows and signal < 0 and signal[1] >= 0 then "Reversal:" + high else "" , if Colorbars == 3 then Color.PLUM else Color.DOWNTICK,
yes);
def revLineTop;
def revLineBot;
if barnumber and D1 {
revLineBot = Double.NaN;
revLineTop = high[1];
} else if barnumber and U1 {
revLineTop = Double.NaN;
revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
revLineBot = revLineBot[1];
revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
revLineTop = revLineTop[1];
revLineBot = Double.NaN;
} else {
revLineTop = Double.NaN;
revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.LIGHT_GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.LIGHT_RED);
#Alerts
def usealerts = no;
#Alert(usealerts and U1, "EI-UP", Alert.BAR, Sound.Bell);
#Alert(usealerts and D1, "EI-DOWN", Alert.BAR, Sound.Chimes);
#Supply Demand Areas
rec data1 = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data1[1] + 1 else data1[1], 0);
def datacount1 = (HighestAll(data1) - data1[1]);
def numbersuppdemandtoshow = 0;
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 = pricel[idx];
rHigh = priceh[idx];
} else {
rLow = rLow[1];
rHigh = rHigh[1];
}
def HighLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rHigh != 0 then rHigh else Double.NaN;
def LowLine = if datacount1 <= numbersuppdemandtoshow and showSupplyDemand != showSupplyDemand.None and !IsNaN(close) and rLow != 0 then rLow else Double.NaN;
def hlUp = if signal > 0 then HighLine else Double.NaN;
def hlDn = if signal < 0 then HighLine else Double.NaN;
def showsupplydemandcloud = no;
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 EIsave1 = if !IsNaN(EISave) then EISave else EIsave1[1];
def EIsave2 = EIsave1;
rec priorEI1 = if EIsave2 != EIsave2[1] then EIsave2[1] else priorEI1[1];
rec priorEI2 = if priorEI1 != priorEI1[1] then priorEI1[1] else priorEI2[1];
rec priorEI3 = if priorEI2 != priorEI2[1] then priorEI2[1] else priorEI3[1];

#Fibonacci Extensions
rec data = CompoundValue(1, if (EISave == priceh or EISave == pricel) then data[1] + 1 else data[1], 0);
def datacount = (HighestAll(data) - data[1]);
def numberextfibstoshow = 2;
rec cpo = if dir[1] != dir then 0 else 1;
def showFibExtLines = no;
def showtodayonly = no;
def today = if showtodayonly == yes then GetDay() == GetLastDay() else GetDay();
def extfib1 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1 else extfib1[1];
def extfib100 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1) and dir < 0 and cpo != 0 then extfib1[1] else Double.NaN;
def extfib1a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a[1];
def extfib382 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a) and dir < 0 and cpo != 0 then extfib1a[1] else Double.NaN;
def extfib2 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2[1];
def extfib618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2) and dir < 0 and cpo != 0 then extfib2[1] else Double.NaN;
def extfib3 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3[1];
def extfib1618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3) and dir < 0 and cpo != 0 then extfib3[1] else Double.NaN;
def extfib3a = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a[1];
def extfib2000 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a) and dir < 0 and cpo != 0 then extfib3a[1] else Double.NaN;
def extfib4 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4[1];
def extfib2618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4) and dir < 0 and cpo != 0 then extfib4[1] else Double.NaN;
def extfib5 = if EISave == priceh then priceh - AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5[1];
def extfib3618 = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5) and dir < 0 and cpo != 0 then extfib5[1] else Double.NaN;
def extfib1_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1 else extfib1_[1];
def extfib100_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1_) and dir > 0 and cpo != 0 then extfib1_[1] else Double.NaN;
def extfib1a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.382 else extfib1a_[1];
def extfib382_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib1a_) and dir > 0 and cpo != 0 then extfib1a_[1] else Double.NaN;
def extfib2_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 0.618 else extfib2_[1];
def extfib618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib2_) and dir > 0 and cpo != 0 then extfib2_[1] else Double.NaN;
def extfib3_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 1.618 else extfib3_[1];
def extfib1618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3_) and dir > 0 and cpo != 0 then extfib3_[1] else Double.NaN;
def extfib3a_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.000 else extfib3a_[1];
def extfib2000_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib3a_) and dir > 0 and cpo != 0 then extfib3a_[1] else Double.NaN;
def extfib4_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 2.618 else extfib4_[1];
def extfib2618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib4_) and dir > 0 and cpo != 0 then extfib4_[1] else Double.NaN;
def extfib5_ = if EISave == pricel then pricel + AbsValue(priorEI2 - priorEI1) * 3.618 else extfib5_[1];
def extfib3618_ = if datacount <= numberextfibstoshow and today and showFibExtLines and !IsNaN(extfib5_) and dir > 0 and cpo != 0 then extfib5_[1] else Double.NaN;
def 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 EISave == priceh or EISave == pricel then TotalSum(volume) else xxvol[1];
def chgvol = if xxvol - xxvol[1] + vol1 == vol then vol else xxvol - xxvol[1];
def showBubblesVolume = no;

AddChartBubble(showBubblesVolume and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (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 );

input usemanualfibskip = no;
#Hint usemanualfibskip: Select no to use preprogrammed fibskip amounts. Select no, to use the amount entered at input fibskip.

input fibskip = .50;
#Hint fibskip: Set input usemanualfibskip == yes to use this amount versus preprogrammed amounts. Standard is 1.0. This is percentage difference between fib high and low before a new fib grid created.

def showBubblesfibratio = no;
def showFibLabel = no;#Hint showfibLabel: Select yes to show label of current fib level as of last price
def showfiblines = no;
def fib1level = .236;
def fib2level = .382;
def fibMlevel = .500;
def fib3level = .618;
def fib4level = .786;

#Fibs
def datacount2 = (HighestAll(data1) - data1[1]);
def numberfibretracementstoshow = 2;
def fibskipit = if usemanualfibskip == no then if close > 800 then .25 else .5 else fibskip;
def EIfibh = if EISave == priceh and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then priceh else EIfibh[1];
def EIfibl = if EISave == pricel and AbsValue(EISave - EISave[1]) > priceh * fibskipit * .01 then pricel else EIfibl[1];
def range = EIfibh - EIfibl;
def fibH = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibh else Double.NaN;
def fibL = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl else Double.NaN;
def fibM = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fibMlevel else Double.NaN;
def fib1 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib1level else Double.NaN;
def fib2 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib2level else Double.NaN;
def fib3 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib3level else Double.NaN;
def fib4 = if showfiblines == no then Double.NaN else if datacount2 <= numberfibretracementstoshow then EIfibl + range * fib4level else Double.NaN;

AddLabel(showFibLabel, Concat( "Current Fib Level ", AsPercent((close - EIfibl) / (range))), if close > EIfibl then Color.GREEN else if EIfibh == close then Color.WHITE else Color.RED);

AddChartBubble(showBubblesfibratio and !IsNaN(EI) and BarNumber() != 1, if isUp then priceh * (1 + bubbleoffset) else pricel * (1 - bubbleoffset) , if isUp then AsPercent((priceh - EIfibl) / (range)) else AsPercent((pricel - EIfibl) / range), if isUp and chghigh > 0 then Color.GREEN else if isUp and chghigh < 0 then Color.RED else if isUp then Color.GREEN else if !isUp and chglow > 0 then Color.GREEN else if !isUp and chglow < 0 then Color.RED else Color.RED, isUp);
#
#
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
438 Online
Create Post

Similar threads

Similar threads

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