• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 8:40am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:40am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How to write contents of variables to a CSV file? 5 replies

Exporting custom indi values to CSV 2 replies

Importing .csv, prn and .txt data 8 replies

Importing data from CSV file 0 replies

Exporting/Importing Template 2 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Exporting & importing Global variables to CSV Files
Cancel

Exporting & importing Global variables to CSV Files

  • Post #1
  • Quote
  • First Post: Oct 2, 2007 5:31pm Oct 2, 2007 5:31pm
  •  herrwolf
  • | Joined Aug 2007 | Status: Member | 6 Posts
Hello,
I am new to EA development. I am currently creating an EA that utilizes multiple tf’s and therefore requires that a few global variables be saved so that they can be reused upon reopening of a chart in Meta Trader 4. Could someone help me out with a code snippet that would help me accomplish my goal? I figure a function call func_gvLoad could be called in the “void init ()” function and func_gvDump could be called in the “void deinit ()” function.

Thank you
  • Post #2
  • Quote
  • Oct 2, 2007 6:03pm Oct 2, 2007 6:03pm
  •  tesla
  • | Joined Oct 2006 | Status: Friendly Neighborhood Programmer | 533 Posts
There's a mechanism to manage variables like that, and coincidently they're called global variables.

Take a look at GlobalVarSet and GlobalVarGet (I think I got the function names right, but can't check 'cause I'm on my Blackberry).

You can save/access values beteen charts/EAs/etc.

Now... Just because you use multiple timeframes doesn't mean you need to open multiple charts, you can access all timeframes from a one minute chart or a monthly.
 
 
  • Post #3
  • Quote
  • Oct 3, 2007 2:45pm Oct 3, 2007 2:45pm
  •  herrwolf
  • | Joined Aug 2007 | Status: Member | 6 Posts
Hello,

Thank you for replying.

I took a look at what you are talking about with the global variables. I think I'm not being clear enough about my intentions or I don't understand what you are trying to tell me. I realize by using the "iTime", "iClose", ect. I can trade any TF from any chart, also I can trade any number of pairs from a single chart using those variables. The problem I have is this: a 4H trade may take two weeks to set up. My computer probably wont be on for those two weeks, since the market closes on the weekends. Therefore: I need a way to permanently save some global variables so that the sequences the EA goes through will not be lost over the weekend. I need to save and retrieve three types of values: "double", "integer" and "datetime". I'm starting to think the best way is to use a binary file instead of a CSV file, because, doubles and integers are converted to strings in CSV files and datetime variables are not. I have some text from the help file. Correct me if I'm wrong: but I think the line "value=FileReadInteger(h1,2)" is where I would use the GlovalVariableSet line. Also, is "h1" from that line the pointer to the specific value I'm trying to read and set?. For example. GV_1 = h1 and GV_2 = 2? Any clarification you could provide would be helpful.

int handle; int value; handle=FileOpen("mydata.dat", FILE_BIN|FILE_READ); if(handle>0) { value=FileReadInteger(h1,2); FileClose(handle); }

Have a good day.
 
 
  • Post #4
  • Quote
  • Last Post: Edited 12:25am Oct 4, 2007 12:13am | Edited 12:25am
  •  tesla
  • | Joined Oct 2006 | Status: Friendly Neighborhood Programmer | 533 Posts
I'll touch on a couple different issues, hopefully some of this information is helpful.

First, regarding global variables...
Global variables store values as doubles, I'm guessing you've figured that out. The good news is that there's no problem storing integers since any valid integer is also a valid double. The other good news is that there's no problem storing datetimes since a datetime is really just an integer (number of seconds since midnight, Jan 1st 1970).

Second, regarding saving your EAs values...
What you're describing is an EA that has to retain "state". That means when it starts up, it has to remember stuff that occurred previously. Usually this can be avoided, and it's often a clue that something might not be written as well as it could be. If, for instance, you're EA needs to know the last cross of some moving averages, this can be done by iterating back and checking values. If it's too CPU intensive, it's something that can be done in the init function. EAs that require state aren't always avoidable, but they're a very rare breed.

Third, if you do have to save values to a file...
If global vars just won't cut it for you, I recommend you take a look at the FileWriteArray(...) and FileReadArray(...) functions. They'll save you some time vs. writing your own parsing routines.

That's all for now, I hope you found some of that useful.
 
 
  • Platform Tech
  • /
  • Exporting & importing Global variables to CSV Files
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023