OptionsTrader
New member
Hey I have this code ive been working on for a while. I finally got everything going for it except for signals and 1 label.
Here is the code:
I want the chop label to be Cyan when none of the other things are true. That doesn't seem to work (bonus points if you can get them all to just be in one label lol)
But more importantly, I want to create 4 different types of signals and I think the code would go something like this:
Basically if all Bullish conditions are true AND a Green candle closes above the high of a blue candle over the last 10 bars then signal Long. Opposite for shorts.
For reversals its the MACDBullReversal and BullCloudReversal are true. Opposite for BearReversal. However I want it to signal on the first candle that all those are true for.
Thanks! Let me know if you have any questions
Here is the code:
Code:
declare once_per_bar;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def theta = GetYYYYMMDD();
def LRV = Inertia(close - ((Highest(high, 20) + Lowest(low, 20)) / 2 + ExpAverage(close, 20)) / 2, 20);
def Value = MovingAverage(AverageType.EXPONENTIAL, close, 10) - MovingAverage(AverageType.EXPONENTIAL, close, 50);
def Avg = MovingAverage(AverageType.EXPONENTIAL, Value, 9);
def periodIndx = theta;
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def VWAP = volumeVwapSum / volumeSum;
def RTH = if SecondsTillTime(1600) >= 0 and SecondsFromTime(925) >= 0 then 1 else 0;
#Cloud 1 Start
input ChartShortLength = 34;
input ChartLongLength = 50;
input AvgType = AverageType.EXPONENTIAL;
def CShort = MovingAverage(AvgType, close, ChartShortLength);
def CLong = MovingAverage(AvgType, close, ChartLongLength);
def BullCloud = CShort > CLong;
def BearCloud = CShort < CLong;
#Cloud 2 Start (Higher Timeframe)
input Period = AggregationPeriod.FIFTEEN_MIN;
input ChartShortLength2 = 5;
input ChartLongLength2 = 13;
input AvgType2 = AverageType.EXPONENTIAL;
def CShort2 = MovingAverage(AvgType, close (period = AggregationPeriod.FIFTEEN_MIN), ChartShortLength2);
def CLong2 = MovingAverage(AvgType, close (period = AggregationPeriod.FIFTEEN_MIN), ChartLongLength2);
def BullCloud2 = CShort2 > CLong2;
def BearCloud2 = CShort2 < CLong2;
#macd start
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};
def MACDValue = MovingAverage(AverageType, close(period = AggregationPeriod.FIFTEEN_MIN), fastLength) - MovingAverage(AverageType, close(period = AggregationPeriod.FIFTEEN_MIN), slowLength);
def MACDAvg = MovingAverage(AverageType, MACDValue, MACDLength);
def MACDBull = MACDValue > 0 and MACDAvg > 0 and MACDValue > MACDAvg;
def MACDBear = MACDValue < 0 and MACDAvg < 0 and MACDValue < MACDAvg;
#CandleTrend Start
def bulltrend = if ((Value > 0 and Avg > 0)) and (LRV > 0 and NetChgAvg > 0) and close[1] > VWAP[1] and close > VWAP and CShort > CLong and CShort2 > CLong2 and MACDBull then 1 else 0;
def beartrend = if ((Value < 0 and Avg < 0)) and (LRV < 0 and NetChgAvg < 0) and close[1] < VWAP[1] and close < VWAP and CShort < CLong and CShort2 < CLong2 and MACDBear then 1 else 0;
def NeutralTrend = !beartrend and !bulltrend;
DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Neutral", Color.BLUE);
DefineGlobalColor("Bearish", Color.RED);
AssignPriceColor(if bulltrend then GlobalColor("Bullish") else if beartrend then GlobalColor("Bearish") else GlobalColor ("Neutral"));
#TrendLabel
def OTrendBull = MACDBull and BullCloud and BullCloud2;
def OTrendBear = MACDBear and BearCloud and BearCloud2;
def BullCloudReversal = BullCloud and close > CLong2;
def BearCloudReversal = BearCloud and close < CLong2;
def MACDBullReversal = MACDValue < 0 and MACDAvg < 0 and MACDValue > MACDAvg or MACDValue > 0 and MACDValue > MACDAvg;
def MACDBearReversal = MACDValue > 0 and MACDAvg > 0 and MACDValue < MACDAvg or MACDValue < 0 and MACDValue < MACDAvg;
def Chop = !OTrendBull and !OTrendBear and !BullCloudReversal and !BearCloudReversal and !MACDBullReversal and !MACDBearReversal;
AddLabel(1, "TREND: Bull", if OTrendBull then Color.GREEN else Color.YELLOW);
AddLabel(1, "TREND: Bear", if OTrendBear then Color.RED else Color.YELLOW);
AddLabel(1, "Reversal: Bull", if BullCloudReversal and MACDBullReversal then Color.GREEN else Color.YELLOW);
AddLabel(1, "Reversal: Bear", if BearCloudReversal and MACDBearReversal then Color.RED else Color.YELLOW);
AddLabel (1, "Chop", if Chop then Color.CYAN else Color.YELLOW);
#End
I want the chop label to be Cyan when none of the other things are true. That doesn't seem to work (bonus points if you can get them all to just be in one label lol)
But more importantly, I want to create 4 different types of signals and I think the code would go something like this:
Code:
AddChartBubble(close[1] and bulltrend and close[1] > high[10] and NeutralTrend, low, "Long", GlobalColor("Bull Labels"), yes);
AddChartBubble(close[1] and beartrend and close[1] > low[10] and NeutralTrend, high, "Short", GlobalColor("Bear Labels"), yes);
AddChartBubble (close[1] and MACDBullReversal and BullCloudReversal, low, "Bullish Reversal", GlobalColor("BullReversal Labels"), yes);
AddChartBubble (close[1] and MACDBearReversal and BearCloudReversal, high, "Bullish Reversal", GlobalColor("BearReversal Labels"), yes);
DefineGlobalColor("Bull Labels", Color.Dark_GREEN);
DefineGlobalColor("Bear Labels", Color.Dark_RED);
DefineGlobalColor("BullReversal Labels", Color.GREEN);
DefineGlobalColor("BearReversal Labels", Color.RED);
Basically if all Bullish conditions are true AND a Green candle closes above the high of a blue candle over the last 10 bars then signal Long. Opposite for shorts.
For reversals its the MACDBullReversal and BullCloudReversal are true. Opposite for BearReversal. However I want it to signal on the first candle that all those are true for.
Thanks! Let me know if you have any questions