Spx gamma Levels

Carlosack

New member
There's this company that posts and gives live data of certain gamma levels throughout the day on the spx chain. Anyone here know how they obtain this data? I want to see if I can obtain these gamma levels on my own. The bigger the candle the more its always attracted to it. Thank you
The video is an example. Thank you
1703079201127.png
 
Solution
I was attempting to get that to chart for SPX and any other ticker symbol (XOM for instance) but I can not seem to get it to work.
# Gamma Exposure Profile Indicator for ThinkOrSwim (XOM)

# Define Inputs
input fromStrike = 0;
input toStrike = 200;

# Define Variables
def todayDate = GetYYYYMMDD();
def fromStrikePrice = fromStrike;
def toStrikePrice = toStrike;

# Calculate Gamma Exposure
def calcGammaEx(S, K, vol, T, r, q, optType, OI) {
if (T == 0 || vol == 0) {
return 0;
}

def dp = (Log(S / K) + (r - q + 0.5 * vol ** 2) * T) / (vol * Sqrt(T));
def dm = dp - vol * Sqrt(T);

def gamma;
if (optType == 'call') {
gamma = Exp(-q * T) * normdist(dp, 0, 1) / (S * vol * Sqrt(T));
} else {
gamma = K *...
I was attempting to get that to chart for SPX and any other ticker symbol (XOM for instance) but I can not seem to get it to work.

Code:
# Gamma Exposure Profile Indicator for ThinkOrSwim (XOM)

# Define Inputs
input fromStrike = 0;
input toStrike = 200;

# Define Variables
def todayDate = GetYYYYMMDD();
def fromStrikePrice = fromStrike;
def toStrikePrice = toStrike;

# Calculate Gamma Exposure
def calcGammaEx(S, K, vol, T, r, q, optType, OI) {
    if (T == 0 || vol == 0) {
        return 0;
}

    def dp = (Log(S / K) + (r - q + 0.5 * vol ** 2) * T) / (vol * Sqrt(T));
def dm = dp - vol * Sqrt(T);

def gamma;
if (optType == 'call') {
        gamma = Exp(-q * T) * normdist(dp, 0, 1) / (S * vol * Sqrt(T));
} else {
        gamma = K * Exp(-r * T) * normdist(dm, 0, 1) / (S * S * vol * Sqrt(T));
}

    return OI * 100 * S * S * 0.01 * gamma;
}

# Chart: Gamma Exposure Profile for XOM
def levels = CompoundValue(1, close, 0);
def totalGamma = 0;
def totalGammaExNext = 0;
def totalGammaExFri = 0;

# Loop through strike levels
for level in levels {
    # Calculate gamma exposure at each strike level
    def callGammaEx = calcGammaEx(level, GetStrike(), GetVolatility(), GetDTE(), 0, 0, "call", GetOpenInterest());
    def putGammaEx = calcGammaEx(level, GetStrike(), GetVolatility(), GetDTE(), 0, 0, "put", GetOpenInterest());

    # Aggregate gamma exposure
    totalGamma += callGammaEx - putGammaEx;

    # Excluding next expiry
    if (GetExpDate() != GetNextExpDate()) {
        totalGammaExNext += callGammaEx - putGammaEx;
    }

    # Excluding next monthly expiry
    if (!IsMonthlyExp()) {
        totalGammaExFri += callGammaEx - putGammaEx;
    }
}

# Find Gamma Flip Point
def zeroCrossIdx = fold i = 1 to TotalItems(levels) with zeroCross = 0 do if Sign(totalGamma[I]) != Sign(totalGamma[i - 1]) then i else zeroCross;
def negGamma = totalGamma[zeroCrossIdx];
def posGamma = totalGamma[zeroCrossIdx + 1];
def negStrike = levels[zeroCrossIdx];
def posStrike = levels[zeroCrossIdx + 1];
def zeroGamma = posStrike - ((posStrike - negStrike) * posGamma / (posGamma - negGamma));

# Plot
plot ChartGamma = totalGamma / 1000000;  # Gamma Exposure in millions for XOM
ChartGamma.SetPaintingStrategy(PaintingStrategy.LINE);
ChartGamma.SetLineWeight(2);
ChartGamma.SetDefaultColor(Color.CYAN);
AddVerticalLine(close, "XOM Spot", Color.RED);

# End of Script[/I]
 
Last edited by a moderator:

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

I was attempting to get that to chart for SPX and any other ticker symbol (XOM for instance) but I can not seem to get it to work.
# Gamma Exposure Profile Indicator for ThinkOrSwim (XOM)

# Define Inputs
input fromStrike = 0;
input toStrike = 200;

# Define Variables
def todayDate = GetYYYYMMDD();
def fromStrikePrice = fromStrike;
def toStrikePrice = toStrike;

# Calculate Gamma Exposure
def calcGammaEx(S, K, vol, T, r, q, optType, OI) {
if (T == 0 || vol == 0) {
return 0;
}

def dp = (Log(S / K) + (r - q + 0.5 * vol ** 2) * T) / (vol * Sqrt(T));
def dm = dp - vol * Sqrt(T);

def gamma;
if (optType == 'call') {
gamma = Exp(-q * T) * normdist(dp, 0, 1) / (S * vol * Sqrt(T));
} else {
gamma = K * Exp(-r * T) * normdist(dm, 0, 1) / (S * S * vol * Sqrt(T));
}

return OI * 100 * S * S * 0.01 * gamma;
}

# Chart: Gamma Exposure Profile for XOM
def levels = CompoundValue(1, close, 0);
def totalGamma = 0;
def totalGammaExNext = 0;
def totalGammaExFri = 0;

# Loop through strike levels
for level in levels {
# Calculate gamma exposure at each strike level
def callGammaEx = calcGammaEx(level, GetStrike(), GetVolatility(), GetDTE(), 0, 0, "call", GetOpenInterest());
def putGammaEx = calcGammaEx(level, GetStrike(), GetVolatility(), GetDTE(), 0, 0, "put", GetOpenInterest());

# Aggregate gamma exposure
totalGamma += callGammaEx - putGammaEx;

# Excluding next expiry
if (GetExpDate() != GetNextExpDate()) {
totalGammaExNext += callGammaEx - putGammaEx;
}

# Excluding next monthly expiry
if (!IsMonthlyExp()) {
totalGammaExFri += callGammaEx - putGammaEx;
}
}

# Find Gamma Flip Point
def zeroCrossIdx = fold i = 1 to TotalItems(levels) with zeroCross = 0 do if Sign(totalGamma) != Sign(totalGamma[i - 1]) then i else zeroCross;
def negGamma = totalGamma[zeroCrossIdx];
def posGamma = totalGamma[zeroCrossIdx + 1];
def negStrike = levels[zeroCrossIdx];
def posStrike = levels[zeroCrossIdx + 1];
def zeroGamma = posStrike - ((posStrike - negStrike) * posGamma / (posGamma - negGamma));

# Plot
plot ChartGamma = totalGamma / 1000000; # Gamma Exposure in millions for XOM
ChartGamma.SetPaintingStrategy(PaintingStrategy.LINE);
ChartGamma.SetLineWeight(2);
ChartGamma.SetDefaultColor(Color.CYAN);
AddVerticalLine(close, "XOM Spot", Color.RED);

# End of Script
I'm using this and work perfect

Ruby:
# GEX Horizontal Axis V2B Jan 17, 2023
# Twitter @2187Nick

# 1-18-24 @brooklyngfellaz Added expiration date label, Base strike label (changes color, above base strike uptick, below downtick), a current price label just to be able to get a quick view of current price and lastly changed the color of base strike so it would stand out.


declare lower;
declare once_per_bar;

def day = 0;

input symbol = "SPY";
input strikeSpacing = 1.0;
input strikes = 10;
input shift_left = 1;
input spacing = 1;
input threshold = 20;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
then BarNumber()
else lastbar[1];

input ManuallySetExpiration = {default "false", "true"};
input Expiration_YYMMDD = 240117;
def DateString_auto = GetYYYYMMDD() - 20000000;
def DateString = if ManuallySetExpiration then Expiration_YYMMDD else DateString_auto;

def agg = AggregationPeriod.Day;
def seconds_left = SecondsTillTime(1615);
def hours_left = seconds_left / 3600;
def days_left = if hours_left <= 0 then 0 else hours_left / 24;

def Vol = imp_volatility(getSymbol());
#addlabel(yes, "Vol: " + Vol, color.white);
def S = close();
#def S = close(period = agg);
#addlabel(yes, "S_close: " + S, color.white);

def t = ((DateString - DateString_auto) + days_left) / 365;
#addlabel(yes, "t: " + t);
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);
def Sqrt_2pi = 2.5066;
def Vol_Sqrt_t_S = S * Vol_Sqrt_t;

DefineGlobalColor("CallColor", Color.GREEN);
DefineGlobalColor("PutColor", Color.downtick);
#AddLabel(yes, "Expiration: " + AsPrice(DateString) , color.uptick);
AddLabel(yes, "Gamma Exposure (GEX): " + AsPrice(DateString), color.cyan);
#AddLabel(yes, "GEX", color.uptick);
#AddLabel(yes, AsPrice(DateString) + "C", GlobalColor("CallColor"));
#AddLabel(yes, AsPrice(DateString) + "P", GlobalColor("PutColor"));

# Open Price
def todayOpen = open(symbol = getSymbol(), period = "DAY");
def yesterdayOpen = open(symbol = getSymbol(), period = "DAY")[1];
def lastPrice = if !IsNaN(close(symbol = getSymbol()))
then close(symbol = getSymbol())
else close(symbol = getSymbol(), period = "DAY", PriceType.LAST);
def openPrice = if !IsNaN(todayOpen) then todayOpen
else if !IsNaN(yesterdayOpen) then yesterdayOpen
else lastPrice;

#def openlevel = open(period = agg);
#addlabel(yes, "open: " + openPrice, color.uptick);
def rounding_factor = if strikeSpacing > 1 and strikeSpacing < 25 then -1 else if strikeSpacing > 24 then -2 else 0;
def floor_or_ceiling = Round(openPrice, rounding_factor);
def base_strike = floor_or_ceiling;
#addlabel(yes, "centerStrike: " + base_strike);

#AddLabel(yes, "Base Strike: " + AsPrice(base_strike), if close > base_strike then Color.uptick else Color.downtick);

def SPY = Close ("SPY");

#AddLabel(Yes, "Current Price: " + AsPrice(close), if close > base_strike then Color.uptick else Color.downtick);

#def closeplot = if !IsNaN(close) and IsNaN(close[-1]) then close else closeplot[1];



Script GEX {
input strike = 0;
input dateString = 0;
input Vol = 0;
input t = 0;
input S = 0;
input todayoryday = 0;
input Sqr_Vol_2 = 0;
input Vol_Sqrt_t = 0;
input Vol_Sqrt_t_S = 0;
def gamma = (Exp(-.5*(Sqr((Log(S / strike) + Sqr_Vol_2) / Vol_Sqrt_t) )) /2.5066) / Vol_Sqrt_t_S;

plot strikeGEX = if IsNaN((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma)
then 0 else Round((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma*S/10000,0);
}



def strike_base = base_strike;
def strike_plus1 = base_strike + strikeSpacing;
def strike_plus2 = base_strike + strikeSpacing * 2;
def strike_plus3 = base_strike + strikeSpacing * 3;
def strike_plus4 = base_strike + strikeSpacing * 4;
def strike_plus5 = base_strike + strikeSpacing * 5;
def strike_plus6 = base_strike + strikeSpacing * 6;
def strike_plus7 = base_strike + strikeSpacing * 7;
def strike_plus8 = base_strike + strikeSpacing * 8;
def strike_plus9 = base_strike + strikeSpacing * 9;
def strike_plus10 = base_strike + strikeSpacing * 10;

def strike_minus1 = base_strike - strikeSpacing;
def strike_minus2 = base_strike - strikeSpacing * 2;
def strike_minus3 = base_strike - strikeSpacing * 3;
def strike_minus4 = base_strike - strikeSpacing * 4;
def strike_minus5 = base_strike - strikeSpacing * 5;
def strike_minus6 = base_strike - strikeSpacing * 6;
def strike_minus7 = base_strike - strikeSpacing * 7;
def strike_minus8 = base_strike - strikeSpacing * 8;
def strike_minus9 = base_strike - strikeSpacing * 9;
def strike_minus10 = base_strike - strikeSpacing * 10;

### GEX
def strike_base_gex = GEX(strike_base, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
#addlabel(yes, "strike_base_gex : " + strike_base_gex , color.yellow);
def strike_plus1_gex = GEX(strike_plus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus2_gex = GEX(strike_plus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus3_gex = GEX(strike_plus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus4_gex = GEX(strike_plus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus5_gex = GEX(strike_plus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus6_gex = GEX(strike_plus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus7_gex = GEX(strike_plus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus8_gex = GEX(strike_plus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus9_gex = GEX(strike_plus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus10_gex = GEX(strike_plus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

def strike_minus1_gex = GEX(strike_minus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus2_gex = GEX(strike_minus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus3_gex = GEX(strike_minus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus4_gex = GEX(strike_minus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus5_gex = GEX(strike_minus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus6_gex = GEX(strike_minus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus7_gex = GEX(strike_minus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus8_gex = GEX(strike_minus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus9_gex = GEX(strike_minus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus10_gex = GEX(strike_minus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

plot base = if BarNumber() == HighestAll(lastbar - (shift_left*10)) then strike_base_gex[shift_left*-10] else Double.Nan;
base.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base.setLineWeight(5);
base.AssignValueColor(if strike_base_gex[shift_left*-10] > 0 then (Createcolor(240,230,107)) else (Createcolor(240,230,107)));
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, 0, base_strike, (Createcolor(240,230,107)), if strike_base_gex[shift_left*-10] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, strike_base_gex[shift_left*-10], strike_base_gex[shift_left*-10], if strike_base_gex[shift_left*-10] > 0 then(Createcolor(240,230,107)) else (Createcolor(240,230,107)), if strike_base_gex > 0 then yes else no);


plot base_plus1 = if BarNumber() == HighestAll(lastbar - (shift_left*9)) then strike_plus1_gex[shift_left*-9] else Double.Nan;
base_plus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus1.setLineWeight(5);
base_plus1.AssignValueColor(if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*9)) and AbsValue(strike_plus1_gex[shift_left*-9]) > threshold then yes else no, strike_plus1_gex[shift_left*-9], strike_plus1_gex[shift_left*-9], if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick, if strike_plus1_gex[shift_left*-9] > 0 then yes else no);

plot base_plus2 = if BarNumber() == HighestAll(lastbar - (shift_left*8)) then strike_plus2_gex[shift_left*-8] else Double.Nan;
base_plus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus2.setLineWeight(5);
base_plus2.AssignValueColor(if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar- (shift_left*8)) and AbsValue(strike_plus2_gex[shift_left*-8]) > threshold then yes else no, strike_plus2_gex[shift_left*-8], strike_plus2_gex[shift_left*-8], if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick, if strike_plus2_gex[shift_left*-8] > 0 then yes else no);


# For Testing
# time condition(barNumber == barNumber - 8)
#AddChartBubble(time condition, price location, text in bubble, color, up)
#AddChartBubble(yes, BarNumber(), strike_plus2_gex[-8], color.white);
#addlabel(yes, "strike_plus2_gex: " + strike_plus2_gex);


plot base_plus3 = if BarNumber() == HighestAll(lastbar - (shift_left*7)) then strike_plus3_gex[shift_left*-7] else Double.Nan;
base_plus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus3.setLineWeight(5);
base_plus3.AssignValueColor(if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*7)) and AbsValue(strike_plus3_gex[shift_left*-7]) > threshold then yes else no, strike_plus3_gex[shift_left*-7], strike_plus3_gex[shift_left*-7], if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick, if strike_plus3_gex[shift_left*-7] > 0 then yes else no);

plot base_plus4 = if BarNumber() == HighestAll(lastbar - (shift_left*6)) then strike_plus4_gex[shift_left*-6] else Double.Nan;
base_plus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus4.setLineWeight(5);
base_plus4.AssignValueColor(if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*6)) and AbsValue(strike_plus4_gex[shift_left*-6]) > threshold then yes else no, strike_plus4_gex[shift_left*-6], strike_plus4_gex[shift_left*-6], if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick, if strike_plus4_gex[shift_left*-6] > 0 then yes else no);

plot base_plus5 = if BarNumber() == HighestAll(lastbar - (shift_left*5)) then strike_plus5_gex[shift_left*-5] else Double.Nan;
base_plus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus5.setLineWeight(5);
base_plus5.AssignValueColor(if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) then yes else no, 0, strike_plus5, color.gray, if strike_plus5_gex[shift_left*-5] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) and AbsValue(strike_plus5_gex[shift_left*-5]) > threshold then yes else no, strike_plus5_gex[shift_left*-5], strike_plus5_gex[shift_left*-5], if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick, if strike_plus5_gex[shift_left*-5] > 0 then yes else no);



plot base_plus6 = if BarNumber() == HighestAll(lastbar - (shift_left*4)) then strike_plus6_gex[shift_left*-4] else Double.Nan;
base_plus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus6.setLineWeight(5);
base_plus6.AssignValueColor(if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*4)) and AbsValue(strike_plus6_gex[shift_left*-4]) > threshold then yes else no, strike_plus6_gex[shift_left*-4], strike_plus6_gex[shift_left*-4], if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick, if strike_plus6_gex[shift_left*-4] > 0 then yes else no);

plot base_plus7 = if BarNumber() == HighestAll(lastbar - (shift_left*3)) then strike_plus7_gex[shift_left*-3] else Double.Nan;
base_plus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus7.setLineWeight(5);
base_plus7.AssignValueColor(if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*3)) and AbsValue(strike_plus7_gex[shift_left*-3]) > threshold then yes else no, strike_plus7_gex[shift_left*-3], strike_plus7_gex[shift_left*-3], if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick, if strike_plus7_gex[shift_left*-3] > 0 then yes else no);


plot base_plus8 = if BarNumber() == HighestAll(lastbar - (shift_left*2)) then strike_plus8_gex[shift_left*-2] else Double.Nan;
base_plus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus8.setLineWeight(5);
base_plus8.AssignValueColor(if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*2)) and AbsValue(strike_plus8_gex[shift_left*-2]) > threshold then yes else no, strike_plus8_gex[shift_left*-2], strike_plus8_gex[shift_left*-2], if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick, if strike_plus8_gex[shift_left*-2] > 0 then yes else no);
plot base_plus9 = if BarNumber() == HighestAll(lastbar - (shift_left)) then strike_plus9_gex[shift_left*-1] else Double.Nan;
base_plus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus9.setLineWeight(5);
base_plus9.AssignValueColor(if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left)) and AbsValue(strike_plus9_gex[shift_left*-1]) > threshold then yes else no, strike_plus9_gex[shift_left*-1], strike_plus9_gex[shift_left*-1], if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick, if strike_plus9_gex[shift_left*-1] > 0 then yes else no);

plot base_plus10 = if BarNumber() == HighestAll(lastbar - (shift_left-1)) then strike_plus10_gex[shift_left-1] else Double.Nan;
base_plus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus10.setLineWeight(5);
base_plus10.AssignValueColor(if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) and AbsValue(strike_plus10_gex[shift_left-1]) > threshold then yes else no, strike_plus10_gex[shift_left-1], strike_plus10_gex[shift_left-1], if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick, if strike_plus10_gex[shift_left-1] > 0 then yes else no);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) then yes else no, 0, strike_plus10, color.gray, if strike_plus10_gex[shift_left-1] > 0 then no else yes);


plot base_minus1 = if BarNumber() == HighestAll(lastbar - (shift_left*11)) then strike_minus1_gex[shift_left*-11] else Double.Nan;
base_minus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus1.setLineWeight(5);
base_minus1.AssignValueColor(if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*11)) and AbsValue(strike_minus1_gex[shift_left*-11]) > threshold then yes else no, strike_minus1_gex[shift_left*-11], strike_minus1_gex[shift_left*-11], if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick, if strike_minus1_gex[shift_left*-11] > 0 then yes else no);

plot base_minus2 = if BarNumber() == HighestAll(lastbar - (shift_left*12)) then strike_minus2_gex[shift_left*-12] else Double.Nan;
base_minus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus2.setLineWeight(5);
base_minus2.AssignValueColor(if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*12)) and AbsValue(strike_minus2_gex[shift_left*-12]) > threshold then yes else no, strike_minus2_gex[shift_left*-12], strike_minus2_gex[shift_left*-12], if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick, if strike_minus2_gex[shift_left*-12] > 0 then yes else no);

