Well, if you provide some details we may be able to get something working for you. But based on what you have given us so far: “I am looking to create signals from price crossing multiple levels of the Persons Pivots in the same trading day”…. we don’t have all the details.
I have to read your code to get a hint of what you are trying to achieve. But trying to read someone’s intention from the code is fraught with error. So let me explain the english version of what your two signals are doing.
up signal: “current bar crossed above PP and close has crossed above SS within the last 90 bars”
down signal: “current bar crossed below PP and close has crossed below RR within the last 90 bars”
So please use the comment section immediately below this answer to provide some more details.
Update: After receiving some clarification on this request I have a solution.
In order to make this correction you will locate and delete the following two lines of code:
plot up = close crosses above pp and (close crosses above ss) within 90 bars;
plot down = close crosses below pp and (close crosses below rr) within 90 bars;
Then within the exact same section of code you will replace those deleted lines with these:
def newDay = GetDay() <> GetDay()[1];
rec hasCrossedAbovePP = if newDay and !newDay[1] then 0 else if close[1] < PP[1] and close > PP then 1 else hasCrossedAbovePP[1];
rec hasCrossedBelowPP = if newDay and !newDay[1] then 0 else if close[1] > PP[1] and close < PP then 1 else hasCrossedBelowPP[1];
def crossAboveRR = close[1] < RR[1] and close > RR;
def crossBelowSS = close[1] > SS[1] and close < SS;
plot up = hasCrossedAbovePP and crossAboveRR;
plot down = hasCrossedBelowPP and crossBelowSS;
Thanks for clarifying. However it seems possible you have confused SS for RR. It’s a real shame you did not include a screenshot with your original question as this would have removed all doubt and made this much easier.
On the chart, RR is ABOVE the PP line and SS is BELOW PP. You have stated you want to detect price crossing above PP first, then crossing above SS, which is below PP. So what you have actually stated is that you need price to cross above PP, then cross back below it, and follow through to cross below SS, then finally cross back above SS. Did you really intend to state it his way?
Yes, indeed. Sorry for the confusion.
up = price crosses ABOVE the PP and then continues to cross ABOVE the RR
down = price crosses BELOW the PP and then continues to cross BELOW the SS
I have updated my answer with the code to correct the behavior of chart study.