#property copyright "Copyright © 2009, Pro FX Experts" #property link "" extern int MAGIC_NUMBER = 28990522; extern bool AccountIsMini = TRUE; extern bool ManageMoney = TRUE; extern double Risk = 0.1; extern double Lots = 0.1; extern double Max_Allowed_Lot = 0.5; extern double Start_GridPips = 20.0; extern double Start_TakeProfit_Pips = 20.0; extern bool Use_LossRecover = TRUE; extern double Recover_Limit_Step_Pips = 40.0; extern double Recover_Lot = 2.0; extern int Max_Recover_Orders = 2; extern double Recover_TakeProfit_Pips = 8.0; extern bool Use_Trend_Reversal_Close = FALSE; extern int Trend_Reversal_TimeFrame = 240; extern bool Use_StopLoss = TRUE; extern double StopLoss_Pips = 800.0; extern bool Profit_Trailing = TRUE; extern int Trailing_Pips = 9; extern bool Use_ProfitLock = TRUE; extern int TriggerPips = 8; extern int Pips_To_Lock = 1; extern int Short_TF = 15; extern int Middle_TF = 60; extern int Long_TF = 240; extern int MA_Period = 20; extern bool Show_Comment = TRUE; extern string EAName = "Royal-Grid"; int g_magic_228; int g_pos_232; int g_slippage_236 = 1; int gi_244 = 1; string gs_dummy_248; string gs_dummy_256; string gs_264; string gs_272; string gs_280; string gs_288; string gs_296; double g_price_320; double g_price_328; bool gi_336 = TRUE; int init() { g_magic_228 = MakeMagicNumber(MAGIC_NUMBER); return (0); } int deinit() { return (0); } int start() { int li_4; int li_8; int li_12; int li_16; bool li_20; bool li_24; int li_28; int li_32; int li_36; int li_40; double l_ima_44; double l_ima_52; double l_ima_60; double l_ima_68; double l_ima_76; double l_ima_84; double ld_92; double ld_100; double ld_unused_108; double ld_unused_116; double ld_unused_124; double ld_unused_132; double ld_unused_140; double ld_148; double ld_156; double ld_unused_164; double ld_unused_172; double ld_180; double ld_188; double ld_unused_196; double ld_unused_204; double ld_unused_212; double ld_unused_220; double ld_228; double ld_236; double ld_unused_244; double ld_unused_252; double l_ima_260; double l_ima_268; string ls_276; int l_spread_284; int li_288; int li_292; int li_296; int l_ord_total_300; int l_ord_total_312; int l_ord_total_320; int l_pos_324; double ld_328; double ld_336; double ld_344; int l_ord_total_352; double ld_356; double ld_364; double ld_372; int l_pos_380; int l_pos_384; int li_0 = 10690; if (li_0 == AccountNumber() || IsDemo()) { RefreshRates(); if (Digits == 5 || Digits == 3) gi_244 = 10; li_4 = 0; li_8 = 0; li_12 = 0; li_16 = 0; li_20 = FALSE; li_24 = FALSE; li_28 = 0; li_32 = 0; li_36 = 0; li_40 = 0; li_4 = CountBuys(g_magic_228); li_8 = CountSells(g_magic_228); li_28 = CountRecBuys(g_magic_228); li_32 = CountRecSells(g_magic_228); li_12 = CountBuyLimit(g_magic_228); li_16 = CountSellLimit(g_magic_228); li_36 = CountRecBuyLimit(g_magic_228); li_40 = CountRecSellLimit(g_magic_228); l_ima_44 = 0; l_ima_52 = 0; l_ima_60 = 0; l_ima_68 = 0; l_ima_76 = 0; l_ima_84 = 0; ld_92 = 0; ld_100 = 0; ld_unused_108 = 0; ld_unused_116 = 0; ld_unused_124 = 0; ld_unused_132 = 0; ld_unused_140 = 0; ld_148 = 0; ld_156 = 0; ld_unused_164 = 0; ld_unused_172 = 0; ld_180 = 0; ld_188 = 0; ld_92 = LastBuyLot(g_magic_228); ld_100 = LastSellLot(g_magic_228); ld_unused_196 = 0; ld_unused_204 = 0; ld_unused_212 = 0; ld_unused_220 = 0; ld_228 = 0; ld_236 = 0; ld_unused_244 = 0; ld_unused_252 = 0; l_ima_260 = 0; l_ima_268 = 0; ls_276 = "-"; l_spread_284 = MarketInfo(Symbol(), MODE_SPREAD); li_288 = 0; li_292 = 0; li_288 = LastBLTime(g_magic_228); li_292 = LastSLTime(g_magic_228); ld_180 = LastBLPrice(g_magic_228); ld_188 = LastSLPrice(g_magic_228); ls_276 = CurrComm(g_magic_228); l_ima_44 = iMA(NULL, Short_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0); l_ima_52 = iMA(NULL, Short_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 3); l_ima_60 = iMA(NULL, Middle_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0); l_ima_68 = iMA(NULL, Middle_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 3); l_ima_76 = iMA(NULL, Long_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0); l_ima_84 = iMA(NULL, Long_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 3); l_ima_260 = iMA(NULL, Trend_Reversal_TimeFrame, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 0); l_ima_268 = iMA(NULL, Trend_Reversal_TimeFrame, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, 3); li_296 = Start_GridPips * gi_244 + l_spread_284; if (Profit_Trailing == TRUE) Trail_Orders(g_magic_228); if (li_4 > 1) ld_228 = AvgBuyTP_Price(g_magic_228); if (li_8 > 1) ld_236 = AvgSellTP_Price(g_magic_228); if (ManageMoney == TRUE) Lots = NormalizeDouble(LotSize(), 2); l_ord_total_300 = OrdersTotal(); for (int l_pos_304 = l_ord_total_300 - 1; l_pos_304 >= 0; l_pos_304--) { OrderSelect(l_pos_304, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_228 && OrderSymbol() == Symbol()) { if (OrderType() == OP_SELLLIMIT && li_8 == 0 && li_16 > 0 || li_40 > 0) OrderDelete(OrderTicket()); if (OrderType() == OP_BUYLIMIT && li_4 == 0 && li_12 > 0 || li_36 > 0) OrderDelete(OrderTicket()); } } if (ObjectFind("TRC " + Symbol()) >= 0 && CountBuyLimit(g_magic_228) == 0 && li_4 == 0 && CountSellLimit(g_magic_228) == 0 && li_8 == 0 && CountRecBuyLimit(g_magic_228) == 0 && CountRecSellLimit(g_magic_228) == 0) ObjectDelete("TRC " + Symbol()); if (Use_Trend_Reversal_Close == TRUE && (li_4 > 0 || li_12 > 0 || li_36 > 0 && (l_ima_260 < l_ima_268 && Close[0] < l_ima_260 && Close[1] < l_ima_260)) || (li_8 > 0 || li_16 > 0 || li_40 > 0 && (l_ima_260 > l_ima_268 && Close[0] > l_ima_260 && Close[1] > l_ima_260))) DrawTRC(); if (ObjectFind("TRC " + Symbol()) >= 0) { for (int li_308 = 20; li_308 > 0; li_308--) { l_ord_total_312 = OrdersTotal(); for (int l_pos_316 = l_ord_total_312 - 1; l_pos_316 >= 0; l_pos_316--) { OrderSelect(l_pos_316, SELECT_BY_POS); if (OrderMagicNumber() == g_magic_228 && OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Yellow); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Yellow); if (OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket()); if (OrderType() == OP_BUYLIMIT) OrderDelete(OrderTicket()); } } } } ld_156 = ld_100 / (10.0 * Lots); li_24 = li_296 + NormalizeDouble(li_296 * ld_156, 0); ld_148 = ld_92 / (10.0 * Lots); li_20 = li_296 + NormalizeDouble(li_296 * ld_148, 0); if (Use_StopLoss == TRUE) g_price_328 = Bid + (li_24 + StopLoss_Pips) * gi_244 * Point; else g_price_328 = 0; if (Use_StopLoss == TRUE) g_price_320 = Ask - (li_20 + StopLoss_Pips) * gi_244 * Point; else g_price_320 = 0; if (gi_336) { for (g_pos_232 = 0; g_pos_232 < OrdersTotal(); g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_BUY && li_4 > 1) if (OrderTakeProfit() != ld_228) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), ld_228 - Point, 0, Green); if (OrderType() == OP_SELL && li_8 > 1) if (OrderTakeProfit() != ld_236) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), ld_236 + Point, 0, Red); } } } if (Use_LossRecover == TRUE) { if (li_36 == 0 && li_40 == 0 && li_4 > 0 && ld_92 + Lots >= Max_Allowed_Lot && li_28 < Max_Recover_Orders) { OrderSend(Symbol(), OP_BUYLIMIT, Recover_Lot, Bid - Recover_Limit_Step_Pips * Point * gi_244, g_slippage_236, g_price_320, Bid - Recover_Limit_Step_Pips * Point * gi_244 + Recover_TakeProfit_Pips * gi_244 * Point, "Rec_Buy", g_magic_228, 0, Blue); } if (li_36 == 0 && li_40 == 0 && li_8 > 0 && ld_100 + Lots >= Max_Allowed_Lot && li_32 < Max_Recover_Orders) OrderSend(Symbol(), OP_SELLLIMIT, Recover_Lot, Ask + Recover_Limit_Step_Pips * Point * gi_244, g_slippage_236, g_price_328, Ask + Recover_Limit_Step_Pips * Point * gi_244 - Recover_TakeProfit_Pips * gi_244 * Point, "Rec_Sell", g_magic_228, 0, Red); } if (li_12 == 0 && li_4 == 0 && li_8 == 0 && l_ima_76 > l_ima_84 && l_ima_60 > l_ima_68 && l_ima_44 > l_ima_52 && Close[0] > l_ima_44 && Close[1] > l_ima_52 && l_ima_76 - l_ima_84 > 1.0 * Point) OrderSend(Symbol(), OP_BUY, Lots, Ask, g_slippage_236, g_price_320, Ask + Start_TakeProfit_Pips * gi_244 * Point, EAName, g_magic_228, 0, Blue); if (li_16 == 0 && li_4 == 0 && li_8 == 0 && l_ima_76 < l_ima_84 && l_ima_60 < l_ima_68 && l_ima_44 < l_ima_52 && Close[0] < l_ima_44 && Close[1] < l_ima_52 && l_ima_84 - l_ima_76 > 1.0 * Point) OrderSend(Symbol(), OP_SELL, Lots, Bid, g_slippage_236, g_price_328, Bid - Start_TakeProfit_Pips * gi_244 * Point, EAName, g_magic_228, 0, Red); if (li_12 == 0 && li_4 > 0 && li_8 == 0 && ld_92 + Lots <= Max_Allowed_Lot) OrderSend(Symbol(), OP_BUYLIMIT, ld_92 + Lots, Bid - li_20 * Point, g_slippage_236, g_price_320, Bid - li_20 * Point + Start_TakeProfit_Pips * gi_244 * Point, "xMTF-Buy", g_magic_228, 0, Tomato); if (li_16 == 0 && li_4 == 0 && li_8 > 0 && ld_100 + Lots <= Max_Allowed_Lot) OrderSend(Symbol(), OP_SELLLIMIT, ld_100 + Lots, Ask + li_24 * Point, g_slippage_236, g_price_328, Ask + li_24 * Point - Start_TakeProfit_Pips * gi_244 * Point, "xMTF-Sell", g_magic_228, 0, DodgerBlue); if (Use_ProfitLock && Pips_To_Lock > 0) { l_ord_total_320 = OrdersTotal(); l_pos_324 = 0; ld_328 = 0; ld_336 = 0; ld_344 = 0; for (l_pos_324 = OrdersTotal() - 1; l_pos_324 >= 0; l_pos_324--) { OrderSelect(l_pos_324, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_228) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_BUY) { ld_328 += OrderOpenPrice() * OrderLots(); ld_336 += OrderStopLoss() * OrderLots(); ld_344 += OrderLots(); } } } if (l_ord_total_320 > 0 && CountBuys(g_magic_228) > 0) { ld_328 = NormalizeDouble(ld_328 / ld_344, Digits); ld_336 = NormalizeDouble(ld_336 / ld_344, Digits); } l_ord_total_352 = OrdersTotal(); ld_356 = 0; ld_364 = 0; ld_372 = 0; l_pos_380 = 0; for (l_pos_380 = OrdersTotal() - 1; l_pos_380 >= 0; l_pos_380--) { OrderSelect(l_pos_380, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_228) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_SELL) { ld_356 += OrderOpenPrice() * OrderLots(); ld_364 += OrderStopLoss() * OrderLots(); ld_372 += OrderLots(); } } } if (l_ord_total_352 > 0 && CountSells(g_magic_228) > 0) { ld_356 = NormalizeDouble(ld_356 / ld_372, Digits); ld_364 = NormalizeDouble(ld_364 / ld_372, Digits); } l_pos_384 = 0; for (l_pos_384 = 0; l_pos_384 < OrdersTotal(); l_pos_384++) { OrderSelect(l_pos_384, SELECT_BY_POS, MODE_TRADES); if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_BUY) if (Bid > ld_328 + TriggerPips * gi_244 * Point && OrderStopLoss() < ld_328 + (Pips_To_Lock - 1) * gi_244 * Point - Point) OrderModify(OrderTicket(), OrderOpenPrice(), ld_328 + Pips_To_Lock * gi_244 * Point, OrderTakeProfit(), 0, Green); if (OrderType() == OP_SELL) if (Ask < ld_356 - TriggerPips * gi_244 * Point && ld_356 - (Pips_To_Lock + 1) * gi_244 * Point + Point < OrderStopLoss()) OrderModify(OrderTicket(), OrderOpenPrice(), ld_356 - Pips_To_Lock * gi_244 * Point, OrderTakeProfit(), 0, Red); } } } if (Profit_Trailing == TRUE) gs_264 = "Yes"; else gs_264 = "No"; if (ManageMoney == TRUE) gs_272 = "Yes"; else gs_272 = "No"; if (Use_ProfitLock == TRUE) gs_280 = "Yes"; else gs_280 = "No"; if (Use_LossRecover == TRUE) gs_288 = "Yes"; else gs_288 = "No"; if (Use_Trend_Reversal_Close == TRUE) gs_296 = "Yes"; else gs_296 = "No"; if (Show_Comment) { Comment("\n " + EAName + " MagicNumber: " + g_magic_228 + "\n ---------------------------------------------------------------" + "\n Current Server Time : " + TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + "\n Account Balance : " + DoubleToStr(NormalizeDouble(AccountBalance(), 2), 2) + "\n Account Equity : " + DoubleToStr(NormalizeDouble(AccountEquity(), 2), 2) + "\n Use Money Manage : " + gs_272 + "\n Trade Risk % : " + DoubleToStr(Risk, 1) + "%" + "\n ---------------------------------------------------------------" + "\n Open Buy orders : " + li_4 + "\n Open Sell orders : " + li_8 + "\n Startup TakeProfit : " + DoubleToStr(Start_TakeProfit_Pips, 1) + "\n Use Trailing : " + gs_264 + "\n Trailing Pips : " + Trailing_Pips + "\n Use ProfitLock : " + gs_280 + "\n Lock Trigger Pips : " + DoubleToStr(TriggerPips, 1) + "\n Pips to Lock : " + DoubleToStr(Pips_To_Lock, 1) + "\n Use Trend Reversal : " + gs_296 + "\n --------------------------------------------------------------" + "\n Use Loss Recover : " + gs_288 + "\n Rec. Limit Step Pips : " + DoubleToStr(Recover_Limit_Step_Pips, 1) + "\n Recover Lot : " + DoubleToStr(Recover_Lot, 1) + "\n Max Recover Orders : " + Max_Recover_Orders + "\n Recover TP Pips : " + DoubleToStr(Recover_TakeProfit_Pips, 1) + "\n --------------------------------------------------------------"); } ObjectCreate("CC", OBJ_LABEL, 0, 0, 0); ObjectSet("CC", OBJPROP_CORNER, 3); ObjectSet("CC", OBJPROP_XDISTANCE, 5); ObjectSet("CC", OBJPROP_YDISTANCE, 5); ObjectSet("CC", OBJPROP_BACK, TRUE); ObjectSetText("CC", "Pro-Fx-Experts Copyright © " + Year() + ", www.Pro-Fx-Experts.com", 8, "Arial", Tomato); } else { if (li_0 != AccountNumber() || !IsDemo()) { Comment("\n " + "\n " + "\n ==================================" + "\n Account No. " + AccountNumber() + " invalid." + "\n ==================================" + "\n Your Account no. is not valid for trading with this expert" + "\n advisor. Only a valid Live account or a Demo account is" + "\n allowed. Please contact Nico Roets at www.Pro-Fx-Experts.com" + "\n to purchase your own lifetime Live account licence." + "\n For more information e-mail: support@pro-fx-experts.com" + "\n =================================="); return (0); } } return (0); } void Trail_Orders(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); double ld_8 = 0; double ld_16 = 0; double ld_24 = 0; for (int l_pos_32 = OrdersTotal() - 1; l_pos_32 >= 0; l_pos_32--) { OrderSelect(l_pos_32, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_228) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_BUY) { ld_8 += OrderOpenPrice() * OrderLots(); ld_16 += OrderStopLoss() * OrderLots(); ld_24 += OrderLots(); } } } if (l_ord_total_4 > 0 && CountBuys(g_magic_228) > 0) { ld_8 = NormalizeDouble(ld_8 / ld_24, Digits); ld_16 = NormalizeDouble(ld_16 / ld_24, Digits); } int l_ord_total_36 = OrdersTotal(); double ld_40 = 0; double ld_48 = 0; double ld_56 = 0; for (int l_pos_64 = OrdersTotal() - 1; l_pos_64 >= 0; l_pos_64--) { OrderSelect(l_pos_64, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_228) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_228) { if (OrderType() == OP_SELL) { ld_40 += OrderOpenPrice() * OrderLots(); ld_48 += OrderStopLoss() * OrderLots(); ld_56 += OrderLots(); } } } if (l_ord_total_36 > 0 && CountSells(g_magic_228) > 0) { ld_40 = NormalizeDouble(ld_40 / ld_56, Digits); ld_48 = NormalizeDouble(ld_48 / ld_56, Digits); } for (g_pos_232 = 0; g_pos_232 < OrdersTotal(); g_pos_232++) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0) { if (OrderType() == OP_BUY) if (Bid - ld_8 > Point * Trailing_Pips * gi_244 && ld_16 < Bid - Point * Trailing_Pips * gi_244 - Point) OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * Trailing_Pips * gi_244, OrderTakeProfit(), 0, Green); if (OrderType() == OP_SELL) if (ld_40 - Ask > Point * Trailing_Pips * gi_244 && ld_48 > Ask + Point * Trailing_Pips * gi_244 + Point) OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * Trailing_Pips * gi_244, OrderTakeProfit(), 0, Red); } } } double LotSize() { double l_lots_0; if (AccountIsMini == FALSE) { l_lots_0 = NormalizeDouble(AccountFreeMargin() * Risk / 100000.0, 1); if (l_lots_0 < 0.1) l_lots_0 = Lots; if (l_lots_0 >= 1.0) l_lots_0 = NormalizeDouble(l_lots_0, 1); if (l_lots_0 >= 100.0) l_lots_0 = 100; } else { l_lots_0 = NormalizeDouble(AccountFreeMargin() * Risk / 100000.0, 2); if (l_lots_0 < 0.01) l_lots_0 = Lots; if (l_lots_0 >= 1.0) l_lots_0 = NormalizeDouble(l_lots_0, 2); if (l_lots_0 >= 100.0) l_lots_0 = 100; } return (l_lots_0); } int CountBuys(int a_magic_0) { int l_count_4 = 0; int l_ord_total_12 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderType() == OP_BUY) l_count_4++; } return (l_count_4); } int CountSells(int a_magic_0) { int l_count_4 = 0; int l_ord_total_12 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderType() == OP_SELL) l_count_4++; } return (l_count_4); } int CountBuyLimit(int a_magic_0) { int li_ret_4; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == a_magic_0 && OrderComment() != "Rec_Buy") li_ret_4++; } return (li_ret_4); } int CountSellLimit(int a_magic_0) { int li_ret_4; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderType() == OP_SELLLIMIT && OrderMagicNumber() == a_magic_0 && OrderComment() != "Rec_Sell") li_ret_4++; } return (li_ret_4); } int CountRecBuyLimit(int a_magic_0) { int li_ret_4; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == a_magic_0 && OrderComment() == "Rec_Buy") li_ret_4++; } return (li_ret_4); } int CountRecSellLimit(int a_magic_0) { int li_ret_4; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderType() == OP_SELLLIMIT && OrderMagicNumber() == a_magic_0 && OrderComment() == "Rec_Sell") li_ret_4++; } return (li_ret_4); } int CountRecBuys(int a_magic_0) { int l_count_4 = 0; int l_ord_total_12 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderType() == OP_BUY && OrderMagicNumber() == a_magic_0 && OrderComment() == "Rec_Buy") l_count_4++; } return (l_count_4); } int CountRecSells(int a_magic_0) { int l_count_4 = 0; int l_ord_total_12 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderType() == OP_SELL && OrderMagicNumber() == a_magic_0 && OrderComment() == "Rec_Sell") l_count_4++; } return (l_count_4); } int MakeMagicNumber(int ai_0) { int li_4 = 0; int li_ret_8 = 0; if (StringFind(Symbol(), "AUDCAD", 0) > -1) li_4 = 1000; else { if (StringFind(Symbol(), "AUDJPY", 0) > -1) li_4 = 2000; else { if (StringFind(Symbol(), "AUDNZD", 0) > -1) li_4 = 3000; else { if (StringFind(Symbol(), "AUDUSD", 0) > -1) li_4 = 4000; else { if (StringFind(Symbol(), "CHFJPY", 0) > -1) li_4 = 5000; else { if (StringFind(Symbol(), "EURAUD", 0) > -1) li_4 = 6000; else { if (StringFind(Symbol(), "EURCAD", 0) > -1) li_4 = 7000; else { if (StringFind(Symbol(), "EURCHF", 0) > -1) li_4 = 8000; else { if (StringFind(Symbol(), "EURGBP", 0) > -1) li_4 = 9000; else { if (StringFind(Symbol(), "EURJPY", 0) > -1) li_4 = 2100; else { if (StringFind(Symbol(), "EURUSD", 0) > -1) li_4 = 1100; else { if (StringFind(Symbol(), "GBPCHF", 0) > -1) li_4 = 1200; else { if (StringFind(Symbol(), "GBPJPY", 0) > -1) li_4 = 1300; else { if (StringFind(Symbol(), "GBPUSD", 0) > -1) li_4 = 1400; else { if (StringFind(Symbol(), "NZDJPY", 0) > -1) li_4 = 1500; else { if (StringFind(Symbol(), "NZDUSD", 0) > -1) li_4 = 1600; else { if (StringFind(Symbol(), "USDCAD", 0) > -1) li_4 = 1700; else { if (StringFind(Symbol(), "USDCHF", 0) > -1) li_4 = 1800; else { if (StringFind(Symbol(), "USDJPY", 0) > -1) li_4 = 1900; else li_4 = 1111; } } } } } } } } } } } } } } } } } } li_ret_8 = ai_0 + li_4; return (li_ret_8); } double LastBuyLot(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; double l_ord_lots_16 = 0; for (int l_pos_24 = 0; l_pos_24 < l_ord_total_4; l_pos_24++) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_ord_lots_16 = OrderLots(); } } return (l_ord_lots_16); } double LastSellLot(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; double l_ord_lots_16 = 0; for (int l_pos_24 = 0; l_pos_24 < l_ord_total_4; l_pos_24++) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_ord_lots_16 = OrderLots(); } } return (l_ord_lots_16); } string CurrComm(int a_magic_0) { int l_datetime_8; string ls_ret_16; int l_ord_total_4 = OrdersTotal(); int l_datetime_12 = 0; for (int l_pos_24 = 0; l_pos_24 < l_ord_total_4; l_pos_24++) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; ls_ret_16 = OrderComment(); } } return (ls_ret_16); } int LastBLTime(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; int l_datetime_16 = 0; for (int l_pos_20 = 0; l_pos_20 < l_ord_total_4; l_pos_20++) { OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_datetime_16 = OrderOpenTime(); } } return (l_datetime_16); } int LastSLTime(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; int l_datetime_16 = 0; for (int l_pos_20 = 0; l_pos_20 < l_ord_total_4; l_pos_20++) { OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_SELLLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_datetime_16 = OrderOpenTime(); } } return (l_datetime_16); } double LastBLPrice(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; double l_ord_open_price_16 = 0; for (int l_pos_24 = 0; l_pos_24 < l_ord_total_4; l_pos_24++) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_BUYLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_ord_open_price_16 = OrderOpenPrice(); } } return (l_ord_open_price_16); } double LastSLPrice(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); int l_datetime_8 = 0; int l_datetime_12 = 0; double l_ord_open_price_16 = 0; for (int l_pos_24 = 0; l_pos_24 < l_ord_total_4; l_pos_24++) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); l_datetime_8 = OrderOpenTime(); if (l_datetime_8 > l_datetime_12 && OrderType() == OP_SELLLIMIT && OrderMagicNumber() == a_magic_0) { l_datetime_12 = l_datetime_8; l_ord_open_price_16 = OrderOpenPrice(); } } return (l_ord_open_price_16); } double AvgBuyTP_Price(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); double ld_ret_8 = 0; double ld_16 = 0; for (g_pos_232 = OrdersTotal() - 1; g_pos_232 >= 0; g_pos_232--) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0) { if (OrderType() == OP_BUY) { ld_ret_8 += OrderTakeProfit() * OrderLots(); ld_16 += OrderLots(); } } } if (l_ord_total_4 > 0) ld_ret_8 = NormalizeDouble(ld_ret_8 / ld_16, Digits); return (ld_ret_8); } double AvgSellTP_Price(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); double ld_ret_8 = 0; double ld_16 = 0; for (g_pos_232 = OrdersTotal() - 1; g_pos_232 >= 0; g_pos_232--) { OrderSelect(g_pos_232, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_0) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == a_magic_0) { if (OrderType() == OP_SELL) { ld_ret_8 += OrderTakeProfit() * OrderLots(); ld_16 += OrderLots(); } } } if (l_ord_total_4 > 0) ld_ret_8 = NormalizeDouble(ld_ret_8 / ld_16, Digits); return (ld_ret_8); } void DrawTRC() { ObjectCreate("TRC " + Symbol(), OBJ_ARROW, 0, Time[0], Close[0]); ObjectSet("TRC " + Symbol(), OBJPROP_COLOR, DeepSkyBlue); ObjectSet("TRC " + Symbol(), OBJPROP_ARROWCODE, 244); ObjectSet("TRC " + Symbol(), OBJPROP_WIDTH, 1); }