Hello fellow coders. I am working on a script to alert a sell but am trying to get rid of the redundant "sell" signals that follow.
I have my conditions met to give me a "buy" signal, and my conditions met to give a "sell" signal. However, the issue is that when a sell signal is thrown, there are sometimes 2 or 3 more "sell" signals that follow. I am trying to code out the "sell" signals that follow the first. I am trying to figure out a way to only have one entry and one exit point plotted on my chart. I know i need it to be a conditional "If" statement, just unsure of the syntax that is involved. Essentially, when a condition to buy or sell is met, i want the script to look back to ensure that the same signal has not already been thrown as the last signal. For example, if the "sell" condition is met, but the last signal is also a "sell" signal, it would return false to avoid a redundant trip. If the last signal was a "buy" signal, the return would be true and would throw a "sell" signal. Script Below
input Length = 20;
input Price = close;
input displace = 0;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.EXPONENTIAL;
def EMA = MovAvgExponential("length" = 200);
def sDev = StDev(data = Price[-displace], length = Length);
def Buy = Price crosses above EMA within 1 bar;
def BBUpper = BollingerBands("length" = Length)."Upper_Band";
def Sell = close crosses below BBUpper within 1 bar;
plot BUYSIGNAL = Buy;
BUYSIGNAL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BUYSIGNAL.SetDefaultColor(Color.GREEN);
BUYSIGNAL.SetLineWeight(5);
plot SELLSIGNAL = Sell;
SELLSIGNAL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SELLSIGNAL.SetDefaultColor(Color.RED);
SELLSIGNAL.SetLineWeight(5);
plot MidLine = MovingAverage(averageType, data = Price[-displace], length = Length);
MidLine.SetDefaultColor(GetColor(1));
plot LowerBand = MidLine + Num_Dev_Dn * sDev;
LowerBand.SetDefaultColor(GetColor(0));
plot UpperBand = MidLine + Num_Dev_up * sDev;
UpperBand.SetDefaultColor(GetColor(5));
I feel like I am overthinking this which is why i am unable to get the code to work.
Thanks for the help.
Corey
I have my conditions met to give me a "buy" signal, and my conditions met to give a "sell" signal. However, the issue is that when a sell signal is thrown, there are sometimes 2 or 3 more "sell" signals that follow. I am trying to code out the "sell" signals that follow the first. I am trying to figure out a way to only have one entry and one exit point plotted on my chart. I know i need it to be a conditional "If" statement, just unsure of the syntax that is involved. Essentially, when a condition to buy or sell is met, i want the script to look back to ensure that the same signal has not already been thrown as the last signal. For example, if the "sell" condition is met, but the last signal is also a "sell" signal, it would return false to avoid a redundant trip. If the last signal was a "buy" signal, the return would be true and would throw a "sell" signal. Script Below
input Length = 20;
input Price = close;
input displace = 0;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.EXPONENTIAL;
def EMA = MovAvgExponential("length" = 200);
def sDev = StDev(data = Price[-displace], length = Length);
def Buy = Price crosses above EMA within 1 bar;
def BBUpper = BollingerBands("length" = Length)."Upper_Band";
def Sell = close crosses below BBUpper within 1 bar;
plot BUYSIGNAL = Buy;
BUYSIGNAL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BUYSIGNAL.SetDefaultColor(Color.GREEN);
BUYSIGNAL.SetLineWeight(5);
plot SELLSIGNAL = Sell;
SELLSIGNAL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SELLSIGNAL.SetDefaultColor(Color.RED);
SELLSIGNAL.SetLineWeight(5);
plot MidLine = MovingAverage(averageType, data = Price[-displace], length = Length);
MidLine.SetDefaultColor(GetColor(1));
plot LowerBand = MidLine + Num_Dev_Dn * sDev;
LowerBand.SetDefaultColor(GetColor(0));
plot UpperBand = MidLine + Num_Dev_up * sDev;
UpperBand.SetDefaultColor(GetColor(5));
I feel like I am overthinking this which is why i am unable to get the code to work.
Thanks for the help.
Corey