molanis.com/forum - Tools for MetaTrader : The place to ask about the best expert advisor builder, expert advisor downloads, and expert advisor programming

AFTER YOU REGISTER SEND US AN EMAIL TO ACTIVATE YOUR ACCOUNT - Before posting:-1- Please read the user guide -2- Try the examples -3- Search in the forum
It is currently Sun May 12, 2024 9:22 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: exit EA does not work
PostPosted: Tue Oct 09, 2012 9:23 pm 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
I just made an exit Expert Advisor. It is designed to close existing positions based on indicator values. I picked 4 indicators which are pretty good at determining the end of a trend. However, they give signals at slightly different times under various trading environments, usually only one candle apart, sometimes 2 or3. So I programmed the ea to close the trade when any 2 out of the 4 are giving an exit signal. This means I had 6 pair of conditions down the left side of the diagram to close long and 6 along the right side for close short.

I put an AND linking each pair of conditions and linked each AND (12 in total) to the "Close" box.

The ea was validated, it generated code and it was accepted into MT4. The expert advisors tab was on, my internet connection was on and Metatrader was running. I put the exit ea on a chart with an existing trade and it did not close it even though all four of those conditions existed. It is programmed to close on completed bars and to trade (not alert).

Anybody know why it didn't close my trade on a demo account?

_________________
Building a future with automated trading


Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Wed Oct 10, 2012 9:53 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
You need to post your strategy file and indicator for us to take a look. Most of the users issues are due to incorrect logic, not getting the right signal from a custom indicator, or using indicators that repaint the current bar (and looking at the chart that shows the indicator at the close)


Top
 Profile  
 
 Post subject: Here is the EA
PostPosted: Wed Oct 10, 2012 12:44 pm 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
This post has been deleted

_________________
Building a future with automated trading


Last edited by AlGer on Thu Oct 11, 2012 10:15 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Wed Oct 10, 2012 12:46 pm 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
There was no custom indicators. All indicators are from Molaonis

_________________
Building a future with automated trading


Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Thu Oct 11, 2012 10:11 am 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
I changed the shift to 1 on all trading blocks thinking that the ea should be comparing the immediately completed bar to the parameter in the program but it still did not work. I can't think of anything else I am doing wrong. I will post the trading diagram as well as the code here.

This Exit ea just is supposed to close the trade based on adx di lines being crossed and the macd main crossing the signal line.


Attachments:
EXIT macd & adx.mol [11.35 KiB]
Downloaded 439 times
EXIT macd & adx.mq4 [87.92 KiB]
Downloaded 456 times
EXIT macd & adx.ex4 [30.25 KiB]
Downloaded 439 times

_________________
Building a future with automated trading
Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Thu Oct 11, 2012 10:13 am 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
Here is the other EXIT ea I was originally talking about. Changed the shifts here to 1 as well.


Attachments:
EXIT - 2 out of 4.mq4 [93.64 KiB]
Downloaded 457 times
EXIT - 2 out of 4.ex4 [39.86 KiB]
Downloaded 408 times
EXIT - 2 out of 4.mol [42.69 KiB]
Downloaded 408 times

_________________
Building a future with automated trading
Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Thu Oct 11, 2012 3:09 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
The positions you want to close are opened manually or with other eas?
Each ea has an id called the magic number. This enable to have two eas trading at the same time in mt4 - the id makes sure the two eas do not mix. If you want to close positions from another ea, you need to set the same magic numbers for both eas. Go to the ea inputs in metatrader and change it there.

Manual positions have a magic number of 0. To close those positions you need to set 0 as the magic number for the ea.

Try our examples first that open and close positions and then build on top. See http://www.molanis.com/products/molanis ... rs-for-mt4 go to example 0 and download all the examples as a zip file


Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Thu Oct 11, 2012 6:46 pm 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
trades are opened manually , yes. I will change the magic number to 0.

I will have only one ea operating on one pair at a time. Since that ea takes the inputs from that pair only, why would it get mixed up with any other ea? It would seem that the magic number would apply if you had more than one ea operating within one pair, or more than one trade within that pair.

Please explain.

_________________
Building a future with automated trading


Top
 Profile  
 
 Post subject: Re: exit EA does not work
PostPosted: Fri Oct 12, 2012 2:05 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Quote:
I will have only one ea operating on one pair at a time.

I think You are right. If you only have one ea per pair you should be ok since eas won't mix.


Top
 Profile  
 
 Post subject: Changed the Magic Number
PostPosted: Fri Oct 12, 2012 2:32 pm 
Offline

Joined: Fri Feb 04, 2011 9:48 pm
Posts: 114
Location: Canada
Hi

I changed the magic number to 0 and now it works. So i know the logic is okay now.

I will try it again without changing the magic number to 0, even though the trade is an existing trade done manually beforehand.

_________________
Building a future with automated trading


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by Molanis © 2009