Noob Questions - Ignore if historic?

Questions about MultiCharts and user contributed studies.
AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Noob Questions - Ignore if historic?

Postby AntiMatter » 09 Mar 2011

Question 1)
E.g. I do something like

if close > open then
begin
do something.....

However, I don't want it to "do something" when loading historic bars. Only on real-time bars. e.g. something like if (close > open ) and ( data != historic) then....

Question 2)
I applied a script to a 5 min resolution. When run in real time, it seems to be evaluate my script on each tick. Thus I used "if barstatus = 0" to only evaluate on the first tick of each new bar. But this seems to now miss some bars!!! How do I evaluate an expression only once every bar?

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Noob Questions - Ignore if historic?

Postby TJ » 09 Mar 2011

AntiMatter wrote:Question 1)
E.g. I do something like

if close > open then
begin
do something.....

However, I don't want it to "do something" when loading historic bars. Only on real-time bars. e.g. something like if (close > open ) and ( data != historic) then....


LastBarOnChart (Function)


The LastBarOnChart function is used to determine if the current bar being evaluated is the last bar on the chart.

Syntax
LastBarOnChart


Returns (Boolean)
True if LastBarOnChart is the last charted bar. False if not.


Parameters
None


Example
In order to play a wave (sound) file only in the last bar of the chart you can write:

If LastBarOnChart Then
Condition1 = PlaySound("C:\window\ding.wav");



Note
This function will return True for all bars on a chart with tick-based interval, which have the same date and time as the last bar of the chart.

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: Noob Questions - Ignore if historic?

Postby TJ » 09 Mar 2011

AntiMatter wrote:...
Question 2)
I applied a script to a 5 min resolution. When run in real time, it seems to be evaluate my script on each tick. Thus I used "if barstatus = 0" to only evaluate on the first tick of each new bar. But this seems to now miss some bars!!! How do I evaluate an expression only once every bar?

try

barstatus = 2

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Re: Noob Questions - Ignore if historic?

Postby janus » 10 Mar 2011

AntiMatter wrote:Question 2)
I applied a script to a 5 min resolution. When run in real time, it seems to be evaluate my script on each tick. Thus I used "if barstatus = 0" to only evaluate on the first tick of each new bar. But this seems to now miss some bars!!! How do I evaluate an expression only once every bar?


If for some reason you are finding barstatus = 0 unreliable, and you really want to know the FIRST tick of a bar then you need to check first when barstatus = 2 (last tick of preceding bar) then use the next tick regardless of the barstatus value (0 or 1). Note too you may also see -1 if you are using multiple data series in the same study, in which case you ignore that tick as it will be a repeat of the one with barstatus = 2.

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: Noob Questions - Ignore if historic?

Postby AntiMatter » 10 Mar 2011

OK thanks for the help people.

Hmmmn...

When I do this:

if ( LastBarOnChart = True ) and ( BarStatus = 2 ) and ( my_bar_count = 1 ) and ( Close > Open ) then
... print some stuff to a file...

Sometimes it gets evaluated twice - e.g. I get two print statements with the same date/time/bar stamp. I really only want one.

Moreover, on tick-resolution market replay, sometimes the above condition is evaluated as false, when it really should be true.

janus
Posts: 755
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 84 times

Re: Noob Questions - Ignore if historic?

Postby janus » 10 Mar 2011

You shouldn't be seeing more than one barstatus=2 tick in a row for studies that update on every tick; that's odd.

As for seeing ticks with the same date/time, that occurs all the time at the end and the beginning of each bar. You should see the following sequence of events on say a 1-minute chart with update on every tick turned on for an indicator or IOG turned on for a signal:

tick with barstatus = 2
tick with barstatus = 0
tick with barstatus = 1

all three with the exact same time. They are generated off the same trigger and so you see them in a cluster of three. Also, the volume associated with the barstatus = 2 tick is always equal to the volume of the previous tick with barstatus = 1. In other words, the barstatus = 2 is a repeat of the previous one. It makes sense since there's no way to know when the last tick has arrived until the bar interval has closed (plus a few seconds more if no other tick has arrived with a time stamp in the next bar to take into account of the latency with data feeds). So, the extra tick is generated to let us know the previous tick was in fact the last tick. Discussions about a better approach to this have been done elsewhere so I won't go into the details. Basically the solution is to use millisecond time stamps when the exchanges provide them. Although not still 100% accurate, it's virtually 100% and more than good enough even for a high frequency scalper. For now we are stuck with the current approach, which is fine for most traders.

If you are wondering how far apart these three ticks are in real time, then the answer I've found on my PC is somewhere around 0 to 30 ms. More often than not they are within one CPU tick count. Also, given I have to use a special routine to make these measurements, it will itself introduce a small delay. So, for all intents and purposes these three update ticks are at the same time, and don't appear to rely on any extra update tick from the data feed. In other words, either it times out when the market is quiet or an fresh tick arrives, and in either case MC generates these three as a burst. At least that's what I've discovered.

The other issue though is very quiet markets where there is no fresh tick for a long while, you may not see a barstatus = 2 tick for say 30 seconds or more on a 1-minute chart. I consider this to be wrong. If a bar is completed according to MC's guidelines (up to about 3 seconds later when no fresh tick has arrived) then it should push out the barstatus = 2 tick immediately, and wait until later to push out the other two. It may be splitting hairs but it should be consistent in its logic.

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: Noob Questions - Ignore if historic?

Postby AntiMatter » 11 Mar 2011

janus wrote:You shouldn't be seeing more than one barstatus=2 tick in a row for studies that update on every tick; that's odd.


lol, i'm an idiot. I had a study inserted on a RT Market scanner, and then a linked chart, with the same study inserted. Doh.

Thanks very much for the informative reply. Believe it or not, I have tried digging around the help files and searching the forum..... search function isn't great though.

I still have the problem that the following evaluates as true on realtime data, but false when I replay the exact same date through the replayer tick-by-tick:
if ( LastBarOnChart = True ) and ( BarStatus = 2 ) and ( my_bar_count = 1 ) and ( Close > Open ) then....
????

AntiMatter
Posts: 60
Joined: 03 Mar 2011
Has thanked: 9 times
Been thanked: 2 times

Re: Noob Questions - Ignore if historic?

Postby AntiMatter » 11 Mar 2011

Hmmmn, further investigations, I don't understand what is going on here.

I am simply trying to count bars through the course of a day.
I have a 5min bars chart.
I am replaying tick-by-tick.
My Study is updated on every tick.

if ( Date <> Date[1] ) then current_day_bar = 0;
if ( BarStatus = 2 ) then current_day_bar = current_day_bar + 1;
plot1( current_day_bar, "DayBar");

The first bar is bar 1.
*But* the second bar is also bar 1
Then the third bar is bar 2, then everything is as expected e.g. 3,4,5,6 etc...


Return to “MultiCharts”