BarStatus(1)=2 - IOG - Clarification

Questions about MultiCharts and user contributed studies.
SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

BarStatus(1)=2 - IOG - Clarification

Postby SUPER » 19 Jul 2012

I am trying to compare value of variable on last tick using BarStatus(1)=2 and "[]" previous bar option in a IOG strategy and have found that on last tick of the bar the values are not same, I don't know if this is exected behaviour or not, so will appreciate some clarification please.

Code: Select all


633.00 , 19-07-12 13:50:24 , BarStatus_Value = 6761.50 , PrevBar_Value = 6761.50
633.00 , 19-07-12 13:50:30 , BarStatus_Value = 6761.50 , PrevBar_Value = 6761.50
633.00 , 19-07-12 13:50:35 , BarStatus_Value = 6761.50 , PrevBar_Value = 6761.50
633.00 , 19-07-12 13:50:37 , BarStatus_Value = 6761.50 , PrevBar_Value = 6761.50
633.00 , 19-07-12 13:50:37 , BarStatus_Value = 6760.50 , PrevBar_Value = 6761.50 <<<<
634.00 , 19-07-12 13:50:38 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
634.00 , 19-07-12 13:50:47 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
634.00 , 19-07-12 13:50:47 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
634.00 , 19-07-12 13:50:49 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
634.00 , 19-07-12 13:50:51 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
634.00 , 19-07-12 13:50:52 , BarStatus_Value = 6760.50 , PrevBar_Value = 6760.50
Sample Strategy code:

Code: Select all

[IntrabarOrderGeneration = True]


Vars: IntrabarPersist BarStatus_Value(0), IntrabarPersist PrevBar_Value(0);


if BarStatus(1)=2 then BarStatus_Value = Round2Fraction ( C );

PrevBar_Value = Round2Fraction(C )[1];


Print( BarNumber," , ",date_time," , "," BarStatus_Value = ", BarStatus_Value," , "," PrevBar_Value = ", PrevBar_Value);

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: BarStatus(1)=2 - IOG - Clarification

Postby JoshM » 19 Jul 2012

pulled back for the second time

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: BarStatus(1)=2 - IOG - Clarification

Postby JoshM » 19 Jul 2012

I was a little bit too soon responding with my first reply, but it seems you're right, depending on how you look at it:

It seems to me that on BarStatus = 2, the close of the bar, Close[1] still refers to the close the previous bar (i.e. not the current bar close). On BarStatus = 1, the Close[1] seems to refer to the tick from BarStatus = 2.

(With the assumption that I read the output below correctly - but I'm not very sure about that :) ).

From 1 minute chart:

Code: Select all

19-07_16:37:58 1 468 Close: 2297 PrevClose: 2297 PrevCloseValue: 2297
19-07_16:37:58 1 468 Close: 2296 PrevClose: 2297 PrevCloseValue: 2297
19-07_16:37:58 1 468 Close: 2297 PrevClose: 2297 PrevCloseValue: 2297
19-07_16:37:59 1 468 Close: 2296 PrevClose: 2297 PrevCloseValue: 2297
19-07_16:38:04 2 468 Close: 2296 PrevClose: 2297 PrevCloseValue: 2296
19-07_16:38:04 0 469 Close: 2296 PrevClose: 2296 PrevCloseValue: 2296
19-07_16:38:07 1 469 Close: 2296 PrevClose: 2296 PrevCloseValue: 2296
19-07_16:38:08 1 469 Close: 2297 PrevClose: 2296 PrevCloseValue: 2296
19-07_16:38:08 1 469 Close: 2297 PrevClose: 2296 PrevCloseValue: 2296
19-07_16:38:08 1 469 Close: 2297 PrevClose: 2296 PrevCloseValue: 2296

Code: Select all

[IntrabarOrderGeneration = True]


Vars:
IntraBarPersist PrevCloseValue(0),
numDeci(DecimalsOfInstrument);

if BarStatus(1) = 2 then
PrevCloseValue = Close;

if (LastBarOnChart_s = True) then begin

once cleardebug;

Print(TimeNow, NumToStr(BarStatus(1), 0), Spaces(3), NumToStr(CurrentBar, 0), Spaces(3),
"Close: ", NumToStr(Close, numDeci), Spaces(3), "PrevClose: ", NumToStr(Close[1], numDeci),
Spaces(3), "PrevCloseValue: ", NumToStr(PrevCloseValue, numDeci));

end;

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: BarStatus(1)=2 - IOG - Clarification

Postby Henry MultiСharts » 19 Jul 2012

Square brackets [1] always refer to the previous bar. That is possible to reference to the previous tick only if your chart resolution is 1 tick.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: BarStatus(1)=2 - IOG - Clarification

Postby SUPER » 19 Jul 2012

Square brackets [1] always refer to the previous bar. That is possible to reference to the previous tick only if your chart resolution is 1 tick.
Henry, Do I take it that the BarStatus(1)=2 working observed by above code is to design and expectation.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: BarStatus(1)=2 - IOG - Clarification

Postby Henry MultiСharts » 24 Jul 2012

Henry, Do I take it that the BarStatus(1)=2 working observed by above code is to design and expectation.
Hello SUPER,

Yes the code provided above works as expected.

Code: Select all

19-07_16:38:04 2 468 Close: 2296 PrevClose: 2297 PrevCloseValue: 2296
"PrevClose" remains the same because the bar is still open on the moment of calculation. The value is updated on the opening tick of the next bar, when the code knows that the bar is closed.

Code: Select all

if BarStatus(1) = 2 then
PrevCloseValue = Close;
Close value is assigned to the "PrevCloseValue" on the last (closing) tick of the bar.
The line with discrepancy appears in the output because you are referencing to logically different values.


Return to “MultiCharts”