#property copyright "MG v2.5 © 2007, James and Felix for Lumen Forex" #property link "www.LumenForex.com" #property show_inputs extern int Capital = 0; extern double MaxAccountMoney = 0.0; extern bool looping = TRUE; extern bool CloseAllNow = FALSE; extern string FirstOrder = "auto"; extern bool MicroAccount = FALSE; extern double Lot = 0.1; extern int TP = 25; extern double TPMoney = 0.0; extern int StopLossRange = 0; extern double SLMoney = 0.0; extern double MaxRiskPercentage = 30.0; extern int MaxLevel = 4; extern int Range = 20; extern double Multiplier = 2.0; extern int StartLevelIncrease = 0; extern int RangeIncrease = 0; extern string DateTimeStart = "2007.08.26 19:29:00"; extern string DateTimeStopLooping = "0"; extern string DateTimeClose = "0"; extern int TrailingStopRange = 3; extern int TrailingStopStartLevel = 2; extern double TrailingStopMoney = 0.0; extern bool StartTrailingStopAfterRange = FALSE; extern int RangeForStartTrailing = 0; string gs_unused_220 = "2008.08.31 23:59:00"; int gi_228; int gi_232; int gi_236 = 0; int gi_240 = 0; int g_count_244 = 0; int g_magic_248 = 0; int g_ord_total_252; int g_pos_256; int g_ticket_260; int gi_264 = 0; int gi_268; int gi_272; int gi_276 = 0; int gi_280; int gi_284; double g_ord_open_price_288; double g_price_296; double gd_304; double g_price_312; double g_lots_320; double g_price_328; double gd_336; double gd_344; double g_ord_open_price_352; double gd_unused_360; double gd_368; double gd_376; double gd_384; double gd_392; double gd_400; double gd_408; string gs_416; string gs_424 = "0"; string gs_432; int g_ord_total_440 = 0; int gi_444 = 0; bool gi_448 = TRUE; bool gi_452; bool gi_456 = FALSE; bool gi_460 = FALSE; bool gi_464 = FALSE; int start() { if (!(ObjectFind("MGONOFF") < 0)) { gi_448 = FALSE; gi_452 = TRUE; gi_444 = FALSE; if (gi_464 == FALSE) { Alert("(c) by James Soetanto"); Alert("3. Click or Drag the Robot into Chart"); Alert("2. Open a New Chart"); Alert("1. Close The Chart"); Alert("TO RUN THE ROBOT AGAIN:"); gi_464 = TRUE; } } if (gi_452 == FALSE) { ObjectsDeleteAll(0); ObjectCreate("label_sub", OBJ_LABEL, 0, 0, 0); ObjectSet("label_sub", OBJPROP_XDISTANCE, 5); ObjectSet("label_sub", OBJPROP_YDISTANCE, 20); ObjectCreate("label_stime", OBJ_LABEL, 0, 0, 0); ObjectSet("label_stime", OBJPROP_XDISTANCE, 5); ObjectSet("label_stime", OBJPROP_YDISTANCE, 40); ObjectCreate("label_ctime", OBJ_LABEL, 0, 0, 0); ObjectSet("label_ctime", OBJPROP_XDISTANCE, 5); ObjectSet("label_ctime", OBJPROP_YDISTANCE, 60); ObjectCreate("label_ltime", OBJ_LABEL, 0, 0, 0); ObjectSet("label_ltime", OBJPROP_XDISTANCE, 5); ObjectSet("label_ltime", OBJPROP_YDISTANCE, 80); ObjectCreate("label_tp", OBJ_LABEL, 0, 0, 0); ObjectSet("label_tp", OBJPROP_XDISTANCE, 5); ObjectSet("label_tp", OBJPROP_YDISTANCE, 100); ObjectCreate("label_tp2", OBJ_LABEL, 0, 0, 0); ObjectSet("label_tp2", OBJPROP_XDISTANCE, 5); ObjectSet("label_tp2", OBJPROP_YDISTANCE, 120); ObjectCreate("label_range", OBJ_LABEL, 0, 0, 0); ObjectSet("label_range", OBJPROP_XDISTANCE, 5); ObjectSet("label_range", OBJPROP_YDISTANCE, 140); ObjectCreate("label_risk", OBJ_LABEL, 0, 0, 0); ObjectSet("label_risk", OBJPROP_XDISTANCE, 5); ObjectSet("label_risk", OBJPROP_YDISTANCE, 160); ObjectCreate("label_etc", OBJ_LABEL, 0, 0, 0); ObjectSet("label_etc", OBJPROP_XDISTANCE, 5); ObjectSet("label_etc", OBJPROP_YDISTANCE, 180); ObjectCreate("label_tsetc", OBJ_LABEL, 0, 0, 0); ObjectSet("label_tsetc", OBJPROP_XDISTANCE, 5); ObjectSet("label_tsetc", OBJPROP_YDISTANCE, 200); ObjectCreate("label_rangeinc", OBJ_LABEL, 0, 0, 0); ObjectSet("label_rangeinc", OBJPROP_XDISTANCE, 5); ObjectSet("label_rangeinc", OBJPROP_YDISTANCE, 220); ObjectSetText("label_sub", " ", 10, "Times New Roman", Violet); ObjectSetText("label_stime", " ", 10, "Times New Roman", Violet); ObjectSetText("label_ctime", " ", 10, "Times New Roman", Violet); ObjectSetText("label_ltime", " ", 10, "Times New Roman", Violet); ObjectSetText("label_tp", " ", 10, "Times New Roman", Violet); ObjectSetText("label_tp2", " ", 10, "Times New Roman", Violet); ObjectSetText("label_range", " ", 10, "Times New Roman", Violet); ObjectSetText("label_risk", " ", 10, "Times New Roman", Violet); ObjectSetText("label_etc", " ", 10, "Times New Roman", Violet); ObjectSetText("label_tsetc", " ", 10, "Times New Roman", Violet); ObjectSetText("label_rangeinc", " ", 10, "Times New Roman", Violet); gi_228 = MarketInfo(Symbol(), MODE_STOPLEVEL) + 1.0; if (gi_228 < 3) gi_228 = 3; gd_408 = Ask - Bid; gi_232 = -1; if (StartLevelIncrease <= 0) { StartLevelIncrease = 0; RangeIncrease = 0; } if (RangeIncrease > 0 && StartTrailingStopAfterRange == TRUE) { Alert("a=> You Should Turn Off The RangeIncrease"); Alert("a=> TS After Range Would Not Works Well"); } if (TrailingStopStartLevel < 1) TrailingStopStartLevel = 0; if (Range < gi_228) { Range = gi_228; Alert("b=>Range will set to " + gi_228); Alert("b=> Your Range is TOO NARROW !"); } if (StartTrailingStopAfterRange == FALSE) RangeForStartTrailing = 0; gd_392 = AccountBalance(); if (StartTrailingStopAfterRange == TRUE && RangeForStartTrailing <= 0) gi_240 = Range; if (StartTrailingStopAfterRange == TRUE && RangeForStartTrailing > 0) gi_240 = RangeForStartTrailing; if (TP < Range) Alert("c=> Warning, Your TP is Smaller than Range " + Range); if (RangeForStartTrailing < Range && StartTrailingStopAfterRange == TRUE && RangeForStartTrailing != 0) { gi_240 = Range; Alert("d=> Start Range For TS will set to " + gi_240); Alert("d=> Your Start Range For TS is Too Narrow!"); } if (TP <= 0) TP = Range; if (StopLossRange < gi_228 && StopLossRange != 0) { gi_268 = gi_228; Alert("Your SL is too short and will set to " + gi_268); } if (StopLossRange >= gi_228) gi_268 = StopLossRange; if (Lot > AccountBalance() / 950.0 / 10.0) Alert("Warning, Your Lot Size is TOO BIG!"); if (TrailingStopRange < gi_228 && TrailingStopRange != 0) Print("Trailing Stop runs on Background mode"); gi_452 = TRUE; } if (TrailingStopRange <= 0) TrailingStopRange = 0; if (MaxRiskPercentage == 0.0) MaxRiskPercentage = 100; if (MaxLevel <= 1) MaxLevel = 1; CheckRisk(); while (gi_448 == TRUE) { RefreshRates(); Comment(TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS)); if (IsDemo() == FALSE) { Alert("Hak Cipta (c) LumenForex.com"); Alert("Robot ini hanya bisa berjalan pada Account Demo"); Alert("Robot ini dibuat untuk Participant Lumen"); gi_448 = FALSE; return (0); } gi_272 = TrailingStopRange; if (StartLevelIncrease <= 0) RangeIncrease = 0; gi_280 = Range; if (StopLossRange <= 0 && StartLevelIncrease <= 0) gi_268 = Range * MaxLevel + Range; if (StopLossRange <= 0 && StartLevelIncrease > 0) gi_268 = 0; if (Capital <= 0) { gd_304 = 100.0 * ((AccountEquity() - gd_392) / gd_392); gd_400 = gd_392; } if (Capital > 0) { if (Capital >= AccountEquity()) gd_304 = 100.0 * ((AccountEquity() - Capital) / Capital); if (Capital < AccountEquity()) gd_304 = 100.0 * (AccountProfit() / Capital); gd_400 = Capital; } if (gi_264 == TRUE) gs_432 = "ON"; else gs_432 = "OFF"; ObjectSetText("label_sub", "MACHINE GUN v2.5 (LumenForex.com)", 10, "Times New Roman", Violet); ObjectSetText("label_tp", "TP= " + TP + " SL= " + gi_268 + " (" + DoubleToStr(gd_336, 4) + ") CYCLE: " + gs_424, 10, "Times New Roman", Yellow); ObjectSetText("label_tp2", "TP Money= " + DoubleToStr(TPMoney, 2) + " SL Money= " + DoubleToStr(SLMoney, 2) + " MaxAccountMoney= " + DoubleToStr(MaxAccountMoney, 2), 10, "Times New Roman", Yellow); ObjectSetText("label_stime", "START DATE / TIME : " + DateTimeStart, 10, "Times New Roman", Yellow); ObjectSetText("label_ctime", "CLOSE DATE / TIME : " + DateTimeClose, 10, "Times New Roman", Yellow); ObjectSetText("label_ltime", "STOP LOOP DATE / TIME : " + DateTimeStopLooping + " LOOPING=" + looping, 10, "Times New Roman", Yellow); ObjectSetText("label_range", "RANGE : " + Range + " MAX LEVEL : " + MaxLevel, 10, "Times New Roman", Yellow); ObjectSetText("label_risk", "RISK : " + DoubleToStr(gd_304, 2) + "% / -" + DoubleToStr(MaxRiskPercentage, 2) + "% ($ " + DoubleToStr(gd_400, 2) + ")", 10, "Times New Roman", Yellow); if (Ask - Bid > gd_408 + 1.0 * Point) ObjectSetText("label_etc", "TRAILING=" + gi_272 + " (" + gs_432 + ") TS START LEVEL=" + TrailingStopStartLevel + " SPREAD=" + DoubleToStr(Ask - Bid, Digits) + " WIDEN!", 10, "Times New Roman", Red); else ObjectSetText("label_etc", "TRAILING=" + gi_272 + " (" + gs_432 + ") TS START LEVEL=" + TrailingStopStartLevel + " SPREAD=" + DoubleToStr(Ask - Bid, Digits), 10, "Times New Roman", Yellow); if (StartTrailingStopAfterRange == TRUE) ObjectSetText("label_tsetc", "START TS FROM RANGE=" + gi_240 + " (ON) START TS MONEY= $" + DoubleToStr(TrailingStopMoney, 2), 10, "Times New Roman", Yellow); else ObjectSetText("label_tsetc", "START TS FROM RANGE=" + gi_240 + " (OFF) START TS MONEY= $" + DoubleToStr(TrailingStopMoney, 2), 10, "Times New Roman", Yellow); ObjectSetText("label_rangeinc", "START LEVEL INCREASE=" + StartLevelIncrease + " Increase=" + RangeIncrease + " MULTIPLIER=" + DoubleToStr(Multiplier, 2), 10, "Times New Roman", Yellow); CheckStop(); if (gs_416 == "nolooping") looping = FALSE; if (gs_416 == "cutall") CloseAllNow = TRUE; if (TimeLocal() >= StrToTime(DateTimeStopLooping) && DateTimeStopLooping != "0") looping = FALSE; if (CloseAllNow == TRUE || gd_304 <= (-MaxRiskPercentage)) { gi_444 = FALSE; gi_448 = FALSE; CloseAll(); } if (TimeLocal() >= StrToTime(DateTimeClose) && DateTimeClose != "0") { gi_444 = FALSE; gi_448 = FALSE; CloseAll(); } if (BuyOrders() + SellOrders() > 0 && gi_444 == FALSE) { gi_444 = TRUE; g_ord_total_440 = OrdersTotal(); if (BuyOrders() > 0 && SellOrders() == 0) gs_424 = "Buy"; if (SellOrders() > 0 && BuyOrders() == 0) gs_424 = "Sell"; } if (BuyOrders() + SellOrders() == 0 && LimitOrders() > 0) CloseAll(); if (BuyOrders() > 0 && SellOrders() > 0) Alert("!! Warning, Open BUY and SELL are in 1 Cycle !!"); if (TPMoney > 0.0 && AccountProfit() >= TPMoney) CloseAll(); if (SLMoney > 0.0 && AccountProfit() <= (-SLMoney)) CloseAll(); if (TimeLocal() >= StrToTime(DateTimeStart) || DateTimeStart == "0") { if (gi_444 == TRUE) { if (g_ord_total_440 == 0 && gi_448 == TRUE && OrdersTotal() == 0) { if (FirstOrder == "auto" || FirstOrder == "Auto" || FirstOrder == "AUTO") { if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) > iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) OpenBuyOrders(); if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) < iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) OpenSellOrders(); } if (FirstOrder == "buy" || FirstOrder == "Buy" || FirstOrder == "BUY") OpenBuyOrders(); if (FirstOrder == "sell" || FirstOrder == "Sell" || FirstOrder == "SELL") OpenSellOrders(); if (FirstOrder == "buy auto" || FirstOrder == "Buy Auto" || FirstOrder == "BUY AUTO") { FirstOrder = "auto"; OpenBuyOrders(); } if (FirstOrder == "sell auto" || FirstOrder == "Sell Auto" || FirstOrder == "SELL AUTO") { FirstOrder = "auto"; OpenSellOrders(); } } } } ObjectSetText("label_tp", "TP= " + TP + " SL= " + gi_268 + " (" + DoubleToStr(gd_336, 4) + ") CYCLE: " + gs_424, 10, "Times New Roman", Yellow); ObjectSetText("label_risk", "RISK : " + DoubleToStr(gd_304, 2) + "% / -" + DoubleToStr(MaxRiskPercentage, 2) + "% ($ " + DoubleToStr(gd_400, 2) + ")", 10, "Times New Roman", Yellow); if (BuyOrders() == 0 && SellOrders() == 0) CloseAll(); if (g_ord_total_440 > OrdersTotal()) CloseAll(); if (BuyOrders() > 0 || SellOrders() > 0) if (gi_272 != 0) trailing(); CheckRisk(); Sleep(1000); } return (0); } void CheckRisk() { if (TPMoney > 0.0 && AccountProfit() >= TPMoney) CloseAll(); if (SLMoney > 0.0 && AccountProfit() <= (-SLMoney)) CloseAll(); if (Capital <= 0) { gd_304 = 100.0 * ((AccountEquity() - gd_392) / gd_392); gd_400 = gd_392; } if (Capital > 0) { if (Capital >= AccountEquity()) gd_304 = 100.0 * ((AccountEquity() - Capital) / Capital); if (Capital < AccountEquity()) gd_304 = 100.0 * (AccountProfit() / Capital); gd_400 = Capital; } ObjectSetText("label_risk", "RISK : " + DoubleToStr(gd_304, 2) + "% / -" + DoubleToStr(MaxRiskPercentage, 2) + "% ($ " + DoubleToStr(gd_400, 2) + ")", 10, "Times New Roman", Yellow); if (CloseAllNow == TRUE || gd_304 <= (-MaxRiskPercentage)) { gi_444 = FALSE; gi_448 = FALSE; CloseAll(); } if (MaxAccountMoney > 0.0 && AccountEquity() >= MaxAccountMoney) { gi_448 = FALSE; CloseAllNow = TRUE; CloseAll(); } } void CloseAll() { int l_ord_total_0; int l_cmd_8; bool li_12; gi_264 = FALSE; gd_unused_360 = 0; gi_276 = 0; gd_368 = 0; gd_336 = 0; gd_384 = 0; gi_280 = Range; gi_460 = FALSE; gi_232 = -1; gi_456 = FALSE; g_ord_open_price_288 = 0; Print("Close All Start at (H.Bid)= " + MarketInfo(Symbol(), MODE_BID)); while (OrdersTotal() != 0) { l_ord_total_0 = OrdersTotal(); for (int l_pos_4 = l_ord_total_0 - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS); l_cmd_8 = OrderType(); li_12 = FALSE; switch (l_cmd_8) { case OP_BUY: li_12 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red); case OP_SELL: li_12 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Violet); continue; } } l_ord_total_0 = OrdersTotal(); for (l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) { OrderSelect(l_pos_4, SELECT_BY_POS); l_cmd_8 = OrderType(); li_12 = FALSE; switch (l_cmd_8) { case OP_BUYLIMIT: case OP_BUYSTOP: case OP_SELLLIMIT: case OP_SELLSTOP: li_12 = OrderDelete(OrderTicket()); } } } Print("Close All Finish at (H.Bid)= " + MarketInfo(Symbol(), MODE_BID)); gi_444 = TRUE; gi_236 = TRUE; g_ord_total_440 = 0; gs_424 = "0"; if (looping == FALSE) { gi_448 = FALSE; gi_444 = FALSE; ObjectCreate("MGONOFF", OBJ_LABEL, 0, 0, 0); ObjectSet("MGONOFF", OBJPROP_XDISTANCE, 5); ObjectSet("MGONOFF", OBJPROP_YDISTANCE, 240); ObjectSetText("MGONOFF", "ROBOT IS OFF OR STOP!", 10, "Times New Roman", Red); } } void OpenBuyOrders() { gs_424 = "0"; while (gs_424 == "0" && Ask - Bid <= gd_408) { while (Ask - Bid <= gd_408 && gs_424 == "0") { if (gs_424 == "0" && OrdersTotal() == 0) { gi_284 = Range; gi_444 = TRUE; if (gi_268 > 0) g_price_296 = MarketInfo(Symbol(), MODE_ASK) - gi_268 * Point; else g_price_296 = 0; if (TP > 0) g_price_312 = MarketInfo(Symbol(), MODE_ASK) + TP * Point; else g_price_312 = 0; g_ticket_260 = OrderSend(Symbol(), OP_BUY, Lot, MarketInfo(Symbol(), MODE_ASK), 100, g_price_296, g_price_312, "BUY", g_magic_248, 0, Green); gs_424 = "Buy"; if (g_ticket_260 < 0) Print("OrderSend failed with error #", GetLastError()); else { g_lots_320 = Lot * Multiplier; if (MicroAccount == TRUE) g_lots_320 = NormalizeDouble(g_lots_320, 2); else g_lots_320 = NormalizeDouble(g_lots_320, 1); for (int l_count_0 = 0; l_count_0 < MaxLevel; l_count_0++) { OrderSelect(g_ticket_260, SELECT_BY_TICKET); if (StartLevelIncrease != 0) { if (l_count_0 >= StartLevelIncrease) gi_280 = gi_284 + RangeIncrease * (l_count_0 - (StartLevelIncrease - 1)); } else gi_280 = Range; g_price_328 = OrderOpenPrice() - gi_280 * Point; if (StopLossRange > 0) g_price_296 = g_price_328 - gi_268 * Point; if (StartLevelIncrease != 0) { if (TP > 0 && l_count_0 < StartLevelIncrease) g_price_312 = g_price_328 + TP * Point; if (TP > 0 && l_count_0 >= StartLevelIncrease) g_price_312 = g_price_328 + gi_280 * Point; } else g_price_312 = g_price_328 + TP * Point; g_ticket_260 = OrderSend(Symbol(), OP_BUYLIMIT, g_lots_320, g_price_328, 3, g_price_296, g_price_312, "Buy limit", g_magic_248, 0, Green); g_lots_320 *= Multiplier; if (MicroAccount == TRUE) g_lots_320 = NormalizeDouble(g_lots_320, 2); else g_lots_320 = NormalizeDouble(g_lots_320, 1); Print(g_lots_320); } g_ord_total_440 = OrdersTotal(); gs_424 = "Buy"; } } } } } void OpenSellOrders() { gs_424 = "0"; while (gs_424 == "0" && Ask - Bid <= gd_408) { while (Ask - Bid <= gd_408 && gs_424 == "0") { if (gs_424 == "0" && OrdersTotal() == 0) { gi_444 = TRUE; gi_284 = Range; if (gi_268 > 0) g_price_296 = MarketInfo(Symbol(), MODE_BID) + gi_268 * Point; else g_price_296 = 0; if (TP > 0) g_price_312 = MarketInfo(Symbol(), MODE_BID) - TP * Point; else g_price_312 = 0; g_ticket_260 = OrderSend(Symbol(), OP_SELL, Lot, MarketInfo(Symbol(), MODE_BID), 100, g_price_296, g_price_312, "SELL", g_magic_248, 0, Green); gs_424 = "Sell"; if (g_ticket_260 < 0) Print("OrderSend failed with error #", GetLastError()); else { g_lots_320 = Lot * Multiplier; if (MicroAccount == TRUE) g_lots_320 = NormalizeDouble(g_lots_320, 2); else g_lots_320 = NormalizeDouble(g_lots_320, 1); for (int l_count_0 = 0; l_count_0 < MaxLevel; l_count_0++) { OrderSelect(g_ticket_260, SELECT_BY_TICKET); if (StartLevelIncrease != 0) { if (l_count_0 >= StartLevelIncrease) gi_280 = gi_284 + RangeIncrease * (l_count_0 - (StartLevelIncrease - 1)); } else gi_280 = Range; g_price_328 = OrderOpenPrice() + gi_280 * Point; if (StopLossRange > 0) g_price_296 = g_price_328 + gi_268 * Point; if (StartLevelIncrease != 0) { if (TP > 0 && l_count_0 < StartLevelIncrease) g_price_312 = g_price_328 - TP * Point; if (TP > 0 && l_count_0 >= StartLevelIncrease) g_price_312 = g_price_328 - gi_280 * Point; } else g_price_312 = g_price_328 - TP * Point; g_ticket_260 = OrderSend(Symbol(), OP_SELLLIMIT, g_lots_320, g_price_328, 3, g_price_296, g_price_312, "Sell limit", g_magic_248, 0, Green); g_lots_320 *= Multiplier; if (MicroAccount == TRUE) g_lots_320 = NormalizeDouble(g_lots_320, 2); else g_lots_320 = NormalizeDouble(g_lots_320, 1); Print(g_lots_320); } g_ord_total_440 = OrdersTotal(); gs_424 = "Sell"; } } } } } void trailing() { if (gi_456 == FALSE) { gi_232 = -1; gi_460 = FALSE; if (gs_424 == "Buy") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248 && gi_232 < TrailingStopStartLevel && gi_456 == FALSE) { gi_232++; if (gi_232 >= TrailingStopStartLevel) { gi_456 = TRUE; g_ord_open_price_288 = OrderOpenPrice(); Print("Trailing Level Price (Buy)= " + g_ord_open_price_288); } } } } } if (gs_424 == "Sell") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248 && gi_232 < TrailingStopStartLevel && gi_456 == FALSE) { gi_232++; if (gi_232 >= TrailingStopStartLevel) { gi_456 = TRUE; g_ord_open_price_288 = OrderOpenPrice(); Print("Trailing Level Price (Sell)= " + g_ord_open_price_288); } } } } } } if (gs_424 == "Buy" && gi_456 == TRUE) if (MarketInfo(Symbol(), MODE_ASK) >= g_ord_open_price_288) gi_460 = TRUE; if (gs_424 == "Sell" && gi_456 == TRUE) if (MarketInfo(Symbol(), MODE_BID) <= g_ord_open_price_288) gi_460 = TRUE; if (gi_460 == TRUE) { if (StartTrailingStopAfterRange == FALSE && gi_272 > 0) { if (AccountProfit() < TrailingStopMoney && gi_276 > 0) { gi_276 = 0; Print("Reset TS dummysign"); } if (BuyOrders() == 0 && SellOrders() == 0 && gi_276 > 0) { gi_276 = 0; Print("Reset TS dummysign, no position"); } gi_236 = FALSE; if (StartTrailingStopAfterRange == FALSE && gi_272 < gi_228) { if (gs_424 == "Buy") { if (AccountProfit() > TrailingStopMoney && gi_276 == 0) { Print("TS Range (BG) = " + gi_272); gi_276 = 1; gd_384 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; Print("TS Start Buy (BG) = " + gd_384); } if (gi_276 == 1 && MarketInfo(Symbol(), MODE_BID) >= gd_384) { gi_276 = 2; gd_376 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Buy (BG)= " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) > gd_376 + gi_272 * Point) { Print("Old TS Buy (BG) = " + gd_376); gd_376 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Buy (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) <= gd_368) { Print("Closing TS Buy (BG) = " + gd_376); gi_276 = 0; gd_368 = 0; gd_376 = 0; gd_384 = 0; CloseAll(); } } if (gs_424 == "Sell") { if (AccountProfit() > TrailingStopMoney && gi_276 == 0) { Print("TS Range (BG) = " + gi_272); gi_276 = 1; gd_384 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; Print("TS Start Sell (BG) = " + gd_384); } if (gi_276 == 1 && MarketInfo(Symbol(), MODE_BID) <= gd_384) { gi_276 = 2; gd_376 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Sell (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) < gd_376 - gi_272 * Point) { Print("Old TS Sell (BG) = " + gd_376); gd_376 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Sell (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) >= gd_368) { Print("Closing TS Sell (BG) = " + gd_376); gi_276 = 0; gd_368 = 0; gd_376 = 0; CloseAll(); } } } if (StartTrailingStopAfterRange == FALSE && gi_272 >= gi_228) { if (gs_424 == "Buy" && AccountProfit() > TrailingStopMoney) { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Sell" && AccountProfit() > TrailingStopMoney) { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Buy" && AccountProfit() > TrailingStopMoney) { if (gi_276 == 0) { Print("TS Range = " + gi_272); gi_276 = 1; gd_344 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; Print("TS Start Buy = " + gd_344); } if (gi_276 == 1) { if (MarketInfo(Symbol(), MODE_BID) >= gd_344 && MarketInfo(Symbol(), MODE_BID) - gi_272 * Point > gd_336) { Print("Old TS Buy = " + gd_336); gi_264 = TRUE; g_price_296 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; g_count_244 = 0; g_ord_total_252 = OrdersTotal(); for (g_pos_256 = g_ord_total_252 - 1; g_pos_256 >= 0; g_pos_256--) { if (gi_236 == FALSE && g_count_244 == 0) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) { OrderModify(OrderTicket(), OrderOpenPrice(), g_price_296, OrderTakeProfit(), 0, Blue); Print("Order Lots = " + OrderLots()); g_count_244++; } if (g_ord_total_440 > OrdersTotal()) CloseAll(); } } } gd_336 = g_price_296; gi_236 = FALSE; g_count_244 = 0; Print("Current TS Buy = " + gd_336); } } } if (gs_424 == "Sell" && AccountProfit() > TrailingStopMoney) { if (gi_276 == 0) { Print("TS Range = " + gi_272); gi_276 = 1; gd_344 = MarketInfo(Symbol(), MODE_ASK) - gi_272 * Point; Print("TS Start Sell = " + gd_344); } if (gi_276 == 1) { if (MarketInfo(Symbol(), MODE_ASK) <= gd_344 && MarketInfo(Symbol(), MODE_ASK) + gi_272 * Point < gd_336) { Print("Old TS Sell = " + gd_336); gi_264 = TRUE; g_price_296 = MarketInfo(Symbol(), MODE_ASK) + gi_272 * Point; g_count_244 = 0; g_ord_total_252 = OrdersTotal(); for (g_pos_256 = g_ord_total_252 - 1; g_pos_256 >= 0; g_pos_256--) { if (gi_236 == FALSE && g_count_244 == 0) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) { OrderModify(OrderTicket(), OrderOpenPrice(), g_price_296, OrderTakeProfit(), 0, Blue); Print("Order Lots = " + OrderLots()); g_count_244++; } if (g_ord_total_440 > OrdersTotal()) CloseAll(); } } } gd_336 = g_price_296; g_count_244 = 0; gi_236 = FALSE; Print("Current TS Sell = " + gd_336); } } } } } if (StartTrailingStopAfterRange == TRUE && gi_272 > 0) { if (gs_424 == "Buy") { if (MarketInfo(Symbol(), MODE_BID) < gd_344 && gi_276 > 0) { gi_276 = 0; Print("Reset TS dummysign Buy"); } } if (gs_424 == "Sell") { if (MarketInfo(Symbol(), MODE_ASK) > gd_344 && gi_276 > 0) { gi_276 = 0; Print("Reset TS dummysign Sell"); } } if (BuyOrders() == 0 && SellOrders() == 0 && gi_276 > 0) { gi_276 = 0; Print("Reset TS dummysign, no position"); } gi_236 = FALSE; if (StartTrailingStopAfterRange == TRUE && gi_272 < gi_228) { if (gs_424 == "Buy") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Sell") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Buy" && BuyOrders() >= 1) gd_344 = g_ord_open_price_352 + gi_240 * Point; if (gs_424 == "Sell" && SellOrders() >= 1) gd_344 = g_ord_open_price_352 - gi_240 * Point; if (gs_424 == "Buy") { if (MarketInfo(Symbol(), MODE_BID) >= gd_344 && gi_276 == 0) { Print("TS Range TR (BG) = " + gi_272); gi_276 = 1; gd_384 = gd_344 + gi_272 * Point; Print("TS Start Buy (BG) = " + gd_384); } if (gi_276 == 1 && MarketInfo(Symbol(), MODE_BID) >= gd_384) { gi_276 = 2; gd_376 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Buy (BG)= " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) > gd_376 + gi_272 * Point) { Print("Old TS Buy (BG) = " + gd_376); gd_376 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Buy (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) <= gd_368) { Print("Closing TS Buy (BG) = " + gd_376); gi_276 = 0; gd_368 = 0; gd_376 = 0; gd_384 = 0; CloseAll(); } } if (gs_424 == "Sell") { if (MarketInfo(Symbol(), MODE_ASK) <= gd_344 && gi_276 == 0) { Print("TS Range TR (BG) = " + gi_272); gi_276 = 1; gd_384 = gd_344 - gi_272 * Point; Print("TS Start Sell (BG) = " + gd_384); } if (gi_276 == 1 && MarketInfo(Symbol(), MODE_BID) <= gd_384) { gi_276 = 2; gd_376 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Sell (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) < gd_376 - gi_272 * Point) { Print("Old TS Sell (BG) = " + gd_376); gd_376 = MarketInfo(Symbol(), MODE_BID) + gi_272 * Point; gd_368 = gd_376; gd_336 = gd_368; gi_264 = TRUE; Print("Current TS Sell (BG) = " + gd_336); } if (gi_276 == 2 && MarketInfo(Symbol(), MODE_BID) >= gd_368) { Print("Closing TS Sell (BG) = " + gd_376); gi_276 = 0; gd_368 = 0; gd_376 = 0; CloseAll(); } } } if (StartTrailingStopAfterRange == TRUE && gi_272 >= gi_228) { gi_236 = FALSE; if (gs_424 == "Buy") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Sell") { g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) { g_ord_open_price_352 = OrderOpenPrice(); gd_336 = OrderStopLoss(); } } } } if (gs_424 == "Buy") { if (BuyOrders() >= 1) gd_344 = g_ord_open_price_352 + (gi_240 + gi_272) * Point; if (MarketInfo(Symbol(), MODE_BID) >= gd_344) { Print("Old TS Buy = " + gd_336); if (MarketInfo(Symbol(), MODE_BID) - gi_272 * Point > gd_336) { gi_264 = TRUE; g_price_296 = MarketInfo(Symbol(), MODE_BID) - gi_272 * Point; g_count_244 = 0; g_ord_total_252 = OrdersTotal(); for (g_pos_256 = g_ord_total_252 - 1; g_pos_256 >= 0; g_pos_256--) { if (gi_236 == FALSE && g_count_244 == 0) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) { OrderModify(OrderTicket(), OrderOpenPrice(), g_price_296, OrderTakeProfit(), 0, Blue); Print("Order Lots = " + OrderLots()); g_count_244++; } if (g_ord_total_440 > OrdersTotal()) CloseAll(); } } } gd_336 = g_price_296; gi_236 = FALSE; g_count_244 = 0; } } } if (gs_424 == "Sell") { if (SellOrders() > 1) gd_344 = g_ord_open_price_352 - (gi_240 - gi_272) * Point; if (MarketInfo(Symbol(), MODE_ASK) <= gd_344) { Print("Old TS Sell = " + gd_336); if (MarketInfo(Symbol(), MODE_ASK) + gi_272 * Point < gd_336) { gi_264 = TRUE; g_price_296 = MarketInfo(Symbol(), MODE_ASK) + gi_272 * Point; g_count_244 = 0; g_ord_total_252 = OrdersTotal(); for (g_pos_256 = g_ord_total_252 - 1; g_pos_256 >= 0; g_pos_256--) { if (gi_236 == FALSE && g_count_244 == 0) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) { OrderModify(OrderTicket(), OrderOpenPrice(), g_price_296, OrderTakeProfit(), 0, Blue); Print("Order Lots = " + OrderLots()); g_count_244++; } if (g_ord_total_440 > OrdersTotal()) CloseAll(); } } } gd_336 = g_price_296; g_count_244 = 0; gi_236 = FALSE; } } } } } } } void CheckStop() { gs_416 = "0"; g_ord_total_252 = OrdersTotal(); for (g_pos_256 = 0; g_pos_256 < g_ord_total_252; g_pos_256++) { if (OrderSelect(g_pos_256, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUYSTOP) gs_416 = "nolooping"; if (OrderType() == OP_SELLSTOP) gs_416 = "cutall"; } } } int SellOrders() { int l_count_0 = 0; int l_count_4 = 0; int l_ord_total_8 = OrdersTotal(); for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) { if (OrderSelect(l_pos_12, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) l_count_0++; if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) l_count_4++; } } return (l_count_4); } int BuyOrders() { int l_count_0 = 0; int l_count_4 = 0; int l_ord_total_8 = OrdersTotal(); for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) { if (OrderSelect(l_pos_12, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUY && OrderMagicNumber() == g_magic_248) l_count_0++; if (OrderType() == OP_SELL && OrderMagicNumber() == g_magic_248) l_count_4++; } } return (l_count_0); } int LimitOrders() { int l_count_0 = 0; int l_ord_total_4 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) { if (OrderSelect(l_pos_8, SELECT_BY_POS) != FALSE) { if (OrderType() == OP_BUYLIMIT && OrderMagicNumber() == g_magic_248) l_count_0++; if (OrderType() == OP_SELLLIMIT && OrderMagicNumber() == g_magic_248) l_count_0++; } } return (l_count_0); }