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 Sat May 11, 2024 1:55 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: MA Strategy Question
PostPosted: Tue Oct 01, 2013 4:05 pm 
Offline

Joined: Sun May 27, 2012 9:51 am
Posts: 26
Hello Everyone,

I am trying to build a strategy that uses Moving Averages. My strategy functions OK in MT4 terminal but does something I would like to eliminate.

When a trade is open and the signal changes the EA will close the open trade and execute a trade based on the new opposite signal.

Can someone tell me how to configure MSB to not close open trades when the signal changes? I want the open trade to remain open until it hits TP or ST. After the open trade closes it can then open another trade based on the current signal.

Thank you for any help you can give.


Top
 Profile  
 
 Post subject: Re: MA Strategy Question
PostPosted: Wed Oct 02, 2013 11:42 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Let's say you want to buy if ma1>ma2 and sell if ma2>ma1, but if there is a long position and ma2>ma1 you do not want to do anything. You want to ignore your signal to sell so it means that your signal to sell is not good enough for trading. So why use it in the first place?
You could build the ea with that logic, you only need to use the count for opened orders and do not take a trade if the count>0 . Some users post the code to use in the mql icon on the forum - you may want to search that or wait a couple of weeks for the new beta with a new mql icon that will allow to get the number of opened positions in a better way.


Top
 Profile  
 
 Post subject: Re: MA Strategy Question
PostPosted: Thu Oct 03, 2013 3:49 pm 
Offline

Joined: Sun May 27, 2012 9:51 am
Posts: 26
Hi molanisfx,

Thanks for the reply.

Are you referring to this post: Re:One trade per day? on Thu Aug 2, 2012 by RJo which says in part:

Quote:
Personally, I haven't had a use for this because I tend to limit my orders by open position count. Basically, I haven't learned the whole time thing. I don't care if I get 1 or 10 orders per day, as long as each is entered at its own set of conditions. For this you can use the special Molanis code,

&& CalculateOpenPositions (Symbol(), OPEN_BUY, MagicNumber==MagicNumberLong)=<0

In effect, this says AND CURRENT OPEN BUY POSITIONS MUST BE ZERO as an additional trade condition.

and for sells:

&& CalculateOpenPositions (Symbol(), OPEN_SELL, MagicNumber==MagicNumberShort)=<0

Don't forget to adjust parentheses to enclose conditions as needed.


If this is not the code you were referring to please post a link to the thread or post.

Thanks


Top
 Profile  
 
 Post subject: Re: MA Strategy Question
PostPosted: Thu Oct 03, 2013 6:27 pm 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
Not sure where that post was but the code seems fine: Try using CalculateOpenPositions (Symbol(), OPEN_BUY, MagicNumberLong)=<0 and CalculateOpenPositions (Symbol(), OPEN_SELL,MagicNumberShort)=<0


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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