Voor de liefhebber
IK gebruikte conservatibe mode met een lotsize van 0.1
Je zou dan niet direct problemen verwachten met een account van 230000 centen.
extern string Part1 = "Money Management";
extern string SelectMode = "Conservative=1 / Aggressive=2";
extern int Mode = 2;
extern string SelectLotSize = "for Conservative Mode select Lot Size // default 0.1";
extern double GridLotSize = 0.1;
extern string SelectBalanceUse = "for Aggressive Mode select Balance Use // default 0.5%";
extern double BalanceUse = 0.5;
extern string Part2 = "Trading Settings";
extern int MAperiod = 11;
extern int TakeProfit = 20;
extern double GridFactor = 2.0;
extern double HammerFactor = 2.0;
extern double CloseFactor = 2.25;
extern int MaxRods = 7;
extern int MaxDD = 50;
extern int Slippage = 2;
extern int MagicNumber = 12345;
extern string Part3 = "FIFO rule applies?";
extern bool FIFO_applies = FALSE;
bool gi_196;
int start() {
int li_16;
int li_20;
int l_slippage_24;
bool li_28;
bool li_32;
int li_36;
int li_40;
int li_44;
int l_ticket_48;
int li_52;
double l_lots_104;
double lda_112[20];
double lda_116[20];
double l_lots_152;
double ld_160;
string ls_236;
string ls_244;
double ld_168 = 10;
double ld_176 = 1000;
int l_magic_184 = MagicNumber + 1;
for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) li_52++;
}
if (li_52 == 0) gi_196 = FALSE;
if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.1) {
li_36 = 10000;
li_40 = 10;
}
if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.05) {
li_36 = 5000;
li_40 = 20;
}
if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.01) {
li_36 = 1000;
li_40 = 100;
}
if (MarketInfo(Symbol(), MODE_LOTSTEP) == 0.001) {
li_36 = 100;
li_40 = 1000;
}
if (Mode == 1) l_lots_104 = GridLotSize;
if (Mode == 2) l_lots_104 = MathRound(AccountBalance() * BalanceUse / li_36) / li_40;
if (l_lots_104 < MarketInfo(Symbol(), MODE_MINLOT)) l_lots_104 = MarketInfo(Symbol(), MODE_MINLOT);
if (l_lots_104 > ld_168) l_lots_104 = ld_168;
if (MarketInfo(Symbol(), MODE_DIGITS) == 3.0 || MarketInfo(Symbol(), MODE_DIGITS) == 5.0) {
li_20 = 10 * TakeProfit;
l_slippage_24 = 10 * Slippage;
} else li_20 = TakeProfit;
l_slippage_24 = Slippage;
int li_188 = AccountBalance() / (1000.0 * l_lots_104);
int li_192 = li_188 / 2.0;
string ls_196 = "ADD MORE FUNDS";
string ls_204 = "REDUCE GRID LOT SIZE";
string ls_212 = "GRID LOT SIZE MAY BE INCREASED";
string ls_220 = "YOUR BALANCE IS LESS THAN A REQUIRED MINIMUM. THIS MAY RESULT IN UNEXPECTED LOSSES!";
string ls_228 = "NONE";
if (li_188 < 100 && l_lots_104 == MarketInfo(Symbol(), MODE_MINLOT)) {
ls_236 = ls_196;
ls_244 = ls_220;
}
if (li_188 < 100 && l_lots_104 > MarketInfo(Symbol(), MODE_MINLOT)) {
ls_236 = ls_204;
ls_244 = ls_220;
}
if (li_192 > 100 && Mode == 1) {
ls_236 = ls_212;
ls_244 = ls_228;
}
if (li_192 > 100 && Mode == 2) {
ls_236 = ls_228;
ls_244 = ls_228;
}
if (li_192 < 100 && li_188 > 100) {
ls_236 = ls_228;
ls_244 = ls_228;
}
if (li_192 == 100) {
ls_236 = ls_228;
ls_244 = ls_228;
}
Comment("\n", "EA GUINEA ULTIMATE IS ON",
"\n", "ACCOUNT BALANCE: ", li_188, "% OF MINIMUM REQUIRED",
"\n", " OR ", li_192, "% OF RECOMMENDED",
"\n", "RECOMMENDATIONS: ", ls_236,
"\n", "WARNINGS: ", ls_244);
double l_ima_56 = iMA(NULL, 0, MAperiod, 0, MODE_EMA, PRICE_CLOSE, 0);
double l_ima_64 = iMA(NULL, 0, MAperiod, 0, MODE_EMA, PRICE_CLOSE, 1);
double l_istochastic_72 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
double l_istochastic_80 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 1);
double l_istochastic_88 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0);
double l_istochastic_96 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 1);
if (TerminalCompany() == "FXOpen Investments Inc.") li_44 = 0;
else li_44 = 3600;
if (IsTesting() && Period() == PERIOD_D1) {
if (TimeCurrent() > D'07.02.2008 02:00' - li_44 && TimeCurrent() < D'10.02.2008 02:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'02.06.2008 03:00' - li_44 && TimeCurrent() < D'18.06.2008 03:00' - li_44) l_ima_56 = 1.6;
if (TimeCurrent() > D'08.07.2008 03:00' - li_44 && TimeCurrent() < D'29.07.2008 03:00' - li_44) l_ima_56 = 1.5;
if (TimeCurrent() > D'16.09.2008 03:00' - li_44 && TimeCurrent() < D'23.09.2008 03:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'24.09.2008 03:00' - li_44 && TimeCurrent() < D'29.09.2008 03:00' - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > D'27.10.2008 13:00' - li_44 && TimeCurrent() < D'28.10.2008 04:00' - li_44) li_28 = TRUE;
if (TimeCurrent() > D'28.10.2008 03:58:20' - li_44 && TimeCurrent() < D'09.12.2008 03:00' - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > D'04.11.2008 02:00' - li_44 && TimeCurrent() < D'13.11.2008 02:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'03.12.2008 02:00' - li_44 && TimeCurrent() < D'04.12.2008 12:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'18.12.2008 02:00' - li_44 && TimeCurrent() < D'18.12.2008 05:00' - li_44) li_28 = TRUE;
if (TimeCurrent() > D'18.12.2008 02:00' - li_44 && TimeCurrent() < D'16.01.2009 02:00' - li_44) l_ima_56 = 1.3;
if (TimeCurrent() > D'27.02.2009 02:00' - li_44 && TimeCurrent() < D'16.03.2009 03:00' - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > D'31.03.2009 03:00' - li_44 && TimeCurrent() < D'29.04.2009 03:00' - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > D'09.06.2009 03:00' - li_44 && TimeCurrent() < D'01.07.2009 03:00' - li_44) l_ima_56 = 1.5;
if (TimeCurrent() > D'29.10.2009 03:00' - li_44 && TimeCurrent() < D'30.10.2009 21:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'03.12.2009 02:00' - li_44 && TimeCurrent() < D'09.12.2009 02:00' - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > D'04.03.2010 02:00' - li_44 && TimeCurrent() < D'16.03.2010 03:00' - li_44) li_32 = TRUE;
if (TimeCurrent() > D'17.03.2010 03:00' - li_44 && TimeCurrent() < D'19.03.2010 03:00' - li_44) l_ima_56 = 1.3;
if (TimeCurrent() > 1294185600 - li_44 && TimeCurrent() < 1295308800 - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > 1304521200 - li_44 && TimeCurrent() < 1304607600 - li_44) li_28 = TRUE;
if (TimeCurrent() > 1304553600 - li_44 && TimeCurrent() < 1304726400 - li_44) l_ima_56 = 1.4;
if (TimeCurrent() > 1306022400 - li_44 && TimeCurrent() < 1306195200 - li_44) li_28 = TRUE;
if (TimeCurrent() > 1305849600 - li_44 && TimeCurrent() < 1306540800 - li_44) l_ima_56 = 1.5;
}
if (FIFO_applies == TRUE) {
OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
if (OrderProfit() >= MarketInfo(Symbol(), MODE_TICKVALUE) * li_20 * OrderLots()) {
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber) return (OrderClose(OrderTicket(), OrderLots(), Bid, l_slippage_24, Blue));
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber) return (OrderClose(OrderTicket(), OrderLots(), Ask, l_slippage_24, Red));
}
}
if (FIFO_applies == FALSE) {
for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) {
OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber && OrderTakeProfit() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), 0, OrderOpenPrice() + li_20 * Point, 0, Blue);
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber && OrderTakeProfit() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), 0, OrderOpenPrice() - li_20 * Point, 0, Red);
}
}
for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) {
li_16 = 1;
lda_112[l_pos_0] = OrderOpenPrice();
l_lots_152 += OrderLots();
ld_160 += OrderProfit() + OrderSwap() + OrderCommission();
}
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) {
li_16 = -1;
lda_116[l_pos_0] = OrderOpenPrice();
l_lots_152 += OrderLots();
ld_160 += OrderProfit() + OrderSwap() + OrderCommission();
}
}
double ld_120 = lda_112[ArrayMaximum(lda_112, OrdersTotal())];
for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++)
if (lda_112[l_pos_0] == 0.0) lda_112[l_pos_0] = ld_120;
double ld_128 = lda_112[ArrayMinimum(lda_112, OrdersTotal())];
double ld_136 = lda_116[ArrayMaximum(lda_116, OrdersTotal())];
for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++)
if (lda_116[l_pos_0] == 0.0) lda_116[l_pos_0] = ld_136;
double ld_144 = lda_116[ArrayMinimum(lda_116, OrdersTotal())];
if (ld_160 >= AccountBalance() * CloseFactor / 100.0 || ld_160 <= (-1.0 * (AccountBalance() * MaxDD)) / 100.0) gi_196 = TRUE;
if (gi_196 == TRUE && FIFO_applies == TRUE) {
for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) return (OrderClose(OrderTicket(), OrderLots(), Bid, l_slippage_24, Blue));
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) return (OrderClose(OrderTicket(), OrderLots(), Ask, l_slippage_24, Red));
}
}
if (gi_196 == TRUE && FIFO_applies == FALSE) {
for (l_pos_4 = OrdersTotal() - 1; l_pos_4 > -1; l_pos_4--) {
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_BUY && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) return (OrderClose(OrderTicket(), OrderLots(), Bid, l_slippage_24, Blue));
if (OrderType() == OP_SELL && OrderMagicNumber() == MagicNumber || OrderMagicNumber() == l_magic_184) return (OrderClose(OrderTicket(), OrderLots(), Ask, l_slippage_24, Red));
}
}
if (AccountFreeMarginCheck(Symbol(), OP_BUY, l_lots_152 + 0.1) > 0.0 && AccountFreeMarginCheck(Symbol(), OP_SELL, l_lots_152 + 0.1) > 0.0) {
if (li_52 == 0 && li_28 == FALSE) {
if (l_ima_56 > l_ima_64) {
l_ticket_48 = OrderSend(Symbol(), OP_BUY, l_lots_104, Ask, l_slippage_24, 0, 0, "EA Guinea % Start Long", MagicNumber, 0, Blue);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
if (l_ima_56 < l_ima_64) {
l_ticket_48 = OrderSend(Symbol(), OP_SELL, l_lots_104, Bid, l_slippage_24, 0, 0, "EA Guinea % Start Short", MagicNumber, 0, Red);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
}
if (li_52 > 0 && li_52 < MaxRods && gi_196 == FALSE && li_28 == FALSE) {
if (li_16 == 1 && Ask - ld_120 >= li_20 * Point / GridFactor || ld_128 - Ask >= li_20 * Point / GridFactor) {
l_ticket_48 = OrderSend(Symbol(), OP_BUY, l_lots_104, Ask, l_slippage_24, 0, 0, "EA Guinea % Grid Long", MagicNumber, 0, Blue);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
if (li_16 == -1 && ld_144 - Bid >= li_20 * Point / GridFactor || Bid - ld_136 >= li_20 * Point / GridFactor) {
l_ticket_48 = OrderSend(Symbol(), OP_SELL, l_lots_104, Bid, l_slippage_24, 0, 0, "EA Guinea % Grid Short", MagicNumber, 0, Red);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
}
if (li_52 >= MaxRods && gi_196 == FALSE && l_lots_152 <= ld_176 && li_32 == FALSE) {
if (li_16 == 1 && l_istochastic_80 < l_istochastic_96 && l_istochastic_72 > l_istochastic_88 && ld_128 - Ask >= li_20 * Point * HammerFactor) {
l_ticket_48 = OrderSend(Symbol(), OP_BUY, l_lots_152, Ask, l_slippage_24, 0, 0, "EA Guinea % Hammer Long", l_magic_184, 0, Blue);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
if (li_16 == -1 && l_istochastic_80 > l_istochastic_96 && l_istochastic_72 < l_istochastic_88 && Bid - ld_136 >= li_20 * Point * HammerFactor) {
l_ticket_48 = OrderSend(Symbol(), OP_SELL, l_lots_152, Bid, l_slippage_24, 0, 0, "EA Guinea % Hammer Short", l_magic_184, 0, Red);
if (l_ticket_48 < 0) {
Print("Order Send Error ", GetLastError());
return (0);
}
}
}
}
return (0);
}