Ajordan930
New member
Ok I have been messing around with building an indicator (very new to coding) that is based on a strategy that is a variation of a system from a trader on Facebook who has a discord but with some adjustments based on a technique used by a friend of mine.
Code below.
Indicator includes
Strategy in a nutshell to qualify for "A+ set up
Bullish set up
Code below.
Indicator includes
- 4 ema's
- 1 is a 1 ema dot
- VWAP w/2SD
- 50 SMA
- 200 SMA
- Labels for the following
- ADD
- VIX
- TICK
- RSI
- Position status (Long Calls, No Set Up, Short Puts, Long Reversal, or Short Reversal)
Strategy in a nutshell to qualify for "A+ set up
Bullish set up
- 2 consecutive Heikin Ashi candles bullish
- 9 over 21 ema
- price over VWAP
- RSI over 55
Ruby:
# Section 1: Moving Averages (EMAs and SMAs)
#--------------------------------------------
input EmaDotLength = 1;
input ShortEmaLength = 9;
input MidEmaLength = 15;
input LongEmaLength = 21;
input showCloud = yes; # Option to turn the EMA cloud on/off
# Define EMAs
def emaDot = ExpAverage(close, EmaDotLength); # EMA Dot (1-period)
def shortEma = ExpAverage(close, ShortEmaLength);
def MidEma = ExpAverage(close, MidEmaLength);
def LongEma = ExpAverage(close, LongEmaLength);
# Plot EMA Dot (1-period EMA as a white dot)
plot EmaDotPlot = emaDot;
EmaDotPlot.SetPaintingStrategy(PaintingStrategy.POINTS);
EmaDotPlot.SetDefaultColor(Color.WHITE);
EmaDotPlot.SetLineWeight(2);
plot ShortEMAPlot = shortEma;
ShortEMAPlot.SetDefaultColor(Color.CYAN);
ShortEMAPlot.SetLineWeight(2);
plot MidEMAPlot = MidEma;
MidEMAPlot.SetDefaultColor(Color.grAY);
MidEMAPlot.SetLineWeight(1);
plot LongEmaPlot = LongEma;
LongEMAPlot.SetDefaultColor(Color.white);
LongEMAPlot.SetLineWeight(3);
# Cloud between short and long EMAs (toggle with showCloud)
AddCloud(if showCloud then shortEma else Double.NaN, if showCloud then LongEma else Double.NaN, Color.GREEN, Color.RED);
# Define SMAs
input FastSMALength = 50;
input SlowSMALength = 200;
def sma50 = SimpleMovingAvg(close, FastSMALength);
def sma200 = SimpleMovingAvg(close, SlowSMALength);
# Plot SMAs
plot Sma50Plot = sma50;
Sma50Plot.SetDefaultColor(Color.GREEN);
Sma50Plot.SetLineWeight(2);
Sma50Plot.SetStyle(Curve.MEDIUM_DASH);
plot Sma200Plot = sma200;
Sma200Plot.SetDefaultColor(Color.RED);
Sma200Plot.SetLineWeight(2);
Sma200Plot.SetStyle(Curve.MEDIUM_DASH);
#STUDY adds label with current TICK reading
addLabel(Yes, "$TICK: " + close("$TICK"),if close("$TICK") > 0 then color.green else color.red );
addLabel(Yes, "$ADD: " + close("$ADD"),if close("$ADD") > 0 then color.green else color.red );
addLabel(Yes, "VIX: " + close("VIX"),if close("VIX") > 0 then color.red else color.green );
# Section 2: Technical Indicators (VWAP, RSI Calc)
#--------------------------------------------------------------
input showVWAP = yes; # Option to show VWAP
input showVWAP_SD = yes; # Option to show VWAP with 2 SD bands
# VWAP Calculation
def vwap = reference VWAP()."VWAP";
def vwapSDUpper = vwap + 2 * stdev(close, 10); # 2 SD upper band
def vwapSDLower = vwap - 2 * stdev(close, 10); # 2 SD lower band
# Plot VWAP and SD bands based on user settings
plot VWAPLine = if showVWAP then vwap else Double.NaN;
VWAPLine.SetDefaultColor(Color.PLUM);
VWAPLine.SetLineWeight(2);
plot VWAPUpperBand = if showVWAP and showVWAP_SD then vwapSDUpper else Double.NaN;
VWAPUpperBand.SetDefaultColor(Color.PLUM);
VWAPUpperBand.SetLineWeight(1);
VWAPUpperBand.SetStyle(Curve.SHORT_DASH);
plot VWAPLowerBand = if showVWAP and showVWAP_SD then vwapSDLower else Double.NaN;
VWAPLowerBand.SetDefaultColor(Color.PLUM);
VWAPLowerBand.SetLineWeight(1);
VWAPLowerBand.SetStyle(Curve.SHORT_DASH);
# RSI
# Define RSI
input rsiLength = 14;
input rsiOversold = 55;
input rsiOverbought = 55;
def rsi = RSI(length = rsiLength);
# Add RSI Label
AddLabel(yes, "RSI: " + AsText(rsi, NumberFormat.TWO_DECIMAL_PLACES),
if rsi > rsiOverbought then Color.GREEN
else if rsi < rsiOversold then Color.RED
else Color.YELLOW);
# Section 4: Strategy Logic
#--------------------------
# ATR Input for bubble offset
input atrLength = 14; # Length of ATR calculation
input atrMultiplier = 1.0; # ATR Multiplier for offset
input showBubbles = no; # Option to show/hide A+ bubbles
# Calculate ATR
def atr = Average(TrueRange(high, close, low), atrLength);
# Calculate Heikin Ashi Candles
def haClose = (open + high + low + close) / 4;
def haOpen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open + close) / 2);
# Define Bullish and Bearish Heikin Ashi Candles
def isBullishHaCandle = haClose > haOpen;
def isBearishHaCandle = haClose < haOpen;
# Conditions for Long, Short, and Reversal
def longCondition = shortEma > longEma and isBullishHaCandle[1] and isBullishHaCandle and rsi > rsiOverbought and close > vwap;
def shortCondition = shortEma < longEma and isBearishHaCandle[1] and isBearishHaCandle and rsi < rsiOversold and close < vwap;
def reversalCondition1 = shortEma > longEma and isBullishHaCandle[1] and isBullishHaCandle and rsi > rsiOverbought and close < vwap;
def reversalCondition2 = shortEma < longEma and isBearishHaCandle[1] and isBearishHaCandle and rsi < rsiOversold and close > vwap;
# Track the first bar where longCondition or shortCondition is true
rec firstLong = if longCondition and !longCondition[1] then 1 else 0;
rec firstShort = if shortCondition and !shortCondition[1] then 1 else 0;
# Offset bubble locations by ATR
def longBubbleOffset = low - (atrMultiplier * atr);
def shortBubbleOffset = high + (atrMultiplier * atr);
# Add Chart Bubbles for the first instance of long or short condition with ATR offset, respect showBubbles input
AddChartBubble(showBubbles and firstLong, longBubbleOffset, "A+Buy", Color.Green, no); # Long condition bubble
AddChartBubble(showBubbles and firstShort, shortBubbleOffset, "A+Sell", Color.Red, yes); # Short condition bubble
Last edited by a moderator: