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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

.txt or .csv TO .hst conversion 12 replies

MT4 - How to save Toolbox News Data in txt or csv? 3 replies

EA/script for making trades from txt file 0 replies

TXT Trading!? 1 reply

how to include a file.txt in an mq4 file ?? 6 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 1
Attachments: EA to send acct balance to a txt file...?
Exit Attachments
Tags: EA to send acct balance to a txt file...?
Cancel

EA to send acct balance to a txt file...?

  • Post #1
  • Quote
  • First Post: Jul 17, 2010 5:57pm Jul 17, 2010 5:57pm
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
Hi there could someone please simpily help me to code an EA that simply sends the account balance and equity to a text file .


Thanks a lot !
  • Post #2
  • Quote
  • Jul 17, 2010 6:20pm Jul 17, 2010 6:20pm
  •  CodeMeister
  • Joined Sep 2009 | Status: Making Code While Making Pips | 1,672 Posts
I think a script is more suited to what you want to do. An EA is for things that you want to perform over and over again. A script is intended to do one off things like you mentioned.

I just wanted to be sure that you have this clear in your mind so that you looking for the right thing. I am sure that such a script exists, but I don't have one myself and never had any interest in such a script.
 
 
  • Post #3
  • Quote
  • Jul 17, 2010 11:15pm Jul 17, 2010 11:15pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey xlr8er...... you should be able to see what i've done here..... if you decide to send other data, just modify the string....

FileWrite(handle,AccountBalance(),AccountEquity()); // add more here

made it a script but if you truely want an ea, just add the init and deinit functions you commonly see.... then it's an ea.......

you can rip out the code and create a standard function..... then use it in any ea or indicator...... thats what i do......

//-----

holler back if need be......h
Attached File(s)
File Type: mq4 xl8r.mq4   1 KB | 364 downloads
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #4
  • Quote
  • Edited 3:48am Jul 18, 2010 3:38am | Edited 3:48am
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
Thanks a lot ! Im trying to put this EA on a chart and it must keep posting data to a text file from there a program written in VB will analyse all this info and draw up some nice records for me Unfortunatly im much better in VB that MQl haha thanks again!

Sorry for being a bit blank but to where do these files get written? Thanx !
 
 
  • Post #5
  • Quote
  • Jul 18, 2010 8:26am Jul 18, 2010 8:26am
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey xlr8er..... the file is sent to the files folder in the experts folder.....

such as,

Crogram FilesInterbank FX Trader 4expertsfiles


also you'll probably need a true ea as you first mentioned.... in that case making the file name a extern input might be handy.....

it will update every tick unless you choke it down.... and that file will get large quick unless you limit it......h

Inserted Code
 
 extern string dataFile   = "xl8r";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| script program start function                                                     |
//+------------------------------------------------------------------+
int start()
  {
//----
  int i;
  int handle;
 
      handle = FileOpen(dataFile,FILE_CSV|FILE_WRITE|FILE_READ,',');   //';');
      FileSeek(handle,0,SEEK_END);
      FileWrite(handle,AccountBalance(),AccountEquity());
      FileClose(handle);
//----
   return(0);
  }
//+------------------------------------------------------------------+
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #6
  • Quote
  • Edited 2:25pm Jul 18, 2010 10:06am | Edited 2:25pm
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
Hey there ! All is well well , do you think we could get this file to open , remove any previous text , close .... So this will solve the file getting too big , the program I am writing in visual basic is going to open this file and retrieve only the first value , so I will have seperate files each for account balance , equity and so forth. Dont worry I know how to get this done, it is just to maybe get it to only have one value in the text file and constantly update that value and ideas ?


Oh yes and I see no file is being created at the moment... I rate its because no new ticks are coming in ? maybe because markets are closed ? or would the file still be created?


1 other thing ! does the metatrader have to be installed...? e.g program files/ metatrader ... Because I always just copy all my terminals from one computer to the other because I need to run about 100 seperate terminals on my server at any time ....
 
 
  • Post #7
  • Quote
  • Jul 19, 2010 1:29am Jul 19, 2010 1:29am
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey xlr8er...... changed the code to create 2 files.... one for accountbalance() and another for accountequity().....

commented out seek_end, so it should write 1 line only......

//-----

not sure i follow about the terminal having to be installed.... it might not have to be installed natively, but it must be installed somewhere.... else it can't run..... or at least it would be difficult for me envsion how it could run.....

generally, 1 or more instances of metatrader are installed each with it's own unique file path..... the ea would write the data in the terminal's files folder which is in the experts folder.....h





//----

Inserted Code
 
//+------------------------------------------------------------------+
//|                                                         xl8r.mq4 |
//|                                                           .....h |
//|                                                 hayseedville.com |
//+------------------------------------------------------------------+
#property copyright ".....h"
#property link      "hayseedville.com"
 
extern string Balance   = "Balance";
extern string Equity    = "Equity";
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- 
  int i;
  int handle;
 
      handle = FileOpen(Balance,FILE_CSV|FILE_WRITE|FILE_READ,',');  
      //FileSeek(handle,0,SEEK_END);
      FileWrite(handle,AccountBalance());
      FileClose(handle);
//-----
      handle = FileOpen(Equity,FILE_CSV|FILE_WRITE|FILE_READ,',');  
      //FileSeek(handle,0,SEEK_END);
      FileWrite(handle,AccountEquity());
      FileClose(handle);
//----
   return(0);
  }
//+------------------------------------------------------------------+
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #8
  • Quote
  • Jul 19, 2010 2:52am Jul 19, 2010 2:52am
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
oh yes this looks good ! Yes the terminals all have their own directory on the server, its always just been one hell of a mission to go and look at all 100 terminals and do the status of the account. This will save me a lot of time


