// More information about this indicator can be found at: // https://fxcodebase.com/code/viewtopic.php?f=38&p=159099#p159099 //+------------------------------------------------------------------------------------------------+ //| Copyright © 2025, Gehtsoft USA LLC | //| http://fxcodebase.com | //+------------------------------------------------------------------------------------------------+ //| Support our efforts by donating | //| Paypal: https://goo.gl/9Rj74e | //+------------------------------------------------------------------------------------------------+ //| Developed by : Mario Jemic | //| mario.jemic@gmail.com | //| https://AppliedMachineLearning.systems | //| Patreon : https://goo.gl/GdXWeN | //+------------------------------------------------------------------------------------------------+ //Your donations will allow the service to continue onward. //+------------------------------------------------------------------------------------------------+ //|BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | //|Ethereum : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D | //|SOL Address : 4tJXw7JfwF3KUPSzrTm1CoVq6Xu4hYd1vLk3VF2mjMYh | //|Cardano/ADA : addr1v868jza77crzdc87khzpppecmhmrg224qyumud6utqf6f4s99fvqv | //|Dogecoin Address : DBGXP1Nc18ZusSRNsj49oMEYFQgAvgBVA8 | //|SHIB Address : 0x1817D9ebb000025609Bf5D61E269C64DC84DA735 | //|Binance(ERC20 & BSC only) : 0xe84751063de8ade7c5fbff5e73f6502f02af4e2c | //|BitCoin Cash : 1BEtS465S3Su438Kc58h2sqvVvHK9Mijtg | //|LiteCoin : LLU8PSY2vsq7B9kRELLZQcKf5nJQrdeqwD | //+------------------------------------------------------------------------------------------------+ #property copyright "Copyright © 2025, Gehtsoft USA LLC" #property link "http://fxcodebase.com" #property version "1.00" #property strict // string EAName = "AutoPending_EA"; #include input int GridLevels = 3; // Number of pending orders input double GridSpacing = 30.0; // Distance between orders (pips) input uint MagicNumber = 123456; // Magic number for EA orders double pipValue; CTrade trade; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double pip(string sym) { sym == "" ? sym = Symbol() : sym = sym; double po = SymbolInfoDouble(sym, SYMBOL_POINT); int di = (int)SymbolInfoInteger(sym, SYMBOL_DIGITS); return (di % 2 == 1 ? po * 10 : po); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { int digits = (int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS); pipValue = pip(Symbol()); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { if(CountMagicPendingOrders() >= GridLevels) return; ulong manualTicket = GetManualPositionTicket(); if(manualTicket <= 0) return; PositionSelectByTicket(manualTicket); double entryPrice = PositionGetDouble(POSITION_PRICE_OPEN); double volume = PositionGetDouble(POSITION_VOLUME); double dir = PositionGetInteger(POSITION_TYPE) == ORDER_TYPE_BUY ? 1 : -1; Comment(manualTicket+" "+entryPrice+" "+volume+" "+dir+" "+(1 * GridSpacing * pipValue)); for(int i = 1; i <= GridLevels; i++) { double offset = i * GridSpacing * pipValue; double price = dir == 1 ? entryPrice - offset : entryPrice + offset; PlacePendingOrder(dir == 1 ? ORDER_TYPE_BUY_LIMIT : ORDER_TYPE_SELL_LIMIT, volume, price, 0, 0); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CountMagicPendingOrders() { int count = 0; int total = OrdersTotal(); for(int i = 0; i < total; i++) { ulong ticket = OrderGetTicket(i); if(OrderSelect(ticket)) { if(OrderGetInteger(ORDER_MAGIC) == MagicNumber && OrderGetString(ORDER_SYMBOL) == _Symbol) count++; } } return(count); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ ulong GetManualPositionTicket() { int total = PositionsTotal(); for(int i = 0; i < total; i++) { ulong ticket = PositionGetTicket(i); if(PositionSelectByTicket(ticket)) { if(PositionGetString(POSITION_SYMBOL) == _Symbol && PositionGetInteger(POSITION_MAGIC) == 0) return ticket; } } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PlacePendingOrder(ENUM_ORDER_TYPE type, double volume, double price, double sl, double tp) { MqlTradeRequest request; MqlTradeResult result; ZeroMemory(request); ZeroMemory(result); request.action = TRADE_ACTION_PENDING; request.symbol = _Symbol; request.magic = MagicNumber; request.type = type; request.price = price; request.volume = volume; request.sl = sl; request.tp = tp; request.deviation = 10; if(!OrderSend(request, result)) PrintFormat("Failed to place pending order: retcode=%d", result.retcode); } //+------------------------------------------------------------------+