Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
Profitability Reports
AUD/USD
Oct 2024 - Jan 2025
0.00 %
Total Trades
10
Won Trades
0
Lost trades
0
Win Rate
0.00 %
Expected payoff
-654.94
Gross Profit
0.00
Gross Loss
-6549.40
Total Net Profit
-6549.40
-100%
-50%
0%
50%
100%
es_capelast_reversed_ECN_v1.02
//+------------------------------------------------------------------+
//| es_capelast_reversed_ECN_v1.02.mq4 |
//| Copyright © 2009, OGUZ BAYRAM |
//| es_cape77@hotmail.com |
//+------------------------------------------------------------------+
#include <WinUser32.mqh>
extern int YourAccountNumber = 123456;
extern double lTakeProfit = 10.0;
extern double sTakeProfit = 10.0;
extern double lStopLoss = 2000.0;
extern double sStopLoss = 2000.0;
extern string gs_addSpread = "Add spread to profit target? T/F";
extern bool gb_addSpread = FALSE;
extern int max_num_orders = 50;
extern int max_orders_per_symbol = 10;
extern color clOpenBuy = Green;
extern color clOpenSell = Red;
extern string Name_Expert = "es_capelast_reversed_ECN_v1.02";
extern int magic_number = 789667;
extern int Slippage = 1;
extern bool UseSound = FALSE;
extern string NameFileSound = "Alert.wav";
extern double Lots = 0.1;
extern bool reverseLogic = FALSE;
//Future switch for another ea to handle trade (eg: Stop loss & Take Profit EA)
//gb_tradeEA = FALSE;
int gi_ticket_number;
double gd_point;
double gd_digit;
bool gi_accountVerified = FALSE;
int init(){
//Rudimentary check for broker trade conditions
int li_stoplevel = GetStopLevel();
if ((lTakeProfit < li_stoplevel) ||
(sTakeProfit < li_stoplevel) ||
(lStopLoss < li_stoplevel) ||
(sStopLoss < li_stoplevel)){
MessageBox("Failed to initialize because profit or stop set too tight.\n Broker minimum is " + li_stoplevel + " pips. Now closing the ea.");
//Shut down the ea
PostMessageA( WindowHandle( Symbol(), Period()), WM_COMMAND, 33050, 0);
return(0);
}
if (IsDemo() == TRUE){
gi_accountVerified = TRUE;
Comment(Name_Expert + " trading on DEMO account");
}
else { //real trading Account
gi_accountVerified = CheckAccountNumber();
if (gi_accountVerified == FALSE) return (0);
Comment(Name_Expert + " trading on LIVE account");
}
gd_point = SetPoint();
gd_digit = SetDigit();
}
void deinit() {
Comment("");
}
int start() {
if (IsTradeAllowed() == FALSE) return (0);
if (Bars < 100) {
Print("bars less than 100");
return (0);
}
if (lTakeProfit < 1.0) {
Print("TakeProfit less than 1");
return (0);
}
if (sTakeProfit < 1.0) {
Print("TakeProfit less than 1");
return (0);
}
double diClose0 = iClose(NULL, PERIOD_M5, 0);
double diMA1 = iMA(NULL, PERIOD_M5, 5, 0, MODE_EMA, PRICE_OPEN, 1);
double diClose2 = iClose(NULL, PERIOD_M5, 0);
double diMA3 = iMA(NULL, PERIOD_M5, 4, 0, MODE_EMA, PRICE_OPEN, 1);
if (AccountFreeMargin() < 1000.0 * Lots) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return (0);
}
if (!ExistPositions()) {
if (diClose0 < diMA1) {
if (reverseLogic) OpenSell();
else OpenBuy();
return (0);
}
if (diClose2 > diMA3) {
if (reverseLogic) OpenBuy();
else OpenSell();
return (0);
}
}
return (0);
}
//Wait to exit positions if all order slots are full
bool ExistPositions() {
if ((OrdersTotal() >= max_num_orders ) || (OrderCount() >= max_orders_per_symbol))
return (TRUE);
else
return (FALSE);
}
//Count orders on current chart symbol
int OrderCount () {
int count=0;
for (int j=0; j<OrdersTotal(); j++) {
if (OrderSelect(j, SELECT_BY_POS, MODE_TRADES))
if (OrderSymbol() == Symbol()) count++;
}
return (count);
}
void OpenBuy() {
double ldLot = GetSizeLot();
double ldStop = GetStopLossBuy();
double ldTake = GetTakeProfitBuy();
string lsComm = GetCommentForOrder();
gi_ticket_number = OrderSend(Symbol(), OP_BUY, ldLot, Ask, Slippage, 0, 0, Name_Expert, magic_number, 0, clOpenBuy);
OrderSelect(gi_ticket_number, SELECT_BY_TICKET);
OrderModify(OrderTicket(), OrderOpenPrice(), ldStop, ldTake, 0, Blue);
if (UseSound) PlaySound(NameFileSound);
}
void OpenSell() {
double ldLot = GetSizeLot();
double ldStop = GetStopLossSell();
double ldTake = GetTakeProfitSell();
string lsComm = GetCommentForOrder();
gi_ticket_number = OrderSend(Symbol(), OP_SELL, ldLot, Bid, Slippage, 0, 0, Name_Expert, magic_number, 0, clOpenSell);
OrderSelect(gi_ticket_number, SELECT_BY_TICKET);
OrderModify(OrderTicket(), OrderOpenPrice(), ldStop, ldTake, 0, Red);
if (UseSound) PlaySound(NameFileSound);
}
string GetCommentForOrder() {
return (Name_Expert);
}
double GetSizeLot() {
return (Lots);
}
double SetPoint() {
double ld_point;
if (Digits < 4) ld_point = 0.01;
else ld_point = 0.0001;
return (ld_point);
}
double SetDigit() {
double ld_digit;
if (Digits < 4) ld_digit = 2;
else ld_digit = 4;
return (ld_digit);
}
double GetStopLevel() {
//get stop level from broker in pips
double ld_stopLevel;
ld_stopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
if (Digits == 3 || Digits == 5) ld_stopLevel /= 10;
return (ld_stopLevel);
}
double GetTakeProfitBuy() {
double ld_takeProfit = Ask + lTakeProfit * gd_point;
//take into account the spread if required
if (gb_addSpread) ld_takeProfit += (gd_point*MarketInfo(Symbol(), MODE_SPREAD));
ld_takeProfit = NormalizeDouble(ld_takeProfit, gd_digit);
return (ld_takeProfit);
}
double GetTakeProfitSell() {
double ld_takeProfit = Bid - sTakeProfit * gd_point;
//take into account the spread if required
if (gb_addSpread) ld_takeProfit -= (gd_point*MarketInfo(Symbol(), MODE_SPREAD));
ld_takeProfit = NormalizeDouble(ld_takeProfit, gd_digit);
return (ld_takeProfit);
}
double GetStopLossBuy() {
return (NormalizeDouble((Bid - lStopLoss * gd_point), gd_digit));
}
double GetStopLossSell() {
return (NormalizeDouble((Ask + sStopLoss * gd_point), gd_digit));
}
bool CheckAccountNumber() {
if (YourAccountNumber == AccountNumber()) return (TRUE);
Alert("AccountNumber entered is incorrect.\n You entered ", YourAccountNumber);
return (FALSE);
}
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
---