plot base_minus3 = if BarNumber() == HighestAll(lastbar - (shift_left*13)) then strike_minus3_gex[shift_left*-13] else Double.Nan;
base_minus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus3.setLineWeight(5);
base_minus3.AssignValueColor(if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*13)) and AbsValue(strike_minus3_gex[shift_left*-13]) > threshold then yes else no, strike_minus3_gex[shift_left*-13], strike_minus3_gex[shift_left*-13], if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick, if strike_minus3_gex[shift_left*-13] > 0 then yes else no);

plot base_minus4 = if BarNumber() == HighestAll(lastbar - (shift_left*14)) then strike_minus4_gex[shift_left*-14] else Double.Nan;
base_minus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus4.setLineWeight(5);
base_minus4.AssignValueColor(if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*14)) and AbsValue(strike_minus4_gex[shift_left*-14]) > threshold then yes else no, strike_minus4_gex[shift_left*-14], strike_minus4_gex[shift_left*-14], if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick, if strike_minus4_gex[shift_left*-14] > 0 then yes else no);


plot base_minus5 = if BarNumber() >= HighestAll(lastbar - (shift_left*15)) and BarNumber() <= HighestAll(lastbar - (shift_left*15)) then strike_minus5_gex[shift_left*-15] else Double.Nan;
base_minus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus5.setLineWeight(5);
base_minus5.AssignValueColor(if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) then yes else no, 0, strike_minus5, color.gray, if strike_minus5_gex[shift_left*-15] > 0 then no else yes);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) and AbsValue(strike_minus5_gex[shift_left*-15]) > threshold then yes else no, strike_minus5_gex[shift_left*-15], strike_minus5_gex[shift_left*-15], if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick, if strike_minus5_gex[shift_left*-15] > 0 then yes else no);

plot base_minus6 = if BarNumber() == HighestAll(lastbar - (shift_left*16)) then strike_minus6_gex[shift_left*-16] else Double.Nan;
base_minus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus6.setLineWeight(5);
base_minus6.AssignValueColor(if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*16)) and AbsValue(strike_minus6_gex[shift_left*-16]) > threshold then yes else no, strike_minus6_gex[shift_left*-16], strike_minus6_gex[shift_left*-16], if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick, if strike_minus6_gex[shift_left*-16] > 0 then yes else no);


plot base_minus7 = if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17)) then strike_minus7_gex[shift_left*-17] else Double.Nan;
base_minus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus7.setLineWeight(5);
base_minus7.AssignValueColor(if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17))and AbsValue(strike_minus7_gex[shift_left*-17]) > threshold then yes else no, strike_minus7_gex[shift_left*-17], strike_minus7_gex[shift_left*-17], if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick, if strike_minus7_gex[shift_left*-17] > 0 then yes else no);

plot base_minus8 = if BarNumber() == HighestAll(lastbar - (shift_left*18)) then strike_minus8_gex[shift_left*-18] else Double.Nan;
base_minus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus8.setLineWeight(5);
base_minus8.AssignValueColor(if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*18)) and BarNumber() <= HighestAll(lastbar - (shift_left*18))and AbsValue(strike_minus8_gex[shift_left*-18]) > threshold then yes else no, strike_minus8_gex[shift_left*-18], strike_minus8_gex[shift_left*-18], if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick, if strike_minus8_gex[shift_left*-18] > 0 then yes else no);

plot base_minus9 = if BarNumber() == HighestAll(lastbar - (shift_left*19)) then strike_minus9_gex[shift_left*-19] else Double.Nan;
base_minus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus9.setLineWeight(5);
base_minus9.AssignValueColor(if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*19)) and AbsValue(strike_minus9_gex[shift_left*-19]) > threshold then yes else no, strike_minus9_gex[shift_left*-19], strike_minus9_gex[shift_left*-19], if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick, if strike_minus9_gex[shift_left*-19] > 0 then yes else no);


plot base_minus10 = if BarNumber() == HighestAll(lastbar - (shift_left*20)) then strike_minus10_gex[shift_left*-20] else Double.Nan;
base_minus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus10.setLineWeight(5);
base_minus10.AssignValueColor(if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*20)) and AbsValue(strike_minus10_gex[shift_left*-20]) > threshold then yes else no, strike_minus10_gex[shift_left*-20], strike_minus10_gex[shift_left*-20], if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick, if strike_minus10_gex[shift_left*-20] > 0 then yes else no);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*20)) and BarNumber() <= HighestAll(lastbar - (shift_left*20)) then yes else no, 0, strike_minus10, color.gray, if strike_minus10 > 0 then yes else no);

#######
plot zeroline = 0;
zeroline.SetDEfaultColor(color.dark_gray);

def base_gex_net = if IsNan(strike_base_gex) then 0 else if AbsValue(strike_base_gex) > threshold then strike_base_gex else 0;
def plus1_gex_net = if IsNan(strike_plus1_gex) then 0 else if AbsValue(strike_plus1_gex) > threshold then strike_plus1_gex else 0;
def plus2_gex_net = if IsNan(strike_plus2_gex) then 0 else if AbsValue(strike_plus2_gex) > threshold then strike_plus2_gex else 0;
def plus3_gex_net = if IsNan(strike_plus3_gex) then 0 else if AbsValue(strike_plus3_gex) > threshold then strike_plus3_gex else 0;
def plus4_gex_net = if IsNan(strike_plus4_gex) then 0 else if AbsValue(strike_plus4_gex) > threshold then strike_plus4_gex else 0;
def plus5_gex_net = if IsNan(strike_plus5_gex) then 0 else if AbsValue(strike_plus5_gex) > threshold then strike_plus5_gex else 0;
def plus6_gex_net = if IsNan(strike_plus6_gex) then 0 else if AbsValue(strike_plus6_gex) > threshold then strike_plus6_gex else 0;
def plus7_gex_net = if IsNan(strike_plus7_gex) then 0 else if AbsValue(strike_plus7_gex) > threshold then strike_plus7_gex else 0;
def plus8_gex_net = if IsNan(strike_plus8_gex) then 0 else if AbsValue(strike_plus8_gex) > threshold then strike_plus8_gex else 0;
def plus9_gex_net = if IsNan(strike_plus9_gex) then 0 else if AbsValue(strike_plus9_gex) > threshold then strike_plus9_gex else 0;
def plus10_gex_net = if IsNan(strike_plus10_gex) then 0 else if AbsValue(strike_plus10_gex) > threshold then strike_plus10_gex else 0;

def minus1_gex_net = if IsNan(strike_minus1_gex) then 0 else if AbsValue(strike_minus1_gex) > threshold then strike_minus1_gex else 0;
def minus2_gex_net = if IsNan(strike_minus2_gex) then 0 else if AbsValue(strike_minus2_gex) > threshold then strike_minus2_gex else 0;
def minus3_gex_net = if IsNan(strike_minus3_gex) then 0 else if AbsValue(strike_minus3_gex) > threshold then strike_minus3_gex else 0;
def minus4_gex_net = if IsNan(strike_minus4_gex) then 0 else if AbsValue(strike_minus4_gex) > threshold then strike_minus4_gex else 0;
def minus5_gex_net = if IsNan(strike_minus5_gex) then 0 else if AbsValue(strike_minus5_gex) > threshold then strike_minus5_gex else 0;
def minus6_gex_net = if IsNan(strike_minus6_gex) then 0 else if AbsValue(strike_minus6_gex) > threshold then strike_minus6_gex else 0;
def minus7_gex_net = if IsNan(strike_minus7_gex) then 0 else if AbsValue(strike_minus7_gex) > threshold then strike_minus7_gex else 0;
def minus8_gex_net = if IsNan(strike_minus8_gex) then 0 else if AbsValue(strike_minus8_gex) > threshold then strike_minus8_gex else 0;
def minus9_gex_net = if IsNan(strike_minus9_gex) then 0 else if AbsValue(strike_minus9_gex) > threshold then strike_minus9_gex else 0;
def minus10_gex_net = if IsNan(strike_minus10_gex) then 0 else if AbsValue(strike_minus10_gex) > threshold then strike_minus10_gex else 0;

def nettotalGEX_today = base_gex_net + plus1_gex_net + plus2_gex_net + plus3_gex_net + plus4_gex_net + plus5_gex_net + plus6_gex_net + plus7_gex_net + plus8_gex_net + plus9_gex_net + plus10_gex_net + minus1_gex_net + minus2_gex_net + minus3_gex_net + minus4_gex_net + minus5_gex_net + minus6_gex_net + minus7_gex_net + minus8_gex_net + minus9_gex_net + minus10_gex_net;

AddLabel(yes, "Net GEX: " + nettotalGEX_today *100, if nettotalGEX_today > 1 then color.uptick else color.downtick);

Screenshot 2024-06-20 130401.png
 
Last edited by a moderator:
Solution
I'm using this and work perfect

Ruby:
# GEX Horizontal Axis V2B Jan 17, 2023
# Twitter @2187Nick

# 1-18-24 @brooklyngfellaz Added expiration date label, Base strike label (changes color, above base strike uptick, below downtick), a current price label just to be able to get a quick view of current price and lastly changed the color of base strike so it would stand out.


declare lower;
declare once_per_bar;

def day = 0;

input symbol = "SPY";
input strikeSpacing = 1.0;
input strikes = 10;
input shift_left = 1;
input spacing = 1;
input threshold = 20;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
then BarNumber()
else lastbar[1];

input ManuallySetExpiration = {default "false", "true"};
input Expiration_YYMMDD = 240117;
def DateString_auto = GetYYYYMMDD() - 20000000;
def DateString = if ManuallySetExpiration then Expiration_YYMMDD else DateString_auto;

def agg = AggregationPeriod.Day;
def seconds_left = SecondsTillTime(1615);
def hours_left = seconds_left / 3600;
def days_left = if hours_left <= 0 then 0 else hours_left / 24;

def Vol = imp_volatility(getSymbol());
#addlabel(yes, "Vol: " + Vol, color.white);
def S = close();
#def S = close(period = agg);
#addlabel(yes, "S_close: " + S, color.white);

def t = ((DateString - DateString_auto) + days_left) / 365;
#addlabel(yes, "t: " + t);
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);
def Sqrt_2pi = 2.5066;
def Vol_Sqrt_t_S = S * Vol_Sqrt_t;

DefineGlobalColor("CallColor", Color.GREEN);
DefineGlobalColor("PutColor", Color.downtick);
#AddLabel(yes, "Expiration: " + AsPrice(DateString) , color.uptick);
AddLabel(yes, "Gamma Exposure (GEX): " + AsPrice(DateString), color.cyan);
#AddLabel(yes, "GEX", color.uptick);
#AddLabel(yes, AsPrice(DateString) + "C", GlobalColor("CallColor"));
#AddLabel(yes, AsPrice(DateString) + "P", GlobalColor("PutColor"));

