# Variables for trade entry signals
Input TradeEntryStartTimeEST = 945;
Input TradeEntryEndTimeEST = 1600;
def TradeEntryRange = if SecondsTillTime(TradeEntryStartTimeEST) <= 0 and
SecondsTillTime(TradeEntryEndTimeEST) >= 0 then 1 else 0;
# EMA Difference - to know the different between EMA and candle close
input EMALength = 10;
def EMADiff = AbsValue(ExpAverage(close, EMALength)) - close;
# Super Trend 1
Input st1AltMult = 2;
input st1_Length = 10;
def ATR1 = ATR(ST1_Length, AverageType.HULL);
def UP_Band_Basic = HL2 + (ST1AltMult * ATR1);
def LW_Band_Basic = HL2 + (-ST1AltMult * ATR1);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];
def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > UP_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
def Long = if close > ST then ST else Double.NaN;
def Short = if close < ST then ST else Double.NaN;
def LTrigger = isNaN(Long[1]) and !isNaN(Long);
def STrigger = isNaN(Short[1]) and !isNaN(Short);
# Super Trend 2
Input st2_AltMult = 4;
input st2_Length = 10;
def ATR2 = ATR(ST2_Length, AverageType.HULL);
def UP_Band_Basic1 = HL2 + (ST2_AltMult * ATR2);
def LW_Band_Basic1 = HL2 + (-ST2_AltMult * ATR2);
def UP_Band1 = if ((UP_Band_Basic1 < UP_Band1[1]) or (close[1] > UP_Band1[1])) then UP_Band_Basic1 else UP_Band1[1];
def LW_Band1 = if ((LW_Band_Basic1 > LW_Band1[1]) or (close[1] < LW_Band1[1])) then LW_Band_Basic1 else LW_Band1[1];
def ST1 = if ((ST1[1] == UP_Band1[1]) and (close < UP_Band1)) then UP_Band1
else if ((ST1[1] == UP_Band1[1]) and (close > UP_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1[1]) and (close > LW_Band1)) then LW_Band1
else if ((ST1[1] == LW_Band1) and (close < LW_Band1)) then UP_Band1
else LW_Band1;
def Long1 = if close > ST1 then ST1 else Double.NaN;
def Short1 = if close < ST1 then ST1 else Double.NaN;
def LTrigger1 = isNaN(Long1[1]) and !isNaN(Long1);
def STrigger1 = isNaN(Short1[1]) and !isNaN(Short1);
# RSI
input RSIOverbought= 60;
input RSIOversold = 40;
input RSILength = 14;
def NetChange = MovingAverage(AverageType.WILDERS, close - close[1], rsilength);
def TotChange = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), rsilength);
def ChgRatio = if TotChange != 0 then NetChange / TotChange else 0;
def RSI = 50 * (ChgRatio + 1);
def longRSI = RSI > rsioverbought;
def shortRSI = RSI < rsioversold;
def bullcrossovercondST = TradeEntryRange and long and long1 and longRSI and EMADiff < 10;
def bearcrossovercondST = TradeEntryRange and Short and short1 and shortRSI and EMADiff < 10;
plot Bullish =
if (long1 and ltrigger) or (long and ltrigger1) then
if longrsI then bullcrossovercondST else double.nan
else if (!bullcrossovercondST[1] and bullcrossovercondST) then bullcrossovercondST else double.nan ;
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(8));
Bullish.SetLineWeight(2);
plot Bearish =
if (short1 and strigger) or (short and strigger1) then
if shortrsI then bearcrossovercondST else double.nan
else if (!bearcrossovercondST[1] and bearcrossovercondST) then bearcrossovercondST else double.nan ;
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(8));
Bearish.SetLineWeight(2);