a1cturner
Well-known member
I cannot figure out for the life of me why one of my sell triggers is not showing properly. I tried to define the crap out of it but it still isn't working.
I am trying to paint a red bar when the RSI crosses below 70 or when the RSI crosses above 30. As of now I am still getting my "hold signal"
I do get a red bar at the end of the day as well as when the EMAs cross but just not when the RSI crosses. It is supposed to be either the EMA cross or RSI cross but always at the end of the day.
Everywhere there is a Red Arrow should be a Red Bar instead.
I am trying to paint a red bar when the RSI crosses below 70 or when the RSI crosses above 30. As of now I am still getting my "hold signal"
I do get a red bar at the end of the day as well as when the EMAs cross but just not when the RSI crosses. It is supposed to be either the EMA cross or RSI cross but always at the end of the day.
Everywhere there is a Red Arrow should be a Red Bar instead.
Code:
#JT EMA, MACD, AND RSI INDICATOR
declare upper;
#EMAs
input EMA1 = 5;
input EMA2 = 12;
input EMA3 = 34;
input EMA4 = 50;
def EMAFast1 = ExpAverage(close, EMA1);
def EMAFast2 = ExpAverage(close, EMA2);
def EMASlow1 = ExpAverage(close, EMA3);
def EMASlow2 = ExpAverage(close, EMA4);
def EMAFastBull = EMAFast1 > EMAFast2;
def EMASlowBull = EMASlow1 > EMASlow2;
def EMAFastBear = EMAFast1 < EMAFast2;
def EMASlowBear = EMASlow1 < EMASlow2;
def EMAFastCrossDown = EMAFast1 crosses below EMAFast2;
def EMAFastCrossUp = EMAFast1 crosses above EMAFast2;
#EMA PERCENT
def EMAPct = ((EMA1 / EMA2) * 100) - 100;
def EMAPctRound = Round(EMAPct, 2);
def EMAPctBull = EMAPct >= EMAPct[1];
def EMAPctBear = EMAPct <= EMAPct[1];
def EMABull = EMAFastBull and EMASlowBull and EMAPctBull;
def EMABear = EMAFastBear and EMASlowBear and EMAPctBear;
#MACD
input MACDFast = 10;
input MACDSlow = 22;
input MACDLength = 8;
def Value = ExpAverage(close, MACDFast) - ExpAverage(close, MACDSlow);
def Average = ExpAverage(Value, MACDLength);
def MACDDiff = Value - Average;
def ZeroLine = 0;
def MACDBull = MACDDiff >= MACDDiff[1];
def MACDBear = MACDDiff <= MACDDiff[1];
#RSI
input RSILength = 14;
input RSIOverBought = 70;
input RSIOverSold = 30;
def NetChgAvg = WildersAverage(close - close[1], RSILength);
def TotChgAvg = WildersAverage(AbsValue(close - close[1]), RSILength);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
def RSIBull = RSI > 40 and RSI >= RSI[1];
def RSIBear = RSI < 60 and RSI <= RSI[1];
def RSICrossDown = RSI crosses below RSIOverBought;
def RSICrossUp = RSI crosses above RSIOverSold;
#START AND END TIME
input StartTime = 0930;
input StartTimeDelay = 30;
input EndTime = 1600;
input EndTimeDelay = 10;
input LastStop = 10;
def Start = SecondsFromTime(StartTime);
def StartSignalDelay = StartTimeDelay * 60;
def StartSignal = Start > StartSignalDelay;
def End = SecondsTillTime(EndTime);
def EndSignalDelay = EndTimeDelay * 60;
def EndSignal = End > EndSignalDelay;
def LastStopDelay = LastStop*60;
def TradingDay = StartSignal and EndSignal;
def EndDay = End == LastStopDelay;
#INDICATORS
def CallBuy = TradingDay and EMABull and MACDBull and RSIBull;
def CallHold = TradingDay and EMABull;
def CallPrev = CallBuy[1] or CallHold[1];
def PutBuy = TradingDay and EMABear and MACDBear and RSIBear;
def PutHold = TradingDay and EMABear;
def PutPrev = PutBuy[1] or PutHold[1];
def CallSell = TradingDay and (EMAFastCrossDown or RSICrossDown);
def PutSell = TradingDay and (EMAFastCrossUp or RSICrossUp);
def CallSignal = if
CallBuy == 1 and EndDay == 0 then CallBuy
else if
CallHold == 1 and CallBuy == 0 and EndDay == 0 then CallHold
else if
CallSell == 1 then CallSell
else if
CallBuy == 1 and EndDay == 1 then EndDay
else if
CallHold == 1 and EndDay ==1 then EndDay
else if
CallBuy == 0 and CallHold == 0 and EndDay ==1 then EndDay
else double.nan;
def PutSignal = if
PutBuy == 1 and EndDay == 0 then PutBuy
else if
PutHold == 1 and PutBuy == 0 and EndDay == 0 then PutHold
else if
PutSell == 1 and CallHold == 0 then PutSell
else if
PutBuy ==1 and EndDay == 1 then EndDay
else if
PutHold ==1 and EndDay == 1 then EndDay
else if
PutBuy == 0 and PutHold == 0 and EndDay ==1 then EndDay
else double.nan;
############TRYING TO ADD LINES AND PROFIT LABELS###############
#def CallOpen = if CallBuy then close else CallOpen[1];
#def CallClose = if CallSell then close else CallClose[1];
#def CallQty = 100;
#def CallProfit = (CallOpen * CallQty) - (CallClose * CallQty);
#addlabel(1, " ", color.black);
#addlabel(1, "Call Profit " + CallProfit, color.green);
#addlabel(1, "Trades " + CallQty/100, color.yellow);
#addlabel(1, "Avg Call Trade $ " + (CallProfit/CallQty), color.yellow);
#plot CBuy = if CallBuy or CallHold then CallClose else double.nan;
##cbuy.setdefaultcolor(color.green);
################################################################
#COLOR BARS
AssignPriceColor(if CallBuy then createcolor(0, 255, 0) else if CallHold then createcolor(153, 255, 153) else if PutBuy then createcolor(0, 0, 255) else if PutHold then createcolor(153, 153, 255) else if CallSell then createcolor(255, 0, 0) else if PutSell then createcolor(255, 0, 0) else if EndDay then createcolor(255, 0, 0) else color.dark_gray);
#ORDERS
input ShowOrders = no;
##BUY
AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and CallBuy, open[-1], 100, Color.GREEN, Color.LIGHT_GREEN, "BUY CALL");
AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and PutBuy, open[-1], 100, Color.GREEN, Color.LIGHT_GREEN, "BUY PUT");
##SELL
AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and CallSell or EndDay, open[-1], 100, Color.RED, Color.LIGHT_RED, "SELL CALL");
AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and PutSell or EndDay, open[-1], 100, Color.RED, Color.LIGHT_RED, "SELL PUT");