# Open Price
def todayOpen = open(symbol = getSymbol(), period = "DAY");
def yesterdayOpen = open(symbol = getSymbol(), period = "DAY")[1];
def lastPrice = if !IsNaN(close(symbol = getSymbol()))
then close(symbol = getSymbol())
else close(symbol = getSymbol(), period = "DAY", PriceType.LAST);
def openPrice = if !IsNaN(todayOpen) then todayOpen
else if !IsNaN(yesterdayOpen) then yesterdayOpen
else lastPrice;

#def openlevel = open(period = agg);
#addlabel(yes, "open: " + openPrice, color.uptick);
def rounding_factor = if strikeSpacing > 1 and strikeSpacing < 25 then -1 else if strikeSpacing > 24 then -2 else 0;
def floor_or_ceiling = Round(openPrice, rounding_factor);
def base_strike = floor_or_ceiling;
#addlabel(yes, "centerStrike: " + base_strike);

#AddLabel(yes, "Base Strike: " + AsPrice(base_strike), if close > base_strike then Color.uptick else Color.downtick);

def SPY = Close ("SPY");

#AddLabel(Yes, "Current Price: " + AsPrice(close), if close > base_strike then Color.uptick else Color.downtick);

#def closeplot = if !IsNaN(close) and IsNaN(close[-1]) then close else closeplot[1];



Script GEX {
input strike = 0;
input dateString = 0;
input Vol = 0;
input t = 0;
input S = 0;
input todayoryday = 0;
input Sqr_Vol_2 = 0;
input Vol_Sqrt_t = 0;
input Vol_Sqrt_t_S = 0;
def gamma = (Exp(-.5*(Sqr((Log(S / strike) + Sqr_Vol_2) / Vol_Sqrt_t) )) /2.5066) / Vol_Sqrt_t_S;

plot strikeGEX = if IsNaN((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma)
then 0 else Round((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma*S/10000,0);
}



def strike_base = base_strike;
def strike_plus1 = base_strike + strikeSpacing;
def strike_plus2 = base_strike + strikeSpacing * 2;
def strike_plus3 = base_strike + strikeSpacing * 3;
def strike_plus4 = base_strike + strikeSpacing * 4;
def strike_plus5 = base_strike + strikeSpacing * 5;
def strike_plus6 = base_strike + strikeSpacing * 6;
def strike_plus7 = base_strike + strikeSpacing * 7;
def strike_plus8 = base_strike + strikeSpacing * 8;
def strike_plus9 = base_strike + strikeSpacing * 9;
def strike_plus10 = base_strike + strikeSpacing * 10;

def strike_minus1 = base_strike - strikeSpacing;
def strike_minus2 = base_strike - strikeSpacing * 2;
def strike_minus3 = base_strike - strikeSpacing * 3;
def strike_minus4 = base_strike - strikeSpacing * 4;
def strike_minus5 = base_strike - strikeSpacing * 5;
def strike_minus6 = base_strike - strikeSpacing * 6;
def strike_minus7 = base_strike - strikeSpacing * 7;
def strike_minus8 = base_strike - strikeSpacing * 8;
def strike_minus9 = base_strike - strikeSpacing * 9;
def strike_minus10 = base_strike - strikeSpacing * 10;

### GEX
def strike_base_gex = GEX(strike_base, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
#addlabel(yes, "strike_base_gex : " + strike_base_gex , color.yellow);
def strike_plus1_gex = GEX(strike_plus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus2_gex = GEX(strike_plus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus3_gex = GEX(strike_plus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus4_gex = GEX(strike_plus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus5_gex = GEX(strike_plus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus6_gex = GEX(strike_plus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus7_gex = GEX(strike_plus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus8_gex = GEX(strike_plus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus9_gex = GEX(strike_plus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus10_gex = GEX(strike_plus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

def strike_minus1_gex = GEX(strike_minus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus2_gex = GEX(strike_minus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus3_gex = GEX(strike_minus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus4_gex = GEX(strike_minus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus5_gex = GEX(strike_minus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus6_gex = GEX(strike_minus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus7_gex = GEX(strike_minus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus8_gex = GEX(strike_minus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus9_gex = GEX(strike_minus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus10_gex = GEX(strike_minus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

plot base = if BarNumber() == HighestAll(lastbar - (shift_left*10)) then strike_base_gex[shift_left*-10] else Double.Nan;
base.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base.setLineWeight(5);
base.AssignValueColor(if strike_base_gex[shift_left*-10] > 0 then (Createcolor(240,230,107)) else (Createcolor(240,230,107)));
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, 0, base_strike, (Createcolor(240,230,107)), if strike_base_gex[shift_left*-10] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, strike_base_gex[shift_left*-10], strike_base_gex[shift_left*-10], if strike_base_gex[shift_left*-10] > 0 then(Createcolor(240,230,107)) else (Createcolor(240,230,107)), if strike_base_gex > 0 then yes else no);


plot base_plus1 = if BarNumber() == HighestAll(lastbar - (shift_left*9)) then strike_plus1_gex[shift_left*-9] else Double.Nan;
base_plus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus1.setLineWeight(5);
base_plus1.AssignValueColor(if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*9)) and AbsValue(strike_plus1_gex[shift_left*-9]) > threshold then yes else no, strike_plus1_gex[shift_left*-9], strike_plus1_gex[shift_left*-9], if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick, if strike_plus1_gex[shift_left*-9] > 0 then yes else no);

plot base_plus2 = if BarNumber() == HighestAll(lastbar - (shift_left*8)) then strike_plus2_gex[shift_left*-8] else Double.Nan;
base_plus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus2.setLineWeight(5);
base_plus2.AssignValueColor(if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar- (shift_left*8)) and AbsValue(strike_plus2_gex[shift_left*-8]) > threshold then yes else no, strike_plus2_gex[shift_left*-8], strike_plus2_gex[shift_left*-8], if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick, if strike_plus2_gex[shift_left*-8] > 0 then yes else no);


# For Testing
# time condition(barNumber == barNumber - 8)
#AddChartBubble(time condition, price location, text in bubble, color, up)
#AddChartBubble(yes, BarNumber(), strike_plus2_gex[-8], color.white);
#addlabel(yes, "strike_plus2_gex: " + strike_plus2_gex);


plot base_plus3 = if BarNumber() == HighestAll(lastbar - (shift_left*7)) then strike_plus3_gex[shift_left*-7] else Double.Nan;
base_plus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus3.setLineWeight(5);
base_plus3.AssignValueColor(if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*7)) and AbsValue(strike_plus3_gex[shift_left*-7]) > threshold then yes else no, strike_plus3_gex[shift_left*-7], strike_plus3_gex[shift_left*-7], if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick, if strike_plus3_gex[shift_left*-7] > 0 then yes else no);

plot base_plus4 = if BarNumber() == HighestAll(lastbar - (shift_left*6)) then strike_plus4_gex[shift_left*-6] else Double.Nan;
base_plus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus4.setLineWeight(5);
base_plus4.AssignValueColor(if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*6)) and AbsValue(strike_plus4_gex[shift_left*-6]) > threshold then yes else no, strike_plus4_gex[shift_left*-6], strike_plus4_gex[shift_left*-6], if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick, if strike_plus4_gex[shift_left*-6] > 0 then yes else no);

plot base_plus5 = if BarNumber() == HighestAll(lastbar - (shift_left*5)) then strike_plus5_gex[shift_left*-5] else Double.Nan;
base_plus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus5.setLineWeight(5);
base_plus5.AssignValueColor(if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) then yes else no, 0, strike_plus5, color.gray, if strike_plus5_gex[shift_left*-5] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) and AbsValue(strike_plus5_gex[shift_left*-5]) > threshold then yes else no, strike_plus5_gex[shift_left*-5], strike_plus5_gex[shift_left*-5], if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick, if strike_plus5_gex[shift_left*-5] > 0 then yes else no);



plot base_plus6 = if BarNumber() == HighestAll(lastbar - (shift_left*4)) then strike_plus6_gex[shift_left*-4] else Double.Nan;
base_plus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus6.setLineWeight(5);
base_plus6.AssignValueColor(if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*4)) and AbsValue(strike_plus6_gex[shift_left*-4]) > threshold then yes else no, strike_plus6_gex[shift_left*-4], strike_plus6_gex[shift_left*-4], if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick, if strike_plus6_gex[shift_left*-4] > 0 then yes else no);

plot base_plus7 = if BarNumber() == HighestAll(lastbar - (shift_left*3)) then strike_plus7_gex[shift_left*-3] else Double.Nan;
base_plus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus7.setLineWeight(5);
base_plus7.AssignValueColor(if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*3)) and AbsValue(strike_plus7_gex[shift_left*-3]) > threshold then yes else no, strike_plus7_gex[shift_left*-3], strike_plus7_gex[shift_left*-3], if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick, if strike_plus7_gex[shift_left*-3] > 0 then yes else no);


plot base_plus8 = if BarNumber() == HighestAll(lastbar - (shift_left*2)) then strike_plus8_gex[shift_left*-2] else Double.Nan;
base_plus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus8.setLineWeight(5);
base_plus8.AssignValueColor(if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*2)) and AbsValue(strike_plus8_gex[shift_left*-2]) > threshold then yes else no, strike_plus8_gex[shift_left*-2], strike_plus8_gex[shift_left*-2], if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick, if strike_plus8_gex[shift_left*-2] > 0 then yes else no);
plot base_plus9 = if BarNumber() == HighestAll(lastbar - (shift_left)) then strike_plus9_gex[shift_left*-1] else Double.Nan;
base_plus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus9.setLineWeight(5);
base_plus9.AssignValueColor(if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left)) and AbsValue(strike_plus9_gex[shift_left*-1]) > threshold then yes else no, strike_plus9_gex[shift_left*-1], strike_plus9_gex[shift_left*-1], if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick, if strike_plus9_gex[shift_left*-1] > 0 then yes else no);

plot base_plus10 = if BarNumber() == HighestAll(lastbar - (shift_left-1)) then strike_plus10_gex[shift_left-1] else Double.Nan;
base_plus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus10.setLineWeight(5);
base_plus10.AssignValueColor(if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) and AbsValue(strike_plus10_gex[shift_left-1]) > threshold then yes else no, strike_plus10_gex[shift_left-1], strike_plus10_gex[shift_left-1], if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick, if strike_plus10_gex[shift_left-1] > 0 then yes else no);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) then yes else no, 0, strike_plus10, color.gray, if strike_plus10_gex[shift_left-1] > 0 then no else yes);


plot base_minus1 = if BarNumber() == HighestAll(lastbar - (shift_left*11)) then strike_minus1_gex[shift_left*-11] else Double.Nan;
base_minus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus1.setLineWeight(5);
base_minus1.AssignValueColor(if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*11)) and AbsValue(strike_minus1_gex[shift_left*-11]) > threshold then yes else no, strike_minus1_gex[shift_left*-11], strike_minus1_gex[shift_left*-11], if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick, if strike_minus1_gex[shift_left*-11] > 0 then yes else no);

plot base_minus2 = if BarNumber() == HighestAll(lastbar - (shift_left*12)) then strike_minus2_gex[shift_left*-12] else Double.Nan;
base_minus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus2.setLineWeight(5);
base_minus2.AssignValueColor(if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*12)) and AbsValue(strike_minus2_gex[shift_left*-12]) > threshold then yes else no, strike_minus2_gex[shift_left*-12], strike_minus2_gex[shift_left*-12], if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick, if strike_minus2_gex[shift_left*-12] > 0 then yes else no);

plot base_minus3 = if BarNumber() == HighestAll(lastbar - (shift_left*13)) then strike_minus3_gex[shift_left*-13] else Double.Nan;
base_minus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus3.setLineWeight(5);
base_minus3.AssignValueColor(if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*13)) and AbsValue(strike_minus3_gex[shift_left*-13]) > threshold then yes else no, strike_minus3_gex[shift_left*-13], strike_minus3_gex[shift_left*-13], if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick, if strike_minus3_gex[shift_left*-13] > 0 then yes else no);

plot base_minus4 = if BarNumber() == HighestAll(lastbar - (shift_left*14)) then strike_minus4_gex[shift_left*-14] else Double.Nan;
base_minus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus4.setLineWeight(5);
base_minus4.AssignValueColor(if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*14)) and AbsValue(strike_minus4_gex[shift_left*-14]) > threshold then yes else no, strike_minus4_gex[shift_left*-14], strike_minus4_gex[shift_left*-14], if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick, if strike_minus4_gex[shift_left*-14] > 0 then yes else no);


plot base_minus5 = if BarNumber() >= HighestAll(lastbar - (shift_left*15)) and BarNumber() <= HighestAll(lastbar - (shift_left*15)) then strike_minus5_gex[shift_left*-15] else Double.Nan;
base_minus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus5.setLineWeight(5);
base_minus5.AssignValueColor(if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) then yes else no, 0, strike_minus5, color.gray, if strike_minus5_gex[shift_left*-15] > 0 then no else yes);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) and AbsValue(strike_minus5_gex[shift_left*-15]) > threshold then yes else no, strike_minus5_gex[shift_left*-15], strike_minus5_gex[shift_left*-15], if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick, if strike_minus5_gex[shift_left*-15] > 0 then yes else no);

plot base_minus6 = if BarNumber() == HighestAll(lastbar - (shift_left*16)) then strike_minus6_gex[shift_left*-16] else Double.Nan;
base_minus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus6.setLineWeight(5);
base_minus6.AssignValueColor(if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*16)) and AbsValue(strike_minus6_gex[shift_left*-16]) > threshold then yes else no, strike_minus6_gex[shift_left*-16], strike_minus6_gex[shift_left*-16], if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick, if strike_minus6_gex[shift_left*-16] > 0 then yes else no);


plot base_minus7 = if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17)) then strike_minus7_gex[shift_left*-17] else Double.Nan;
base_minus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus7.setLineWeight(5);
base_minus7.AssignValueColor(if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17))and AbsValue(strike_minus7_gex[shift_left*-17]) > threshold then yes else no, strike_minus7_gex[shift_left*-17], strike_minus7_gex[shift_left*-17], if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick, if strike_minus7_gex[shift_left*-17] > 0 then yes else no);

plot base_minus8 = if BarNumber() == HighestAll(lastbar - (shift_left*18)) then strike_minus8_gex[shift_left*-18] else Double.Nan;
base_minus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus8.setLineWeight(5);
base_minus8.AssignValueColor(if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*18)) and BarNumber() <= HighestAll(lastbar - (shift_left*18))and AbsValue(strike_minus8_gex[shift_left*-18]) > threshold then yes else no, strike_minus8_gex[shift_left*-18], strike_minus8_gex[shift_left*-18], if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick, if strike_minus8_gex[shift_left*-18] > 0 then yes else no);

plot base_minus9 = if BarNumber() == HighestAll(lastbar - (shift_left*19)) then strike_minus9_gex[shift_left*-19] else Double.Nan;
base_minus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus9.setLineWeight(5);
base_minus9.AssignValueColor(if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*19)) and AbsValue(strike_minus9_gex[shift_left*-19]) > threshold then yes else no, strike_minus9_gex[shift_left*-19], strike_minus9_gex[shift_left*-19], if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick, if strike_minus9_gex[shift_left*-19] > 0 then yes else no);


plot base_minus10 = if BarNumber() == HighestAll(lastbar - (shift_left*20)) then strike_minus10_gex[shift_left*-20] else Double.Nan;
base_minus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus10.setLineWeight(5);
base_minus10.AssignValueColor(if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*20)) and AbsValue(strike_minus10_gex[shift_left*-20]) > threshold then yes else no, strike_minus10_gex[shift_left*-20], strike_minus10_gex[shift_left*-20], if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick, if strike_minus10_gex[shift_left*-20] > 0 then yes else no);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*20)) and BarNumber() <= HighestAll(lastbar - (shift_left*20)) then yes else no, 0, strike_minus10, color.gray, if strike_minus10 > 0 then yes else no);

