Bands dont build correctly Upper and Lower

Posted By: qweqwe

Bands dont build correctly Upper and Lower - 08/27/17 17:51

Hi! I have a problem! Why BBands build Lower and Upper not properly?

This is my code

Click to reveal..

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(priceClose())),signal,NbDevUp,NbDevDn,MAType_SMA);
vars upperBand = series(rRealUpperBand);
vars lowerBand = series(rRealLowerBand);

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

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

}



Description: This
Attached picture Untitled.png
Posted By: sodiumchloride

Re: Bands dont build correctly Upper and Lower - 09/01/17 13:32

hey,
i changed your script little bit
- removed the optimization
- changed filling to grey (black filling = wtf??, but i guess u thought the color of the lower band is the color of the lower band grin it aint :D)
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;


int signal = 30;
vars Close = series(priceClose());
var NbDevUp= 2;
var NbDevDn =2;
BBands((series(priceClose())),signal,NbDevUp,NbDevDn,MAType_SMA);
vars upperBand = series(rRealUpperBand);
vars lowerBand = series(rRealLowerBand);

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();

}


looks "normal" now. so, its about your optimized parameters?
have you entered the resulting parameters f.e. in metatrader 4? and then check is the BB "disappear" there too?
greetings
Posted By: qweqwe

Re: Bands dont build correctly Upper and Lower - 09/01/17 16:45

Thx! Yes, now its correct! But I would like to use it with optimization. It means my code is crearly? and Bands lag cause of optimization settings?
Posted By: johnnyp

Re: Bands dont build correctly Upper and Lower - 09/15/17 06:17

@sodiumchloride try again with signal = 20 instead of 30. The bands are certainly not normal.

Posted By: Brax

Re: Bands dont build correctly Upper and Lower - 09/15/17 20:06

Hi.

I´ve seen all your threads concerning BBands.

The problem is simple, BBands in TA-lib is buggy, especially for intraday ranges. The solution is here:

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=441209

If you use hourly or daily bars is unlikely for this error to appear.

Hope it helps.
Posted By: johnnyp

Re: Bands dont build correctly Upper and Lower - 09/16/17 08:52

Brilliant. Thanks.

It is a pity that the search function on this forum is limited to one year, otherwise I would have found it.
Posted By: Brax

Re: Bands dont build correctly Upper and Lower - 09/16/17 11:41

Yes, the search function shouldn´t be restricted.

I think i found it googling "bbands plot zorro" or something similar...

Glad it worked.
© 2024 lite-C Forums