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