#######
plot zeroline = 0;
zeroline.SetDEfaultColor(color.dark_gray);

def base_gex_net = if IsNan(strike_base_gex) then 0 else if AbsValue(strike_base_gex) > threshold then strike_base_gex else 0;
def plus1_gex_net = if IsNan(strike_plus1_gex) then 0 else if AbsValue(strike_plus1_gex) > threshold then strike_plus1_gex else 0;
def plus2_gex_net = if IsNan(strike_plus2_gex) then 0 else if AbsValue(strike_plus2_gex) > threshold then strike_plus2_gex else 0;
def plus3_gex_net = if IsNan(strike_plus3_gex) then 0 else if AbsValue(strike_plus3_gex) > threshold then strike_plus3_gex else 0;
def plus4_gex_net = if IsNan(strike_plus4_gex) then 0 else if AbsValue(strike_plus4_gex) > threshold then strike_plus4_gex else 0;
def plus5_gex_net = if IsNan(strike_plus5_gex) then 0 else if AbsValue(strike_plus5_gex) > threshold then strike_plus5_gex else 0;
def plus6_gex_net = if IsNan(strike_plus6_gex) then 0 else if AbsValue(strike_plus6_gex) > threshold then strike_plus6_gex else 0;
def plus7_gex_net = if IsNan(strike_plus7_gex) then 0 else if AbsValue(strike_plus7_gex) > threshold then strike_plus7_gex else 0;
def plus8_gex_net = if IsNan(strike_plus8_gex) then 0 else if AbsValue(strike_plus8_gex) > threshold then strike_plus8_gex else 0;
def plus9_gex_net = if IsNan(strike_plus9_gex) then 0 else if AbsValue(strike_plus9_gex) > threshold then strike_plus9_gex else 0;
def plus10_gex_net = if IsNan(strike_plus10_gex) then 0 else if AbsValue(strike_plus10_gex) > threshold then strike_plus10_gex else 0;

def minus1_gex_net = if IsNan(strike_minus1_gex) then 0 else if AbsValue(strike_minus1_gex) > threshold then strike_minus1_gex else 0;
def minus2_gex_net = if IsNan(strike_minus2_gex) then 0 else if AbsValue(strike_minus2_gex) > threshold then strike_minus2_gex else 0;
def minus3_gex_net = if IsNan(strike_minus3_gex) then 0 else if AbsValue(strike_minus3_gex) > threshold then strike_minus3_gex else 0;
def minus4_gex_net = if IsNan(strike_minus4_gex) then 0 else if AbsValue(strike_minus4_gex) > threshold then strike_minus4_gex else 0;
def minus5_gex_net = if IsNan(strike_minus5_gex) then 0 else if AbsValue(strike_minus5_gex) > threshold then strike_minus5_gex else 0;
def minus6_gex_net = if IsNan(strike_minus6_gex) then 0 else if AbsValue(strike_minus6_gex) > threshold then strike_minus6_gex else 0;
def minus7_gex_net = if IsNan(strike_minus7_gex) then 0 else if AbsValue(strike_minus7_gex) > threshold then strike_minus7_gex else 0;
def minus8_gex_net = if IsNan(strike_minus8_gex) then 0 else if AbsValue(strike_minus8_gex) > threshold then strike_minus8_gex else 0;
def minus9_gex_net = if IsNan(strike_minus9_gex) then 0 else if AbsValue(strike_minus9_gex) > threshold then strike_minus9_gex else 0;
def minus10_gex_net = if IsNan(strike_minus10_gex) then 0 else if AbsValue(strike_minus10_gex) > threshold then strike_minus10_gex else 0;

def nettotalGEX_today = base_gex_net + plus1_gex_net + plus2_gex_net + plus3_gex_net + plus4_gex_net + plus5_gex_net + plus6_gex_net + plus7_gex_net + plus8_gex_net + plus9_gex_net + plus10_gex_net + minus1_gex_net + minus2_gex_net + minus3_gex_net + minus4_gex_net + minus5_gex_net + minus6_gex_net + minus7_gex_net + minus8_gex_net + minus9_gex_net + minus10_gex_net;

AddLabel(yes, "Net GEX: " + nettotalGEX_today *100, if nettotalGEX_today > 1 then color.uptick else color.downtick);

View attachment 22163
I downloaded the code, but all I get is chart bubbles on the zero line. The histogram doesn't show. Any suggestions as to what I am doing wrong?
 
I'm using this and work perfect

Ruby:
# GEX Horizontal Axis V2B Jan 17, 2023
# Twitter @2187Nick

# 1-18-24 @brooklyngfellaz Added expiration date label, Base strike label (changes color, above base strike uptick, below downtick), a current price label just to be able to get a quick view of current price and lastly changed the color of base strike so it would stand out.


declare lower;
declare once_per_bar;

def day = 0;

input symbol = "SPY";
input strikeSpacing = 1.0;
input strikes = 10;
input shift_left = 1;
input spacing = 1;
input threshold = 20;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
then BarNumber()
else lastbar[1];

input ManuallySetExpiration = {default "false", "true"};
input Expiration_YYMMDD = 240117;
def DateString_auto = GetYYYYMMDD() - 20000000;
def DateString = if ManuallySetExpiration then Expiration_YYMMDD else DateString_auto;

def agg = AggregationPeriod.Day;
def seconds_left = SecondsTillTime(1615);
def hours_left = seconds_left / 3600;
def days_left = if hours_left <= 0 then 0 else hours_left / 24;

def Vol = imp_volatility(getSymbol());
#addlabel(yes, "Vol: " + Vol, color.white);
def S = close();
#def S = close(period = agg);
#addlabel(yes, "S_close: " + S, color.white);

def t = ((DateString - DateString_auto) + days_left) / 365;
#addlabel(yes, "t: " + t);
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);
def Sqrt_2pi = 2.5066;
def Vol_Sqrt_t_S = S * Vol_Sqrt_t;

DefineGlobalColor("CallColor", Color.GREEN);
DefineGlobalColor("PutColor", Color.downtick);
#AddLabel(yes, "Expiration: " + AsPrice(DateString) , color.uptick);
AddLabel(yes, "Gamma Exposure (GEX): " + AsPrice(DateString), color.cyan);
#AddLabel(yes, "GEX", color.uptick);
#AddLabel(yes, AsPrice(DateString) + "C", GlobalColor("CallColor"));
#AddLabel(yes, AsPrice(DateString) + "P", GlobalColor("PutColor"));

# Open Price
def todayOpen = open(symbol = getSymbol(), period = "DAY");
def yesterdayOpen = open(symbol = getSymbol(), period = "DAY")[1];
def lastPrice = if !IsNaN(close(symbol = getSymbol()))
then close(symbol = getSymbol())
else close(symbol = getSymbol(), period = "DAY", PriceType.LAST);
def openPrice = if !IsNaN(todayOpen) then todayOpen
else if !IsNaN(yesterdayOpen) then yesterdayOpen
else lastPrice;

#def openlevel = open(period = agg);
#addlabel(yes, "open: " + openPrice, color.uptick);
def rounding_factor = if strikeSpacing > 1 and strikeSpacing < 25 then -1 else if strikeSpacing > 24 then -2 else 0;
def floor_or_ceiling = Round(openPrice, rounding_factor);
def base_strike = floor_or_ceiling;
#addlabel(yes, "centerStrike: " + base_strike);

#AddLabel(yes, "Base Strike: " + AsPrice(base_strike), if close > base_strike then Color.uptick else Color.downtick);

def SPY = Close ("SPY");

#AddLabel(Yes, "Current Price: " + AsPrice(close), if close > base_strike then Color.uptick else Color.downtick);

#def closeplot = if !IsNaN(close) and IsNaN(close[-1]) then close else closeplot[1];



Script GEX {
input strike = 0;
input dateString = 0;
input Vol = 0;
input t = 0;
input S = 0;
input todayoryday = 0;
input Sqr_Vol_2 = 0;
input Vol_Sqrt_t = 0;
input Vol_Sqrt_t_S = 0;
def gamma = (Exp(-.5*(Sqr((Log(S / strike) + Sqr_Vol_2) / Vol_Sqrt_t) )) /2.5066) / Vol_Sqrt_t_S;

plot strikeGEX = if IsNaN((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma)
then 0 else Round((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma*S/10000,0);
}



def strike_base = base_strike;
def strike_plus1 = base_strike + strikeSpacing;
def strike_plus2 = base_strike + strikeSpacing * 2;
def strike_plus3 = base_strike + strikeSpacing * 3;
def strike_plus4 = base_strike + strikeSpacing * 4;
def strike_plus5 = base_strike + strikeSpacing * 5;
def strike_plus6 = base_strike + strikeSpacing * 6;
def strike_plus7 = base_strike + strikeSpacing * 7;
def strike_plus8 = base_strike + strikeSpacing * 8;
def strike_plus9 = base_strike + strikeSpacing * 9;
def strike_plus10 = base_strike + strikeSpacing * 10;

def strike_minus1 = base_strike - strikeSpacing;
def strike_minus2 = base_strike - strikeSpacing * 2;
def strike_minus3 = base_strike - strikeSpacing * 3;
def strike_minus4 = base_strike - strikeSpacing * 4;
def strike_minus5 = base_strike - strikeSpacing * 5;
def strike_minus6 = base_strike - strikeSpacing * 6;
def strike_minus7 = base_strike - strikeSpacing * 7;
def strike_minus8 = base_strike - strikeSpacing * 8;
def strike_minus9 = base_strike - strikeSpacing * 9;
def strike_minus10 = base_strike - strikeSpacing * 10;

### GEX
def strike_base_gex = GEX(strike_base, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
#addlabel(yes, "strike_base_gex : " + strike_base_gex , color.yellow);
def strike_plus1_gex = GEX(strike_plus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus2_gex = GEX(strike_plus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus3_gex = GEX(strike_plus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus4_gex = GEX(strike_plus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus5_gex = GEX(strike_plus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus6_gex = GEX(strike_plus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus7_gex = GEX(strike_plus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus8_gex = GEX(strike_plus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus9_gex = GEX(strike_plus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus10_gex = GEX(strike_plus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

def strike_minus1_gex = GEX(strike_minus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus2_gex = GEX(strike_minus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus3_gex = GEX(strike_minus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus4_gex = GEX(strike_minus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus5_gex = GEX(strike_minus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus6_gex = GEX(strike_minus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus7_gex = GEX(strike_minus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus8_gex = GEX(strike_minus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus9_gex = GEX(strike_minus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus10_gex = GEX(strike_minus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

plot base = if BarNumber() == HighestAll(lastbar - (shift_left*10)) then strike_base_gex[shift_left*-10] else Double.Nan;
base.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base.setLineWeight(5);
base.AssignValueColor(if strike_base_gex[shift_left*-10] > 0 then (Createcolor(240,230,107)) else (Createcolor(240,230,107)));
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, 0, base_strike, (Createcolor(240,230,107)), if strike_base_gex[shift_left*-10] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, strike_base_gex[shift_left*-10], strike_base_gex[shift_left*-10], if strike_base_gex[shift_left*-10] > 0 then(Createcolor(240,230,107)) else (Createcolor(240,230,107)), if strike_base_gex > 0 then yes else no);


plot base_plus1 = if BarNumber() == HighestAll(lastbar - (shift_left*9)) then strike_plus1_gex[shift_left*-9] else Double.Nan;
base_plus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus1.setLineWeight(5);
base_plus1.AssignValueColor(if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*9)) and AbsValue(strike_plus1_gex[shift_left*-9]) > threshold then yes else no, strike_plus1_gex[shift_left*-9], strike_plus1_gex[shift_left*-9], if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick, if strike_plus1_gex[shift_left*-9] > 0 then yes else no);

plot base_plus2 = if BarNumber() == HighestAll(lastbar - (shift_left*8)) then strike_plus2_gex[shift_left*-8] else Double.Nan;
base_plus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus2.setLineWeight(5);
base_plus2.AssignValueColor(if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar- (shift_left*8)) and AbsValue(strike_plus2_gex[shift_left*-8]) > threshold then yes else no, strike_plus2_gex[shift_left*-8], strike_plus2_gex[shift_left*-8], if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick, if strike_plus2_gex[shift_left*-8] > 0 then yes else no);


# For Testing
# time condition(barNumber == barNumber - 8)
#AddChartBubble(time condition, price location, text in bubble, color, up)
#AddChartBubble(yes, BarNumber(), strike_plus2_gex[-8], color.white);
#addlabel(yes, "strike_plus2_gex: " + strike_plus2_gex);


plot base_plus3 = if BarNumber() == HighestAll(lastbar - (shift_left*7)) then strike_plus3_gex[shift_left*-7] else Double.Nan;
base_plus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus3.setLineWeight(5);
base_plus3.AssignValueColor(if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*7)) and AbsValue(strike_plus3_gex[shift_left*-7]) > threshold then yes else no, strike_plus3_gex[shift_left*-7], strike_plus3_gex[shift_left*-7], if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick, if strike_plus3_gex[shift_left*-7] > 0 then yes else no);

plot base_plus4 = if BarNumber() == HighestAll(lastbar - (shift_left*6)) then strike_plus4_gex[shift_left*-6] else Double.Nan;
base_plus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus4.setLineWeight(5);
base_plus4.AssignValueColor(if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*6)) and AbsValue(strike_plus4_gex[shift_left*-6]) > threshold then yes else no, strike_plus4_gex[shift_left*-6], strike_plus4_gex[shift_left*-6], if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick, if strike_plus4_gex[shift_left*-6] > 0 then yes else no);

plot base_plus5 = if BarNumber() == HighestAll(lastbar - (shift_left*5)) then strike_plus5_gex[shift_left*-5] else Double.Nan;
base_plus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus5.setLineWeight(5);
base_plus5.AssignValueColor(if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) then yes else no, 0, strike_plus5, color.gray, if strike_plus5_gex[shift_left*-5] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) and AbsValue(strike_plus5_gex[shift_left*-5]) > threshold then yes else no, strike_plus5_gex[shift_left*-5], strike_plus5_gex[shift_left*-5], if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick, if strike_plus5_gex[shift_left*-5] > 0 then yes else no);



plot base_plus6 = if BarNumber() == HighestAll(lastbar - (shift_left*4)) then strike_plus6_gex[shift_left*-4] else Double.Nan;
base_plus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus6.setLineWeight(5);
base_plus6.AssignValueColor(if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*4)) and AbsValue(strike_plus6_gex[shift_left*-4]) > threshold then yes else no, strike_plus6_gex[shift_left*-4], strike_plus6_gex[shift_left*-4], if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick, if strike_plus6_gex[shift_left*-4] > 0 then yes else no);

plot base_plus7 = if BarNumber() == HighestAll(lastbar - (shift_left*3)) then strike_plus7_gex[shift_left*-3] else Double.Nan;
base_plus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus7.setLineWeight(5);
base_plus7.AssignValueColor(if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*3)) and AbsValue(strike_plus7_gex[shift_left*-3]) > threshold then yes else no, strike_plus7_gex[shift_left*-3], strike_plus7_gex[shift_left*-3], if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick, if strike_plus7_gex[shift_left*-3] > 0 then yes else no);


plot base_plus8 = if BarNumber() == HighestAll(lastbar - (shift_left*2)) then strike_plus8_gex[shift_left*-2] else Double.Nan;
base_plus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus8.setLineWeight(5);
base_plus8.AssignValueColor(if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*2)) and AbsValue(strike_plus8_gex[shift_left*-2]) > threshold then yes else no, strike_plus8_gex[shift_left*-2], strike_plus8_gex[shift_left*-2], if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick, if strike_plus8_gex[shift_left*-2] > 0 then yes else no);
plot base_plus9 = if BarNumber() == HighestAll(lastbar - (shift_left)) then strike_plus9_gex[shift_left*-1] else Double.Nan;
base_plus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus9.setLineWeight(5);
base_plus9.AssignValueColor(if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left)) and AbsValue(strike_plus9_gex[shift_left*-1]) > threshold then yes else no, strike_plus9_gex[shift_left*-1], strike_plus9_gex[shift_left*-1], if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick, if strike_plus9_gex[shift_left*-1] > 0 then yes else no);

plot base_plus10 = if BarNumber() == HighestAll(lastbar - (shift_left-1)) then strike_plus10_gex[shift_left-1] else Double.Nan;
base_plus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus10.setLineWeight(5);
base_plus10.AssignValueColor(if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) and AbsValue(strike_plus10_gex[shift_left-1]) > threshold then yes else no, strike_plus10_gex[shift_left-1], strike_plus10_gex[shift_left-1], if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick, if strike_plus10_gex[shift_left-1] > 0 then yes else no);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) then yes else no, 0, strike_plus10, color.gray, if strike_plus10_gex[shift_left-1] > 0 then no else yes);


plot base_minus1 = if BarNumber() == HighestAll(lastbar - (shift_left*11)) then strike_minus1_gex[shift_left*-11] else Double.Nan;
base_minus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus1.setLineWeight(5);
base_minus1.AssignValueColor(if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*11)) and AbsValue(strike_minus1_gex[shift_left*-11]) > threshold then yes else no, strike_minus1_gex[shift_left*-11], strike_minus1_gex[shift_left*-11], if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick, if strike_minus1_gex[shift_left*-11] > 0 then yes else no);

