Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
Close_Basket2
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| close-all-orders.mq4 |
//| Copyright © 2005, Matias Romeo. |
//| (Hack by rosst@yahoo.com) Custom Metatrader Systems. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Matias Romeo."
#property link "mailto:matiasDOTromeoATgmail.com"
extern int ProfitTarget = 100; // Profit target in dollars
datetime BarTime;
string TotalAP = "";
//##################
int start()
{
int cnt, total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
//################## ORDER CLOSURE ###################################################
// If Orders are in force then check for closure against the total account profit level
if (AccountProfit() >= 100)
{
TotalAP = "closeall";
}
//start closing orders;
{
total=OrdersTotal();
if(total>0)
{
for(cnt=0;cnt<total;cnt++)
{
//CLOSE LONG Entries:
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
if (TotalAP == "closeall")
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close LONG position
}}
//CLOSE SHORT ENTRIES:
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELL && OrderSymbol()==Symbol()) // check for symbol
{
if (TotalAP == "closeall")
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close SHORT position
}}
} // for loop return
} // close 1st if
return(0);
}
if(result == false)
{
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
}
}
return(0);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---