#property copyright "Copyright © 2008, Julia Saveliev" #property link "metaexpert323@gmail.com" string gs_76 = "2009.06.14"; extern double Lots = 0.1; bool gi_92 = TRUE; int g_shift_96 = 430; int gi_100 = 430; int gi_104 = 430; int gi_108 = 5; int gi_112; int gi_116; double gd_120 = 5.0; double gd_128 = 5.0; double gd_136 = 3.0; double gd_144 = 7.0; double gd_152 = 500.0; double gd_160 = 15.0; double gd_168 = 20.0; double gd_176 = 20.0; int gi_184; int gi_unused_196 = 0; int gi_unused_200 = 0; bool gi_204 = FALSE; bool gi_208 = FALSE; bool gi_212 = FALSE; double gd_216 = 20.0; bool gi_unused_224 = FALSE; int g_count_228 = 0; int g_pos_232 = 0; int g_slippage_236 = 5; double g_price_240 = 0.0; double g_price_248 = 0.0; double g_lots_256 = 0.0; double gd_unused_264 = 0.0; int gi_272; int g_datetime_276; int g_datetime_280; int gi_288; double g_iclose_292 = 0.0; double g_iclose_300 = 10000.0; double gd_308 = 0.0; double gd_unused_316 = 10000.0; double gd_unused_324 = 0.0; double gd_unused_332 = 10000.0; double gd_unused_340 = 0.0; double gd_unused_348 = 0.0; double gd_unused_356 = 10000.0; double g_iclose_364 = 0.0; double gd_unused_372 = 0.0; double gd_unused_380 = 0.0; double g_iopen_400 = 0.0; double g_iopen_408 = 0.0; int gi_416 = 0; string gs_420; string gs_428; int gi_436; double gd_440; double gd_448; int g_magic_456 = 20081009; string gs_unused_460 = ""; string gs_unused_468 = ""; int init() { if (gi_204) { Comment("Account Number = " + AccountNumber() + ", Lots = automatic" + "\n" + "\n" + "Copyright © 2008, Julia Saveliev, support metaexpert323@gmail.com"); } else { Comment("Account Number = " + AccountNumber() + ", Lots = ", Lots + "\n" + "\n" + "Copyright © 2008, Julia Saveliev, support metaexpert323@gmail.com"); } if (Point == 0.00001) { gd_448 = 10.0 * Point; gi_436 = 5; } else { if (Point == 0.0001) { gd_448 = Point; gi_436 = 4; } else { if (Point == 0.001) { gd_448 = 10.0 * Point; gi_436 = 3; } else { if (Point == 0.01) { gd_448 = Point; gi_436 = 2; } } } } return (0); } int deinit() { return (0); } int start() { double l_price_68; int l_count_80; if (TimeDayOfYear(StrToTime(gs_76)) < DayOfYear() || TimeYear(TimeCurrent()) > 2009 && !(TimeYear(TimeCurrent()) < 2009)) { Comment("Your trial version is expired."); return (0); } int l_ord_total_0 = OrdersTotal(); gd_440 = Lots; g_lots_256 = Lots; double ld_4 = Lots / 0.1; g_count_228 = 0; int l_count_12 = 0; int l_count_16 = 0; double ld_20 = 0; double l_ord_lots_28 = 0; int l_datetime_36 = 0; int l_datetime_40 = 0; string ls_44 = "999999999999999999999999999999"; int l_str2int_52 = 0; int li_unused_56 = 0; int l_count_60 = 0; bool li_64 = TRUE; gi_416 = 0; gd_unused_316 = 10000; gd_unused_332 = 10000; gd_unused_324 = 0; gd_unused_340 = 0; gi_112 = gi_108; gi_116 = gi_108; while (li_64) { li_64 = FALSE; for (g_pos_232 = 0; g_pos_232 < l_ord_total_0; g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456) { if (StrToInteger(StringSubstr(ls_44, 15, 10)) > StrToInteger(StringSubstr(OrderComment(), 15, 10))) { if (StrToInteger(StringSubstr(OrderComment(), 15, 10)) > l_str2int_52) { ls_44 = OrderComment(); li_64 = TRUE; } } l_count_60++; } } if (li_64) { l_str2int_52 = StrToInteger(StringSubstr(ls_44, 15, 10)); for (int l_pos_76 = 0; l_pos_76 < l_ord_total_0; l_pos_76++) { OrderSelect(l_pos_76, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456 && ls_44 == OrderComment()) { g_count_228++; if (gi_92) ld_20 = ld_20 + OrderProfit() + OrderSwap(); else ld_20 += OrderProfit(); if (l_ord_lots_28 < OrderLots()) l_ord_lots_28 = OrderLots(); if (OrderType() == OP_SELL) { l_count_12++; if (OrderOpenTime() > l_datetime_36) l_datetime_36 = OrderOpenTime(); } if (OrderType() == OP_BUY) { l_count_16++; if (OrderOpenTime() > l_datetime_40) l_datetime_40 = OrderOpenTime(); } } } if (l_datetime_40 > l_datetime_36) gi_416 = 1; if (l_datetime_40 < l_datetime_36) gi_416 = 2; if (ld_20 >= gd_128 * g_lots_256 && g_count_228 > 1) { l_count_80 = 1000; while (l_count_80 > 0) { for (g_pos_232 = OrdersTotal(); g_pos_232 >= 0; g_pos_232--) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456 && ls_44 == OrderComment()) { if (OrderType() == OP_BUY) l_price_68 = Bid; else { if (OrderType() == OP_SELL) l_price_68 = Ask; else l_price_68 = 0; } OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(l_price_68, gi_436), g_slippage_236, Blue); } } l_count_80 = 0; for (g_pos_232 = 0; g_pos_232 < OrdersTotal(); g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456 && ls_44 == OrderComment()) l_count_80++; } } return (0); } SetLots(l_ord_lots_28 / ld_4); if (g_count_228 == 1 && l_count_16 == 1 && iClose(Symbol(), 0, 1) < StrToDouble(StringSubstr(ls_44, 0, 6)) - (gd_168 - gd_160) * gd_144 * gd_448) { for (g_pos_232 = 0; g_pos_232 < OrdersTotal(); g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456 && ls_44 == OrderComment()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit() + 200.0 * gd_448, 0); } SendSellOrder(gd_440 * ld_4, ls_44); } if (g_count_228 > 1 && gi_416 == 1 && iClose(Symbol(), 0, 1) < StrToDouble(StringSubstr(ls_44, 0, 6)) - (gd_168 - gd_160) * gd_144 * gd_448) SendSellOrder(gd_440 * ld_4, ls_44); if (g_count_228 == 1 && l_count_12 == 1 && iClose(Symbol(), 0, 1) > StrToDouble(StringSubstr(ls_44, 6, 6)) + (gd_168 - gd_160) * gd_144 * gd_448) { for (g_pos_232 = 0; g_pos_232 < OrdersTotal(); g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_456 && ls_44 == OrderComment()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderTakeProfit() - 200.0 * gd_448, 0); } SendBuyOrder(gd_440 * ld_4, ls_44); } if (g_count_228 > 1 && gi_416 == 2 && iClose(Symbol(), 0, 1) > StrToDouble(StringSubstr(ls_44, 6, 6)) + (gd_168 - gd_160) * gd_144 * gd_448) SendBuyOrder(gd_440 * ld_4, ls_44); } ls_44 = "999999999999999999999999999999"; g_count_228 = 0; l_count_16 = 0; l_count_12 = 0; l_ord_lots_28 = 0; l_datetime_40 = 0; l_datetime_36 = 0; ld_20 = 0; } if (TimeToStr(TimeCurrent(), TIME_DATE) + ":" + TimeToStr(TimeCurrent(), TIME_MINUTES) != TimeToStr(gi_288, TIME_DATE) + ":" + TimeToStr(gi_288, TIME_MINUTES)) { g_iclose_292 = 0; g_iclose_300 = 10000; gd_308 = 0; l_ord_lots_28 = 0; if (gi_272 < iTime(Symbol(), 0, gi_108)) { if (g_iclose_364 > 0.0) g_shift_96 = iBarShift(Symbol(), 0, gi_272, FALSE); for (g_pos_232 = g_shift_96; g_pos_232 > 0; g_pos_232--) { if (iClose(Symbol(), 0, g_pos_232) > g_iclose_292) g_iclose_292 = iClose(Symbol(), 0, g_pos_232); if (iClose(Symbol(), 0, g_pos_232) < g_iclose_300) g_iclose_300 = iClose(Symbol(), 0, g_pos_232); gd_308 = g_iclose_292 - g_iclose_300; if (gd_308 >= gd_160 * gd_448 && g_shift_96 - g_pos_232 < gi_108) { gi_272 = iTime(Symbol(), 0, g_shift_96 - 1); break; } if (g_shift_96 - g_pos_232 >= gi_108) gi_184 = g_shift_96 - g_pos_232; } } if ((g_shift_96 - g_pos_232 >= gi_108 && g_iclose_300 == iClose(Symbol(), 0, 1)) || (gi_184 >= gi_108 && gi_184 != g_shift_96 - g_pos_232 && g_iclose_300 == iClose(Symbol(), 0, 1))) { if (gd_308 >= gd_160 * gd_448) { if (SellAlowed(g_iclose_292) && LastSmallRectangleLower(g_iclose_292)) { if (gi_436 == 2) { if (g_iclose_300 >= 100.0 && g_iclose_292 >= 100.0) gs_428 = DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "SEL" + TimeCurrent(); else { if (g_iclose_300 < 100.0 && g_iclose_292 < 100.0) gs_428 = "0" + DoubleToStr(g_iclose_300, gi_436) + "0" + DoubleToStr(g_iclose_292, gi_436) + "SEL" + TimeCurrent(); else gs_428 = "0" + DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "SEL" + TimeCurrent(); } } else { if (gi_436 == 3) { if (g_iclose_300 >= 100.0 && g_iclose_292 >= 100.0) gs_428 = DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "SEL" + TimeCurrent(); else { if (g_iclose_300 < 100.0 && g_iclose_292 < 100.0) gs_428 = "0" + DoubleToStr(g_iclose_300, gi_436 - 1) + "0" + DoubleToStr(g_iclose_292, gi_436 - 1) + "SEL" + TimeCurrent(); else gs_428 = "0" + DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "SEL" + TimeCurrent(); } } else { if (gi_436 == 4) gs_428 = DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "SEL" + TimeCurrent(); else gs_428 = DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "SEL" + TimeCurrent(); } } SendSellOrder(Lots, gs_428); } g_iclose_364 = iClose(Symbol(), 0, 1); gi_272 = iTime(Symbol(), 0, 1); gi_288 = iTime(Symbol(), 0, 0); g_iopen_400 = iOpen(Symbol(), 0, 0); gi_184 = 0; return (0); } } if ((g_shift_96 - g_pos_232 >= gi_108 && g_iclose_292 == iClose(Symbol(), 0, 1)) || (gi_184 >= gi_108 && gi_184 != g_shift_96 - g_pos_232 && g_iclose_292 == iClose(Symbol(), 0, 1))) { if (gd_308 >= gd_160 * gd_448) { if (BuyAlowed(g_iclose_300) && LastSmallRectangleHigher(g_iclose_300)) { if (gi_436 == 2) { if (g_iclose_300 >= 100.0 && g_iclose_292 >= 100.0) gs_420 = DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "BUY" + TimeCurrent(); else { if (g_iclose_300 < 100.0 && g_iclose_292 < 100.0) gs_420 = "0" + DoubleToStr(g_iclose_300, gi_436) + "0" + DoubleToStr(g_iclose_292, gi_436) + "BUY" + TimeCurrent(); else gs_420 = "0" + DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "BUY" + TimeCurrent(); } } else { if (gi_436 == 3) { if (g_iclose_300 >= 100.0 && g_iclose_292 >= 100.0) gs_420 = DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "BUY" + TimeCurrent(); else { if (g_iclose_300 < 100.0 && g_iclose_292 < 100.0) gs_420 = "0" + DoubleToStr(g_iclose_300, gi_436 - 1) + "0" + DoubleToStr(g_iclose_292, gi_436 - 1) + "BUY" + TimeCurrent(); else gs_420 = "0" + DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "BUY" + TimeCurrent(); } } else { if (gi_436 == 4) gs_420 = DoubleToStr(g_iclose_300, gi_436) + DoubleToStr(g_iclose_292, gi_436) + "BUY" + TimeCurrent(); else gs_420 = DoubleToStr(g_iclose_300, gi_436 - 1) + DoubleToStr(g_iclose_292, gi_436 - 1) + "BUY" + TimeCurrent(); } } SendBuyOrder(Lots, gs_420); } g_iclose_364 = iClose(Symbol(), 0, 1); gi_272 = iTime(Symbol(), 0, 1); gi_288 = iTime(Symbol(), 0, 0); g_iopen_408 = iOpen(Symbol(), 0, 0); gi_184 = 0; return (0); } } } return (0); } void SetLots(double ad_0) { if (gi_204) { if (!gi_208) { gd_440 = MathCeil(AccountFreeMargin() * gd_216 / 1000000.0); if (gd_440 < 1.0) gd_440 = 1; } else { if (gi_212) { gd_440 = NormalizeDouble(AccountFreeMargin() * gd_216 / 1000000.0, 2); if (gd_440 < 0.01) gd_440 = 0.01; } else { gd_440 = NormalizeDouble(AccountFreeMargin() * gd_216 / 1000000.0, 1); if (gd_440 < 0.1) gd_440 = 0.1; } } } else gd_440 = Lots; if (ad_0 > 0.0) gd_440 = NormalizeDouble(ad_0 * gd_136, 1); if (gd_440 > 100.0) gd_440 = 100; } void SendSellOrder(double a_lots_0, string a_comment_8) { if (a_lots_0 == Lots) g_price_248 = Bid - NormalizeDouble(gd_120 * gd_448, gi_436); else g_price_248 = Bid - NormalizeDouble((gd_120 + 500.0) * gd_448, gi_436); g_price_240 = Bid + NormalizeDouble(gd_152 * gd_448, gi_436); OrderSend(Symbol(), OP_SELL, a_lots_0, NormalizeDouble(Bid, gi_436), g_slippage_236, g_price_240, g_price_248, a_comment_8, g_magic_456, 0, Red); } void SendBuyOrder(double a_lots_0, string a_comment_8) { if (a_lots_0 == Lots) g_price_248 = Ask + NormalizeDouble(gd_120 * gd_448, gi_436); else g_price_248 = Ask + NormalizeDouble((gd_120 + 500.0) * gd_448, gi_436); g_price_240 = Ask - NormalizeDouble(gd_152 * gd_448, gi_436); OrderSend(Symbol(), OP_BUY, a_lots_0, NormalizeDouble(Ask, gi_436), g_slippage_236, g_price_240, g_price_248, a_comment_8, g_magic_456, 0, Blue); } int SellAlowed(double ad_0) { double l_iclose_8 = 0; double l_iclose_16 = 10000; double ld_24 = 0; g_datetime_276 = 0; int li_48 = 1100; gi_100 = 300; for (g_pos_232 = gi_100; g_pos_232 > 0; g_pos_232--) { if (iClose(Symbol(), 0, g_pos_232) > l_iclose_8) l_iclose_8 = iClose(Symbol(), 0, g_pos_232); if (iClose(Symbol(), 0, g_pos_232) < l_iclose_16) l_iclose_16 = iClose(Symbol(), 0, g_pos_232); ld_24 = l_iclose_8 - l_iclose_16; if (ld_24 > gd_168 * gd_448 && gi_100 - g_pos_232 < gi_112 || li_48 - g_pos_232 < gi_112) { g_datetime_276 = iTime(Symbol(), 0, gi_100 - 1); l_iclose_8 = 0; l_iclose_16 = 10000; ld_24 = 0; if (li_48 == 1100) g_pos_232 = gi_100; else g_pos_232 = li_48; li_48 = g_pos_232 - 1; } if (ld_24 > gd_168 * gd_448 && gi_100 - g_pos_232 >= gi_112 && g_pos_232 > 1) { l_iclose_8 = 0; l_iclose_16 = 10000; ld_24 = 0; li_48 = g_pos_232 - 1; } } if (l_iclose_8 == ad_0) return (1); return (0); } int BuyAlowed(double ad_0) { double l_iclose_8 = 0; double l_iclose_16 = 10000; double ld_24 = 0; g_datetime_280 = 0; int li_48 = 1100; gi_104 = 300; for (g_pos_232 = gi_104; g_pos_232 > 0; g_pos_232--) { if (iClose(Symbol(), 0, g_pos_232) > l_iclose_8) l_iclose_8 = iClose(Symbol(), 0, g_pos_232); if (iClose(Symbol(), 0, g_pos_232) < l_iclose_16) l_iclose_16 = iClose(Symbol(), 0, g_pos_232); ld_24 = l_iclose_8 - l_iclose_16; if (ld_24 > gd_176 * gd_448 && gi_104 - g_pos_232 < gi_116 || li_48 - g_pos_232 < gi_116) { g_datetime_280 = iTime(Symbol(), 0, gi_104 - 1); l_iclose_8 = 0; l_iclose_16 = 10000; ld_24 = 0; if (li_48 == 1100) g_pos_232 = gi_104; else g_pos_232 = li_48; li_48 = g_pos_232 - 1; } if (ld_24 > gd_176 * gd_448 && gi_104 - g_pos_232 >= gi_116 && g_pos_232 > 1) { l_iclose_8 = 0; l_iclose_16 = 10000; ld_24 = 0; li_48 = g_pos_232 - 1; } } if (l_iclose_16 == ad_0) return (1); return (0); } int LastSmallRectangleLower(double ad_unused_0) { double l_iclose_8 = 0; double l_iclose_16 = 0; double l_iclose_24 = 10000; double ld_32 = 0; gi_272 = 0; int li_56 = 1100; g_shift_96 = 300; for (g_pos_232 = g_shift_96; g_pos_232 > 3; g_pos_232--) { if (iClose(Symbol(), 0, g_pos_232) > l_iclose_16) l_iclose_16 = iClose(Symbol(), 0, g_pos_232); if (iClose(Symbol(), 0, g_pos_232) < l_iclose_24) l_iclose_24 = iClose(Symbol(), 0, g_pos_232); ld_32 = l_iclose_16 - l_iclose_24; if (ld_32 > gd_160 * gd_448 && g_shift_96 - g_pos_232 < gi_108 || li_56 - g_pos_232 < gi_108) { gi_272 = iTime(Symbol(), 0, g_shift_96 - 1); l_iclose_16 = 0; l_iclose_24 = 10000; ld_32 = 0; if (li_56 == 1100) g_pos_232 = g_shift_96; else g_pos_232 = li_56; li_56 = g_pos_232 - 1; } if (ld_32 > gd_160 * gd_448 && g_shift_96 - g_pos_232 >= gi_108 && g_pos_232 > 1) { l_iclose_8 = l_iclose_16; l_iclose_16 = 0; l_iclose_24 = 10000; ld_32 = 0; li_56 = g_pos_232 - 1; } } if (l_iclose_8 < l_iclose_16) return (1); return (0); } int LastSmallRectangleHigher(double ad_unused_0) { double l_iclose_8 = 0; double l_iclose_16 = 0; double l_iclose_24 = 10000; double ld_32 = 0; gi_272 = 0; int li_56 = 1100; g_shift_96 = 300; for (g_pos_232 = g_shift_96; g_pos_232 > 3; g_pos_232--) { if (iClose(Symbol(), 0, g_pos_232) > l_iclose_16) l_iclose_16 = iClose(Symbol(), 0, g_pos_232); if (iClose(Symbol(), 0, g_pos_232) < l_iclose_24) l_iclose_24 = iClose(Symbol(), 0, g_pos_232); ld_32 = l_iclose_16 - l_iclose_24; if (ld_32 > gd_160 * gd_448 && g_shift_96 - g_pos_232 < gi_108 || li_56 - g_pos_232 < gi_108) { gi_272 = iTime(Symbol(), 0, g_shift_96 - 1); l_iclose_16 = 0; l_iclose_24 = 10000; ld_32 = 0; if (li_56 == 1100) g_pos_232 = g_shift_96; else g_pos_232 = li_56; li_56 = g_pos_232 - 1; } if (ld_32 > gd_160 * gd_448 && g_shift_96 - g_pos_232 >= gi_108 && g_pos_232 > 1) { l_iclose_8 = l_iclose_24; l_iclose_16 = 0; l_iclose_24 = 10000; ld_32 = 0; li_56 = g_pos_232 - 1; } } if (l_iclose_8 > l_iclose_24) return (1); return (0); }