i modify the Standard Deviation CHannel Code to become 2 more Lines...
When i load the Study its okay like but one bar later the calculation is wrong like I mark all modify by me as //NEW
Code: Select all
inputs:
Length (50), { // Length of Linear Regression // }
BeginDate ( 0), { // Choose Zero to use full length // }
BeginTime ( 0), { // Choose Zero to use full time // }
EndDate ( 0), { // Choos?e Zero for Current Day // }
EndTime ( 0), { // Choose Zero for Current Time // }
NumInnerCircleUP( 1), { // Standard deviations for upper // }
NumInnerCircleDOWN( -1), { // Standard deviations for lower // }
NumOuterCircleUP1 ( 1.618), { // Standard deviations for upper // }
NumOuterCircleDOWN1 ( -1.618), { // Standard deviations for lower // }
NumOuterCircleUP2 ( 2.618), { // Standard deviations for upper // }
NumOuterCircleDOWN2 ( -2.618), { // Standard deviations for lower // }
SEEColor(Blue) , { // Color for Lower Boundary // }
ExtRight ( false), { // Set to true to extend to right // }
ExtLeft ( false); { // Set to true to extend to left // }
variables:
FirstDate ( 0 ), FirstTime ( 0 ),
UpperBand ( 0 ), UpperBand_1 ( 0 ),UpperBand_2 ( 0 ),UpperBand_21 ( 0 ), UpperBand_3 ( 0 ),UpperBand_31 ( 0 ),
LowerBand ( 0 ), LowerBand_1 ( 0 ), LowerBand_2 ( 0 ),LowerBand_21 (0), LowerBand_3 ( 0 ),LowerBand_31 (0),
LRV ( 0 ), LRV_1 ( 0 ), TL_LRV ( 0 ), TL_UB ( 0 ), TL_LB ( 0 ), TL_UB2 ( 0 ), TL_LB2 ( 0 ), TL_UB3 ( 0 ), TL_LB3 ( 0 ),
Flag ( 0 ),
Size(1),
SDev ( 0 );
if BeginDate = 0 then
FirstDate = date[ Length - 1 ] else FirstDate = BeginDate;
if BeginTime = 0 then
FirstTime = time[ Length - 1 ] else FirstTime = BeginTime;
{ ///////////////////////////////////////////////////////////////////// }
if Flag = 0 then
begin
if ( EndDate = CurrentDate or EndDate = 0 ) and LastBarOnChart then begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDEV =StdError(Close, Length);
UpperBand = LRV + NumInnerCircleUP* SDev;
LowerBand = LRV + NumInnerCircleDOWN* SDev;
UpperBand_1 = LRV_1 + NumInnerCircleUP* SDev;
LowerBand_1 = LRV_1 + NumInnerCircleDOWN* SDev;
UpperBand_2 = LRV + NumOuterCircleUP1 * SDev; //NEW
LowerBand_2 = LRV + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_21 = LRV_1 + NumOuterCircleUP1 * SDev; //NEW
LowerBand_21 = LRV_1 + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_3 = LRV + NumOuterCircleUP2 * SDev; //NEW
LowerBand_3 = LRV + NumOuterCircleDOWN2 * SDev; //NEW
UpperBand_31 = LRV_1 + NumOuterCircleUP2 * SDev; //NEW
LowerBand_31 = LRV_1 + NumOuterCircleDOWN2 * SDev; //NEW
TL_LRV = TL_New( FirstDate, FirstTime, LRV_1, date, time, LRV );
TL_UB = TL_New( FirstDate, FirstTime, UpperBand_1, date, time, UpperBand );
TL_LB = TL_New( FirstDate, FirstTime, LowerBand_1, date, time, LowerBand );
TL_UB2 = TL_New( FirstDate, FirstTime, UpperBand_21, date, time, UpperBand_2 ); //NEW
TL_LB2 = TL_New( FirstDate, FirstTime, LowerBand_21, date, time, LowerBand_2); //NEW
TL_UB3 = TL_New( FirstDate, FirstTime, UpperBand_31, date, time, UpperBand_3 ); //NEW
TL_LB3 = TL_New( FirstDate, FirstTime, LowerBand_31, date, time, LowerBand_3); //NEW
Flag = 1 ;
end
else if date = EndDate and ( time = EndTime or EndTime = 0 ) then begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDEV = StdError(Close, Length);
UpperBand = LRV + NumInnerCircleUP* SDev;
LowerBand = LRV + NumInnerCircleDOWN* SDev;
UpperBand_1 = LRV_1 + NumInnerCircleUP* SDev;
LowerBand_1 = LRV_1 + NumInnerCircleDOWN* SDev;
UpperBand_2 = LRV + NumOuterCircleUP1 * SDev; //NEW
LowerBand_2 = LRV + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_21 = LRV_1 + NumOuterCircleUP1 * SDev; //NEW
LowerBand_21 = LRV_1 + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_3 = LRV + NumOuterCircleUP2 * SDev; //NEW
LowerBand_3 = LRV + NumOuterCircleDOWN2 * SDev; //NEW
UpperBand_31 = LRV_1 + NumOuterCircleUP2 * SDev; //NEW
LowerBand_31 = LRV_1 + NumOuterCircleDOWN2 * SDev; //NEW
TL_LRV = TL_New( FirstDate, FirstTime, LRV_1, date, time, LRV );
TL_UB = TL_New( FirstDate, FirstTime, UpperBand_1, date, time, UpperBand );
TL_LB = TL_New( FirstDate, FirstTime, LowerBand_1, date, time, LowerBand );
TL_UB2 = TL_New( FirstDate, FirstTime, UpperBand_21, date, time, UpperBand_2 ); //NEW
TL_LB2 = TL_New( FirstDate, FirstTime, LowerBand_21, date, time, LowerBand_2); //NEW
TL_UB3 = TL_New( FirstDate, FirstTime, UpperBand_31, date, time, UpperBand_3 ); //NEW
TL_LB3 = TL_New( FirstDate, FirstTime, LowerBand_31, date, time, LowerBand_3); //NEW
Flag = 2;
end;
if Flag = 1 or Flag = 2 then begin
TL_SetColor( TL_LRV, SEEColor );
TL_SetColor( TL_UB, SEEColor );
TL_SetColor( TL_LB, SEEColor );
TL_SetColor( TL_UB2, SEEColor ); //NEW
TL_SetColor( TL_LB2, SEEColor ); //NEW
TL_SetColor( TL_UB3, SEEColor ); //NEW
TL_SetColor( TL_LB3, SEEColor ); //NEW
TL_SetStyle(TL_LRV,2);
TL_SetStyle(TL_LB3,5);
TL_SetStyle(TL_UB3,5);
TL_SetSize(TL_LRV, Size);
TL_SetSize(TL_UB2, size);
TL_SetSize(TL_LB2, size);
TL_SetExtLeft( TL_LRV, ExtLeft );
TL_SetExtLeft( TL_UB, ExtLeft );
TL_SetExtLeft( TL_LB, ExtLeft );
TL_SetExtRight( TL_LRV, ExtRight );
TL_SetExtRight( TL_UB, ExtRight );
TL_SetExtRight( TL_LB, ExtRight );
end;
end
else
if Flag = 1 then begin
LRV = LinearRegValue( Close, Length, 0 );
LRV_1 = LinearRegValue( Close, Length, Length - 1 );
SDEV = StdError(Close, Length);
UpperBand = LRV + NumInnerCircleUP* SDev;
LowerBand = LRV + NumInnerCircleDOWN* SDev;
UpperBand_1 = LRV_1 + NumInnerCircleUP* SDev;
LowerBand_1 = LRV_1 + NumInnerCircleDOWN* SDev;
UpperBand_2 = LRV + NumOuterCircleUP1 * SDev; //NEW
LowerBand_2 = LRV + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_21 = LRV_1 + NumOuterCircleUP1 * SDev; //NEW
LowerBand_21 = LRV_1 + NumOuterCircleDOWN1 * SDev; //NEW
UpperBand_3 = LRV + NumOuterCircleUP2 * SDev; //NEW
LowerBand_3 = LRV + NumOuterCircleDOWN2 * SDev; //NEW
UpperBand_31 = LRV_1 + NumOuterCircleUP2 * SDev; //NEW
LowerBand_31 = LRV_1 + NumOuterCircleDOWN2 * SDev; //NEW
TL_SetBegin( TL_LRV, FirstDate, FirstTime, LRV_1 );
TL_SetBegin( TL_UB, FirstDate, FirstTime, UpperBand_1 );
TL_SetBegin( TL_LB, FirstDate, FirstTime, LowerBand_1 );
TL_SetBegin( TL_UB2, FirstDate, FirstTime, UpperBand_2 ); //NEW
TL_SetBegin( TL_LB2, FirstDate, FirstTime, LowerBand_2 ); //NEW
TL_SetBegin( TL_UB3, FirstDate, FirstTime, UpperBand_3 ); //NEW
TL_SetBegin( TL_LB3, FirstDate, FirstTime, LowerBand_3 ); //NEW
TL_SetEnd( TL_LRV, date, time, LRV );
TL_SetEnd( TL_UB, date, time, UpperBand );
TL_SetEnd( TL_LB, date, time, LowerBand );
TL_SetEnd( TL_UB2, date, time, UpperBand_1 ); //NEW
TL_SetEnd( TL_LB2, date, time, LowerBand_1); //NEW
TL_SetEnd( TL_UB3, date, time, UpperBand_2 ); //NEW
TL_SetEnd( TL_LB3, date, time, LowerBand_2); //NEW
end;
![Sad :(](./images/smilies/icon_sad.gif)
Best Regards