How to remove redundant signals

RegularRob

New member
VIP
Hi, I get multiple signals that clutter up my chart with arrows. What is the best way to only plot one arrow if conditions are met?

Code:
plot signal = if positive5 and oktobuy and positive and arrows
then 2
else 0;

plot signal2 = if negative5 and oktoshort and negative and arrows
then 1
else 0;

Alert(alert and signal == 2, "Ok_to_Buy", Alert.bar, Sound.Ding);
signal.SetDefaultColor(Color.violet);
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.setLineWeight (1);

Alert( alert and signal2 ==1, "Ok_to_Short", Alert.bar, Sound.Ding);
signal2.SetDefaultColor(Color.violet);
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
signal2.setLineWeight (1);
 

RegularRob

New member
VIP
Code:
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
input Period = aggregationPeriod.five_MIN;
input arrows = yes;
input alert= yes;

plot ema5 = MovingAverage(averageType.EXPONENTIAL, close(period = period), 200);
ema5.setdefaultcolor(color.white);
def value5 = MovingAverage(macdAverageType, close(period = period), fastLength) - MovingAverage(macdAverageType, close(period = period), slowLength);
def average5 = MovingAverage(macdAverageType, value5, macdLength);

Def positive5 = average5 is less than or equal to MACD()."ZeroLine" and close(period = period) is greater than ema5;
Def negative5 = average5 is greater than or equal to MACD()."ZeroLine" and close(period = period) is less than ema5;

def positive =  MACD()."Avg"  is less than MACD()."ZeroLine";
Def negative =MACD()."avg" is Greater than MACD()."ZeroLine";

def oktobuy = TTM_Wave()."Wave2High" is greater than or equal to TTM_Wave()."Wave2High" from 1 bars ago and TTM_Squeeze()."Histogram" is greater than or equal to TTM_Squeeze()."Histogram" from 1 bars ago;
def oktoshort = TTM_Wave()."Wave2High"  is less than or equal to TTM_Wave()."Wave2High" from 1 bars ago and TTM_Squeeze()."Histogram" is less than or equal to TTM_Squeeze()."Histogram" from 1 bars ago;

plot signal = if positive5 and oktobuy and positive and arrows
then 2
else 0;

plot signal2 = if negative5 and oktoshort and negative and arrows
then 1
else 0;

Alert(alert and signal == 2, "Ok_to_Buy", Alert.bar, Sound.Ding);
signal.SetDefaultColor(Color.violet);
signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
signal.setLineWeight (1);

Alert( alert and signal2 ==1, "Ok_to_Short", Alert.bar, Sound.Ding);
signal2.SetDefaultColor(Color.violet);
signal2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
signal2.setLineWeight (1);
 

BenTen

Administrative
Staff
VIP
@RegularRob Here you go, try this:

Code:
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input macdAverageType = AverageType.EXPONENTIAL;
input Period = aggregationPeriod.five_MIN;
input arrows = yes;
input alert= yes;

plot ema5 = MovingAverage(averageType.EXPONENTIAL, close(period = period), 200);
ema5.setdefaultcolor(color.white);
def value5 = MovingAverage(macdAverageType, close(period = period), fastLength) - MovingAverage(macdAverageType, close(period = period), slowLength);
def average5 = MovingAverage(macdAverageType, value5, macdLength);

Def positive5 = average5 is less than or equal to MACD()."ZeroLine" and close(period = period) is greater than ema5;
Def negative5 = average5 is greater than or equal to MACD()."ZeroLine" and close(period = period) is less than ema5;

def positive =  MACD()."Avg"  is less than MACD()."ZeroLine";
Def negative =MACD()."avg" is Greater than MACD()."ZeroLine";

def oktobuy = TTM_Wave()."Wave2High" is greater than or equal to TTM_Wave()."Wave2High" from 1 bars ago and TTM_Squeeze()."Histogram" is greater than or equal to TTM_Squeeze()."Histogram" from 1 bars ago;
def oktoshort = TTM_Wave()."Wave2High"  is less than or equal to TTM_Wave()."Wave2High" from 1 bars ago and TTM_Squeeze()."Histogram" is less than or equal to TTM_Squeeze()."Histogram" from 1 bars ago;

def signal = if positive5 and oktobuy and positive and arrows
then 2
else 0;

def signal2 = if negative5 and oktoshort and negative and arrows
then 1
else 0;

plot arrow = signal and signal[1] is false;
plot arrow2 = signal2 and signal2[1] is false;


Alert(alert and signal == 2, "Ok_to_Buy", Alert.bar, Sound.Ding);
arrow.SetDefaultColor(Color.violet);
arrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
arrow.setLineWeight(1);

Alert( alert and signal2 ==1, "Ok_to_Short", Alert.bar, Sound.Ding);
arrow2.SetDefaultColor(Color.violet);
arrow2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_Down);
arrow2.setLineWeight(1);
 

Similar threads

Top