Opening Tick Clarification!

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

Opening Tick Clarification!

Postby SUPER » 25 Nov 2011

I am running following test code to see what vaules I get for "Open", "High", "Low" and "Close" on the first tick of a bar, to my surprise they are different, it was my belief that on first tick of a new bar they all should be same. I will appreciate clarification.

Code: Select all

[IntrabarOrderGeneration = True]

Vars: Intrabarpersist FirstTickLow(0),Intrabarpersist FirstTickHigh(0),Intrabarpersist FirstTickOpen(0),
Intrabarpersist FirstTickClose(0),Intrabarpersist CloseOfPrevBar(0);

if BarStatus=2 then CloseOfPrevBar=C;

if BarStatus(1)=1 then begin
FirstTickLow=Low;
FirstTickHigh=High;
FirstTickOpen=Open;
FirstTickClose=Close;
end;
Print(BarNumber,",","CloseOfPrevBar=",CloseOfPrevBar,",","FirstTickLow=",FirstTickLow,",",
"FirstTickHigh=",FirstTickHigh,",","FirstTickOpen=",FirstTickOpen,",","FirstTickClose=",FirstTickClose);


Test results:
  • 569.00,CloseOfPrevBar=5466.00,FirstTickLow=5463.00,FirstTickHigh=5466.00,FirstTickOpen=5466.00,FirstTickClose=5463.00
    569.00,CloseOfPrevBar=5466.00,FirstTickLow=5463.00,FirstTickHigh=5466.00,FirstTickOpen=5466.00,FirstTickClose=5465.00
    569.00,CloseOfPrevBar=5465.00,FirstTickLow=5463.00,FirstTickHigh=5466.00,FirstTickOpen=5466.00,FirstTickClose=5465.00
    570.00,CloseOfPrevBar=5465.00,FirstTickLow=5463.00,FirstTickHigh=5466.00,FirstTickOpen=5466.00,FirstTickClose=5465.00 570.00,CloseOfPrevBar=5465.00,FirstTickLow=5461.50,FirstTickHigh=5462.50,FirstTickOpen=5462.50,FirstTickClose=5461.50
    570.00,CloseOfPrevBar=5465.00,FirstTickLow=5461.50,FirstTickHigh=5462.50,FirstTickOpen=5462.50,FirstTickClose=5462.00

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

Re: Opening Tick Clarification!

Postby JoshM » 26 Nov 2011

Hi Super,
I am running following test code to see what vaules I get for "Open", "High", "Low" and "Close" on the first tick of a bar, to my surprise they are different, it was my belief that on first tick of a new bar they all should be same. I will appreciate clarification.
I've taken the liberty to rewrite your script and couldn't find any inconsistencies with the opening tick. For example, the output...

Code: Select all

--------------- -------------- -----------------
1915 Last: 116.04 Open: 116.04 High: 116.04 Low: 116.04 PrevClose: 116.05
1915 Last: 116.05 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.04 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.05 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.04 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.05 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.04 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.05 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.04 Open: 116.04 High: 116.05 Low: 116.04 PrevClose: 116.05
1915 Last: 116.06 Open: 116.04 High: 116.06 Low: 116.04 PrevClose: 116.06
--------------- -------------- -----------------
1916 Last: 116.07 Open: 116.07 High: 116.07 Low: 116.07 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.06 PrevClose: 116.06
1916 Last: 116.05 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.05 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.07 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.07 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.05 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.05 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.05 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.07 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.06 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.06
1916 Last: 116.07 Open: 116.07 High: 116.07 Low: 116.05 PrevClose: 116.07
--------------- -------------- -----------------
1917 Last: 116.08 Open: 116.08 High: 116.08 Low: 116.08 PrevClose: 116.07
1917 Last: 116.07 Open: 116.08 High: 116.08 Low: 116.07 PrevClose: 116.07
1917 Last: 116.08 Open: 116.08 High: 116.08 Low: 116.07 PrevClose: 116.07
1917 Last: 116.09 Open: 116.08 High: 116.09 Low: 116.07 PrevClose: 116.07
..is correct if you look at the first tick (i.e. "Last: ...") of each bar: the high and low for that bar are equal to the opening tick (as should be expected). If a following new tick is lower or higher than the High or Low for that bar, the corresponding high or low value is updated to reflect that.