plot base_minus2 = if BarNumber() == HighestAll(lastbar - (shift_left*12)) then strike_minus2_gex[shift_left*-12] else Double.Nan;
base_minus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus2.setLineWeight(5);
base_minus2.AssignValueColor(if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*12)) and AbsValue(strike_minus2_gex[shift_left*-12]) > threshold then yes else no, strike_minus2_gex[shift_left*-12], strike_minus2_gex[shift_left*-12], if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick, if strike_minus2_gex[shift_left*-12] > 0 then yes else no);

plot base_minus3 = if BarNumber() == HighestAll(lastbar - (shift_left*13)) then strike_minus3_gex[shift_left*-13] else Double.Nan;
base_minus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus3.setLineWeight(5);
base_minus3.AssignValueColor(if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*13)) and AbsValue(strike_minus3_gex[shift_left*-13]) > threshold then yes else no, strike_minus3_gex[shift_left*-13], strike_minus3_gex[shift_left*-13], if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick, if strike_minus3_gex[shift_left*-13] > 0 then yes else no);

plot base_minus4 = if BarNumber() == HighestAll(lastbar - (shift_left*14)) then strike_minus4_gex[shift_left*-14] else Double.Nan;
base_minus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus4.setLineWeight(5);
base_minus4.AssignValueColor(if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*14)) and AbsValue(strike_minus4_gex[shift_left*-14]) > threshold then yes else no, strike_minus4_gex[shift_left*-14], strike_minus4_gex[shift_left*-14], if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick, if strike_minus4_gex[shift_left*-14] > 0 then yes else no);


plot base_minus5 = if BarNumber() >= HighestAll(lastbar - (shift_left*15)) and BarNumber() <= HighestAll(lastbar - (shift_left*15)) then strike_minus5_gex[shift_left*-15] else Double.Nan;
base_minus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus5.setLineWeight(5);
base_minus5.AssignValueColor(if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) then yes else no, 0, strike_minus5, color.gray, if strike_minus5_gex[shift_left*-15] > 0 then no else yes);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) and AbsValue(strike_minus5_gex[shift_left*-15]) > threshold then yes else no, strike_minus5_gex[shift_left*-15], strike_minus5_gex[shift_left*-15], if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick, if strike_minus5_gex[shift_left*-15] > 0 then yes else no);

plot base_minus6 = if BarNumber() == HighestAll(lastbar - (shift_left*16)) then strike_minus6_gex[shift_left*-16] else Double.Nan;
base_minus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus6.setLineWeight(5);
base_minus6.AssignValueColor(if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*16)) and AbsValue(strike_minus6_gex[shift_left*-16]) > threshold then yes else no, strike_minus6_gex[shift_left*-16], strike_minus6_gex[shift_left*-16], if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick, if strike_minus6_gex[shift_left*-16] > 0 then yes else no);


plot base_minus7 = if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17)) then strike_minus7_gex[shift_left*-17] else Double.Nan;
base_minus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus7.setLineWeight(5);
base_minus7.AssignValueColor(if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17))and AbsValue(strike_minus7_gex[shift_left*-17]) > threshold then yes else no, strike_minus7_gex[shift_left*-17], strike_minus7_gex[shift_left*-17], if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick, if strike_minus7_gex[shift_left*-17] > 0 then yes else no);

plot base_minus8 = if BarNumber() == HighestAll(lastbar - (shift_left*18)) then strike_minus8_gex[shift_left*-18] else Double.Nan;
base_minus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus8.setLineWeight(5);
base_minus8.AssignValueColor(if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*18)) and BarNumber() <= HighestAll(lastbar - (shift_left*18))and AbsValue(strike_minus8_gex[shift_left*-18]) > threshold then yes else no, strike_minus8_gex[shift_left*-18], strike_minus8_gex[shift_left*-18], if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick, if strike_minus8_gex[shift_left*-18] > 0 then yes else no);

plot base_minus9 = if BarNumber() == HighestAll(lastbar - (shift_left*19)) then strike_minus9_gex[shift_left*-19] else Double.Nan;
base_minus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus9.setLineWeight(5);
base_minus9.AssignValueColor(if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*19)) and AbsValue(strike_minus9_gex[shift_left*-19]) > threshold then yes else no, strike_minus9_gex[shift_left*-19], strike_minus9_gex[shift_left*-19], if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick, if strike_minus9_gex[shift_left*-19] > 0 then yes else no);


plot base_minus10 = if BarNumber() == HighestAll(lastbar - (shift_left*20)) then strike_minus10_gex[shift_left*-20] else Double.Nan;
base_minus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus10.setLineWeight(5);
base_minus10.AssignValueColor(if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*20)) and AbsValue(strike_minus10_gex[shift_left*-20]) > threshold then yes else no, strike_minus10_gex[shift_left*-20], strike_minus10_gex[shift_left*-20], if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick, if strike_minus10_gex[shift_left*-20] > 0 then yes else no);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*20)) and BarNumber() <= HighestAll(lastbar - (shift_left*20)) then yes else no, 0, strike_minus10, color.gray, if strike_minus10 > 0 then yes else no);

#######
plot zeroline = 0;
zeroline.SetDEfaultColor(color.dark_gray);

def base_gex_net = if IsNan(strike_base_gex) then 0 else if AbsValue(strike_base_gex) > threshold then strike_base_gex else 0;
def plus1_gex_net = if IsNan(strike_plus1_gex) then 0 else if AbsValue(strike_plus1_gex) > threshold then strike_plus1_gex else 0;
def plus2_gex_net = if IsNan(strike_plus2_gex) then 0 else if AbsValue(strike_plus2_gex) > threshold then strike_plus2_gex else 0;
def plus3_gex_net = if IsNan(strike_plus3_gex) then 0 else if AbsValue(strike_plus3_gex) > threshold then strike_plus3_gex else 0;
def plus4_gex_net = if IsNan(strike_plus4_gex) then 0 else if AbsValue(strike_plus4_gex) > threshold then strike_plus4_gex else 0;
def plus5_gex_net = if IsNan(strike_plus5_gex) then 0 else if AbsValue(strike_plus5_gex) > threshold then strike_plus5_gex else 0;
def plus6_gex_net = if IsNan(strike_plus6_gex) then 0 else if AbsValue(strike_plus6_gex) > threshold then strike_plus6_gex else 0;
def plus7_gex_net = if IsNan(strike_plus7_gex) then 0 else if AbsValue(strike_plus7_gex) > threshold then strike_plus7_gex else 0;
def plus8_gex_net = if IsNan(strike_plus8_gex) then 0 else if AbsValue(strike_plus8_gex) > threshold then strike_plus8_gex else 0;
def plus9_gex_net = if IsNan(strike_plus9_gex) then 0 else if AbsValue(strike_plus9_gex) > threshold then strike_plus9_gex else 0;
def plus10_gex_net = if IsNan(strike_plus10_gex) then 0 else if AbsValue(strike_plus10_gex) > threshold then strike_plus10_gex else 0;

def minus1_gex_net = if IsNan(strike_minus1_gex) then 0 else if AbsValue(strike_minus1_gex) > threshold then strike_minus1_gex else 0;
def minus2_gex_net = if IsNan(strike_minus2_gex) then 0 else if AbsValue(strike_minus2_gex) > threshold then strike_minus2_gex else 0;
def minus3_gex_net = if IsNan(strike_minus3_gex) then 0 else if AbsValue(strike_minus3_gex) > threshold then strike_minus3_gex else 0;
def minus4_gex_net = if IsNan(strike_minus4_gex) then 0 else if AbsValue(strike_minus4_gex) > threshold then strike_minus4_gex else 0;
def minus5_gex_net = if IsNan(strike_minus5_gex) then 0 else if AbsValue(strike_minus5_gex) > threshold then strike_minus5_gex else 0;
def minus6_gex_net = if IsNan(strike_minus6_gex) then 0 else if AbsValue(strike_minus6_gex) > threshold then strike_minus6_gex else 0;
def minus7_gex_net = if IsNan(strike_minus7_gex) then 0 else if AbsValue(strike_minus7_gex) > threshold then strike_minus7_gex else 0;
def minus8_gex_net = if IsNan(strike_minus8_gex) then 0 else if AbsValue(strike_minus8_gex) > threshold then strike_minus8_gex else 0;
def minus9_gex_net = if IsNan(strike_minus9_gex) then 0 else if AbsValue(strike_minus9_gex) > threshold then strike_minus9_gex else 0;
def minus10_gex_net = if IsNan(strike_minus10_gex) then 0 else if AbsValue(strike_minus10_gex) > threshold then strike_minus10_gex else 0;

def nettotalGEX_today = base_gex_net + plus1_gex_net + plus2_gex_net + plus3_gex_net + plus4_gex_net + plus5_gex_net + plus6_gex_net + plus7_gex_net + plus8_gex_net + plus9_gex_net + plus10_gex_net + minus1_gex_net + minus2_gex_net + minus3_gex_net + minus4_gex_net + minus5_gex_net + minus6_gex_net + minus7_gex_net + minus8_gex_net + minus9_gex_net + minus10_gex_net;

AddLabel(yes, "Net GEX: " + nettotalGEX_today *100, if nettotalGEX_today > 1 then color.uptick else color.downtick);

View attachment 22163
I corrected that error by putting an * between (Vol) and .5 and another between .5 and (t). I still can't get the histogram to show. All I get is a few chart bubbles on the Zeroline.
 

Attachments

  • gamma.png
    gamma.png
    8.7 KB · Views: 100
I corrected that error by putting an * between (Vol) and .5 and another between .5 and (t). I still can't get the histogram to show. All I get is a few chart bubbles on the Zeroline.
I don't know what to say , but still working for me , put TF in Today 1m and the market has to be open , 9:30 am to 4:00 pm
 
Last edited:
I'm using this and work perfect

Ruby:
# GEX Horizontal Axis V2B Jan 17, 2023
# Twitter @2187Nick

# 1-18-24 @brooklyngfellaz Added expiration date label, Base strike label (changes color, above base strike uptick, below downtick), a current price label just to be able to get a quick view of current price and lastly changed the color of base strike so it would stand out.


declare lower;
declare once_per_bar;

def day = 0;

input symbol = "SPY";
input strikeSpacing = 1.0;
input strikes = 10;
input shift_left = 1;
input spacing = 1;
input threshold = 20;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
then BarNumber()
else lastbar[1];

input ManuallySetExpiration = {default "false", "true"};
input Expiration_YYMMDD = 240117;
def DateString_auto = GetYYYYMMDD() - 20000000;
def DateString = if ManuallySetExpiration then Expiration_YYMMDD else DateString_auto;

def agg = AggregationPeriod.Day;
def seconds_left = SecondsTillTime(1615);
def hours_left = seconds_left / 3600;
def days_left = if hours_left <= 0 then 0 else hours_left / 24;

def Vol = imp_volatility(getSymbol());
#addlabel(yes, "Vol: " + Vol, color.white);
def S = close();
#def S = close(period = agg);
#addlabel(yes, "S_close: " + S, color.white);

def t = ((DateString - DateString_auto) + days_left) / 365;
#addlabel(yes, "t: " + t);
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);
def Sqrt_2pi = 2.5066;
def Vol_Sqrt_t_S = S * Vol_Sqrt_t;

DefineGlobalColor("CallColor", Color.GREEN);
DefineGlobalColor("PutColor", Color.downtick);
#AddLabel(yes, "Expiration: " + AsPrice(DateString) , color.uptick);
AddLabel(yes, "Gamma Exposure (GEX): " + AsPrice(DateString), color.cyan);
#AddLabel(yes, "GEX", color.uptick);
#AddLabel(yes, AsPrice(DateString) + "C", GlobalColor("CallColor"));
#AddLabel(yes, AsPrice(DateString) + "P", GlobalColor("PutColor"));

# Open Price
def todayOpen = open(symbol = getSymbol(), period = "DAY");
def yesterdayOpen = open(symbol = getSymbol(), period = "DAY")[1];
def lastPrice = if !IsNaN(close(symbol = getSymbol()))
then close(symbol = getSymbol())
else close(symbol = getSymbol(), period = "DAY", PriceType.LAST);
def openPrice = if !IsNaN(todayOpen) then todayOpen
else if !IsNaN(yesterdayOpen) then yesterdayOpen
else lastPrice;

#def openlevel = open(period = agg);
#addlabel(yes, "open: " + openPrice, color.uptick);
def rounding_factor = if strikeSpacing > 1 and strikeSpacing < 25 then -1 else if strikeSpacing > 24 then -2 else 0;
def floor_or_ceiling = Round(openPrice, rounding_factor);
def base_strike = floor_or_ceiling;
#addlabel(yes, "centerStrike: " + base_strike);

#AddLabel(yes, "Base Strike: " + AsPrice(base_strike), if close > base_strike then Color.uptick else Color.downtick);

def SPY = Close ("SPY");

#AddLabel(Yes, "Current Price: " + AsPrice(close), if close > base_strike then Color.uptick else Color.downtick);

#def closeplot = if !IsNaN(close) and IsNaN(close[-1]) then close else closeplot[1];



