Hi,
Sometimes it’s possible to catch good runs and to make some profit when Bollinger bands start to diverge after a squeeze. But as Nicolas and some other members mentioned it is difficult to program this squeeze and divergence. I did some backtesting in excel and the results are kind of OK depends of individual’s expectations. I need your help to write a code to screen the market for opportunities based on my excel spreadsheet.
The difference between upper and lower Bollinger bands must be smaller or equal to the minimum difference between Bollinerg bands over 100 periods multiplied with a constant (e.g. 1.1) (upper Bollinger – lower Bollinger) <= 1.1*min(upper Bollinger – lower Bollinger) over 100 periods . The signal that triggers a ‘buy’ will be given when the bands will start to diverge (current upper Bollinger > previous period upper Bollinger and current lower Bollinger > previous period lower Bollinger) with the price closing above upper Bollinger. To be on the conservative side 7 period moving average should be greater than 23 period moving average. I downloaded a spreadsheet and screenshot.
It is for an uptrend market on a weekly timeframe.
Thank you very much.
Best Regards,
Petru
Thanks. I will have a look at this next week. Remind me if I don’t
Fr7Participant
Master
Hi Petrus,
I tried to make your system, but I can not get the signal of divergence ……. Let’s see if Nicolás can improve it. I leave the indicator so you can see it and tell me where the fault may be.
BS=BollingerUp(close)
BI=BollingerDown(close)
BS100=BollingerUp[100](close)
BI100=BollingerDown[100](close)
DIF=(BI100-BS100)
DIFF100= (1.1 *min (DIF,0))
MA7=AVERAGE[7](CLOSE)
MA23=AVERAGE[23](CLOSE)
MMup=MA7>MA23
MMdown=MA7<MA23
/////////////////////condiTIONS///////////
if ((BS-BI) <= DIFF100) AND BS>BS[1] AND BI>BI[1] AND CLOSE>BS AND MMup then
direction = 1
elsif ((BS-BI) > DIFF100)AND CLOSE<BI and MMdown then
direction = -1
endif
if direction > 0 then
backgroundcolor(10,255,10,100)
else
backgroundcolor(255,10,10,100)
endif
RETURN BS as "BS",BI AS "BI",BS[1] AS "BS-PAST",BI[1] AS "BI-PAST",MA7 AS "MA7",MA23 AS "MA23",close AS "CLOSE"
Fr7Participant
Master
RETURN BS as "BS",BI AS "BI",BS[1] AS "BS-PAST",BI[1] AS "BI-PAST",MA7 AS "MA7",MA23 AS "MA23",close AS "CLOSE",bs100 as "BS100",bi100 as "BI100"
Fr7Participant
Master
Here the code without divergences
BS=BollingerUp(close)
BI=BollingerDown(close)
BS100=BollingerUp[100](close)
BI100=BollingerDown[100](close)
DIF=BS-BI
DIF100=(BI100-BS100)
MA7=AVERAGE[7](CLOSE)
MA23=AVERAGE[23](CLOSE)
MMup=MA7>MA23
MMdown=MA7<MA23
/////////////////////condiTIONS///////////
if DIF>DIF100 AND CLOSE>BS AND MMup then
direction = 1
elsif CLOSE<BI and MMdown then
direction = -1
endif
if direction > 0 then
backgroundcolor(10,255,10,100)
else
backgroundcolor(255,10,10,100)
endif
RETURN BS as "BS",BI AS "BI",BS[1] AS "BS-PAST",BI[1] AS "BI-PAST",MA7 AS "MA7",MA23 AS "MA23",close AS "CLOSE",bs100 as "BS100",bi100 as "BI100"
Thank you and I appreciate very much your help. As I mentioned it is a great forum and people like Nicolas, you and others is keeping it alive. Unfortunately my programming skills are not great but gladly I can share my ideas written in spreadsheets.
Hi again,
I do get ‘syntax error’ when I am using the code (see attached). Help me to fix this error, please. May be I am doing something wrong , but I don’t know where can be.
Regards]
Petru
ProScreener does not support graphic keywords, like BACKGROUNDCOLOR etc…, just comment them out. The code above is an indicator, you must work a tiny bit on it to convert it to a ProScreener code.
Please attach only .ITF files for import and screenshots for examples or to show issues you may encounter, or at most text files. Avoid attaching .PDF and especially .DOCx files, since many members might not have them installed thus reducing your chances to be helped.
I will try. I hope I can make it work.
Fr7 has made an indicator for you (thanks to him), not a screener. Here is my own view of your query:
bolup=BollingerUp[20](close)
boldn=BollingerDown[20](close)
diff=bolup-boldn
c1 = diff<=lowest[100](diff)*1.1
c2 = bolup>bolup[1] and boldn>boldn[1]
c3 = close > bolup
c4 = average[7]>average[23]
test = c1 and c2 and c3 and c4
screener[test]
Not so much results, c1 condition is very restrictive. Are you sure about c2 (where bolling upper band is superior to its previous one AND the same for the bollinger lower band).
Fr7Participant
Master
TIMEFRAME(DEFAULT)
BS=BollingerUp(close)
BI=BollingerDown(close)
BS100=BollingerUp[100](close)
BI100=BollingerDown[100](close)
DIF=BS-BI
DIF100=(BI100-BS100)
MA7=AVERAGE[7](CLOSE)
MA23=AVERAGE[23](CLOSE)
MMup=MA7>MA23
MMdown=MA7<MA23
/////////////////////condiTIONS///////////
if DIF>DIF100 AND CLOSE>BS AND MMup then
signal = 1////BULL SIGNAL
elsif CLOSE<BI and MMdown then
signal = -1////BEAR SIGNAL
endif
SCREENER (signal AS "signal")
Fr7Participant
Master
Here is the screener. In this are not divergences, you can try mine or Nicolas. And will say what is most appropriate.
Hi Nicolas and Fr7,
Nicolas, you’re right. My conditions are too restrictive and how market behaved in the last few days I don’t have many hits. I have to change a little bit.
Fr7, it is not what I wanted but for sure can be modified and I can use it. I wanted to compare the actual Bollinger difference with minimum (minimal or lowest) difference between bands in the last 100 periods with the same settings, not Bollinger bands with 100 periods as SMA and 2 standard deviations for BS100 and BI100, may be I wasn’t clear in my request
Thank you both of you for your help.
Regards,
Petru