Forex
Google

Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-11-2007, 08:19 PM
forextrend's Avatar
forextrend forextrend is offline
Senior Member
 
Join Date: Nov 2005
Posts: 114
forextrend is an unknown quantity at this point
Thumbs up Controlling number of trades

Has anyone got code i can use to control the number of trades and EA opens in a day.
Such as open just 3 trades per day and do not open anymore trades until the next trading day.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-11-2007, 08:55 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by forextrend View Post
Has anyone got code i can use to control the number of trades and EA opens in a day.
Such as open just 3 trades per day and do not open anymore trades until the next trading day.
Call this function :

PHP Code:
int DailyCount()
{
      
int iDailyCount 0;   
      for(
OrdersTotal()-1>= 0--)
      {
            if(!
OrderSelect(iSELECT_BY_POSMODE_TRADES)) continue;
            if(
OrderSymbol() != Symbol()) continue;
            if(
OrderMagicNumber() != Magic) continue;
            if(
TimeDayOfYear(OrderOpenTime()) == DayOfYear()) DailyCount ++;
      }
      return(
DailyCount);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-11-2007, 10:45 PM
forextrend's Avatar
forextrend forextrend is offline
Senior Member
 
Join Date: Nov 2005
Posts: 114
forextrend is an unknown quantity at this point
Thumbs up

Call the function where in the code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-11-2007, 10:52 PM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by forextrend View Post
Call the function where in the code.
It depends of your code. If you do not know, copy your code here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-11-2007, 11:41 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Thumbs up

Quote:
Originally Posted by Michel View Post
Call this function :

PHP Code:
int DailyCount()
{
      
int iDailyCount 0;   
      for(
OrdersTotal()-1>= 0--)
      {
            if(!
OrderSelect(iSELECT_BY_POSMODE_TRADES)) continue;
            if(
OrderSymbol() != Symbol()) continue;
            if(
OrderMagicNumber() != Magic) continue;
            if(
TimeDayOfYear(OrderOpenTime()) == DayOfYear()) DailyCount ++;
      }
      return(
DailyCount);

Very good and clean code! I like this function.
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-12-2007, 01:19 AM
forextrend's Avatar
forextrend forextrend is offline
Senior Member
 
Join Date: Nov 2005
Posts: 114
forextrend is an unknown quantity at this point
Post

here:

// Closing of Open Orders
void OpenOrdClose()
{
int total=OrdersTotal();

for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(total-cnt-1, SELECT_BY_POS);
int mode=OrderType();
bool res = false;
bool condition = false;
if (OrderMagicNumber()==Magic ) condition = true;
if (condition && ( mode==OP_BUY || mode==OP_SELL ))
{

// - BUY Orders
if(mode==OP_BUY)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_BID),3,Yellow);

if( !res )
{
Print(" BUY: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
else
// - SELL Orders
if( mode == OP_SELL)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_ASK),3,White);

if( !res )
{
Print(" SELL: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
}
}
}


void TotalProfit()
{
int total=OrdersTotal();
totalPips = 0;
totalProfits = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);

int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((Bid-OrderOpenPrice())/Point);
totalProfits += OrderProfit();
break;

case OP_SELL:
totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((OrderOpenPrice()-Ask)/Point);
totalProfits += OrderProfit();
break;
}
}

if (UseSwap) {

SwapProfit();
totalProfits = totalProfits + valueswap;
}

}
}

void sidePips()
{
int total=OrdersTotal();

shortPips = 0;
longPips = 0;

for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);

int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
longPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));

break;

case OP_SELL:
shortPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));

break;
}
}

}

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-12-2007, 06:13 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by forextrend View Post
here:

// Closing of Open Orders
void OpenOrdClose()
{
int total=OrdersTotal();

for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(total-cnt-1, SELECT_BY_POS);
int mode=OrderType();
bool res = false;
bool condition = false;
if (OrderMagicNumber()==Magic ) condition = true;
if (condition && ( mode==OP_BUY || mode==OP_SELL ))
{

// - BUY Orders
if(mode==OP_BUY)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_BID),3,Yellow);

if( !res )
{
Print(" BUY: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
else
// - SELL Orders
if( mode == OP_SELL)
{
res = OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_ASK),3,White);

if( !res )
{
Print(" SELL: OrderClose failed with error #",GetLastError());
Print(" Ticket=",OrderTicket());
Sleep(3000);
}
}
}
}
}


void TotalProfit()
{
int total=OrdersTotal();
totalPips = 0;
totalProfits = 0;
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);

int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((Bid-OrderOpenPrice())/Point);
totalProfits += OrderProfit();
break;

case OP_SELL:
totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));
//totalPips += MathRound((OrderOpenPrice()-Ask)/Point);
totalProfits += OrderProfit();
break;
}
}

if (UseSwap) {

SwapProfit();
totalProfits = totalProfits + valueswap;
}

}
}

void sidePips()
{
int total=OrdersTotal();

shortPips = 0;
longPips = 0;

for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);

int mode=OrderType();
bool condition = false;
if ( Magic>0 && OrderMagicNumber()==Magic ) condition = true;
else if ( Magic==0 ) condition = true;
if (condition)
{
switch (mode)
{
case OP_BUY:
longPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));

break;

case OP_SELL:
shortPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));

break;
}
}

}

}
There is nowhere here the part of the code which eventualy open a position. That's there that the code has to be modified, so please past your whole code.
It will be more lisible if you enclose it in the "PHP" brackets, but you can also attach the mq4 file.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-12-2007, 06:20 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by codersguru View Post
Very good and clean code! I like this function.
Thanks, Guru ! What an honour for me to have your approbation !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-12-2007, 06:31 AM
forextrend's Avatar
forextrend forextrend is offline
Senior Member
 
Join Date: Nov 2005
Posts: 114
forextrend is an unknown quantity at this point
Thumbs up

Attached is the whole EA i am using. Also plaese explain how to use your code in detail so i can use it with other EA's in the furture.
Attached Files
File Type: mq4 Samuray_v7.mq4 (23.5 KB, 29 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-12-2007, 08:10 AM
Michel Michel is offline
Senior Member
 
Join Date: Feb 2006
Posts: 502
Michel is on a distinguished road
Quote:
Originally Posted by forextrend View Post
Attached is the whole EA i am using. Also plaese explain how to use your code in detail so i can use it with other EA's in the furture.
Here is the modified one, all modifications have "Michel" as comment so you can easily find them. I didn't try it, tell me if it works ok.
Attached Files
File Type: mq4 Samuray_v7.1.mq4 (24.2 KB, 68 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maximum number of open trades per MT4 account fxtrader625 Metatrader 4 10 06-07-2007 06:59 PM
Controlling number of lots on the Multi Lot Scalper rbowles Expert Advisors - Metatrader 4 1 08-14-2006 07:59 PM
number of indicators deepdrunk Indicators - Metatrader 4 3 07-11-2006 12:34 AM
ANy limit to number of trades an EA can do? shazan Expert Advisors - Metatrader 4 2 04-15-2006 04:34 PM


All times are GMT. The time now is 09:45 PM.