Script GEX {
input strike = 0;
input dateString = 0;
input Vol = 0;
input t = 0;
input S = 0;
input todayoryday = 0;
input Sqr_Vol_2 = 0;
input Vol_Sqrt_t = 0;
input Vol_Sqrt_t_S = 0;
def gamma = (Exp(-.5*(Sqr((Log(S / strike) + Sqr_Vol_2) / Vol_Sqrt_t) )) /2.5066) / Vol_Sqrt_t_S;

plot strikeGEX = if IsNaN((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma)
then 0 else Round((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma*S/10000,0);
}



def strike_base = base_strike;
def strike_plus1 = base_strike + strikeSpacing;
def strike_plus2 = base_strike + strikeSpacing * 2;
def strike_plus3 = base_strike + strikeSpacing * 3;
def strike_plus4 = base_strike + strikeSpacing * 4;
def strike_plus5 = base_strike + strikeSpacing * 5;
def strike_plus6 = base_strike + strikeSpacing * 6;
def strike_plus7 = base_strike + strikeSpacing * 7;
def strike_plus8 = base_strike + strikeSpacing * 8;
def strike_plus9 = base_strike + strikeSpacing * 9;
def strike_plus10 = base_strike + strikeSpacing * 10;

def strike_minus1 = base_strike - strikeSpacing;
def strike_minus2 = base_strike - strikeSpacing * 2;
def strike_minus3 = base_strike - strikeSpacing * 3;
def strike_minus4 = base_strike - strikeSpacing * 4;
def strike_minus5 = base_strike - strikeSpacing * 5;
def strike_minus6 = base_strike - strikeSpacing * 6;
def strike_minus7 = base_strike - strikeSpacing * 7;
def strike_minus8 = base_strike - strikeSpacing * 8;
def strike_minus9 = base_strike - strikeSpacing * 9;
def strike_minus10 = base_strike - strikeSpacing * 10;

### GEX
def strike_base_gex = GEX(strike_base, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
#addlabel(yes, "strike_base_gex : " + strike_base_gex , color.yellow);
def strike_plus1_gex = GEX(strike_plus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus2_gex = GEX(strike_plus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus3_gex = GEX(strike_plus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus4_gex = GEX(strike_plus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus5_gex = GEX(strike_plus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus6_gex = GEX(strike_plus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus7_gex = GEX(strike_plus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus8_gex = GEX(strike_plus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus9_gex = GEX(strike_plus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus10_gex = GEX(strike_plus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

def strike_minus1_gex = GEX(strike_minus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus2_gex = GEX(strike_minus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus3_gex = GEX(strike_minus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus4_gex = GEX(strike_minus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus5_gex = GEX(strike_minus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus6_gex = GEX(strike_minus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus7_gex = GEX(strike_minus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus8_gex = GEX(strike_minus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus9_gex = GEX(strike_minus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus10_gex = GEX(strike_minus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

plot base = if BarNumber() == HighestAll(lastbar - (shift_left*10)) then strike_base_gex[shift_left*-10] else Double.Nan;
base.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base.setLineWeight(5);
base.AssignValueColor(if strike_base_gex[shift_left*-10] > 0 then (Createcolor(240,230,107)) else (Createcolor(240,230,107)));
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, 0, base_strike, (Createcolor(240,230,107)), if strike_base_gex[shift_left*-10] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, strike_base_gex[shift_left*-10], strike_base_gex[shift_left*-10], if strike_base_gex[shift_left*-10] > 0 then(Createcolor(240,230,107)) else (Createcolor(240,230,107)), if strike_base_gex > 0 then yes else no);


plot base_plus1 = if BarNumber() == HighestAll(lastbar - (shift_left*9)) then strike_plus1_gex[shift_left*-9] else Double.Nan;
base_plus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus1.setLineWeight(5);
base_plus1.AssignValueColor(if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*9)) and AbsValue(strike_plus1_gex[shift_left*-9]) > threshold then yes else no, strike_plus1_gex[shift_left*-9], strike_plus1_gex[shift_left*-9], if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick, if strike_plus1_gex[shift_left*-9] > 0 then yes else no);

plot base_plus2 = if BarNumber() == HighestAll(lastbar - (shift_left*8)) then strike_plus2_gex[shift_left*-8] else Double.Nan;
base_plus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus2.setLineWeight(5);
base_plus2.AssignValueColor(if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar- (shift_left*8)) and AbsValue(strike_plus2_gex[shift_left*-8]) > threshold then yes else no, strike_plus2_gex[shift_left*-8], strike_plus2_gex[shift_left*-8], if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick, if strike_plus2_gex[shift_left*-8] > 0 then yes else no);


# For Testing
# time condition(barNumber == barNumber - 8)
#AddChartBubble(time condition, price location, text in bubble, color, up)
#AddChartBubble(yes, BarNumber(), strike_plus2_gex[-8], color.white);
#addlabel(yes, "strike_plus2_gex: " + strike_plus2_gex);


plot base_plus3 = if BarNumber() == HighestAll(lastbar - (shift_left*7)) then strike_plus3_gex[shift_left*-7] else Double.Nan;
base_plus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus3.setLineWeight(5);
base_plus3.AssignValueColor(if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*7)) and AbsValue(strike_plus3_gex[shift_left*-7]) > threshold then yes else no, strike_plus3_gex[shift_left*-7], strike_plus3_gex[shift_left*-7], if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick, if strike_plus3_gex[shift_left*-7] > 0 then yes else no);

plot base_plus4 = if BarNumber() == HighestAll(lastbar - (shift_left*6)) then strike_plus4_gex[shift_left*-6] else Double.Nan;
base_plus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus4.setLineWeight(5);
base_plus4.AssignValueColor(if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*6)) and AbsValue(strike_plus4_gex[shift_left*-6]) > threshold then yes else no, strike_plus4_gex[shift_left*-6], strike_plus4_gex[shift_left*-6], if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick, if strike_plus4_gex[shift_left*-6] > 0 then yes else no);

plot base_plus5 = if BarNumber() == HighestAll(lastbar - (shift_left*5)) then strike_plus5_gex[shift_left*-5] else Double.Nan;
base_plus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus5.setLineWeight(5);
base_plus5.AssignValueColor(if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) then yes else no, 0, strike_plus5, color.gray, if strike_plus5_gex[shift_left*-5] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) and AbsValue(strike_plus5_gex[shift_left*-5]) > threshold then yes else no, strike_plus5_gex[shift_left*-5], strike_plus5_gex[shift_left*-5], if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick, if strike_plus5_gex[shift_left*-5] > 0 then yes else no);



plot base_plus6 = if BarNumber() == HighestAll(lastbar - (shift_left*4)) then strike_plus6_gex[shift_left*-4] else Double.Nan;
base_plus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus6.setLineWeight(5);
base_plus6.AssignValueColor(if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*4)) and AbsValue(strike_plus6_gex[shift_left*-4]) > threshold then yes else no, strike_plus6_gex[shift_left*-4], strike_plus6_gex[shift_left*-4], if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick, if strike_plus6_gex[shift_left*-4] > 0 then yes else no);

plot base_plus7 = if BarNumber() == HighestAll(lastbar - (shift_left*3)) then strike_plus7_gex[shift_left*-3] else Double.Nan;
base_plus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus7.setLineWeight(5);
base_plus7.AssignValueColor(if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*3)) and AbsValue(strike_plus7_gex[shift_left*-3]) > threshold then yes else no, strike_plus7_gex[shift_left*-3], strike_plus7_gex[shift_left*-3], if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick, if strike_plus7_gex[shift_left*-3] > 0 then yes else no);


plot base_plus8 = if BarNumber() == HighestAll(lastbar - (shift_left*2)) then strike_plus8_gex[shift_left*-2] else Double.Nan;
base_plus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus8.setLineWeight(5);
base_plus8.AssignValueColor(if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*2)) and AbsValue(strike_plus8_gex[shift_left*-2]) > threshold then yes else no, strike_plus8_gex[shift_left*-2], strike_plus8_gex[shift_left*-2], if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick, if strike_plus8_gex[shift_left*-2] > 0 then yes else no);
plot base_plus9 = if BarNumber() == HighestAll(lastbar - (shift_left)) then strike_plus9_gex[shift_left*-1] else Double.Nan;
base_plus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus9.setLineWeight(5);
base_plus9.AssignValueColor(if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left)) and AbsValue(strike_plus9_gex[shift_left*-1]) > threshold then yes else no, strike_plus9_gex[shift_left*-1], strike_plus9_gex[shift_left*-1], if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick, if strike_plus9_gex[shift_left*-1] > 0 then yes else no);

plot base_plus10 = if BarNumber() == HighestAll(lastbar - (shift_left-1)) then strike_plus10_gex[shift_left-1] else Double.Nan;
base_plus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus10.setLineWeight(5);
base_plus10.AssignValueColor(if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) and AbsValue(strike_plus10_gex[shift_left-1]) > threshold then yes else no, strike_plus10_gex[shift_left-1], strike_plus10_gex[shift_left-1], if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick, if strike_plus10_gex[shift_left-1] > 0 then yes else no);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) then yes else no, 0, strike_plus10, color.gray, if strike_plus10_gex[shift_left-1] > 0 then no else yes);


plot base_minus1 = if BarNumber() == HighestAll(lastbar - (shift_left*11)) then strike_minus1_gex[shift_left*-11] else Double.Nan;
base_minus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus1.setLineWeight(5);
base_minus1.AssignValueColor(if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*11)) and AbsValue(strike_minus1_gex[shift_left*-11]) > threshold then yes else no, strike_minus1_gex[shift_left*-11], strike_minus1_gex[shift_left*-11], if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick, if strike_minus1_gex[shift_left*-11] > 0 then yes else no);

plot base_minus2 = if BarNumber() == HighestAll(lastbar - (shift_left*12)) then strike_minus2_gex[shift_left*-12] else Double.Nan;
base_minus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus2.setLineWeight(5);
base_minus2.AssignValueColor(if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*12)) and AbsValue(strike_minus2_gex[shift_left*-12]) > threshold then yes else no, strike_minus2_gex[shift_left*-12], strike_minus2_gex[shift_left*-12], if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick, if strike_minus2_gex[shift_left*-12] > 0 then yes else no);

plot base_minus3 = if BarNumber() == HighestAll(lastbar - (shift_left*13)) then strike_minus3_gex[shift_left*-13] else Double.Nan;
base_minus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus3.setLineWeight(5);
base_minus3.AssignValueColor(if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*13)) and AbsValue(strike_minus3_gex[shift_left*-13]) > threshold then yes else no, strike_minus3_gex[shift_left*-13], strike_minus3_gex[shift_left*-13], if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick, if strike_minus3_gex[shift_left*-13] > 0 then yes else no);

plot base_minus4 = if BarNumber() == HighestAll(lastbar - (shift_left*14)) then strike_minus4_gex[shift_left*-14] else Double.Nan;
base_minus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus4.setLineWeight(5);
base_minus4.AssignValueColor(if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*14)) and AbsValue(strike_minus4_gex[shift_left*-14]) > threshold then yes else no, strike_minus4_gex[shift_left*-14], strike_minus4_gex[shift_left*-14], if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick, if strike_minus4_gex[shift_left*-14] > 0 then yes else no);


plot base_minus5 = if BarNumber() >= HighestAll(lastbar - (shift_left*15)) and BarNumber() <= HighestAll(lastbar - (shift_left*15)) then strike_minus5_gex[shift_left*-15] else Double.Nan;
base_minus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus5.setLineWeight(5);
base_minus5.AssignValueColor(if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) then yes else no, 0, strike_minus5, color.gray, if strike_minus5_gex[shift_left*-15] > 0 then no else yes);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) and AbsValue(strike_minus5_gex[shift_left*-15]) > threshold then yes else no, strike_minus5_gex[shift_left*-15], strike_minus5_gex[shift_left*-15], if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick, if strike_minus5_gex[shift_left*-15] > 0 then yes else no);

plot base_minus6 = if BarNumber() == HighestAll(lastbar - (shift_left*16)) then strike_minus6_gex[shift_left*-16] else Double.Nan;
base_minus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus6.setLineWeight(5);
base_minus6.AssignValueColor(if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*16)) and AbsValue(strike_minus6_gex[shift_left*-16]) > threshold then yes else no, strike_minus6_gex[shift_left*-16], strike_minus6_gex[shift_left*-16], if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick, if strike_minus6_gex[shift_left*-16] > 0 then yes else no);


plot base_minus7 = if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17)) then strike_minus7_gex[shift_left*-17] else Double.Nan;
base_minus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus7.setLineWeight(5);
base_minus7.AssignValueColor(if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17))and AbsValue(strike_minus7_gex[shift_left*-17]) > threshold then yes else no, strike_minus7_gex[shift_left*-17], strike_minus7_gex[shift_left*-17], if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick, if strike_minus7_gex[shift_left*-17] > 0 then yes else no);

plot base_minus8 = if BarNumber() == HighestAll(lastbar - (shift_left*18)) then strike_minus8_gex[shift_left*-18] else Double.Nan;
base_minus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus8.setLineWeight(5);
base_minus8.AssignValueColor(if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*18)) and BarNumber() <= HighestAll(lastbar - (shift_left*18))and AbsValue(strike_minus8_gex[shift_left*-18]) > threshold then yes else no, strike_minus8_gex[shift_left*-18], strike_minus8_gex[shift_left*-18], if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick, if strike_minus8_gex[shift_left*-18] > 0 then yes else no);

plot base_minus9 = if BarNumber() == HighestAll(lastbar - (shift_left*19)) then strike_minus9_gex[shift_left*-19] else Double.Nan;
base_minus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus9.setLineWeight(5);
base_minus9.AssignValueColor(if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*19)) and AbsValue(strike_minus9_gex[shift_left*-19]) > threshold then yes else no, strike_minus9_gex[shift_left*-19], strike_minus9_gex[shift_left*-19], if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick, if strike_minus9_gex[shift_left*-19] > 0 then yes else no);


plot base_minus10 = if BarNumber() == HighestAll(lastbar - (shift_left*20)) then strike_minus10_gex[shift_left*-20] else Double.Nan;
base_minus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus10.setLineWeight(5);
base_minus10.AssignValueColor(if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*20)) and AbsValue(strike_minus10_gex[shift_left*-20]) > threshold then yes else no, strike_minus10_gex[shift_left*-20], strike_minus10_gex[shift_left*-20], if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick, if strike_minus10_gex[shift_left*-20] > 0 then yes else no);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*20)) and BarNumber() <= HighestAll(lastbar - (shift_left*20)) then yes else no, 0, strike_minus10, color.gray, if strike_minus10 > 0 then yes else no);

#######
plot zeroline = 0;
zeroline.SetDEfaultColor(color.dark_gray);

def base_gex_net = if IsNan(strike_base_gex) then 0 else if AbsValue(strike_base_gex) > threshold then strike_base_gex else 0;
def plus1_gex_net = if IsNan(strike_plus1_gex) then 0 else if AbsValue(strike_plus1_gex) > threshold then strike_plus1_gex else 0;
def plus2_gex_net = if IsNan(strike_plus2_gex) then 0 else if AbsValue(strike_plus2_gex) > threshold then strike_plus2_gex else 0;
def plus3_gex_net = if IsNan(strike_plus3_gex) then 0 else if AbsValue(strike_plus3_gex) > threshold then strike_plus3_gex else 0;
def plus4_gex_net = if IsNan(strike_plus4_gex) then 0 else if AbsValue(strike_plus4_gex) > threshold then strike_plus4_gex else 0;
def plus5_gex_net = if IsNan(strike_plus5_gex) then 0 else if AbsValue(strike_plus5_gex) > threshold then strike_plus5_gex else 0;
def plus6_gex_net = if IsNan(strike_plus6_gex) then 0 else if AbsValue(strike_plus6_gex) > threshold then strike_plus6_gex else 0;
def plus7_gex_net = if IsNan(strike_plus7_gex) then 0 else if AbsValue(strike_plus7_gex) > threshold then strike_plus7_gex else 0;
def plus8_gex_net = if IsNan(strike_plus8_gex) then 0 else if AbsValue(strike_plus8_gex) > threshold then strike_plus8_gex else 0;
def plus9_gex_net = if IsNan(strike_plus9_gex) then 0 else if AbsValue(strike_plus9_gex) > threshold then strike_plus9_gex else 0;
def plus10_gex_net = if IsNan(strike_plus10_gex) then 0 else if AbsValue(strike_plus10_gex) > threshold then strike_plus10_gex else 0;

