Download MetaTrader 5
To add comments, please log in or register
Find and download Code Base apps via MetaTrader. It is fast!
Adam Davies
352
Adam Davies 2015.04.12 00:42 

Hi, in my last post I asked how to change barcount in my ea code to something more reliable but was told that the barcount was fine in my code.. So I'm going to leave that now. I now have an issue with this code though. It is great and works perfectly to choose when to start and end the trading week, however the lines that say CloseAllBuy(""); and CloseAllSell(""); show up as errors when compiling so I can't get the function to work where I can choose to close all open trades at a certain time. What do I need to change to lose these errors and to make the code work for this? Thank you!

extern string e="Weekend";
extern int StartDay=1;
extern int StartHour=3;
extern int EndDay=5;
extern int EndHour=21;
extern int CloseHour=21;
extern int CloseMinute=50;

bool Weekend=false;
bool CloseAll=false;

int start()
{
//----

if (DayOfWeek()==StartDay)
{
if (Hour()>=StartHour)
{
Weekend=false;
CloseAll=false;
}
}

if (DayOfWeek()==EndDay)
{
if (Hour()>=EndHour)
{
Weekend=true;
}
}


if (DayOfWeek()==EndDay&&CloseAll==false)
{
if (Hour()>=CloseHour&&Minute()>=CloseMinute)
{
Print("Close Orders before Weekend!");
CloseAllBuy("");
CloseAllSell("");
CloseAll=true;
}
}


if (Weekend==true)
{Comment("Wochenende -keine Trades"); return(0);}
Stuart Browne
5701
Stuart Browne 2015.04.12 00:50  

Hi Adele

Without seeing those 2 functions this has to be a guess, but try removing the quotes from the function call parameter:

 

CloseAllBuy();
CloseAllSell();

Cheers 

Adam Davies
352
Adam Davies 2015.04.12 00:58  
Filter:

Hi Adele

Without seeing those 2 functions this has to be a guess, but try removing the quotes from the function call parameter:

 

Cheers 

I did think they looked a little out of place there but I am new to coding. I will try that now and if it works I will come back to thank you ! I don't suppose you could look at my last forum post about the barcount and confirm what I was told by someone about not needing to worry about using barcount? it was only a few posts ago. If not it's ok, i feel cheeky asking a lot of questions on here!
Stuart Browne
5701
Stuart Browne 2015.04.12 01:22  
Yeah, looks like you have incomplete code there Adele as both of those functions don't exist. I haven't gone through your code in depth but at a quick glance I can see there are also logic errors in there. If you're not comfortable debugging it yourself I'd suggest hiring a coder in the freelance section as it will take a bit of time to sort that lot out.

Cheers
Stu
Adam Davies
352
Adam Davies 2015.04.12 01:30  
Oh ok. Apart from that function everything seems to be working perfectly when I test on demo account or on the strategy tester. It trades during the night when the EUR and USD markets are closed and when the indicators are optimized it brings profit. (I also have a separate ea which trades the daytime more volatile periods but that uses a different strategy). So as far as I was aware that was the only function that I have not got to work. I did think about asking a coder to do it but I will feel more accomplished if I manage to do it myself. Thanks for taking a look though. It is much appreciated 
Stuart Browne
5701
Stuart Browne 2015.04.12 01:51  

You're very welcome :)

If you want to give it a go yourself (which I think is fantastic!) using the same logic that's in there, all you really need to do is create one function to close everything. So you could try something like this. Remove those CloseAllBuy() & CloseAllSell() calls and replace it with CloseAllOrders(). Then create that Function like this:

void CloseAllOrders()
{
  for (int i = OrdersTotal(); i >=0; i--) 
  {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      // Add logic here for closing orders
  }
}

 

 I've left the logic blank so you can have a crack at it. Let me know if you're still struggling with it, post up your code for that function and we'll walk you through it :)

Cheers

Adam Davies
352
Adam Davies 2015.04.12 02:20  
Filter:

You're very welcome :)

If you want to give it a go yourself (which I think is fantastic!) using the same logic that's in there, all you really need to do is create one function to close everything. So you could try something like this. Remove those CloseAllBuy() & CloseAllSell() calls and replace it with CloseAllOrders(). Then create that Function like this:

 

 I've left the logic blank so you can have a crack at it. Let me know if you're still struggling with it, post up your code for that function and we'll walk you through it :)

Cheers

Ok thanks! I am going to get some sleep now as I've been starring t the screen way too long. I will have a look at that tomorrow afternoon though and let you know how I get on!
Stuart Browne
5701
Stuart Browne 2015.04.12 02:30  
Bluntside:
Ok thanks! I am going to get some sleep now as I've been starring t the screen way too long. I will have a look at that tomorrow afternoon though and let you know how I get on!
No problem. I think most of us have burnt out eyeballs from staring at MT too long :D 
/
To add comments, please log in or register