Thanks for all the trouble !
 
 
  • Post #9
  • Quote
  • Jul 19, 2010 3:40am Jul 19, 2010 3:40am
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
Hey.. or should I say Hay? haha All is working fine I am getting the data over to my VB program now , I wanted to ask 1 more thing , you dont have to help with this but I need to get the values of each open trade that I have aswell as the market price of that currency. So for example AUDUSD is running at +1200 at the price of 0.8693, one file will retrieve the +1200 and the other will retrieve the 0.8693

Any ideas on this?

Thanks a bunch. And if you are willing to help me on a regular basis I am prepaired to pay you I dont think professional service should be free

Bye for now
 
 
  • Post #10
  • Quote
  • Jul 19, 2010 3:25pm Jul 19, 2010 3:25pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey xlr.... the values of each open trade ..... what values might these be.... profit, if so, in pips or dollars?.....

as the market price of that currency...... would that be bid or ask?....

of each open trade..... how many orders per symbol will be open at a time?......

//-------

added the code for retrieving the current ask....

just threw some 'ibfx' symbols into an array as an example..... h

//------

Inserted Code
 
//+------------------------------------------------------------------+
//|                                                         xl8r.mq4 |
//|                                                           .....h |
//|                                                 hayseedville.com |
//+------------------------------------------------------------------+
#property copyright ".....h"
#property link      "hayseedville.com"
 
extern string Balance   = "Balance";
extern string Equity    = "Equity";
       string sym[20]   = {"GBPUSDm","EURGBPm","EURJPYm","GBPJPYm","USDCHFm","AUDJPYm","NZDUSDm","EURUSDm","USDJPYm","EURCHFm","GBPCHFm","CHFJPYm","AUDUSDm","NZDJPYm" };
       int    time[8]   = {1,5,15,30,60,240,1440,10080,43200};
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- 
  int i;
  int handle;
 
      handle = FileOpen(Balance,FILE_CSV|FILE_WRITE);  
      FileWrite(handle,AccountBalance());
      FileClose(handle);
//-----
      handle = FileOpen(Equity,FILE_CSV|FILE_WRITE);  
      FileWrite(handle,AccountEquity());
      FileClose(handle);
//-----
 
      for(int j=0;j<14;j++)
      {
      RefreshRates();
      handle = FileOpen(sym[j],FILE_CSV|FILE_WRITE);  
      FileWrite(handle,MarketInfo(sym[j],MODE_ASK));
      FileClose(handle);
      }
 
 
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
to trade and code, keep both simple... no call to impress....h
 
 
  • Post #11
  • Quote
  • Jul 19, 2010 3:49pm Jul 19, 2010 3:49pm
  •  Xlr8er
  • | Joined Feb 2010 | Status: Member | 81 Posts
This looks good , uhm I want to get the profit in dollars...
The bid or ask price wont realy matter as spreads are all like 1 pip...
Only one order per symbol will be open and a total of 20 orders will be open at any one time...


Send me an email sometime hayseed at [email protected] I hate being helped without giving somthing in return haha
 
 
  • Post #12
  • Quote
  • Last Post: Jul 19, 2010 4:45pm Jul 19, 2010 4:45pm
  •  hayseed
  • Joined Nov 2006 | Status: Member | 3,604 Posts
hey xlr..... be sure to edit the symbols to match yours, i use ibfx, yours might be different.....

change the 14 as noted in the code to reflect your symbol list - 1.....

there is no choke on this so it will update at every tick..... unless there is a need for being that current, using a new bar on the 1 minute chart might be better.......h



Inserted Code
 
//+------------------------------------------------------------------+
//|                                                         xl8r.mq4 |
//|                                                           .....h |
//|                                                 hayseedville.com |
//+------------------------------------------------------------------+
#property copyright ".....h"
#property link      "hayseedville.com"
 
extern string Balance   = "Balance";
extern string Equity    = "Equity";
       string sym[20]   = {"GBPUSDm","EURGBPm","EURJPYm","GBPJPYm","USDCHFm","AUDJPYm","NZDUSDm","EURUSDm","USDJPYm","EURCHFm","GBPCHFm","CHFJPYm","AUDUSDm","NZDJPYm" };
       int    time[8]   = {1,5,15,30,60,240,1440,10080,43200};
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
 
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//---- 
  int i;
  int handle;
 
      handle = FileOpen(Balance,FILE_CSV|FILE_WRITE);  
      FileWrite(handle,AccountBalance());
      FileClose(handle);
//-----
      handle = FileOpen(Equity,FILE_CSV|FILE_WRITE);  
      FileWrite(handle,AccountEquity());
      FileClose(handle);
//-----
 
      for(int j=0;j<14;j++)                       //  change the 14 to how ever many symbols you have -1.... 
      {
      RefreshRates();
      handle = FileOpen(sym[j],FILE_CSV|FILE_WRITE);  
      FileWrite(handle,MarketInfo(sym[j],MODE_ASK));
      FileClose(handle);
      }
 
 
      for(int k=0;k<14;k++)                       //  change the 14 to how ever many symbols you have -1.... 
      {
      double profit;
      for(int l=0; l<OrdersTotal(); l++)
      {
      if(OrderSelect(l, SELECT_BY_POS, MODE_TRADES))
      {
      if(OrderSymbol() != sym[k]) continue;
      {
      profit = OrderProfit();
      }
      }
      }
      handle = FileOpen(sym[k]+"Profit",FILE_CSV|FILE_WRITE);  
      FileWrite(handle,profit);
      FileClose(handle);
      }
 
//----
   return(0);
  }
//+------------------------------------------------------------------+
to trade and code, keep both simple... no call to impress....h
 
 
  • Platform Tech
  • /
  • EA to send acct balance to a txt file...?
  • 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