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 6:21 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Use trade entry as exit condition
PostPosted: Wed Jun 13, 2012 6:45 am 
Offline

Joined: Wed Jun 13, 2012 3:40 am
Posts: 4
I have constructed an EA on Molanis that besides the Technical Indicators also have to use the "trade entry" as an exit condition. More specifically, when Technical Indicators point to an exit of a long position then this must only be allowed if the close of the previous bar (current price) is higher than the trade entry and the reverse for short positions.

I have searched Molanis but cannot find anything that will allow me to make the trade entry point a condition of exiting the trade.

Can you please advise?


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Thu Jun 14, 2012 7:38 am 
Offline
Site Admin

Joined: Fri Oct 16, 2009 3:40 pm
Posts: 451
If you mean the opened price for the position, we might have it in the next release after the summer


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Thu Jun 14, 2012 8:01 am 
Offline

Joined: Wed Jun 13, 2012 3:40 am
Posts: 4
Yes, that is what I mean. If that is not possible at present :cry: , what about an alternative: A condition that the EA only close the trade if the trade is in profit?


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Thu Jun 14, 2012 8:32 am 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
I would review this thread for a related discussion of the same trade condition: http://www.molanis.com/forum/viewtopic.php?f=2&t=1497.

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Sat Jun 30, 2012 2:05 pm 
Offline

Joined: Wed Jun 13, 2012 3:40 am
Posts: 4
I am really struggling with this but need the code to finalise my ea. Is there anyone on this forum who can assist. What I need is code for the MQL block where I choose as trade condition the indicator "iClose" to be > the tade entry price (in a long trade) and I have no idea how to define the "trade entry price" in the MQL block. :?

Anyone who can help?


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Sun Jul 01, 2012 12:57 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Try this for your buy position:

((OrderSelect(0,SELECT_BY_POS)==true)&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumberLong)&&(OrderType()==OP_BUY))&&((OrderOpenPrice())<(MarketInfo(Symbol(),MODE_ASK))

And this for your sell position:

((OrderSelect(0,SELECT_BY_POS)==true)&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumberShort)&&(OrderType()==OP_SELL))&&((OrderOpenPrice())>(MarketInfo(Symbol(),MODE_BID))

Not sure if these will work. :| I submitted a request at http://www.molanis.com/forum/viewtopic.php?p=4631#p4631 to see which code can be included in an MQL block. Please post your results here or there if you try these code blocks.

_________________
I'm not a programmer, but I play one on TV.


Last edited by RJo on Thu Jul 26, 2012 3:58 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Sun Jul 01, 2012 10:31 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
RJo wrote:
Try this for your buy position:

((OrderSelect(0,SELECT_BY_POS)==true)&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumberLong)&&(OrderType()==OP_BUY))&&((OrderOpenPrice())>(MarketInfo(Symbol(),MODE_BID))

And this for your sell position:

((OrderSelect(0,SELECT_BY_POS)==true)&&(OrderSymbol()==Symbol())&&(OrderMagicNumber()==MagicNumberShort)&&(OrderType()==OP_SELL))&&((OrderOpenPrice())<(MarketInfo(Symbol(),MODE_ASK))

Not sure if these will work. :| I submitted a request at http://www.molanis.com/forum/viewtopic.php?p=4631#p4631 to see which code can be included in an MQL block. Please post your results here or there if you try these code blocks.


UPDATE: Per admin, mql4 commands work in the MQL block while special Molanis commands do not. So the above code should work--all commands are standard mql4.

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Mon Jul 02, 2012 2:25 am 
Offline

Joined: Wed Jun 13, 2012 3:40 am
Posts: 4
Thank you very much RJo, will give it a try. :)


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Mon Jul 02, 2012 10:47 am 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
No problem... however I just realized my > and < are backwards according to your 1st post. The marketinfo part is basically the current price, so I thnk you need to switch < for > and vise versa.

I have edited my previous post to reflect these changes.

_________________
I'm not a programmer, but I play one on TV.


Top
 Profile  
 
 Post subject: Re: Use trade entry as exit condition
PostPosted: Thu Aug 23, 2012 3:02 pm 
Offline

Joined: Thu Aug 23, 2012 2:00 pm
Posts: 49
I was very happy to find this post as I have been struggling with exactly the same issue.... ONLY problem is that I get told :x that the trading Condition has got errors...

Where you able to get this right Skollie?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

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