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 Apr 27, 2024 11:24 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: One trade per day?
PostPosted: Wed Aug 01, 2012 8:55 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Is there a way to make the EA open only one trade per pair, per day? One particular EA I have been testing will close out a trade and immediately open another one if the conditions are met. I am wanting it to take only one trade per day.

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Aug 01, 2012 1:17 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Here's to you... living up to your name: http://www.molanis.com/forum/viewtopic.php?f=2&t=1678. :shock:

You need SB Pro for this.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 02, 2012 11:53 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Thanks for your reply, I do have the Pro version but looks like I'll need to do some reading about basic programming.

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 02, 2012 1:45 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
I'm sure it's not too difficult. For starters, look in your mq4 where it says, "//trading code starts here." This is where you're TA conditions are laid out. Once you find out how to code the additional condition, just add it to each trade condition using "&&".

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.

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


Last edited by RJo on Wed Aug 15, 2012 8:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Tue Aug 07, 2012 11:17 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Man this stuff is doing my head in... Thanks for your reply BTW.

I found this code on another forum.. http://forum.mql4.com/4439

int tradeDay=0;

int start()
{ if(tradeDay != TimeDay(curTime())) tradeDay=0;

..

if(tradeDay==0)
{ if(BuyInCondition())
{ OrderSend(..);
tradeDay = TimeDay(curTime());
}
}
}

But I can't get it to work. First I pasted the 'int tradeDay=0;' part in the trading variables alone, and the EA ran OK.

Then.. I went to int start() and pasted the rest of the code like this and then the EA wouldn't run.

Image

Any help would be much appreciated.

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Aug 08, 2012 9:14 am 
Offline

Joined: Tue Dec 22, 2009 12:22 am
Posts: 1761
You cannot add it like that. You need to find what and where to add it

int tradeDay=0; - The variable definition should be added at the top with all other variables

This part should be fine:
int start()
{ if(tradeDay != TimeDay(curTime())) tradeDay=0;
Just add the if(tradeDay != TimeDay(curTime())) tradeDay=0; after the {

Now the difficult part, look for the conditions that trigger the buy and sell, then you need to add this before

if(tradeDay==0)
{ conditions from molanis are here
Then after Buy or sell line add this tradeDay = TimeDay(curTime());

Add the } at the end of the conditions

It's a bit complex, I just wonder how many people use this feature. We do not have it because people do not tend to limit the number of trades a day. They tend to limit the number of losses a day.


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Tue Aug 14, 2012 8:42 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Thanks for your reply, I will try and tackle this and see how I go.. I think a few people would use it, this particular strategy that I'm working on uses a breakout of previous 'x' amount of bars as an entry. The problem with this is if the trade goes in my direction and takes profit sometimes a new trade is opened straight away as my conditions are still met for a new entry, even though the daily range might already exceed its ATR so odds are not favourable for another trade. I have used a % of ATR filter but found I miss a lot of good trades and a simple way around it would be to have a '1 trade per day' option so that the EA only chases one explosive move per day, and then stepped aside when the market has probably run its course. :)

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Aug 15, 2012 9:33 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Ahh man, I can't work it out. How do you limit the maximum amount of losses per day please?

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Aug 15, 2012 6:51 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
This is a totally barbaric workaround to achieve one trade per day, but...

1. Open your existing mol and enter 1 for Maximum Number of Positions in START.
2. Add a TIME icon to your existing TA(s) in your mol and connect with AND.
3. Select Monday 00:00 to 23:59 (the entire day).
4. Save As the mol as "[your_EA_name]]Monday" and generate code.
5. In the TIME icon, change Monday to Tuesday.
6. Save As the mol as "[your_EA_name]]Tuesday" and generate code.
7. And so on for the other 3 days of the week.
8. Open 5 charts for your desired currency pair in MT4.
9. Attach your Monday EA to one, Tuesday to another, and so on... changing each EA's magic numbers as you go.

This should set you up for a maximum of one trade per day for one 5 day week (5 max trades total). Make sure any time filters in START are OFF. If you want 10 potential trades for 2 weeks, open 5 more charts, repeat, and so on. Mind you, I have never actually used the TIME icon so this is all my crazy grandiose vision. Hope it works.

Being a rather well experienced hack, I can tell you that you can manage this whole mess of trades together using a simple "Swiss Army" EA or the more complex "Multi Purpose Trade Manager" EA. Both have a ManageBySymbol option and both are free.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Aug 15, 2012 8:29 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Here is yet another block of code for a more appropriate solution: http://www.forexfactory.com/showthread.php?t=73826. Use Rabid's code.

Paste the first (large) block of code under your int start(), and paste the code below (a one liner) under each set of existing trading conditions (see //trading conditions start here):

&& FoundRecentOpenedOrder(1440) == TRUE

Don't forget to move your ending parentheses down from what previously was your last trading condtion in each set, to this new last trading conditon in each set.

As I understand it, this code basically says, if the day of the last order is one or more days ago, then return a value of TRUE. Otherwise (zero days ago--by process of elimination) return FALSE. Hence the usage of TRUE in the trading conditon.

Now I challenge you to mess this up! ;)

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3, 4  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