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:30 am

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: Tue Jan 08, 2013 3:07 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
nolube wrote:
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


Edit: THIS CODE IS FOR ONE TRADE PER BAR (CURRENT CHART TIMEFRAME)

Up top in globals:
Code:
datetime lastOrderTime;


Below your start function:
Code:
// Get last closed order time--Created by User
for (int j=OrdersHistoryTotal(); j>=0; j--)
   {
     if ( ( OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) // Only orders w/
        &&  OrderMagicNumber()  == MagicNumberShort     // my magic number
        &&  OrderSymbol()       == Symbol()             // and my pair.
        &&  OrderType()         <= OP_SELL )            // Avoid cr/bal forum.mql4.com/32363#325360
     || (   OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) // Only orders w/
        &&  OrderMagicNumber()  == MagicNumberLong      // my magic number
        &&  OrderSymbol()       == Symbol()             // and my pair.
        &&  OrderType()         <= OP_BUY ) )           // Avoid cr/bal forum.mql4.com/32363#325360
       {
         lastOrderTime = OrderOpenTime();
         break;
       }
   }


And in each set of your trading conditions:
Code:
if  ( lastOrderTime < Time[0] )

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


Last edited by RJo on Thu Jan 10, 2013 10:54 am, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Thu Jan 10, 2013 2:02 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Mate you're a legend, I think I love you... Have got to head out soon but will try this later on.

Thanks!


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Sun Dec 08, 2013 11:08 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
RJo, would love to test strategy with the condition of one trade per day, but allowed multiple positions.. The idea being that a winning position is added to if the trade conditions are met the following day. Would you have any idea how to do this?

Regards


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Sat Dec 21, 2013 2:40 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
I believe that what you describe is commonly known as trade stacking. The stock Molanis code includes a Martingale input, "afterWin." That input, along with your trading condtion(s) and one trade per day filter, should function as you describe. Don't forget to set the other Martingale inputs as necessary.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Sun Dec 29, 2013 5:29 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Sorry for the delayed reply, but you're a genius.. once again thanks for your help!


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Mon Jan 06, 2014 4:48 am 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
Hi RJo, this works flawlessly when back tested on one broker.. I use a maximum positions of 3 and set martingale after profit to true (also set martingale to true) and set the multiplier to 0.5..

This makes the 1st position 1 lot, 2nd 0.5 lots and 3rd 0.25 lots.... Flawless - EXACTLY what I was after..



My OTHER broker, exact same EA, same settings...

1st position is 1 lot, 2nd is also 1 lot, and 3rd 1 lot again.. now because they are all wins, the 4th trade is now 0.5 lots.. It's like it's not recognizing the open profit of the 1st position as a win.


I'm hoping you might have an idea of something I've overlooked???


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Mon Jan 06, 2014 10:01 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
I reset the settings in the broker that was working and re-entered all the values, now it is doing what my other broker is doing... any ideas? It's got me stumped!


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Tue Jan 07, 2014 7:26 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Whoa... that's strange. I remember reading somewhere that the order of trades in MT4's history is not documented by MetaQuotes and therefore, not guaranteed to be logged in any particular order by any particular broker. I can only suspect that your broker(s) may be logging the trades randomly.

As a side note, I have never experienced this personally, and I would switch brokers if I did.

Edit: It sounds like you might have a lot reduction factor working that shouldn't be. Make sure LotManagement is off. Martingale is supposed to override LotManagement, but there's a //comment in the code not to use them together.

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


Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Wed Jan 08, 2014 10:29 pm 
Offline

Joined: Wed Jul 18, 2012 11:06 pm
Posts: 78
It is really weird RJo, BTW thanks for getting back to me! :)

So one broker was working, now both are not... I suspected it could have had something to do with lot management but it is definitely switched off and I even tried changing the values to 0 after you mentioned it.

Here's my EA settings, can you see anything else that it might be?


Attachments:
EAss.jpg
EAss.jpg [ 116.6 KiB | Viewed 80382 times ]
Top
 Profile  
 
 Post subject: Re: One trade per day?
PostPosted: Fri Jan 10, 2014 2:03 pm 
Offline

Joined: Sun Jun 19, 2011 9:38 pm
Posts: 270
Getting back to you... in my posting preferences here, I had "Notify me of new replies by default" set to No. I think it was messing with my individual thread notifications. We'll see. Anyway...

Check your MT4 Experts tab for Martingale errors. Successfully executed Martingale trades should also be reported there. I suspect that Martingale is not functioning at all when your initial lot size is simpy being repeated.

I have no idea who your dealers/brokers are, but it's possible that they changed the default sorting of the trade history pool on their trade servers: (a) coincidentally while you were trading, or (b) in response to your profitable trade stacking. This is probably unlikely to happen at 2 different brokers, but you may want to contact them and verify whether their trade history pools are stored.

Edit: I just realized you have MaxNumberofPositions set to 3, and in an earlier post, you mentioned open profit. I don't believe the "stock" Martingale code is intended nor written to function in this way. I coded my own whileOpen and MartingalePips inputs some time ago. At this point, you may want to have a look at an EA containing those changes posted at my own site: http://mqlautocoder.com/showthread.php?tid=51.

@mods, I posted some similar code at your request in another molanis.com thread some time ago. I may have coded additonal features since then (I caN'T remember), so please feel free to download whatever you like from the site linked above.

_________________
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 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