Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 728 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Bollinger Bands: upper and lower band unite with middle band #441209
05/15/14 12:38
05/15/14 12:38
Joined: Jul 2013
Posts: 3
M
michas Offline OP
Guest
michas  Offline OP
Guest
M

Joined: Jul 2013
Posts: 3
I am trying to plot a price curve with Bollinger Bands. Using the sample code from Zorro help seems to work. However, there are periods when all three bands unite. For instance using price data from 12/2/2013 between 5am and 7am (but one can find this in any others day data). How come?

Best wishes

Michas

I am using the following code:

function run()
{
set(PLOTNOW);

StartDate = 20121203;
EndDate = 20121203;

BarPeriod = 1;

BBands(series(price()),30,2,2,MAType_SMA);
plot("Bollinger1",rRealUpperBand,BAND1,0x000000CC);
plot("Bollinger2",rRealLowerBand,BAND2,0x800000FF);
plot("Price", price(),LINE, RED);

}

Attached Files BBands.png
Re: Bollinger Bands: upper and lower band unite with middle band [Re: michas] #441233
05/16/14 06:23
05/16/14 06:23
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The Bollinger Bands function is not from Zorro, but from the TA-Lib, so I can't say why it unites. Maybe this happens due to gaps in the data. 1-minute data are very likely to have gaps. We'll look into that, maybe we can automatically fill the gaps for working around such cases.

Re: Bollinger Bands: upper and lower band unite with middle band [Re: jcl] #441242
05/16/14 10:35
05/16/14 10:35
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Ok, I was informed that the reason was _not_ gaps in the data, but a lower limit to the standard deviation function in the TA-Lib. If the StdDev is below 0.0001, it's assumed to be zero. Therefore you'll get bands with zero width.

As a simple workaround, just multiply the data with 10 for preventing that the StdDev gets below 0.0001:

BBands(series(10*price()),30,2,2,MAType_SMA);
plot("Bollinger1",rRealUpperBand/10,BAND1,0x000000CC);
plot("Bollinger2",rRealLowerBand/10,BAND2,0x800000FF);

Re: Bollinger Bands: upper and lower band unite with middle band [Re: jcl] #468070
09/16/17 14:51
09/16/17 14:51
Joined: Aug 2017
Posts: 40
J
johnnyp Offline
Newbie
johnnyp  Offline
Newbie
J

Joined: Aug 2017
Posts: 40
This isn't mentionned in the manual, and unlike the SAR, a corrected lite-c version hasn't been made.

Why?

I can understand not wanting to replace the current function because it might throw off some existing strategies, but at the very least this should be mentioned in the Remarks section of the manual page on indicators.

Re: Bollinger Bands: upper and lower band unite with middle band [Re: jcl] #468136
09/19/17 17:04
09/19/17 17:04
Joined: Aug 2017
Posts: 3
Q
qweqwe Offline
Guest
qweqwe  Offline
Guest
Q

Joined: Aug 2017
Posts: 3
But, How we can use it with optimize function?

Re: Bollinger Bands: upper and lower band unite with middle band [Re: qweqwe] #468138
09/19/17 19:25
09/19/17 19:25
Joined: Aug 2017
Posts: 40
J
johnnyp Offline
Newbie
johnnyp  Offline
Newbie
J

Joined: Aug 2017
Posts: 40
Just multiply the prices by 10 before calculating the bands, then divide by 10 before storing/using the results.

Code:
function run()
{
StartDate = 20170501;
EndDate = 20170502;
NumWFOCycles = 10;
DataSplit = 60; // activate WFO
NumCores = 4;
BarPeriod = 5;
set(BINARY);
Slippage = 0;
Spread = Commission = 0;
LifeTime = 1;

WinPayout = 75;
LossPayout = 0;

set(PARAMETERS);
int signal = optimize(20,5,30,1);
vars Close = series(priceClose());
var NbDevUp = optimize(2,1,4,0.5);
var NbDevDn = optimize(2,1,4,0.5);
BBands((series(10*priceClose())),signal,NbDevUp,NbDevDn,MAType_SMA);
vars upperBand = series(rRealUpperBand/10);
vars lowerBand = series(rRealLowerBand/10);

plot("Bollinger1",rRealUpperBand,BAND1,BLACK);
plot("Bollinger2",rRealLowerBand,BAND2,GREY);
set(PLOTNOW);

if (crossOver(Close, upperBand))
enterShort(); //close short trades and open a long position
if (crossUnder(Close, lowerBand))
enterLong();

}


Re: Bollinger Bands: upper and lower band unite with middle band [Re: johnnyp] #468146
09/20/17 08:55
09/20/17 08:55
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
If you trade a low value asset as Corn/USD I recommend to use x100, more safe...


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1