Display only first two signals


Category:
0
0

alright. so this does what i want but i got one problem left with this.
i only want the first and second signal from a row of the same color. so if there is 20 dots in a row, i only want the first 2. how do i do that?
thanks a bunch. you have taught me a ton.

input showBreakoutSignals = yes;
input SMALength = 4;

def greencandle = open < close;
def redcandle = open > close;

def OBV = TotalSum(Sign(close – close[1]) * volume);
def SMA = Average(OBV, SMALength);

def obvbuy = OBV > SMA;
def obvsell = OBV < SMA;

def buy = if greencandle[5] then close > close[5] else close > open[5];
def sell = if greencandle[5] then close < close[5] else close < open [5];

plot buysignal = obvbuy is true and buy is true;
def sellsignal = obvsell is true and sell is true;

AssignBackgroundColor(if buysignal then Color.CYAN else if sellsignal then Color.YELLOW else Color.CURRENT);

Marked as spam
Posted by (Questions: 6, Answers: 5)
Asked on October 23, 2019 9:56 am
36 views
0
Private answer

I don't see anything in this code that plots dots. So I am guessing here. Your signals are generated as follows:

plot buysignal = obvbuy is true and buy is true;
def sellsignal = obvsell is true and sell is true;

There is some redundancy here so let's clear things up, and modify the variable names to use camelCase to make them easier to read:

def buySignal = obvBuy and buy;
def sellSignal = obvSell and sell;

Notice that I also changed the plot to def. Because in order to complete this we need a second stage. After modifying those two lines we can apply the second stage so that only the first and second consecutive "dots" or included.

plot minimizedBuy = (buySignal and !buySignal[1]) or (buySignal and !buySignal[2]);
plot minimizedSell = (sellSignal and !sellSignal[1]) or (sellSignal and !sellSignal[2]);

Give that a shot. I have not tested this. Just working from memory and experience.

Marked as spam
Posted by (Questions: 37, Answers: 4090)
Answered on October 23, 2019 1:55 pm
0
this seems to work. i will do more testing. since its for a watchlist it gave me the "exactly one plot expected" but thats an easy adjustment. i use the -input showBreakoutSignals = yes;- to pick dots in the menu. thank you for the help. this counting thing is where i still have problems figuring things out on my own. so why did you use -or- in this code? and why the !buySignal with !
( at October 24, 2019 4:45 am)
0
The 'or' was used because you want the first dot OR the second dot but not the third dot. The exclamation point applies the opposite of the variable it precedes. So placing the exclamation mark before buySignal literally means "NOT buySignal". (buySignal == false)
( at October 24, 2019 7:36 am)
0
thank you. the '!' still confuses me s i got to do reading on that. everything else makes sense now. you are a good teacher. i appreciate your time.
( at October 24, 2019 1:24 pm)
0
"!buySignal" is the exact same thing as "buySignal == no". They can be used interchangeably with the exact same results. "!buySignal" is the short-hand version.
( at October 24, 2019 3:47 pm)
0
i was just typing out my answer and more questions and as im typing i understood what you did there. now i get it. i just couldnt understand how saying yes and no in the same () made the signal. but now i get it. thank you
( at October 25, 2019 7:38 am)