Page 1 of 1

Creating a Forex EA - mql4?

Posted: Sat Jun 29, 2013 5:12 pm
by PoLyGLoT
Hi all,

Is it possible to use livecode to create forex expert advisors? Or to analyze stock or currency charts and send an email when certain conditions are met?

I know this kind of thing is possible with MQL4 code, but I don't know MQL4 code at all so I was wondering if you could do this kind of thing within Livecode.

Thanks.

Re: Creating a Forex EA - mql4?

Posted: Sat Jun 29, 2013 9:07 pm
by Simon
Hi PoLyGLoT,
More specific question to programming are, can LC:
Retrieve data?
Parse that data?
Perform actions based on the results of the data?
YES!

As far as copying Forex EA, that probably is a pretty big job as you'd have to get into legal stuff about unassisted financial transactions. They do have an API that might take care of that side of things.

But as you said "...send an email..." I'm thinking you want this for personal use? Maybe just read an html page and parse out the info you want then email you when the price is right?
Yes, LC can do that.

It would be a good fulfilling project to mess about with.

Simon

Re: Creating a Forex EA - mql4?

Posted: Sat Jun 29, 2013 9:45 pm
by PoLyGLoT
Hi Simon,

Thank you so much!! You've hit the nail on the head - this would just be for personal use. And instead of entirely automating things, I would love for it to be able to retrieve data and send me an email when certain conditions are met.

This would be truly awesome if I could tinker with this. Could you give me any idea on how LC can retrieve web data? Or how to make it send emails?

Thanks so much,
PoLyGLoT

Re: Creating a Forex EA - mql4?

Posted: Mon Jul 01, 2013 4:38 pm
by PoLyGLoT
Sorry for the shameless bump, but I'm hoping someone can answer these questions before the thread goes cold.

I'm wondering how LC can:

1) Analyze web data (or retrieve data from some other source in general)
2) Set it up to automatically email a specific address when certain conditions are met

I'd be very grateful for some input on these two fronts. I feel I can then tweak the system further once I've got my foot in the door.

Thanks,
PoLy

Re: Creating a Forex EA - mql4?

Posted: Mon Jul 01, 2013 5:59 pm
by jacque
The question is pretty broad which is probably why you aren't getting many responses. But in general, to retrieve a web page, you only need one line of code:

get url "http://www.google.com"

That will return the entire page content to the script. See "get" in the dictionary. Then you'd parse the content to extract the things you want, which will vary for every url. You'll need to examine the page content and figure out what parts of it your script needs. We can help you with that if you ask specific questions about it.

For email, there are several ways. The easiest is the built-in revMail command if you don't mind launching the user's mail client and having them physically send the mail. If you want it all done by script you can call out to shell. Or there are a few mail libraries floating around, though I think shell is a little more reliable.

Re: Creating a Forex EA - mql4?

Posted: Mon Jul 01, 2013 9:37 pm
by Simon
Hi PoLyGLoT,
Grabbing the data isn't difficult, autosend of emails may be a bit trying for first time SMTP'ers.

OK the easy part:
New main stack with 1 field and 1 button. In the button put

Code: Select all

global gHTML
on mouseUp
put URL "http://www.nasdaq.com/markets/most-active.aspx" into gHTML
put gHTML into fld 1 -- just so you can see it
end mouseUp
That URL is just some stock exchange page with current values http://www.nasdaq.com/markets/most-active.aspx. You will see that it returns some 4000 lines of code you'll want to parse that down to just the stuff you want.
Now add a second button:

Code: Select all

global gHTML
on mouseUp
   put "" into fld 1
   put 0 into tStart
   put 0 into tEnd
   repeat
      if shiftKey() is down then exit repeat --use in case of runaway
      put wordOffset("class='mostactive'",gHTML) into tStart
      if tStart = 0 then exit repeat
      put wordOffset("</tr>",gHTML,tStart) into tEnd
      put word tStart to (tEnd+tStart) of gHTML after fld 1
      delete word 1 to (tEnd+tStart) of gHTML
   end repeat
put fld 1 into gHTML
end mouseUp
You will see that the now only the important stuff is left in gHTML and the fld.
You get to parse out the rest of the data. Look up wordOffset, lineOffset, offset in the dictionary (watch out "lines to skip" works but not how I thought it would).

Once you've completed that and made your value comparisons you'll want to send the alert email.
Here in the forums search on "SMTP".
I just tested using PowerShell on win7 and that worked. google "Send email powershell"
There are plenty of gotchas in any of the methods, just copying scripts didn't work for me because of things like port numbers.
Don't know the shell for Mac.

Have Fun!
Simon

Re: Creating a Forex EA - mql4?

Posted: Tue Jul 02, 2013 4:29 pm
by PoLyGLoT
You guys rule. This gives me plenty of fodder for my own tinkering.

THANK YOU SO MUCH!

Re: Creating a Forex EA - mql4?

Posted: Tue Jan 07, 2014 12:42 pm
by FarhatAltaf
what is this forez ea .. ea stand for?

Re: Creating a Forex EA - mql4?

Posted: Tue Jan 07, 2014 7:59 pm
by Klaus
FarhatAltaf wrote:what is this forez ea .. ea stand for?
Is your GOOGLE broken? 8)
It may work, when you enter the correct search string. :D