A
OTTOMH - something like this...
extern int MagicNumber = 911; extern int StartWeekHour = 2; extern int EndOfWeekHour = 18; //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- if (DayOfWeek()==0) return (0); // Do nothing on Sunday if (DayOfWeek()==1 && Hour() < StartWeekHour) return (0); // Do nothing on Monday before time if (DayOfWeek()==5 && Hour() == EndOfWeekHour) // Close everything its time to go home { CloseAllBuyOrders(); CloseAllSellOrders(); } if (DayOfWeek()==5 && Hour() >= EndOfWeekHour) return (0); // Do nothing on Friday after time //+------------------------------------------------------------------+ // Your trading code goes here //+------------------------------------------------------------------+ return(0); } void CloseAllBuyOrders() { int i, iTotalOrders; iTotalOrders=OrdersTotal()-1; // Rosh line for (i=iTotalOrders; i>=0; i--) // Rosh line { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber()==MagicNumber) { if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet); if (OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket()); if (OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket()); } } } } void CloseAllSellOrders() { int i, iTotalOrders; iTotalOrders=OrdersTotal()-1; // Rosh line for (i=iTotalOrders; i>=0; i--) // Rosh line { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber()==MagicNumber) { if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet); if (OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket()); if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); } } } }
FWIW
-BB-
BarrowBoy:
A
OTTOMH - something like this...
FWIW
-BB-
really nice, thanks i will try it and get back. thanks so much
adesijsig:
really nice, thanks i will try it and get back. thanks so much. it wored fine
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
pls i need a code for my EA to close all trade 18:00 on Friday and stop tradeand open 2:00 on Monday.
also i want the EA to calculate a particular percentage of free margin as lot for every trade. i want u guyz to help me with these codes pls.
thanks in anticipation