def minus1_gex_net = if IsNan(strike_minus1_gex) then 0 else if AbsValue(strike_minus1_gex) > threshold then strike_minus1_gex else 0;
def minus2_gex_net = if IsNan(strike_minus2_gex) then 0 else if AbsValue(strike_minus2_gex) > threshold then strike_minus2_gex else 0;
def minus3_gex_net = if IsNan(strike_minus3_gex) then 0 else if AbsValue(strike_minus3_gex) > threshold then strike_minus3_gex else 0;
def minus4_gex_net = if IsNan(strike_minus4_gex) then 0 else if AbsValue(strike_minus4_gex) > threshold then strike_minus4_gex else 0;
def minus5_gex_net = if IsNan(strike_minus5_gex) then 0 else if AbsValue(strike_minus5_gex) > threshold then strike_minus5_gex else 0;
def minus6_gex_net = if IsNan(strike_minus6_gex) then 0 else if AbsValue(strike_minus6_gex) > threshold then strike_minus6_gex else 0;
def minus7_gex_net = if IsNan(strike_minus7_gex) then 0 else if AbsValue(strike_minus7_gex) > threshold then strike_minus7_gex else 0;
def minus8_gex_net = if IsNan(strike_minus8_gex) then 0 else if AbsValue(strike_minus8_gex) > threshold then strike_minus8_gex else 0;
def minus9_gex_net = if IsNan(strike_minus9_gex) then 0 else if AbsValue(strike_minus9_gex) > threshold then strike_minus9_gex else 0;
def minus10_gex_net = if IsNan(strike_minus10_gex) then 0 else if AbsValue(strike_minus10_gex) > threshold then strike_minus10_gex else 0;

def nettotalGEX_today = base_gex_net + plus1_gex_net + plus2_gex_net + plus3_gex_net + plus4_gex_net + plus5_gex_net + plus6_gex_net + plus7_gex_net + plus8_gex_net + plus9_gex_net + plus10_gex_net + minus1_gex_net + minus2_gex_net + minus3_gex_net + minus4_gex_net + minus5_gex_net + minus6_gex_net + minus7_gex_net + minus8_gex_net + minus9_gex_net + minus10_gex_net;

AddLabel(yes, "Net GEX: " + nettotalGEX_today *100, if nettotalGEX_today > 1 then color.uptick else color.downtick);

View attachment 22163
Hi! Can u please explain how you made it Vertical? I see ur profile indicator but have no idea how to add him to my TOS client, many thanks!
 
Last edited:
I'm using this and work perfect

Ruby:
# GEX Horizontal Axis V2B Jan 17, 2023
# Twitter @2187Nick

# 1-18-24 @brooklyngfellaz Added expiration date label, Base strike label (changes color, above base strike uptick, below downtick), a current price label just to be able to get a quick view of current price and lastly changed the color of base strike so it would stand out.


declare lower;
declare once_per_bar;

def day = 0;

input symbol = "SPY";
input strikeSpacing = 1.0;
input strikes = 10;
input shift_left = 1;
input spacing = 1;
input threshold = 20;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close)
then BarNumber()
else lastbar[1];

input ManuallySetExpiration = {default "false", "true"};
input Expiration_YYMMDD = 240117;
def DateString_auto = GetYYYYMMDD() - 20000000;
def DateString = if ManuallySetExpiration then Expiration_YYMMDD else DateString_auto;

def agg = AggregationPeriod.Day;
def seconds_left = SecondsTillTime(1615);
def hours_left = seconds_left / 3600;
def days_left = if hours_left <= 0 then 0 else hours_left / 24;

def Vol = imp_volatility(getSymbol());
#addlabel(yes, "Vol: " + Vol, color.white);
def S = close();
#def S = close(period = agg);
#addlabel(yes, "S_close: " + S, color.white);

def t = ((DateString - DateString_auto) + days_left) / 365;
#addlabel(yes, "t: " + t);
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);
def Sqrt_2pi = 2.5066;
def Vol_Sqrt_t_S = S * Vol_Sqrt_t;

DefineGlobalColor("CallColor", Color.GREEN);
DefineGlobalColor("PutColor", Color.downtick);
#AddLabel(yes, "Expiration: " + AsPrice(DateString) , color.uptick);
AddLabel(yes, "Gamma Exposure (GEX): " + AsPrice(DateString), color.cyan);
#AddLabel(yes, "GEX", color.uptick);
#AddLabel(yes, AsPrice(DateString) + "C", GlobalColor("CallColor"));
#AddLabel(yes, AsPrice(DateString) + "P", GlobalColor("PutColor"));

# Open Price
def todayOpen = open(symbol = getSymbol(), period = "DAY");
def yesterdayOpen = open(symbol = getSymbol(), period = "DAY")[1];
def lastPrice = if !IsNaN(close(symbol = getSymbol()))
then close(symbol = getSymbol())
else close(symbol = getSymbol(), period = "DAY", PriceType.LAST);
def openPrice = if !IsNaN(todayOpen) then todayOpen
else if !IsNaN(yesterdayOpen) then yesterdayOpen
else lastPrice;

#def openlevel = open(period = agg);
#addlabel(yes, "open: " + openPrice, color.uptick);
def rounding_factor = if strikeSpacing > 1 and strikeSpacing < 25 then -1 else if strikeSpacing > 24 then -2 else 0;
def floor_or_ceiling = Round(openPrice, rounding_factor);
def base_strike = floor_or_ceiling;
#addlabel(yes, "centerStrike: " + base_strike);

#AddLabel(yes, "Base Strike: " + AsPrice(base_strike), if close > base_strike then Color.uptick else Color.downtick);

def SPY = Close ("SPY");

#AddLabel(Yes, "Current Price: " + AsPrice(close), if close > base_strike then Color.uptick else Color.downtick);

#def closeplot = if !IsNaN(close) and IsNaN(close[-1]) then close else closeplot[1];



Script GEX {
input strike = 0;
input dateString = 0;
input Vol = 0;
input t = 0;
input S = 0;
input todayoryday = 0;
input Sqr_Vol_2 = 0;
input Vol_Sqrt_t = 0;
input Vol_Sqrt_t_S = 0;
def gamma = (Exp(-.5*(Sqr((Log(S / strike) + Sqr_Vol_2) / Vol_Sqrt_t) )) /2.5066) / Vol_Sqrt_t_S;

plot strikeGEX = if IsNaN((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma)
then 0 else Round((open_interest("."+ getSymbol() + AsPrice(dateString) + "C" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday] - open_interest("."+ getSymbol() + AsPrice(dateString) + "P" + AsPrice(strike),AggregationPeriod.DAY)[todayoryday]) * gamma*S/10000,0);
}



def strike_base = base_strike;
def strike_plus1 = base_strike + strikeSpacing;
def strike_plus2 = base_strike + strikeSpacing * 2;
def strike_plus3 = base_strike + strikeSpacing * 3;
def strike_plus4 = base_strike + strikeSpacing * 4;
def strike_plus5 = base_strike + strikeSpacing * 5;
def strike_plus6 = base_strike + strikeSpacing * 6;
def strike_plus7 = base_strike + strikeSpacing * 7;
def strike_plus8 = base_strike + strikeSpacing * 8;
def strike_plus9 = base_strike + strikeSpacing * 9;
def strike_plus10 = base_strike + strikeSpacing * 10;

def strike_minus1 = base_strike - strikeSpacing;
def strike_minus2 = base_strike - strikeSpacing * 2;
def strike_minus3 = base_strike - strikeSpacing * 3;
def strike_minus4 = base_strike - strikeSpacing * 4;
def strike_minus5 = base_strike - strikeSpacing * 5;
def strike_minus6 = base_strike - strikeSpacing * 6;
def strike_minus7 = base_strike - strikeSpacing * 7;
def strike_minus8 = base_strike - strikeSpacing * 8;
def strike_minus9 = base_strike - strikeSpacing * 9;
def strike_minus10 = base_strike - strikeSpacing * 10;

### GEX
def strike_base_gex = GEX(strike_base, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
#addlabel(yes, "strike_base_gex : " + strike_base_gex , color.yellow);
def strike_plus1_gex = GEX(strike_plus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus2_gex = GEX(strike_plus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus3_gex = GEX(strike_plus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus4_gex = GEX(strike_plus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus5_gex = GEX(strike_plus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus6_gex = GEX(strike_plus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus7_gex = GEX(strike_plus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus8_gex = GEX(strike_plus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus9_gex = GEX(strike_plus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_plus10_gex = GEX(strike_plus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

def strike_minus1_gex = GEX(strike_minus1, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus2_gex = GEX(strike_minus2, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus3_gex = GEX(strike_minus3, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus4_gex = GEX(strike_minus4, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus5_gex = GEX(strike_minus5, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus6_gex = GEX(strike_minus6, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus7_gex = GEX(strike_minus7, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus8_gex = GEX(strike_minus8, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus9_gex = GEX(strike_minus9, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;
def strike_minus10_gex = GEX(strike_minus10, dateString, Vol, t, S, day, Sqr_Vol_2, Vol_Sqrt_t, Vol_Sqrt_t_S).strikeGEX;

plot base = if BarNumber() == HighestAll(lastbar - (shift_left*10)) then strike_base_gex[shift_left*-10] else Double.Nan;
base.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base.setLineWeight(5);
base.AssignValueColor(if strike_base_gex[shift_left*-10] > 0 then (Createcolor(240,230,107)) else (Createcolor(240,230,107)));
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, 0, base_strike, (Createcolor(240,230,107)), if strike_base_gex[shift_left*-10] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*10)) then yes else no, strike_base_gex[shift_left*-10], strike_base_gex[shift_left*-10], if strike_base_gex[shift_left*-10] > 0 then(Createcolor(240,230,107)) else (Createcolor(240,230,107)), if strike_base_gex > 0 then yes else no);


plot base_plus1 = if BarNumber() == HighestAll(lastbar - (shift_left*9)) then strike_plus1_gex[shift_left*-9] else Double.Nan;
base_plus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus1.setLineWeight(5);
base_plus1.AssignValueColor(if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*9)) and AbsValue(strike_plus1_gex[shift_left*-9]) > threshold then yes else no, strike_plus1_gex[shift_left*-9], strike_plus1_gex[shift_left*-9], if strike_plus1_gex[shift_left*-9] > 0 then Color.uptick else Color.downtick, if strike_plus1_gex[shift_left*-9] > 0 then yes else no);

plot base_plus2 = if BarNumber() == HighestAll(lastbar - (shift_left*8)) then strike_plus2_gex[shift_left*-8] else Double.Nan;
base_plus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus2.setLineWeight(5);
base_plus2.AssignValueColor(if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar- (shift_left*8)) and AbsValue(strike_plus2_gex[shift_left*-8]) > threshold then yes else no, strike_plus2_gex[shift_left*-8], strike_plus2_gex[shift_left*-8], if strike_plus2_gex[shift_left*-8] > 0 then Color.uptick else Color.downtick, if strike_plus2_gex[shift_left*-8] > 0 then yes else no);


# For Testing
# time condition(barNumber == barNumber - 8)
#AddChartBubble(time condition, price location, text in bubble, color, up)
#AddChartBubble(yes, BarNumber(), strike_plus2_gex[-8], color.white);
#addlabel(yes, "strike_plus2_gex: " + strike_plus2_gex);


plot base_plus3 = if BarNumber() == HighestAll(lastbar - (shift_left*7)) then strike_plus3_gex[shift_left*-7] else Double.Nan;
base_plus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus3.setLineWeight(5);
base_plus3.AssignValueColor(if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*7)) and AbsValue(strike_plus3_gex[shift_left*-7]) > threshold then yes else no, strike_plus3_gex[shift_left*-7], strike_plus3_gex[shift_left*-7], if strike_plus3_gex[shift_left*-7] > 0 then Color.uptick else Color.downtick, if strike_plus3_gex[shift_left*-7] > 0 then yes else no);

plot base_plus4 = if BarNumber() == HighestAll(lastbar - (shift_left*6)) then strike_plus4_gex[shift_left*-6] else Double.Nan;
base_plus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus4.setLineWeight(5);
base_plus4.AssignValueColor(if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*6)) and AbsValue(strike_plus4_gex[shift_left*-6]) > threshold then yes else no, strike_plus4_gex[shift_left*-6], strike_plus4_gex[shift_left*-6], if strike_plus4_gex[shift_left*-6] > 0 then Color.uptick else Color.downtick, if strike_plus4_gex[shift_left*-6] > 0 then yes else no);

plot base_plus5 = if BarNumber() == HighestAll(lastbar - (shift_left*5)) then strike_plus5_gex[shift_left*-5] else Double.Nan;
base_plus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus5.setLineWeight(5);
base_plus5.AssignValueColor(if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) then yes else no, 0, strike_plus5, color.gray, if strike_plus5_gex[shift_left*-5] > 0 then no else yes);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*5)) and AbsValue(strike_plus5_gex[shift_left*-5]) > threshold then yes else no, strike_plus5_gex[shift_left*-5], strike_plus5_gex[shift_left*-5], if strike_plus5_gex[shift_left*-5] > 0 then Color.uptick else Color.downtick, if strike_plus5_gex[shift_left*-5] > 0 then yes else no);



plot base_plus6 = if BarNumber() == HighestAll(lastbar - (shift_left*4)) then strike_plus6_gex[shift_left*-4] else Double.Nan;
base_plus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus6.setLineWeight(5);
base_plus6.AssignValueColor(if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*4)) and AbsValue(strike_plus6_gex[shift_left*-4]) > threshold then yes else no, strike_plus6_gex[shift_left*-4], strike_plus6_gex[shift_left*-4], if strike_plus6_gex[shift_left*-4] > 0 then Color.uptick else Color.downtick, if strike_plus6_gex[shift_left*-4] > 0 then yes else no);

plot base_plus7 = if BarNumber() == HighestAll(lastbar - (shift_left*3)) then strike_plus7_gex[shift_left*-3] else Double.Nan;
base_plus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus7.setLineWeight(5);
base_plus7.AssignValueColor(if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*3)) and AbsValue(strike_plus7_gex[shift_left*-3]) > threshold then yes else no, strike_plus7_gex[shift_left*-3], strike_plus7_gex[shift_left*-3], if strike_plus7_gex[shift_left*-3] > 0 then Color.uptick else Color.downtick, if strike_plus7_gex[shift_left*-3] > 0 then yes else no);


plot base_plus8 = if BarNumber() == HighestAll(lastbar - (shift_left*2)) then strike_plus8_gex[shift_left*-2] else Double.Nan;
base_plus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus8.setLineWeight(5);
base_plus8.AssignValueColor(if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*2)) and AbsValue(strike_plus8_gex[shift_left*-2]) > threshold then yes else no, strike_plus8_gex[shift_left*-2], strike_plus8_gex[shift_left*-2], if strike_plus8_gex[shift_left*-2] > 0 then Color.uptick else Color.downtick, if strike_plus8_gex[shift_left*-2] > 0 then yes else no);
plot base_plus9 = if BarNumber() == HighestAll(lastbar - (shift_left)) then strike_plus9_gex[shift_left*-1] else Double.Nan;
base_plus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus9.setLineWeight(5);
base_plus9.AssignValueColor(if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left)) and AbsValue(strike_plus9_gex[shift_left*-1]) > threshold then yes else no, strike_plus9_gex[shift_left*-1], strike_plus9_gex[shift_left*-1], if strike_plus9_gex[shift_left*-1] > 0 then Color.uptick else Color.downtick, if strike_plus9_gex[shift_left*-1] > 0 then yes else no);

