Noob EA question

 
Hi,

In lesson 13, there is (My First EA) - based on dual moving average crosses with trailing stop.

as shown here:

http://paste.pound-python.org/show/10966/


I'm Noob coder just learning and want to experiment some now that I've read the lesssons and Documentation.
I'm guessing I can simply just change these 2 lines of code as follows:

   shortEma = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0);
   longEma = iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0);

// for MACD I changed it to this:

   shortEma = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   longEma = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);

Please confirm this usage of the code above or did I miss something ? 

I think it's fine but wanted a pro to confirm or correct me, thanks
 
I'm not a "Pro" but it looks OK to me . . assuming that the values you are using actually give you what you are looking for . . . maybe you should change your variable names to something more meaningful ?
 
Thanks

I'm trying to get rid of the trailing stop and just use stoploss now just to get a better understanding of the preprocessors and the checking for open orders command and structure

when metatrader editor give me the errors and shows the line such as 145,3
How can I make the editor show me the line numbers so I can hunt down the error a little easier.

Please advise and thanks for the help.

P.S I did rename some things as suggested it was going to make it hard to understand if I keep building onto it.
 
I I have made changes which allow me to use this template as a standard MACD with takeprofit and stoploss.
I'm not 100% sure that the stop loss and stop loss check is needed in this way but I'm playing with it and likely there is a shorter method for this.

Basically used some part that I thought I needed and removed others and made a few edits.

http://paste.pound-python.org/show/11022/

It appears to work partially but when I set the dates of testing from 1-1-2011 to current/today, The EA only appears to test in a portion of a month of March

Also changing the time frames does not help if I change from 7-1-2001 to current/today it only tests up to around 7-13-2001 for some reason
Also profit and stop loss are not working correctly so I have something wrong here also.

See the report here
http://www.iclbiz.com/ea_test/StrategyTester.htm

Also notice that the last close at the bottom is always some strange HUGE loss for some reason which says close a stop, but it's actually didn't; and No matter the time frame I test this last trade/close is always some HUGE loss but the size of the loss does vary.

Well any tips would be great, thanks
 
Ahh think I'm getting somewhere here.

I made changes and put this for the OP_BUY and OP_SELL and got rid of some other pending order checks at the bottom
http://paste.pound-python.org/show/11024/

So I added the Ask-StopLoss*Point and Ask+StopLoss*Point

I think this will help,


I noticed that all the orders are sell orders so I have something wrong here too.

I'll likely make some progress while waiting for any responders, but any info is good info at this point since I'm NOOB LOL. But it's really fun learning this anyhow.

Back to the drawing board.
 
You will get a Buy order when isCrossed changes from 2 to 1, that will happen when faster > slower.
 

Made a few more edits and think I have it fixed now without the HUGE loss at the end and now taking trades in both directions as it should
Just forgot to put (*Point) for the OP_SELL orders

http://paste.pound-python.org/show/11028/


So because of isCrossed do I even need to check for open orders ?

Seems like the open orders checking of this code is a bit long. Is this a typical method used ?

 
Just had an idea

Seem to me the (for) statement should be removed altogether

Changed to something in this method instead:

if (total >= 1) then use OrderClose.

I'll hack this it up some more tomorrow.
Thanks for reading.

 
Agent86:
Just had an idea

Seem to me the (for) statement should be removed altogether

Changed to something in this method instead:

if (total >= 1) then use OrderClose.

I'll hack this it up some more tomorrow.
Thanks for reading.


If you don't loop through all the open orders how can you find the correct one to close ? do you intend to run this EA on just one pair ? and never have any manual trading on the same terminal ?
 
Hmmmm good question.

Perhaps I don't understand the TotalOrders() function, but at the time it seems like a good idea. lol

I think I need to re-read the code to make sure I understand it better

the current code has if (total < 1) and if Crossed=1 and if isCrossed=2

Seem like this would only open orders if there were no currently opened orders listed in the TotalOrders which is good and yes I want to close the open orders so that the reverse orders will open.


Something like this:

http://paste.pound-python.org/show/11063/

I realize the problem with the Bid price in the OrderClose but I thought I could shorten things a bit with this method if I could get it working right.


I guess the real question is in the code currently ? Is the for loop the most typical to check open orders for reverse signals etc. Or is there something else that is considered the normal method which is better then this code from lesson 13 ?

Thanks for the tips, I need all I can get.
 
Agent86:
Hmmmm good question.

Perhaps I don't understand the TotalOrders() function, but at the time it seems like a good idea. lol

I think I need to re-read the code to make sure I understand it better

the current code has if (total < 1) and if Crossed=1 and if isCrossed=2

Seem like this would only open orders if there were no currently opened orders listed in the TotalOrders which is good and yes I want to close the open orders so that the reverse orders will open.


You are probably correct.

int OrdersTotal( )

Returns market and pending orders count.

from here: https://docs.mql4.com/trading/OrdersTotal

If you have this EA on 5 pairs OrdersTotal will return the number of open orders for the EAs on the 5 pairs and also any that were opened by other EAs or manual trading . . . if you only ever plan to run this EA on one pair and no other EA on any pair on the same terminal then you might be OK.

Reason: