bool gi_76 = FALSE; bool gi_80 = FALSE; int g_slippage_84 = 5; bool gi_88 = TRUE; int gi_92 = 30; int gi_96 = 1; extern double Lots = 0.1; extern bool UseStopLoss = TRUE; extern int StopLoss = 50; extern bool UseTakeProfit = TRUE; extern int TakeProfit = 100; extern bool UseTrailingStop = TRUE; extern int TrailingStop = 30; extern int MagicNumber = 273663; int g_bars_136; int gi_140; bool gi_144 = FALSE; int init() { g_bars_136 = Bars; if (gi_80) gi_140 = 0; else gi_140 = 1; return (0); } int deinit() { return (0); } int start() { int l_ticket_8; double l_price_12; double l_price_20; int li_0 = 0; if (gi_80 && Bars != g_bars_136) gi_144 = FALSE; int l_ord_total_4 = OrdersTotal(); li_0 = 0; double l_iao_28 = iAO(NULL, 0, gi_140 + 0); double l_iao_36 = iAO(NULL, 0, gi_140 + 1); double l_icustom_44 = iCustom(NULL, 0, "iRobot_Indicator", 13, 0, gi_140 + 0); double l_icustom_52 = iCustom(NULL, 0, "iRobot_Indicator", 13, 1, gi_140 + 0); double l_istochastic_60 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, gi_140 + 0); bool li_68 = FALSE; for (int l_pos_72 = 0; l_pos_72 < l_ord_total_4; l_pos_72++) { OrderSelect(l_pos_72, SELECT_BY_POS, MODE_TRADES); if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { li_68 = TRUE; if (OrderType() == OP_BUY) { if (l_iao_28 < l_iao_36) li_0 = 3; if (li_0 == 3 && (gi_80 && !gi_144) || (!gi_80 && Bars != g_bars_136)) { OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_84, MediumSeaGreen); if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy"); if (!gi_80) g_bars_136 = Bars; li_68 = FALSE; } else { if (gi_88 && gi_92 > 0) { if (Bid - OrderOpenPrice() >= Point * gi_92) { if (OrderStopLoss() < OrderOpenPrice() + Point * gi_96) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + Point * gi_96, OrderTakeProfit(), 0, Red); if (!(!gi_80)) continue; g_bars_136 = Bars; continue; } } } if (UseTrailingStop && TrailingStop > 0) { if (Bid - OrderOpenPrice() > Point * TrailingStop) { if (OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen); if (!gi_80) g_bars_136 = Bars; } } } } } else { if (l_iao_28 > l_iao_36) li_0 = 4; if (li_0 == 4 && (gi_80 && !gi_144) || (!gi_80 && Bars != g_bars_136)) { OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_84, DarkOrange); if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell"); if (!gi_80) g_bars_136 = Bars; li_68 = FALSE; } else { if (gi_88 && gi_92 > 0) { if (OrderOpenPrice() - Ask >= Point * gi_92) { if (OrderStopLoss() > OrderOpenPrice() - Point * gi_96) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - Point * gi_96, OrderTakeProfit(), 0, Red); if (!(!gi_80)) continue; g_bars_136 = Bars; continue; } } } if (UseTrailingStop && TrailingStop > 0) { if (OrderOpenPrice() - Ask > Point * TrailingStop) { if (OrderStopLoss() > Ask + Point * TrailingStop || OrderStopLoss() == 0.0) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange); if (!gi_80) g_bars_136 = Bars; } } } } } } } if (l_iao_28 > l_iao_36 && l_istochastic_60 > 50.0) li_0 = 1; if (l_iao_28 < l_iao_36 && l_istochastic_60 < 50.0) li_0 = 2; if (li_0 == 1 && (gi_80 && !gi_144) || (!gi_80 && Bars != g_bars_136)) { if (!li_68) { if (AccountFreeMargin() < 1000.0 * Lots) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return (0); } if (UseStopLoss) l_price_12 = Ask - StopLoss * Point; else l_price_12 = 0.0; if (UseTakeProfit) l_price_20 = Ask + TakeProfit * Point; else l_price_20 = 0.0; l_ticket_8 = OrderSend(Symbol(), OP_BUY, Lots, Ask, g_slippage_84, l_price_12, l_price_20, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); if (l_ticket_8 > 0) { if (OrderSelect(l_ticket_8, SELECT_BY_TICKET, MODE_TRADES)) { Print("BUY order opened : ", OrderOpenPrice()); if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy"); } else Print("Error opening BUY order : ", GetLastError()); } if (gi_80) gi_144 = TRUE; if (!gi_80) g_bars_136 = Bars; return (0); } } if (li_0 == 2 && (gi_80 && !gi_144) || (!gi_80 && Bars != g_bars_136)) { if (!li_68) { if (AccountFreeMargin() < 1000.0 * Lots) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return (0); } if (UseStopLoss) l_price_12 = Bid + StopLoss * Point; else l_price_12 = 0.0; if (UseTakeProfit) l_price_20 = Bid - TakeProfit * Point; else l_price_20 = 0.0; l_ticket_8 = OrderSend(Symbol(), OP_SELL, Lots, Bid, g_slippage_84, l_price_12, l_price_20, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink); if (l_ticket_8 > 0) { if (OrderSelect(l_ticket_8, SELECT_BY_TICKET, MODE_TRADES)) { Print("SELL order opened : ", OrderOpenPrice()); if (gi_76) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell"); } else Print("Error opening SELL order : ", GetLastError()); } if (gi_80) gi_144 = TRUE; if (!gi_80) g_bars_136 = Bars; return (0); } } if (!gi_80) g_bars_136 = Bars; return (0); }