[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dll problem



PureBytes Links

Trading Reference Links

"MICHAEL STEWART" <MPST@xxxxxxxxxxxxx> wrote:
> Would anyone skilled in dll's be able to spot why this simple 1 tick
> indicator wont work for me in a
> 2 tick chart but plots the 2 tick values?

I don't quite follow.  You run the Make indicator on a 1-tick chart, 
and the Take indicator on the 2-tick?  What do you mean by "this 
simple 1 tick indicator won't work for me in a 2 tick chart but plots 
the 2 tick values" ?  The 1tick indicator won't work if you run it on 
a 2tick chart??

> Plot1(Myfunction(price,Length),"Myfunction");
> setDefObj("Myfunction");
> putAtDef("1tick", Myfunction(price,length));

If I remember the Hashnums parameters right, you're storing the 
Myfunction value on a key named "1tick".  Right?  But realize that 
you're storing the value for EVERY tick on that "1tick" key, so each 
tick's value overwrites the previous tick's value.  The 2tick chart 
is going to read whatever value was the "last / most current" value 
on the 1 tick chart.  That might work OK for real-time ticks, but any 
ticks plotted from history will be wrong.  I suspect this is the 
cause of your problem.

Try storing each tick's MyFunction value in a separate key in the 
Hashnums database.  For example, instead of

  putAtDef("1tick", xxx);

you could do something like

  putAtDef(CurrentBar, xxx);

That way ALL values from the 1tick chart are available, even when 
plotting past (historical) ticks.

Unfortunately, accessing the values from the 2tick chart is going to 
be tricky.  You can't use CurrentBar because the 2tick chart has half 
as many bars, and it might not even start at the same time.

I've done something like this with *time* based charts, and used the 
time as the indexing value.  E.g. I stored the values from a 1-minute 
chart.  I stored a "Base Time" value so I knew when the 1min chart 
started, and then I used the time offset of each bar (how many 
minutes it's offset from the "Base" time) as the index in the global 
memory array.  Then when I read the values on an N-tick chart, I just 
displayed whatever value was appropriate for the current minute 
associated with the current tick bar.

But you're not going to be able to do that with your 1tick and 2tick 
charts, since you'll have many "bars" in each minute.  I think your 
best bet is to take advantage of the 2-to-1 ratio between the bar 
lengths.  You could do something like this:  store a "Base" time for 
your 1tick chart.  Choose a "Base" tick that is the FIRST tick in a 
new minute; i.e. if Base is not set yet and Time<>Time[1], the 
current tick is your Base tick and the current time is your Base 
time.  Store the Base time (and date) in Hashnums, and start storing 
each tick's value in Hashnums as explained above.

Now in your 2tick chart, do the same "Base not set and Time<>Time[1]" 
check, but also make sure that Date/Time = your stored 1tick Base 
date/time.  That synchronizes the two charts within 1 tick.  (You 
don't know if the "Base" tick on the 1tick chart is the first tick in 
your 1tick bar, or if it's the 2nd tick and the 1st tick is actually 
the last tick of the previous minute.  If you wanted it synched 
exactly to the tick, you'd have to do something like store the value 
for the first few 1tick bars, and compare that to the 2tick bar 
open/close, etc.)  Now you can read every other 1tick value out of 
Hashnums (i.e. for the Nth 2tick bar after the syncronized start, 
read the 2*Nth stored value from Hashnums), or read 2*N and 2*N+1 and 
average them if that makes more sense for your application.  If you 
know you're only going to read the 1tick values in a 2tick chart, 
i.e. you'll never try to read it from a 3tick or 7tick or whatever 
chart, then you could just STORE every other value from the 1tick 
chart and save some memory.

Make sure the 1tick chart gets initialized BEFORE the 2tick chart so 
the Base time is set before the 2tick chart runs.

Hope that helps,
Gary