My mql4 learning adventures

 

I tried about 4 times to learn mql4 from 'the book', and gave up.

This time I just watched lots of videos on youtube on it and hurray, I can now build a simple EA myself (after just 3 days of video watching!). Awesome!

A few bits and bobs remain though to finish the strategy.

Most of them I just took from the EAs posted on this site (so thank you to all EA posters!).

The one thing I can't find, despite going through a hundred EA's posted here is this :

==Let's say I have a very simple strategy, it comes to placing a BUY order (as an example, I also have the same SELL order) (example for the BUY is below)

if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
   if(OrdersTotal()==0)
      OrderSend(Symbol(),OP_BUY,LotSize,Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,NULL,MagicNumber,0,Green);


I need to add to this something like this:

if (Last Executed Order was a BUY) => Then don't BUY on this order

if (Last Executed Order was a SELL) => Then BUY on this order

I know how to add generally (I know how to add it with the && function or by creating another 'if' below it, that's not a problem), I just don't know how to make it look for the 'last executed order' and check if that order was a buy or sell.

Is there another EA I can take appart and borrow this part from (I'l cut the EA myself)? Or is there a simpler way of doing it?

Any help? :(

 
niko:

I tried about 4 times to learn mql4 from 'the book', and gave up.

This time I just watched lots of videos on youtube on it and hurray, I can now build a simple EA myself (after just 3 days of video watching!). Awesome!

A few bits and bobs remain though to finish the strategy.

Most of them I just took from the EAs posted on this site (so thank you to all EA posters!).

The one thing I can't find, despite going through a hundred EA's posted here is this :

==Let's say I have a very simple strategy, it comes to placing a BUY order (as an example, I also have the same SELL order) (example for the BUY is below)


I need to add to this something like this:

if (Last Executed Order was a BUY) => Then don't BUY on this order

if (Last Executed Order was a SELL) => Then BUY on this order

I know how to add generally (I know how to add it with the && function or by creating another 'if' below it, that's not a problem), I just don't know how to make it look for the 'last executed order' and check if that order was a buy or sell.

Is there another EA I can take appart and borrow this part from (I'l cut the EA myself)? Or is there a simpler way of doing it?

Any help? :(


Do you know what this means ??

if(OrdersTotal()==0)

makes the EA not working if you have open not from this EA other trades.....

So why don't you check with a loop function if there are open trades same Symbol() same MagicNumber() ??

that is also the way how you can find from a specific trade its OrderType()

Might be this is not explained in videos on youtube ??

 
niko:

I tried about 4 times to learn mql4 from 'the book', and gave up.

This time I just watched lots of videos on youtube on it and hurray, I can now build a simple EA myself (after just 3 days of video watching!). Awesome!

A few bits and bobs remain though to finish the strategy.

You need to check if your OrderSend() worked or not . . . if it fails you need to know why, the same applies to all your trading functions: What are Function return values ? How do I use them ?

For some help with a loop to find the last Order type, it's not exactly what you were after but read, understand and learn from it: Loops and Closing or Deleting Orders

 

Thank you guys!

The youtube videos are mostly basic, they don't go into all the details.

DeVries:

if(OrdersTotal()==0)

This checks how many orders are live at the moment. This prevents the EA from opening more than 1 live order (which is what I need).

I'm interested in the last 'closed' order (I think I wasn't specific enough), to check if it was a buy or sell, so that the next opened live order would not be the same but would be the opposite (eg: if last order closed was buy, the next will be sell, etc).

Raptor:

1. Thank you, I'l add a GetError part to the OrderSend

2. The Loops and Closing or Deleting Orders - going through it right now...

I think this is what I will use:

&& ( OrderType() == OP_BUY

But I don't know how to make that apply to 'last closed order' (in the link it applies to current live orders, which is not what I need)?

if this was prorealtime code then I'd just add a [1] at the end of OrderType, but mql4 is more complex :(

Any ideas?

 
niko:


But I don't know how to make that apply to 'last closed order' (in the link it applies to current live orders, which is not what I need)?

if this was prorealtime code then I'd just add a [1] at the end of OrderType, but mql4 is more complex :(

Loop through all the Closed orders, check if they belong to your EA (Magic Number) and Symbol and then find the one that has the largest (most recent) OrderCloseTime() then that is the most recently closed Order . . .

By the way, what deVries was meaning, I think, is that if you have a manually opened Order your EA will not work . . . or if you have a second EA placing Orders your EA won't work. If you want your EA to only open one order at a time check if it has any open Orders and if not then open one . . . .

 

I see, thank you.

I'm building the EA to get statistics for what I do manually now (I don't use technical or fundamental analyses anymore, after 15 years of all sorts of experiments, I just rely on pure statistics now).

So before I even think about launching this EA live, it will go through a lot of statistical analyses, then demo runs, etc, then I'l have a paid programmer check it at depth and only then I will think about launching it live.

But before all that I need to just create an EA to run on probacktester to gather some stats for me. Hence right now I'm not too worried about GetLastError etc, I just need a core code to get done and then I'l start adding to it based on what happens in probacktester.


If you could point me how to do this : --through all the Closed orders--:

Then the rest (check magic number, symbol etc) I can figure out from other EAs on this site.

I can't find any info on how to check the closed orders (tons of info on how to check current live orders, and none on closed orders)

 
niko: I tried about 4 times to learn mql4 from 'the book', and gave up.
Then there is no common language for us to communicate with and you are wasting our time trying to help you. It is this simple: learn to code it, or pay someone.
 
niko:

I see, thank you.

I'm building the EA to get statistics for what I do manually now (I don't use technical or fundamental analyses anymore, after 15 years of all sorts of experiments, I just rely on pure statistics now).

So before I even think about launching this EA live, it will go through a lot of statistical analyses, then demo runs, etc, then I'l have a paid programmer check it at depth and only then I will think about launching it live.

But before all that I need to just create an EA to run on probacktester to gather some stats for me. Hence right now I'm not too worried about GetLastError etc, I just need a core code to get done and then I'l start adding to it based on what happens in probacktester.

Testing function return values and reporting errors is core functionality as far as I am concerned, how will you ensure your code is running correctly without it ? how will you fix problems in the way you place, modify and close trades without it ? how will you address error 130 if it occurs ? or error 1 ?

niko:

If you could point me how to do this : --through all the Closed orders--:

Then the rest (check magic number, symbol etc) I can figure out from other EAs on this site.

I can't find any info on how to check the closed orders (tons of info on how to check current live orders, and none on closed orders)

Read the thread I linked to about closing/deleting orders and read the documentation for OrderSelect()
 

Good point, I guess I meant I'l add error part as the last, i'm trying to keep it step by step at the moment (but you'r right, I wont run the test now without the detailed error part; otherwise its a bit silly) :)

Oh I see, its the first thing in OrderSelect - sorry I missed it the first time I read it :)

Will - I'm trying to learn, you guys already know it all, but for a total beginner this is like Japanese language without any live teachers (you guys are the only proper teachers).

Raptor - Thank you for not simply bouncing me out of this thread.

Ok, i'l get back to learning OrderSelect and the other links you sent.

Thank you, that's what I needed, a point in the right direction.

I don't want people to write the code for me, I want to learn it myself (thats way more useful).

 
niko:

I don't want people to write the code for me, I want to learn it myself (thats way more useful).

 

coding is really awesome! #i figured out another way to code what I needed, coded it, it worked, and it opened up a whole other side to what I was doing!

coding rocks!