Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
I am having problems with MT4 in that it does not appear to save variable data on a tick by tick basis, but rather only at end of 1 min bars.
To explain: I have included a simple indicator, it does not display to screen, it is only writes to console (using Print). It is only for example.
In this short program i have created 1 variable, lastClose, which i have made "static". When a tick comes in I check and see if the current close is greater, lessor or equal to the previous lastClose. I print a message to the console and then set the lastClose to = the current Close.
Simple enough.
The lastClose data is only updated at the end of the 1 min bar. So, if there is only 1 tick in the current 1 min bar, the simple code works fine. Where it messes up is when there are multiple ticks in 1 bar.
Say, the last 1 min close was 1.280 then the first tick comes in for a new bar. Say the new price (close) = 1.281, lastClose will = 1.280, and the program Prints "Up..." and the program "tries" or "appears" to update the lastClose to 1.281. Now, say a second tick arrives during this same 1 min bar, Close[0] now == 1.282. lastClose, however, reverts back to 1.280, the close of the last 1 min bar, it does not Hold it's value i set in the last tick (1.281), after the completion of this tick, the new value for lastClose should == 1.282. But, if another tick comes in on the same 1 min bar the lastClose will again be reverted back to 1.280. Now say the new tick close = 1.281. That is a price that is LESS then the last tick, so my program should say that the price has gone DOWN, instead, it still says the price has gone UP because the lastClose value keeps reverting back to 1.280. If the last tick of this current bar =, say, 1.283, and we update the lastClose, it will finally save that value only when we have advanced to the next new 1 min bar.
Now, i am running this on 1 min bars on the chart, so i am not sure how it works on, say a 15 min chart.
But, it appears that MT4 code only Temporarily writes a variable's value durng the course of a tick, but, then reverts that variables data to the last 1 min bar, until the bar has completed, then it finally updates the variable.
Anyone has had similar experience, and/or found a work around?
(NOTE - you can only see the problem i am showing here when there are more than 1 tick per 1 min bar, in an active market, and you need to look at the Print results in the Experts window of the console/terminal.)
Last edited by unltdsoul; 07-03-2006 at 09:05 PM.
Reason: reloaded good test file
(The problem was that data in an indicator/expert was only being saved by MT4 at the end of a min bar, and even though i set a value to a variable, it would revert to the previous bar's value for that variable if i get multiple ticks in the same 1 min bar)
I wrote a library file with 2 functions. SaveData and ReadData and I made a local global array in the library for saving the data. In my main Indicator or Expert program, if i need to save and read data on tick by tick basis (within a 1 min bar), i save the data to SaveData(ptr, value) (ptr is the index to the data array in the library function), then to get the data, i call ReadData(ptr).
The data in the library does not revert back to the previous bar's data while gettng multiple ticks in one bar.
I have attached both a new TickData test file and the library function
(Libraries go in the /library sub dir)