plot base_plus10 = if BarNumber() == HighestAll(lastbar - (shift_left-1)) then strike_plus10_gex[shift_left-1] else Double.Nan;
base_plus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_plus10.setLineWeight(5);
base_plus10.AssignValueColor(if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) and AbsValue(strike_plus10_gex[shift_left-1]) > threshold then yes else no, strike_plus10_gex[shift_left-1], strike_plus10_gex[shift_left-1], if strike_plus10_gex[shift_left-1] > 0 then Color.uptick else Color.downtick, if strike_plus10_gex[shift_left-1] > 0 then yes else no);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left-1)) then yes else no, 0, strike_plus10, color.gray, if strike_plus10_gex[shift_left-1] > 0 then no else yes);


plot base_minus1 = if BarNumber() == HighestAll(lastbar - (shift_left*11)) then strike_minus1_gex[shift_left*-11] else Double.Nan;
base_minus1.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus1.setLineWeight(5);
base_minus1.AssignValueColor(if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*11)) and AbsValue(strike_minus1_gex[shift_left*-11]) > threshold then yes else no, strike_minus1_gex[shift_left*-11], strike_minus1_gex[shift_left*-11], if strike_minus1_gex[shift_left*-11] > 0 then Color.uptick else Color.downtick, if strike_minus1_gex[shift_left*-11] > 0 then yes else no);

plot base_minus2 = if BarNumber() == HighestAll(lastbar - (shift_left*12)) then strike_minus2_gex[shift_left*-12] else Double.Nan;
base_minus2.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus2.setLineWeight(5);
base_minus2.AssignValueColor(if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*12)) and AbsValue(strike_minus2_gex[shift_left*-12]) > threshold then yes else no, strike_minus2_gex[shift_left*-12], strike_minus2_gex[shift_left*-12], if strike_minus2_gex[shift_left*-12] > 0 then Color.uptick else Color.downtick, if strike_minus2_gex[shift_left*-12] > 0 then yes else no);

plot base_minus3 = if BarNumber() == HighestAll(lastbar - (shift_left*13)) then strike_minus3_gex[shift_left*-13] else Double.Nan;
base_minus3.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus3.setLineWeight(5);
base_minus3.AssignValueColor(if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*13)) and AbsValue(strike_minus3_gex[shift_left*-13]) > threshold then yes else no, strike_minus3_gex[shift_left*-13], strike_minus3_gex[shift_left*-13], if strike_minus3_gex[shift_left*-13] > 0 then Color.uptick else Color.downtick, if strike_minus3_gex[shift_left*-13] > 0 then yes else no);

plot base_minus4 = if BarNumber() == HighestAll(lastbar - (shift_left*14)) then strike_minus4_gex[shift_left*-14] else Double.Nan;
base_minus4.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus4.setLineWeight(5);
base_minus4.AssignValueColor(if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*14)) and AbsValue(strike_minus4_gex[shift_left*-14]) > threshold then yes else no, strike_minus4_gex[shift_left*-14], strike_minus4_gex[shift_left*-14], if strike_minus4_gex[shift_left*-14] > 0 then Color.uptick else Color.downtick, if strike_minus4_gex[shift_left*-14] > 0 then yes else no);


plot base_minus5 = if BarNumber() >= HighestAll(lastbar - (shift_left*15)) and BarNumber() <= HighestAll(lastbar - (shift_left*15)) then strike_minus5_gex[shift_left*-15] else Double.Nan;
base_minus5.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus5.setLineWeight(5);
base_minus5.AssignValueColor(if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) then yes else no, 0, strike_minus5, color.gray, if strike_minus5_gex[shift_left*-15] > 0 then no else yes);

AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*15)) and AbsValue(strike_minus5_gex[shift_left*-15]) > threshold then yes else no, strike_minus5_gex[shift_left*-15], strike_minus5_gex[shift_left*-15], if strike_minus5_gex[shift_left*-15] > 0 then Color.uptick else Color.downtick, if strike_minus5_gex[shift_left*-15] > 0 then yes else no);

plot base_minus6 = if BarNumber() == HighestAll(lastbar - (shift_left*16)) then strike_minus6_gex[shift_left*-16] else Double.Nan;
base_minus6.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus6.setLineWeight(5);
base_minus6.AssignValueColor(if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*16)) and AbsValue(strike_minus6_gex[shift_left*-16]) > threshold then yes else no, strike_minus6_gex[shift_left*-16], strike_minus6_gex[shift_left*-16], if strike_minus6_gex[shift_left*-16] > 0 then Color.uptick else Color.downtick, if strike_minus6_gex[shift_left*-16] > 0 then yes else no);


plot base_minus7 = if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17)) then strike_minus7_gex[shift_left*-17] else Double.Nan;
base_minus7.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus7.setLineWeight(5);
base_minus7.AssignValueColor(if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*17)) and BarNumber() <= HighestAll(lastbar - (shift_left*17))and AbsValue(strike_minus7_gex[shift_left*-17]) > threshold then yes else no, strike_minus7_gex[shift_left*-17], strike_minus7_gex[shift_left*-17], if strike_minus7_gex[shift_left*-17] > 0 then Color.uptick else Color.downtick, if strike_minus7_gex[shift_left*-17] > 0 then yes else no);

plot base_minus8 = if BarNumber() == HighestAll(lastbar - (shift_left*18)) then strike_minus8_gex[shift_left*-18] else Double.Nan;
base_minus8.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus8.setLineWeight(5);
base_minus8.AssignValueColor(if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*18)) and BarNumber() <= HighestAll(lastbar - (shift_left*18))and AbsValue(strike_minus8_gex[shift_left*-18]) > threshold then yes else no, strike_minus8_gex[shift_left*-18], strike_minus8_gex[shift_left*-18], if strike_minus8_gex[shift_left*-18] > 0 then Color.uptick else Color.downtick, if strike_minus8_gex[shift_left*-18] > 0 then yes else no);

plot base_minus9 = if BarNumber() == HighestAll(lastbar - (shift_left*19)) then strike_minus9_gex[shift_left*-19] else Double.Nan;
base_minus9.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus9.setLineWeight(5);
base_minus9.AssignValueColor(if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*19)) and AbsValue(strike_minus9_gex[shift_left*-19]) > threshold then yes else no, strike_minus9_gex[shift_left*-19], strike_minus9_gex[shift_left*-19], if strike_minus9_gex[shift_left*-19] > 0 then Color.uptick else Color.downtick, if strike_minus9_gex[shift_left*-19] > 0 then yes else no);


plot base_minus10 = if BarNumber() == HighestAll(lastbar - (shift_left*20)) then strike_minus10_gex[shift_left*-20] else Double.Nan;
base_minus10.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
base_minus10.setLineWeight(5);
base_minus10.AssignValueColor(if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick);
AddChartBubble(if BarNumber() == HighestAll(lastbar - (shift_left*20)) and AbsValue(strike_minus10_gex[shift_left*-20]) > threshold then yes else no, strike_minus10_gex[shift_left*-20], strike_minus10_gex[shift_left*-20], if strike_minus10_gex[shift_left*-20] > 0 then Color.uptick else Color.downtick, if strike_minus10_gex[shift_left*-20] > 0 then yes else no);
AddChartBubble(if BarNumber() >= HighestAll(lastbar - (shift_left*20)) and BarNumber() <= HighestAll(lastbar - (shift_left*20)) then yes else no, 0, strike_minus10, color.gray, if strike_minus10 > 0 then yes else no);

#######
plot zeroline = 0;
zeroline.SetDEfaultColor(color.dark_gray);

def base_gex_net = if IsNan(strike_base_gex) then 0 else if AbsValue(strike_base_gex) > threshold then strike_base_gex else 0;
def plus1_gex_net = if IsNan(strike_plus1_gex) then 0 else if AbsValue(strike_plus1_gex) > threshold then strike_plus1_gex else 0;
def plus2_gex_net = if IsNan(strike_plus2_gex) then 0 else if AbsValue(strike_plus2_gex) > threshold then strike_plus2_gex else 0;
def plus3_gex_net = if IsNan(strike_plus3_gex) then 0 else if AbsValue(strike_plus3_gex) > threshold then strike_plus3_gex else 0;
def plus4_gex_net = if IsNan(strike_plus4_gex) then 0 else if AbsValue(strike_plus4_gex) > threshold then strike_plus4_gex else 0;
def plus5_gex_net = if IsNan(strike_plus5_gex) then 0 else if AbsValue(strike_plus5_gex) > threshold then strike_plus5_gex else 0;
def plus6_gex_net = if IsNan(strike_plus6_gex) then 0 else if AbsValue(strike_plus6_gex) > threshold then strike_plus6_gex else 0;
def plus7_gex_net = if IsNan(strike_plus7_gex) then 0 else if AbsValue(strike_plus7_gex) > threshold then strike_plus7_gex else 0;
def plus8_gex_net = if IsNan(strike_plus8_gex) then 0 else if AbsValue(strike_plus8_gex) > threshold then strike_plus8_gex else 0;
def plus9_gex_net = if IsNan(strike_plus9_gex) then 0 else if AbsValue(strike_plus9_gex) > threshold then strike_plus9_gex else 0;
def plus10_gex_net = if IsNan(strike_plus10_gex) then 0 else if AbsValue(strike_plus10_gex) > threshold then strike_plus10_gex else 0;

def minus1_gex_net = if IsNan(strike_minus1_gex) then 0 else if AbsValue(strike_minus1_gex) > threshold then strike_minus1_gex else 0;
def minus2_gex_net = if IsNan(strike_minus2_gex) then 0 else if AbsValue(strike_minus2_gex) > threshold then strike_minus2_gex else 0;
def minus3_gex_net = if IsNan(strike_minus3_gex) then 0 else if AbsValue(strike_minus3_gex) > threshold then strike_minus3_gex else 0;
def minus4_gex_net = if IsNan(strike_minus4_gex) then 0 else if AbsValue(strike_minus4_gex) > threshold then strike_minus4_gex else 0;
def minus5_gex_net = if IsNan(strike_minus5_gex) then 0 else if AbsValue(strike_minus5_gex) > threshold then strike_minus5_gex else 0;
def minus6_gex_net = if IsNan(strike_minus6_gex) then 0 else if AbsValue(strike_minus6_gex) > threshold then strike_minus6_gex else 0;
def minus7_gex_net = if IsNan(strike_minus7_gex) then 0 else if AbsValue(strike_minus7_gex) > threshold then strike_minus7_gex else 0;
def minus8_gex_net = if IsNan(strike_minus8_gex) then 0 else if AbsValue(strike_minus8_gex) > threshold then strike_minus8_gex else 0;
def minus9_gex_net = if IsNan(strike_minus9_gex) then 0 else if AbsValue(strike_minus9_gex) > threshold then strike_minus9_gex else 0;
def minus10_gex_net = if IsNan(strike_minus10_gex) then 0 else if AbsValue(strike_minus10_gex) > threshold then strike_minus10_gex else 0;

def nettotalGEX_today = base_gex_net + plus1_gex_net + plus2_gex_net + plus3_gex_net + plus4_gex_net + plus5_gex_net + plus6_gex_net + plus7_gex_net + plus8_gex_net + plus9_gex_net + plus10_gex_net + minus1_gex_net + minus2_gex_net + minus3_gex_net + minus4_gex_net + minus5_gex_net + minus6_gex_net + minus7_gex_net + minus8_gex_net + minus9_gex_net + minus10_gex_net;

AddLabel(yes, "Net GEX: " + nettotalGEX_today *100, if nettotalGEX_today > 1 then color.uptick else color.downtick);

View attachment 22163
Hi, Great post, while loading the script into TOS, getting an error in the below line,
#def t = 1/365;
def Sqr_Vol_2 = Sqr(Vol).5 t;
def Vol_Sqrt_t = Vol * Sqrt(t);

Please share TOS script code to avoid confusion. Thanks in advance
 
This seems to be the new craze in the options market, GAMMA or GEX.

The main problem is in how the data is aggregated. Gammas exposure is best stated and measured in how the dealers or market makers are positioned.

If you open up time and sales in TOS on the SPX, there is no way to determine if a trade is made by a market maker or even if it is closing or opening trade.

Although determining opening and closing trades might be a little easier if you can determine if it was done on the ask or the bid. If a retail trader buys a call thinking the SPX is going up, the market maker sells them the call. So the trader is long delta and the market maker is short delta.

Since all market makers are delta neutral at all times, the market maker will have to either buy SPY shares or ES futures. So this one transaction would be easy to determine by looking at if the trade was at the ask or bid. Since the trader bought a call, they would be buying on the bid. Easy to determine by comparing the time and sales to the current bid/ask spread at the exact moment of the trade.

However, what if the trade was at the mid price, is it an opening or closing transaction? Did someone sell a call or buy a call. Impossible to tell. Herein is the problem with this data. Impossible to determine the exact value of the Gamma of this trade. Now multiple this times millions of trades in SPX per day and there is no way to determine valid Gamma exposure from the data that TOS provides. Just on Friday (9-21-24) alone, the SPX traded 3,221,027 contracts. Keep this in mind when relying on data from TOS.
 
Last edited by a moderator:
This seems to be the new craze in the options market, GAMMA or GEX.

The main problem is in how the data is aggregated. Gammas exposure is best stated and measured in how the dealers or market makers are positioned.

If you open up time and sales in TOS on the SPX, there is no way to determine if a trade is made by a market maker or even if it is closing or opening trade.

Although determining opening and closing trades might be a little easier if you can determine if it was done on the ask or the bid. If a retail trader buys a call thinking the SPX is going up, the market maker sells them the call. So the trader is long delta and the market maker is short delta.

Since all market makers are delta neutral at all times, the market maker will have to either buy SPY shares or ES futures. So this one transaction would be easy to determine by looking at if the trade was at the ask or bid. Since the trader bought a call, they would be buying on the bid. Easy to determine by comparing the time and sales to the current bid/ask spread at the exact moment of the trade.

However, what if the trade was at the mid price, is it an opening or closing transaction? Did someone sell a call or buy a call. Impossible to tell. Herein is the problem with this data. Impossible to determine the exact value of the Gamma of this trade. Now multiple this times millions of trades in SPX per day and there is no way to determine valid Gamma exposure from the data that TOS provides. Just on Friday (9-21-24) alone, the SPX traded 3,221,027 contracts. Keep this in mind when relying on data from TOS.

I have been noticing the same thing.

Still rather new to this concept, but with regards to your thoughts, the open interest field in TOS options trader kinda gives you a bit of a clue as to where the institutional strikes are at.

For SPX quarterlies expiring next Monday you can kinda figure that there's a gamma wall at 5750 with 48636 open calls at that price and the next wall at 5800 with 10353 open calls.

If we shoot past this wall today, that's gonna lead to that melt up scenario where they most probably need to buy 5800 futures to balance off their delta.

Looking forward to December expirations, That most significant gamma wall at the moment is likely to be at 6000 strike with 6505 open contracts and leading up to 6000 strike, there's about 3000 open calls at the moment every $50 increment from $5800 onwards.

High chance of us hitting 5800 based on this following September expirations.

Hope this made some sense!
 
Last edited by a moderator:
Replace the syntax on line 44 with this

def Sqr_Vol_2 = Sqr(Vol) * 0.5 * t;

Good luck

Fair Warning I cannot seem to get it to work for SPX. It seems to work ok on SPY and I also have no idea to make it vertical instead of horizontal.
 
Last edited:
I never use any script on my gamma exposure, I just use excel and compute them by time what direction they are heading, Look at the result
 

Attachments

  • 112624 SPX option.png
    112624 SPX option.png
    38.6 KB · Views: 63
  • 112724 SPX option.png
    112724 SPX option.png
    33.2 KB · Views: 64
  • 112724 SPX 2 option.png
    112724 SPX 2 option.png
    41 KB · Views: 64

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
307 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