Help on a SHOWBAR and SHOWVIEW script

Hi,

I am trying to script a signal into the showbar tool. I want to see a green arrow when price closes above the upper line of a 125-day Bollinger Band set to 1 standard deviation and I also want to see a red arrow when price closes below the lower line of a 125-day Bollinger Band set to 1 standard deviation. I have two separate scripts for this that are working:

Close() CrossesAbove BB(BARS=125, STDDEV=1.000000)
Close() CrossesBelow BB(BARS=125, DEFAULT=LowerLine, STDDEV=1.000000)

I now want to take this a step further. Please take a look at the attached pictures. Picture 1 is what I want to see and picture 1 is what my current scripts show. The difference is that I don’t want to see a green arrow every time the close is above the upper BB. I want to see a green arrow every time price crosses above the upper BB after a red arrow has triggered - which happens when price closes below the lower BB, but that only when it happens after a green arrow is triggered. How do I make it so my green arrow shows only after a red arrow and my red arrow shows only after a green arrow?

As a second part of this, you will notice that I have tried to recreate the bottom plot from picture 1 using the showview tool in picture 2. It does not look like picture 1. The signal is given but then does not stay shaded until the next signal. How do I recreate this?

Thank you so much!

Hi,

This can be done using a mix of SignalAfter() functions and the Switch() function.

For the arrows on the chart you can use the following:

Crosses Above

V1 = Close() CrossesAbove BB(BARS=125, STDDEV=1.000000);
V2 = Close() CrossesBelow BB(BARS=125, DEFAULT=LowerLine, STDDEV=1.000000);
SIGNALAFTER(V2,V1)

Crosses Below

V1 = Close() CrossesAbove BB(BARS=125, STDDEV=1.000000);
V2 = Close() CrossesBelow BB(BARS=125, DEFAULT=LowerLine, STDDEV=1.000000);
SIGNALAFTER(V1,V2)

For the Indicator along the bottom the following will work:

V1 = Close() CrossesAbove BB(BARS=125, STDDEV=1.000000);
V2 = Close() CrossesBelow BB(BARS=125, DEFAULT=LowerLine, STDDEV=1.000000);
V3 = SWITCH(V1,V2);
IF(V3 == 1,1,-1)

This is how it would all look on a chart…
Ex2

Thank you very much. This works perfectly.