Unless I overlooked an error, the output above is correct. Why your output is off, I don't know for sure. Perhaps this is caused by your BarStatus statement, or do you have 'Skip identical ticks' on? (Btw, since it's weekend, the above output is based on PlayBack data)

Anyway, here's the code:

Code: Select all

[IntrabarOrderGeneration = True]

Variables:
IntraBarPersist BarLow(0), // "low price of the current bar"
IntraBarPersist BarHigh(0), // "high price of the current bar"
IntraBarPersist BarOpen(0), // "open price of the current bar"
IntraBarPersist CloseOfPrevBar(0), // Close of previous bar
currentBarNumber(0),
IntraBarPersist PrevBarNumber(0), // for 'bar break' in output
barBreakText(""),
lastPrice(0); // last price/tick

if LastBarOnChart_s = True then begin

currentBarNumber = BarNumber;

lastPrice = Close; // or 'last' when using real-time data

BarLow = Low;
BarHigh = High;
BarOpen = Open;

// Generate a string to highlight the difference between bars
if (currentBarNumber <> PrevBarNumber) then
barBreakText = Text("---------------", Spaces(5), "--------------", Spaces(5), "-----------------", NewLine)
else
barBreakText = "";

// Save last price previous bar
if BarStatus(1) = 2 then
CloseOfPrevBar = lastPrice;

Print(barBreakText,
NumToStr(currentBarNumber, 0), Spaces(3), "Last: ", NumToStr(lastPrice, 2),
Spaces(3), "Open: ", NumToStr(BarOpen, 2),
Spaces(3), "High: ", NumToStr(BarHigh, 2),
Spaces(3), "Low: ", NumToStr(BarLow, 2),
Spaces(3), "PrevClose: ", NumToStr(CloseOfPrevBar, 2)
);

PrevBarNumber = currentBarNumber;
end;
Regards,
Josh

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

Re: Opening Tick Clarification!

Postby SUPER » 26 Nov 2011

JoshM

Many thanks for your feedback, I really admire your programing skills.

I will try out your code on Monday when I have access to live data, I suspect BarStatus(1)=1 could be responsible as I do remember from old discussion that it does not work same way as TS. Yes, I have "skip identical ticks" selection and will try out test without it also.

Have a great weekend.

Regards
Super

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Opening Tick Clarification!

Postby TJ » 26 Nov 2011

JoshM

Many thanks for your feedback, I really admire your programing skills.

I will try out your code on Monday when I have access to live data, I suspect BarStatus(1)=1 could be responsible as I do remember from old discussion that it does not work same way as TS. Yes, I have "skip identical ticks" selection and will try out test without it also.

Have a great weekend.

Regards
Super
why are you using

BarStatus(1)=1

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

Re: Opening Tick Clarification!

Postby SUPER » 26 Nov 2011

TJ,

I use intrabar strategy and would like to work within the bar, so my calculation would like to keep track of open, high, low, close of the working bar and for that reason it is very important that I have correct values to work with.

"BarStatus(1)=1", represents "tick within a bar" as per definition and based on this assumption the first tick theoritically should reflect the opening values of the new bar.

Regards
Super

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

Re: Opening Tick Clarification!

Postby SUPER » 28 Nov 2011

JoshM,

Your code works perfectly, and it gave me some valuable clues with regard to coding intrabarorder generated system. What I figured out is that all intrabar calculations should be at top part of the code(begining section) followed by calculation performed end of the bar.

Also another interesting bit is that BarStatus(1)=0 gives you correct values of the first tick, which I have been trying so hard to find.

BarStatus(1)=1 skips the first tick of the bar which was messing up my code.

Once again many thanks for your help.

Regards
Super


Return to “MultiCharts”