Gapless Bollinger band in signal on two time frame

Questions about MultiCharts and user contributed studies.
marco21
Posts: 1
Joined: 10 Nov 2015

Gapless Bollinger band in signal on two time frame

Postby marco21 » 10 Nov 2015

Hello to the Multicharts forum,
I am trying to creates the following trading system which look at one stock on 5mins bar (serie of data1) bar and 60mins bars (seris of data4)
I am looking at this stock for my backtest without split adjustment so there is large gap on the historic.
To palliate this I tried to use the gapless bollinger band described here:
https://community.TS.com/disc ... c_id=77574

it works well for the serie of data1 in 5mins bar but doing the wrong calculation for the series of data4 in 60 mins and it work wekk when it is used as an indicator on each series.

But I am facing issue when I am using it in a signal.

the code of my signal is the following:

Code: Select all

variables:
RelO1h(open),
RelH1h(high),
RelL1h(low),
RelC1h(close),
Accum1h(0),
gap1h(0),
RelO(open),
RelH(high),
RelL(low),
RelC(close),
gap(0),
Accum(0),
third(1/3),
WtMean1h(third*(high+low+close)),
WtMean(third*(high+low+close)),
Avg( 0 ),
SDev( 0 ),
LowerBand( 0 ),
UpperBand( 0 ),
Avg1h( 0 ),
SDev1h( 0 ),
LowerBand1h( 0 ),
UpperBand1h( 0 );


// GapLess BB for 5mins bar
// gapless O,H,L,C where O=C[1]
if date<>date[1] then begin
gap = O-C[1];
Accum = Accum+gap;
end;

RelO = O-Accum;
RelC = C-Accum;
RelH = H-Accum;
RelL = L-Accum;

WtMean = third*(RelH+RelL+RelC);

// Gapless bars - end for 5mins bar
Avg = AverageFC( WtMean, BBLength ) + accum ;
SDev = StandardDev( WtMean, BBLength, 1 ) ;
UpperBand = Avg + NumDevsUp * SDev ;
LowerBand = Avg + NumDevsDn * SDev ;



// replication of the above calculation for the 60mins bar
if date of data4<>date of data4[1]
and time of data4<>time of data4[1] //to insulate the unique change of day on the 60mins bars
and time of data1 -time of data4<5
then begin
gap1h = open of data4 -Close of data4[1];
Accum1h = Accum1h+gap1h;

end;

if time of data4<>time of data4[1] //Attempt to get the Bollinger band calculated only once per 60mins bar
and time of data1 <>time of data1[1]

then begin
RelO1h = open of data4-Accum1h;
RelC1h = close of data4-Accum1h;
RelH1h = high of data4-Accum1h;
RelL1h = low of data4-Accum1h;

WtMean1h = third*(RelH1h+RelL1h+RelC1h);

// Gapless bars - end for 1h

Avg1h = AverageFC(WtMean1h, BBLength1h ) + Accum1h ;
SDev1h = StandardDev( WtMean1h, BBLength1h, 1 ) ;
UpperBand1h = Avg1h + NumDevsUp1h * SDev1h ;
LowerBand1h = Avg1h + NumDevsDn1h * SDev1h ;
end;



if marketposition=0
and H > UpperBand then begin
sellshort ( "1" ) next bar at H limit ;
end;

setprofittarget(200);


if marketposition=-1 and high of data4>UpperBand1h then begin
buytocover ( "1h exit" ) next bar at market ;

end;


print(date," ",time," ", C," ", Accum," ", date of data4," ",time of data4," ", High of data4,"",
close of data4,"C 1h ", open of data4,"o 1h", Accum1h,"accum",WtMean1h,"WtM 1h", Avg1h,"avg", UpperBand1h ,"Up BB1h " );
and the print results are:
Image


my problem is that the detected value of the gap for the 60mins bar series od data4 (i.e -0.12= close prevois day - open= 6.93-7.05) is reset at zero in the signal at the next 5mins bar.

The problem seems to come from because the chage of day do not happen on the sane bar for the 5mins bar and 6omins bar.

Do you know why or what I am doing wrong please to be able to use this indicator in my signal on both the 5mins and 60mins bars?

thank you.

Return to “MultiCharts”