Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2006, 07:59 PM
unltdsoul's Avatar
Junior Member
 
Join Date: May 2006
Posts: 2
unltdsoul is on a distinguished road
Problem using Variables Tick-by-Tick

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.)
Attached Files
File Type: mq4 TestTickData.mq4 (1.8 KB, 17 views)

Last edited by unltdsoul; 07-03-2006 at 08:05 PM. Reason: reloaded good test file
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-04-2006, 12:34 AM
unltdsoul's Avatar
Junior Member
 
Join Date: May 2006
Posts: 2
unltdsoul is on a distinguished road
Found Work-Around

Well, I found my own work-around to the problem

(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)
Attached Files
File Type: mq4 TestTickData.mq4 (2.3 KB, 19 views)
File Type: mq4 my-library.mq4 (968 Bytes, 22 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-04-2006, 03:36 AM
elihayun's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 350
elihayun is on a distinguished road
Quote:
Originally Posted by unltdsoul
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.
I did the following and it works

PHP Code:
   static double  lastClose;
   
   
double b Bid;
   
   if( 
lastClose )
      Print(
TimeToStr(Time[0])," Up  Close="+DoubleToStr(b,Digits)+"  lastClose="+DoubleToStr(lastClose,Digits));
   else if( 
blastClose )
         Print(
TimeToStr(Time[0])," Dn  Close="+DoubleToStr(b,Digits)+"  lastClose="+DoubleToStr(lastClose,Digits)); 
      else
         Print(
TimeToStr(Time[0])," NoChange  Close="+DoubleToStr(b,Digits)+"  lastClose="+DoubleToStr(lastClose,Digits));   
         
   
lastClose b;
   return(
0); 
06:33:14 Tick Data USDCHF,M1: 2006.07.04 06:33 Up Close=1.2235 lastClose=0.0000
06:33:14 Tick Data USDCHF,M1: 2006.07.04 06:33 NoChange Close=1.2235 lastClose=1.2235
06:34:25 Tick Data USDCHF,M1: 2006.07.04 06:34 Dn Close=1.2234 lastClose=1.2235
06:34:28 Tick Data USDCHF,M1: 2006.07.04 06:34 Up Close=1.2235 lastClose=1.2234
06:34:29 Tick Data USDCHF,M1: 2006.07.04 06:34 Dn Close=1.2234 lastClose=1.2235
06:34:31 Tick Data USDCHF,M1: 2006.07.04 06:34 Up Close=1.2235 lastClose=1.2234
06:34:32 Tick Data USDCHF,M1: 2006.07.04 06:34 Dn Close=1.2234 lastClose=1.2235
06:34:59 Tick Data USDCHF,M1: 2006.07.04 06:34 Up Close=1.2235 lastClose=1.2234
06:36:20 Tick Data USDCHF,M1: 2006.07.04 06:36 Up Close=1.2237 lastClose=1.2235
06:36:20 Tick Data USDCHF,M1: 2006.07.04 06:36 Dn Close=1.2235 lastClose=1.2237
06:36:20 Tick Data USDCHF,M1: 2006.07.04 06:36 Up Close=1.2236 lastClose=1.2235
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tick Indicator Alex.Piech.FinGeR Metatrader 4 95 08-30-2008 08:27 PM
What's the best way to check if the tick is the first tick of the new bar? blooms Metatrader 4 2 10-31-2006 06:10 AM
Using tick data? 100% MQ? Willis11of12 Metatrader 4 5 03-28-2006 03:20 PM


All times are GMT. The time now is 08:26 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.