Writing a simple MA expert advisor...

 

All,


I'm new to the world of MT and mql code writing. I've been using Amibroker for a while now and write AFL's to suit my trading requirements. I wanted to test the logic from one of my AFL's in the MT for the Dow chart. So I started to write an expert advisor after reading a bit about Mql4.


My logic for starters is pretty straight forward and I've attached a GIF file that show the arrows for buys and sells (just simple back-testing for Dow).


Buy -> Close > 10ma

Sell -> Close < 10ma


What I am unable to understand are these ->


1) For each signal, there seems to be three objects - a trendline and two arrows. Also, these arrows don't seem to be point to the date on which the signal is generated

2) Secondly, when dow closes above 10ma, I get the First Buy signals. I continue to get buy signals until the SELL Criteria is met. How do I prevent repetitive follow-up signals being generated until the reverse signal is given ?


Any pointers will be helpful.


Thanks in advance.


Cheers,

Girish


Dow - Sample

 

It looks like the arrows are BUY/SELL orders (to be 100% sure we need to see the code). To avoid opening new positions add an if verifying the number of open positions. We have some products that create EA and a moving average example - just search the forum for molanis.

I want to learn more about Amibroker. How good is Amibroker and how big is its online community/number of users? Which forums are the best Amibroker forums? Thanks.

 

Regarding the repeating Buy signals, it seems that the EA is not checking to see if an order is already open. Although, I do not know for sure because I don't have your code, I have made an assumption and suggest the following as a possible solution.


What I think your code is doing:


if( Close > 10ma) {

OrderSend(Buy);

}


Every time that the EA loops, the condition in the if statement is checked and as long the condition is true, then a new order will be generated. The EA does not check to see if an order is already open, it just does what it is told and opens a new order even if there is already an open order.


I suggest that you check to see if you already have an open order.


What your code should be doing:


if( Close > 10ma) {

if(there are no other orders open) {

OrderSend(Buy);

}

}


See how in the pseudo code example, the program checks to see if there already is an order open before sending another order?


The same should follow for Sell orders.


This can be extended, for example the EA could be programmed to close out the buy order when you get a sell signal.


Regarding the arrows, maybe they show where the order got filled???


As mentioned before, I have not seen your code and this limits what advice I can give you.


Like molanisfx, I am also interested to read about Amibroker. What other alternatives to MetaTrader are there?

Reason: