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 7:35 pm

All times are UTC - 5 hours




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

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Hey mate, thanks for taking the time to reply! Not real keen on your barbaric way around the problem as it would make tweaking the EA a huge extra load of work and leave myself open for 5 times the amount of mistakes... also, doesn't that option only limit the amount of 'open' positions? Not the amount of trades allowed in one day? Anyways, that's not really important here.

On the other front, believe it or not I have accepted your challenge and won - by messing it all up! Grrrr!

Would I be able to ask a huge favour and have you insert the coding correctly onto one of the simple EA examples on the Molanis site so I can see exactly how it's supposed to look? This is a condition I would like to apply to a few of the EAs I am working on and I would like to understand how the code should be inserted properly. I would also prefer (I THINK!) to use the code from the MQL4 forum which I posted, as it seems to me from my limited knowledge that it will limit the trades to 1 per DAY, whereas the one you posted seems to limit your trades to 1 per 1440 minutes. So if a trade occurred at midday server time the previous day, a new trade would not be able to be opened until midday the following day.

Hope this makes sense...

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 16, 2012 8:00 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
molanisfx wrote:

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.


Just to add to this, I think it would be a very useful tool for SB to possess purely as a safeguard to protect from any buy and sell conflicts* that mightn't show up in testing.

nolube

* A conflict being where a buy and close long (for example) overlap and you are left with a million little losing trades the size of the spread!

PS. How do you go about limiting the amount of losses a day??


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 16, 2012 2:53 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Yeah, I see your point. The barbaric approach could cause you to have multiple trades in the same day, even though one at a time.

1440 is simply mql code for MT4's daily time frame, so your broker's D1 open and close would still be taken into account. It's not actually saying, 1440 minutes from the last order time.

Your mql4.com code is more concise but somehow harder to follow. It looks like it does the same thing but goes about it differently. Rereading molanisfx's post, I think I can do this and post back.

Due to copyright/unscrupulous people, we don't post full Molanis EA code in this forum, so I will post code snippets from MACD-EA2 in a way that's easy for you to copy and paste in your own MACD-EA2.

In the mean time, you might consider doing some reading about mql4 global variables, int start(), and conditional operators--all on mql4.com. I'm just trying to get you started in what probably seems like a sea of nonsense right now.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 16, 2012 4:40 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Attachment:
global.jpg
global.jpg [ 108.89 KiB | Viewed 65478 times ]


Attachment:
int start().jpg
int start().jpg [ 93.48 KiB | Viewed 65472 times ]


Attachment:
conditions.jpg
conditions.jpg [ 179.79 KiB | Viewed 65449 times ]


2 things: Note that I used TimeCurrent in lieu of curTime. The MT4 build I have no longer recognizes curTime. And the compound if statement was killing me--something with the brackets I guess... so I simply added the time filter as another trading condition. This may use slightly more CPU resources because MT4 will run through 3 conditions instead of merely checking a an if first.

On a general note... When you copy this stuff, don't just paste it. Editing code is rarely this easy. Punctuation marks are almost always interrupted when you insert new code. Once you learn the meaning of the various punctuation marks, this becomes more apparent. For each left parenthesis, there is a right parentheses. For each left bracket, there is a right bracket. And there are compound sets of these--a left and a right within another left and another right... within another left and another right, and so on. Count up the sets to determine the code they are capturing. Then you can identify the groups of code, and see where to insert your new code without creating havoc. I emphasize this because my screenshots are cut off on the right side. With a straight copy and paste, you are bound to wind up with an extra ) } or ; which will throw compilation errors.

The first 2 screenshots are self explanatory. In the 3rd, my highlighted code already contains the end-of-group punctuation--so use your own full MACD-EA2 code to see which punctuation needs to be deleted from the end of the line immediately preceding each new insertion (this is no longer the end of the group).

This is not tested, so test and go from there.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Mon Aug 20, 2012 9:01 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Thanks Rjo, haven't forgotten about this. Just focussed on another EA for the time being. Will have a crack when time permits and let you know how I go. :)

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 23, 2012 2:05 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Thanks RJo, that seems to work a treat! Once I realised I could use the compile followed by clicking on the errors it was pretty easy to sort out. Many thanks man! :)

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Aug 30, 2012 10:56 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Hey RJo, lets say I want to allow MT4 to take 2 trades per day... I'm guessing it's a simple alteration of this code? :)

nolube


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Fri Aug 31, 2012 2:29 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Well... not quite. The simple fix we used was counting days, not counting open trades. And so you will have to add custom code to your trading conditions that does count open trades. Keep what you have, and copy the entire block of all trading code--conditions, operators, and all, starting with your first if. Paste this block directly below the block you copied. After neatening up a bit, add this to each set of BUY conditions in your pasted block of code:

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

And change && tradeDay==0 to && tradeDay==TimeDay(TimeCurrent())

For SELLs, add:

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

And change && tradeDay==0 to && tradeDay==TimeDay(TimeCurrent())

Don't forget to edit your punctuation. :geek: This is basically saying, if there is one open trade AND it was opened today, then open another... I think.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Mon Sep 03, 2012 5:59 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Thanks mate, will give it a crack this week :)


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Tue Jan 08, 2013 10:19 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Hi RJo, never got around to testing 2 trades per day as the plan changed. However I'm working on something else aaaaaand..... what if I wanted my EA to take only one signal per 4h bar? Is that at all possible? I suppose I could run 6 different EA's with different time settings but I'd prefer to keep it as one so it's easily managed. Any thoughts?


nolube


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