Please use this to post code . . . it makes it easier to read.
gabrejos:
Hello, I am newbie, and I dont know about programing, I take a e.a. that close every order in loss. I only need that this e.a. do this every xxx minutes, not every time, only each xxx minutes (for example 120 minutes).
No Slaves here, learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you.
Hello, I am newbie, and I dont know about programing, I take a e.a. that close every order in loss. I only need that this e.a. do this every xxx minutes, not every time, only each xxx minutes (for example 120 minutes).
RaptorUK:
Thank you very much, SorryPlease use this to post code . . . it makes it easier to read.
//+------------------------------------------------------------------+ //| close-all-orders.mq4 | //| Copyright © 2005, Matias Romeo. | //| Custom Metatrader Systems. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, Matias Romeo." #property link "mailto:matiasDOTromeoATgmail.com" //Some Modifications, Functional/Visual By ForexSaint4u@gmail.com extern int LT = -20; // Maximum Loss target in Dollars/Euro or whichever Currency you have in your account extern string Loss_Target= "Enter LT above To limit the loss to that Amount in per -OPEN trade "; extern string Use1= "To Limit losses in Losing Trades"; extern string Use2= "Kinda StopLoss to,OPEN Trades in Profit.In this case LT has to be a Positive Integer"; int start() { int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : if ( OrderProfit() <= LT) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; //Close opened short positions case OP_SELL : if ( OrderProfit() <= LT) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } if(result == false) { //Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(0); } } return(0); }Sorry again
Add these . . .
extern string Use2= "Kinda StopLoss to,OPEN Trades in Profit.In this case LT has to be a Positive Integer"; extern int CloseTradesTimePeriod = 120; // time period in minutes < ----- ADD int start() { static int LastCloseTradesTime = 0; // time that trades were last closed < ----- ADD if (TimeCurrent() < LastCloseTradesTime + (CloseTradesTimePeriod * 60) ) return(0); // < ----- ADD else LastCloseTradesTime = TimeCurrent(); // < ----- ADD int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType();
Thank you again, sorry for my ignorance, I add it at the end, or in some specific place?
Thank you again
RaptorUK:
Add these . . .
Ok I understood.
Thank you very much for your atention.
You are very nice

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
Hello, I am newbie, and I dont know about programing, I take a e.a. that close every order in loss. I only need that this e.a. do this every xxx minutes, not every time, only each xxx minutes (for example 120 minutes).
//+------------------------------------------------------------------+
//| close-all-orders.mq4 |
//| Copyright © 2005, Matias Romeo. |
//| Custom MetaTrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Matias Romeo."
#property link "mailto:matiasDOTromeoATgmail.com"
//Some Modifications, Functional/Visual By ForexSaint4u@gmail.com
extern int LT = -20; // Maximum Loss target in Dollars/Euro or whichever Currency you have in your account
extern string Loss_Target= "Enter LT above To limit the loss to that Amount in per -OPEN trade ";
extern string Use1= "To Limit losses in Losing Trades";
extern string Use2= "Kinda StopLoss to,OPEN Trades in Profit.In this case LT has to be a Positive Integer";
int start()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : if ( OrderProfit() <= LT) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
break;
//Close opened short positions
case OP_SELL : if ( OrderProfit() <= LT) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
if(result == false)
{
//Alert("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );
Sleep(0);
}
}
return(0);
}