Help creating signals

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:

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
 
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:

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


i added some labels and a bubble to the end of your code
disabled you labels


the bubble shows the variables in the chop formula. it will turn cyan when chop is true.
i never saw chop as true.
i think you will need to look over the variables used for chop and figure out why it doesn't go true.


instead of combining all of the labels, which can get messy, might be easier to show a label only if the signal is true.
should only be 1 at a time or non of them.


in your bubbles, you have a price, close[1], as one of the conditions. although a number should be treated as a true, it would be better if close is compared to something, not just a price by itself.


i added some code at the end for green and blue candles... but your words don't describe which bars to compare, for the 10 bars.
so this isn't finished.


Code:
# bull_bear_chop_signals_00

#https://usethinkscript.com/threads/help-creating-signals.15593/
#Help creating signals
#0ptionsTrader  6/8

#I have this code ive been working on for a while. I finally got everything going for it except for signals and 1 label.



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;

input labels1 = no;
AddLabel(labels1, "TREND: Bull", if OTrendBull then Color.GREEN else Color.YELLOW);
AddLabel(labels1, "TREND: Bear", if OTrendBear then Color.RED else Color.YELLOW);
AddLabel(labels1, "Reversal: Bull", if BullCloudReversal and MACDBullReversal then Color.GREEN else Color.YELLOW);
AddLabel(labels1, "Reversal: Bear", if BearCloudReversal and MACDBearReversal then Color.RED else Color.YELLOW);

AddLabel(labels1, "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:


input bubbles1 = no;
AddChartBubble(bubbles1 and close[1] and bulltrend and close[1] > high[10] and NeutralTrend, low, "Long", GlobalColor("Bull Labels"), no);
AddChartBubble(bubbles1 and close[1] and beartrend and close[1] > low[10] and NeutralTrend, high, "Short", GlobalColor("Bear Labels"), yes);
AddChartBubble(bubbles1 and close[1] and MACDBullReversal and BullCloudReversal, low, "Bullish Reversal", GlobalColor("BullReversal Labels"), no);
AddChartBubble(bubbles1 and 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);



#------------------------

# redo the labels

# instead of combining all of the labels , only show a label if the signal is true. should only be 1 at a time or non
# add a white separator label

input labels2 = yes;

addlabel(labels2, "   ", color.white);

AddLabel(labels2 and OTrendBull, "TREND: Bull", if OTrendBull then Color.GREEN else Color.YELLOW);
AddLabel(labels2 and OTrendBear, "TREND: Bear", if OTrendBear then Color.RED else Color.YELLOW);
AddLabel(labels2 and BullCloudReversal and MACDBullReversal, "Reversal: Bull", if BullCloudReversal and MACDBullReversal then Color.GREEN else Color.YELLOW);
AddLabel(labels2 and BearCloudReversal and MACDBearReversal, "Reversal: Bear", if BearCloudReversal and MACDBearReversal then Color.RED else Color.YELLOW);

AddLabel(labels2 and chop, "Chop", if Chop then Color.CYAN else Color.YELLOW);


#-------------------

# show a bubble with several variables

input test3_bubbles = no;
addchartbubble(test3_bubbles, low, 
chop + "\n" +
!OTrendBull + "\n" +
!OTrendBear + "\n" +
!BullCloudReversal + "\n" +
!BearCloudReversal + "\n" +
!MACDBullReversal + "\n" +
!MACDBearReversal
, (if chop then color.cyan else color.gray), no);



#--------------------

#AssignPriceColor(if bulltrend then GlobalColor("Bullish") else if beartrend then GlobalColor("Bearish") else GlobalColor ("Neutral"));


# 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.

def blu = (!bulltrend and !beartrend);

def up = OTrendBull and BullCloudReversal and MACDBullReversal;
def grn = close > open;

def dwn = OTrendBear and BearCloudReversal and MACDBearReversal;
def red = close < open;

# not sure which bars to compare for the '10 bars'


# 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.

#
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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