Geen omschrijving

Pulse_EA_project_MT5.mq5 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. //+------------------------------------------------------------------+
  2. //| Pulse_EA_project_MT5.mq5 |
  3. //| Copyright 2024, MQL Development |
  4. //| https://www.mqldevelopment.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2024, MQL Development"
  7. #property link "https://www.mqldevelopment.com/"
  8. #property version "1.00"
  9. #include <Trade\Trade.mqh>
  10. CTrade trade;
  11. #define MaxOrders 10000
  12. struct new_trade_store
  13. {
  14. int trade_ticket;
  15. int trade_type;
  16. int trade_magic_no;
  17. double trade_open_price;
  18. double trade_close_price;
  19. datetime trade_open_time;
  20. datetime trade_close_time;
  21. double trade_sl;
  22. double trade_tp;
  23. double trade_lot;
  24. double trade_profit;
  25. new_trade_store()
  26. {
  27. trade_ticket = -1;
  28. trade_type = -1;
  29. trade_magic_no = -1;
  30. trade_open_price = -1;
  31. trade_close_price = -1;
  32. trade_open_time = -1;
  33. trade_close_time = -1;
  34. trade_sl = -1;
  35. trade_tp = -1;
  36. trade_lot = -1;
  37. trade_profit = -1;
  38. }
  39. };
  40. new_trade_store od[MaxOrders];
  41. enum trade_typ
  42. {
  43. buy, // Buy
  44. reverse, // Reverse
  45. };
  46. enum EA_TYPE
  47. {
  48. Tally_Sim, // Tally Sim
  49. Tally_Trade, // Tally Trade
  50. };
  51. input string gnrlsettings = " ================ General Settings =================== ";//_
  52. input EA_TYPE eaType = Tally_Sim; // EA Option
  53. input double tpPips = 20; // Tp Pips
  54. input double slPips = 20; // SL Pips
  55. input double lot = 0.1; // Lot Size
  56. input string gnrlesettings = " ================ Tally Sim Settings =================== ";//_
  57. trade_typ ordTyp = buy; // Order Type (Tally Sim)
  58. input int magicNo = 123; // Magic #
  59. input string fileName = "TradeDataFile"; // File Name (Tally Sim)
  60. input string grlesettings = " ================ Tally Trade Settings =================== ";//_
  61. input trade_typ tradesDirection = buy; // Order Type (Tally Trade)
  62. input int magicNo1 = 1; // Copy Trade Magic #
  63. input bool CopyTallyTrade = true; // Enable Copy Trade
  64. input double glTp = 20; // Copy Take Profit
  65. input double glSl = 10; // Copy Stop Loss
  66. input string Settings6 = "------------- Display Settings -------------"; //_
  67. input int tradeLineThickness = 2; // Trade Line Thickness
  68. input int dollarFontSize = 10; // Dollar Text Font Size
  69. input color dollarFontColor = clrAqua; // Dollar Text Font Colour
  70. input string horizontalLineName = "close"; // Horizontal Line Name
  71. input string Settings5 = "------------- Time Filter Settings -------------"; //_
  72. input bool enableTimeFilter = false; // Enable Time Filter
  73. input string startTime = "22:00"; // Start Time
  74. input string endTime = "01:00"; // End Time
  75. input bool useFridayClose = false; // Use Friday Close
  76. input string closeFriday = "23:00"; // Friday Close Time
  77. input bool useMondayOpen = false; // Use Monday Open
  78. input string mondayOpen = "01:00"; // Monday Open Time
  79. input string Settings25 = "------------- Daily Draw Limit Settings -------------"; //_
  80. input bool UseDailyDrawdownLimit = true; // Enable Daily Draw Down
  81. input double DailyDrawdownAmount = 2000; // $2000 limit
  82. input string DrawdownResetTime = "05:00"; // Enable Trading At
  83. input string indSettings = " ================ Indicator Settings =================== ";//_
  84. input color Dot_Color = clrOrangeRed;
  85. input double StartingBalance = 10000;
  86. input string MagicNumbers = "123";
  87. input int MA_Period = 5;
  88. input ENUM_MA_METHOD MA_Method = MODE_SMA;
  89. input string fileName1 = "TradeDataFile"; // File Name
  90. input int historyTrades = 50;
  91. bool tpSlHit = false;
  92. int ticketAssigner = 1;
  93. int handler;
  94. double bufferData[];
  95. ushort u_sep; // The code of the separator character
  96. string sep = ":"; // A separator as a character
  97. string result1[];
  98. datetime startTradingTime = 0, endTradingTime = 0, dailyDrawDownTime = 0;
  99. datetime mondayTradingStart = 0, fridayTradingClose = 0;
  100. datetime eaStartTime; // Store EA start time
  101. double g_dailyStartBalance;
  102. bool enableTradingDaily = true;
  103. bool doTrading = true;
  104. int prevOrderCount = 0;
  105. //+------------------------------------------------------------------+
  106. //| |
  107. //+------------------------------------------------------------------+
  108. string filename = fileName + Symbol() + ".csv";
  109. //+------------------------------------------------------------------+
  110. //| Expert initialization function |
  111. //+------------------------------------------------------------------+
  112. int OnInit()
  113. {
  114. //---
  115. if(eaType == Tally_Sim)
  116. {
  117. FileDelete(filename,FILE_WRITE|FILE_CSV|FILE_COMMON|FILE_END);
  118. int filehandle = FileOpen(filename,FILE_WRITE|FILE_CSV|FILE_COMMON|FILE_END,",");
  119. if(filehandle != INVALID_HANDLE)
  120. {
  121. FileClose(filehandle);
  122. }
  123. }
  124. else
  125. {
  126. prevOrderCount = orderCount();
  127. }
  128. string typ = eaType == 0 ? "Tally Sim" :"Tally Trade";
  129. Comment(" Current Mode: ",typ);
  130. tpSlHit = false;
  131. doTrading = true;
  132. ticketAssigner = 1;
  133. if(eaType == Tally_Trade)
  134. {
  135. ArrayInitialize(bufferData,0.0);
  136. handler = iCustom(Symbol(),PERIOD_CURRENT,"Pulse Balance Indicator Sim",Dot_Color,StartingBalance,MagicNumbers,MA_Period,MA_Method,fileName1,historyTrades);
  137. ArraySetAsSeries(bufferData,true);
  138. }
  139. trade.SetExpertMagicNumber(magicNo1);
  140. trade.SetDeviationInPoints(10);
  141. trade.SetTypeFilling(ORDER_FILLING_IOC);
  142. trade.LogLevel(LOG_LEVEL_ALL);
  143. trade.SetAsyncMode(false);
  144. setStart_EndTime_modify(true,startTime,endTime,startTradingTime,endTradingTime);
  145. setStart_EndTime(true,startTime,endTime,startTradingTime,endTradingTime);
  146. g_dailyStartBalance = AccountInfoDouble(ACCOUNT_BALANCE);
  147. enableTradingDaily = true;
  148. eaStartTime = TimeCurrent(); // Track EA start time
  149. //---
  150. return(INIT_SUCCEEDED);
  151. }
  152. //+------------------------------------------------------------------+
  153. //| Expert deinitialization function |
  154. //+------------------------------------------------------------------+
  155. void OnDeinit(const int reason)
  156. {
  157. //---
  158. if(eaType == Tally_Sim)
  159. {
  160. deleteObjects();
  161. }
  162. Comment("");
  163. }
  164. //+------------------------------------------------------------------+
  165. //| Expert tick function |
  166. //+------------------------------------------------------------------+
  167. void OnTick()
  168. {
  169. //---
  170. doTrading = true;
  171. timeConversion();
  172. if(TimeCurrent() >= dailyDrawDownTime && enableTradingDaily == false)
  173. {
  174. enableTradingDaily = true;
  175. }
  176. if(eaType == Tally_Trade)
  177. {
  178. markClosedOrder(eaStartTime);
  179. CheckVirtualGlobalTpSl();
  180. }
  181. if(eaType == Tally_Sim)
  182. checkTPSLHit();
  183. newBar();
  184. if(newDayBar())
  185. {
  186. g_dailyStartBalance = AccountInfoDouble(ACCOUNT_BALANCE);
  187. }
  188. MqlDateTime dt;
  189. TimeToStruct(TimeCurrent(), dt);
  190. if(useMondayOpen)
  191. {
  192. if(dt.day_of_week == 1 && TimeCurrent() < mondayTradingStart) // it's Monday
  193. {
  194. doTrading = false;
  195. }
  196. }
  197. if(useFridayClose)
  198. {
  199. if(dt.day_of_week == 5 && TimeCurrent() >= fridayTradingClose) // it's Friday
  200. {
  201. doTrading = false;
  202. closeAllActiveOrders();
  203. }
  204. }
  205. setStart_EndTime_modify(false,startTime,endTime,startTradingTime,endTradingTime);
  206. setStart_EndTime(false,startTime,endTime,startTradingTime,endTradingTime);
  207. if(enableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime)
  208. {
  209. return;
  210. }
  211. placeTrade();
  212. }
  213. //+------------------------------------------------------------------+
  214. //| |
  215. //+------------------------------------------------------------------+
  216. bool newBar()
  217. {
  218. static datetime lastbar;
  219. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  220. if(lastbar != curbar)
  221. {
  222. lastbar = curbar;
  223. Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
  224. return (true);
  225. }
  226. else
  227. {
  228. return (false);
  229. }
  230. }
  231. //+------------------------------------------------------------------+
  232. //| |
  233. //+------------------------------------------------------------------+
  234. bool newDayBar()
  235. {
  236. static datetime lastbar1;
  237. datetime curbar1 = iTime(Symbol(), PERIOD_D1, 0);
  238. if(lastbar1 != curbar1)
  239. {
  240. lastbar1 = curbar1;
  241. Print(" ---------------------- New Day Bar :: ---------------------- ",lastbar1);
  242. return (true);
  243. }
  244. else
  245. {
  246. return (false);
  247. }
  248. }
  249. //+------------------------------------------------------------------+
  250. //| |
  251. //+------------------------------------------------------------------+
  252. void closeAllActiveOrders()
  253. {
  254. for(int i=PositionsTotal()-1; i >=0 ; i--)
  255. {
  256. ulong ticket = PositionGetTicket(i);
  257. if(PositionSelectByTicket(ticket))
  258. {
  259. if(PositionGetInteger(POSITION_MAGIC) == magicNo &&
  260. PositionGetString(POSITION_SYMBOL) == Symbol())
  261. {
  262. if(trade.PositionClose(ticket))
  263. {
  264. Print("Closing All Active Orders");
  265. Print("Position closed ", ticket);
  266. }
  267. else
  268. {
  269. Print("Cannot close order: ",GetLastError());
  270. }
  271. }
  272. }
  273. }
  274. }
  275. //+------------------------------------------------------------------+
  276. //| |
  277. //+------------------------------------------------------------------+
  278. void timeConversion()
  279. {
  280. MqlDateTime date1, date_1,date_2;
  281. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date1);
  282. u_sep=StringGetCharacter(sep,0);
  283. StringSplit(mondayOpen,u_sep,result1);
  284. date1.hour = (int)StringToInteger(result1[0]);
  285. date1.min = (int)StringToInteger(result1[1]);
  286. mondayTradingStart = StructToTime(date1);
  287. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date_1);
  288. StringSplit(closeFriday,u_sep,result1);
  289. date_1.hour = (int)StringToInteger(result1[0]);
  290. date_1.min = (int)StringToInteger(result1[1]);
  291. fridayTradingClose = StructToTime(date_1);
  292. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date_2);
  293. StringSplit(DrawdownResetTime,u_sep,result1);
  294. date_2.hour = (int)StringToInteger(result1[0]);
  295. date_2.min = (int)StringToInteger(result1[1]);
  296. dailyDrawDownTime = StructToTime(date_2);
  297. }
  298. //+------------------------------------------------------------------+
  299. //| |
  300. //+------------------------------------------------------------------+
  301. void placeTrade()
  302. {
  303. if(tpSlHit == false || eaType == Tally_Trade)
  304. {
  305. if(ordTyp == buy)
  306. {
  307. placeBuyTrade();
  308. }
  309. if(ordTyp == reverse)
  310. {
  311. placeSellTrade();
  312. }
  313. tpSlHit = true;
  314. }
  315. }
  316. //+------------------------------------------------------------------+
  317. //| |
  318. //+------------------------------------------------------------------+
  319. void placeBuyTrade()
  320. {
  321. double buySl = 0,buyTp=0;
  322. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  323. if(slPips != 0)
  324. {
  325. buySl = Ask - (slPips * Point() * 10);
  326. }
  327. if(tpPips != 0)
  328. {
  329. buyTp = Ask + (tpPips * Point() * 10);
  330. }
  331. if(eaType == Tally_Sim)
  332. {
  333. AddToStructure(ticketAssigner,0,magicNo,Ask,0,TimeCurrent(),0,buySl,buyTp,lot,0);
  334. ticketAssigner++;
  335. DrawVirtualBuyOpen(Ask);
  336. }
  337. else
  338. {
  339. int count = orderCount();
  340. if(prevOrderCount != count && count != -1)
  341. {
  342. for(int k = prevOrderCount + 1;k <= count;k++)
  343. {
  344. getTicketByNumber(k,buySl,buyTp);
  345. if(enableTradingDaily == true && doTrading == true)
  346. {
  347. if(eaType == Tally_Trade && CopyTallyTrade)
  348. {
  349. if(CopyBuffer(handler, 0, 0, 4, bufferData) < 0)
  350. {
  351. Print("Error in copying Buffer data ", GetLastError());
  352. }
  353. double balance = bufferData[1];
  354. if(CopyBuffer(handler, 1, 0, 4, bufferData) < 0)
  355. {
  356. Print("Error in copying Buffer data ", GetLastError());
  357. }
  358. double MA = bufferData[1];
  359. Print(" Balance = ",balance," MA = ",MA);
  360. if(tradesDirection == buy)
  361. {
  362. if(balance > MA)
  363. {
  364. if(!trade.Buy(lot, Symbol(),SymbolInfoDouble(Symbol(),SYMBOL_ASK),buySl,buyTp,"Buy Trade"))
  365. {
  366. Print(" Error in Placing Buy Trade : ",GetLastError());
  367. }
  368. }
  369. else
  370. {
  371. Print(" Trade is not Placed because Balance is less than MA Value ");
  372. }
  373. }
  374. else
  375. {
  376. if(balance < MA)
  377. {
  378. if(!trade.Sell(lot,Symbol(),SymbolInfoDouble(Symbol(),SYMBOL_BID),buyTp,buySl,"Sell Trade"))
  379. {
  380. Print(" Error in Placing Sell Trade : ",GetLastError());
  381. }
  382. }
  383. else
  384. {
  385. Print(" Trade is not Placed because Balance is less than MA Value ");
  386. }
  387. }
  388. }
  389. }
  390. }
  391. prevOrderCount = count;
  392. }
  393. }
  394. }
  395. //+------------------------------------------------------------------+
  396. //| |
  397. //+------------------------------------------------------------------+
  398. void placeSellTrade()
  399. {
  400. double sellSl = 0, sellTp = 0;
  401. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  402. if(slPips != 0)
  403. {
  404. sellSl = Bid + (slPips * 10 * Point());
  405. }
  406. if(tpPips != 0)
  407. {
  408. sellTp = Bid - (tpPips * 10 * Point());
  409. }
  410. if(eaType == Tally_Sim)
  411. {
  412. AddToStructure(ticketAssigner,1,magicNo,Bid,0,TimeCurrent(),0,sellSl,sellTp,lot,0);
  413. ticketAssigner++;
  414. }
  415. else
  416. {
  417. int count = orderCount();
  418. if(prevOrderCount != count && count != -1)
  419. {
  420. for(int k = prevOrderCount + 1;k <= count;k++)
  421. {
  422. getTicketByNumber(k,sellSl,sellTp);
  423. if(enableTradingDaily == true)
  424. {
  425. if(eaType == Tally_Trade && CopyTallyTrade)
  426. {
  427. if(CopyBuffer(handler, 0, 0, 4, bufferData) < 0)
  428. {
  429. Print("Error in copying Buffer data ", GetLastError());
  430. }
  431. double balance = bufferData[1];
  432. if(CopyBuffer(handler, 1, 0, 4, bufferData) < 0)
  433. {
  434. Print("Error in copying Buffer data ", GetLastError());
  435. }
  436. double MA = bufferData[1];
  437. Print(" Balance = ",balance," MA = ",MA);
  438. if(tradesDirection == reverse)
  439. {
  440. if(balance < MA)
  441. {
  442. if(!trade.Sell(lot,Symbol(),Bid,sellSl,sellTp,"Sell Trade"))
  443. {
  444. Print(" Error in Placing Sell Trade : ",GetLastError());
  445. }
  446. }
  447. else
  448. {
  449. Print(" Trade is not Placed because Balance is less than MA Value ");
  450. }
  451. }
  452. else
  453. {
  454. if(balance > MA)
  455. {
  456. if(!trade.Buy(lot,Symbol(),SymbolInfoDouble(Symbol(),SYMBOL_ASK),sellTp,sellSl,"Buy Trade"))
  457. {
  458. Print(" Error in Placing Buy Trade : ",GetLastError());
  459. }
  460. }
  461. else
  462. {
  463. Print(" Trade is not Placed because Balance is less than MA Value ");
  464. }
  465. }
  466. }
  467. }
  468. }
  469. prevOrderCount = count;
  470. }
  471. }
  472. }
  473. //+------------------------------------------------------------------+
  474. //| |
  475. //+------------------------------------------------------------------+
  476. void AddToStructure(int ticket, int type, int magic, double open_price,
  477. double close_price, datetime open_time, datetime close_time,
  478. double sl, double tp, double lotSize, double profit)
  479. {
  480. for(int i = 0; i < MaxOrders; i++)
  481. {
  482. if(od[i].trade_ticket == -1)
  483. {
  484. od[i].trade_ticket = ticket;
  485. od[i].trade_type = type;
  486. od[i].trade_magic_no = magic;
  487. od[i].trade_open_price = open_price;
  488. od[i].trade_close_price = close_price;
  489. od[i].trade_open_time = open_time;
  490. od[i].trade_close_time = close_time;
  491. od[i].trade_sl = sl;
  492. od[i].trade_tp = tp;
  493. od[i].trade_lot = lotSize;
  494. od[i].trade_profit = profit;
  495. Print(" ========== Trade Placed of Ticket ========== ",ticket);
  496. Print("[AddToStructure] Added at index: ", i,
  497. " | Ticket = ", ticket,
  498. " | Type = ", type,
  499. " | Magic = ", magic,
  500. " | OpenPrice = ", open_price,
  501. " | ClosePrice = ", close_price,
  502. " | SL = ", sl,
  503. " | TP = ", tp,
  504. " | Lots = ", lotSize,
  505. " | Profit = ", profit);
  506. break;
  507. }
  508. }
  509. }
  510. //+------------------------------------------------------------------+
  511. //| |
  512. //+------------------------------------------------------------------+
  513. void checkTPSLHit()
  514. {
  515. double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
  516. double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
  517. for(int i = 0; i < MaxOrders; i++)
  518. {
  519. if(od[i].trade_ticket != -1 && od[i].trade_close_price == 0)
  520. {
  521. int ticket = od[i].trade_ticket;
  522. int type = od[i].trade_type;
  523. double sl = od[i].trade_sl;
  524. double tp = od[i].trade_tp;
  525. double closePrice = 0;
  526. // ----------------------------------------------
  527. // BUY ORDER CHECK
  528. // ----------------------------------------------
  529. if(type == 0)
  530. {
  531. // TP hit → Bid >= TP
  532. if(bid >= tp && tp > 0)
  533. {
  534. closePrice = bid;
  535. Print(" ======== Buy Trade TP Hit ======= ",ticket);
  536. }
  537. // SL hit → Bid <= SL
  538. if(bid <= sl && sl > 0)
  539. {
  540. closePrice = bid;
  541. Print(" ======== Buy Trade SL Hit ======= ",ticket);
  542. }
  543. }
  544. // ----------------------------------------------
  545. // SELL ORDER CHECK
  546. // ----------------------------------------------
  547. if(type == 1)
  548. {
  549. // TP hit → Ask <= TP (price goes DOWN)
  550. if(ask <= tp && tp > 0)
  551. {
  552. closePrice = ask;
  553. Print(" ======== Sell Trade TP Hit ======= ",ticket);
  554. }
  555. // SL hit → Ask >= SL
  556. if(ask >= sl && sl > 0)
  557. {
  558. closePrice = ask;
  559. Print(" ======== Sell Trade SL Hit ======= ",ticket);
  560. }
  561. }
  562. // ----------------------------------------------
  563. // IF ANYTHING TRIGGERED → CLOSE TRADE
  564. // ----------------------------------------------
  565. if(closePrice > 0)
  566. {
  567. od[i].trade_close_price = closePrice;
  568. od[i].trade_close_time = TimeCurrent();
  569. double tpdifference = type == 1 ? (od[i].trade_open_price - od[i].trade_close_price) / Point() : (od[i].trade_close_price - od[i].trade_open_price) / Point();
  570. od[i].trade_profit += tpinDollar(od[i].trade_lot, tpdifference);
  571. Print("======= TRADE CLOSED of ticket =======",ticket);
  572. Print("Index: ", i,
  573. " | Ticket: ", ticket,
  574. " | Type: ", type,
  575. " | ClosePrice: ", closePrice,
  576. " | Time: ", od[i].trade_close_time,
  577. " | Profit: ", od[i].trade_profit);
  578. DrawVirtualBuyClose(closePrice);
  579. datetime t1 = od[i].trade_open_time;
  580. double price1 = od[i].trade_open_price;
  581. datetime t2 = od[i].trade_close_time;
  582. double price2 = od[i].trade_close_price;
  583. DrawDottedTrendline("Ticket "+string(ticket), t1, price1, t2, price2, clrGreen);
  584. tpSlHit = false; // make these zero so new trade place's
  585. string line = MakeTradeString(
  586. od[i].trade_ticket,
  587. od[i].trade_type,
  588. od[i].trade_magic_no,
  589. od[i].trade_open_price,
  590. od[i].trade_close_price,
  591. od[i].trade_open_time,
  592. od[i].trade_close_time,
  593. od[i].trade_sl,
  594. od[i].trade_tp,
  595. od[i].trade_lot,
  596. od[i].trade_profit
  597. );
  598. writeDatainFile(line);
  599. }
  600. }
  601. }
  602. }
  603. //+------------------------------------------------------------------+
  604. //| |
  605. //+------------------------------------------------------------------+
  606. double tpinDollar(double lotSize, double distance)
  607. {
  608. double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
  609. pipvalue = pipvalue / 10;
  610. double dollar = lotSize * distance * pipvalue;
  611. return NormalizeDouble(dollar,2);
  612. }
  613. //+------------------------------------------------------------------+
  614. //| |
  615. //+------------------------------------------------------------------+
  616. void writeDatainFile(string str)
  617. {
  618. int filehandle = FileOpen(filename,FILE_WRITE|FILE_CSV|FILE_COMMON|FILE_END,",");
  619. if(filehandle != INVALID_HANDLE)
  620. {
  621. FileSeek(filehandle, 0, SEEK_END);
  622. FileWrite(filehandle,str);
  623. Print(str);
  624. FileClose(filehandle);
  625. }
  626. }
  627. //+------------------------------------------------------------------+
  628. //| |
  629. //+------------------------------------------------------------------+
  630. string MakeTradeString(int ticket, int type, int magic,
  631. double open_price, double close_price,
  632. datetime open_time, datetime close_time,
  633. double sl, double tp, double lotSize, double profit)
  634. {
  635. string str = StringFormat("%d,%d,%d,%.5f,%.5f,%s,%s,%.5f,%.5f,%.2f,%.2f",
  636. ticket,
  637. type,
  638. magic,
  639. open_price,
  640. close_price,
  641. TimeToString(open_time, TIME_DATE|TIME_SECONDS),
  642. TimeToString(close_time, TIME_DATE|TIME_SECONDS),
  643. sl,
  644. tp,
  645. lotSize,
  646. profit);
  647. return str;
  648. }
  649. //+------------------------------------------------------------------+
  650. //| |
  651. //+------------------------------------------------------------------+
  652. void setStart_EndTime(bool onInit,string start,string end,datetime & sessionStart,datetime & sessionEnd)
  653. {
  654. int newYorkStartHour = 0, newYorkStartMin = 0, newYorkEndHour = 0, newYorkEndMin = 0;
  655. datetime newYorkStartTrading,newYorkEndTrading;
  656. string time[];
  657. StringSplit(start,':',time);
  658. newYorkStartHour = (int)StringToInteger(time[0]);
  659. newYorkStartMin = (int)StringToInteger(time[1]);
  660. EventSetMillisecondTimer(500);
  661. time[0] = "";
  662. time[1] = "";
  663. StringSplit(end,':',time);
  664. newYorkEndHour = (int)StringToInteger(time[0]);
  665. newYorkEndMin = (int)StringToInteger(time[1]);
  666. // Print(" Start Time Hour: ",newYorkStartHour," Start Time Min: ",newYorkStartMin);
  667. // Print(" End Time Hour: ",newYorkEndHour," End Time Min: ",newYorkEndMin);
  668. datetime startDateTime;
  669. MqlDateTime st;
  670. TimeCurrent(st); // get current date
  671. st.hour = newYorkStartHour;
  672. st.min = newYorkStartMin;
  673. st.sec = 0;
  674. startDateTime = StructToTime(st);
  675. datetime endDateTime;
  676. MqlDateTime et;
  677. TimeCurrent(et); // get current date
  678. et.hour = newYorkEndHour;
  679. et.min = newYorkEndMin;
  680. et.sec = 0;
  681. endDateTime = StructToTime(et);
  682. MqlDateTime sdate,edate;
  683. datetime start_Time = 0, end_Time = 0;
  684. if(startDateTime > endDateTime)
  685. {
  686. if(onInit)
  687. {
  688. start_Time = iTime(Symbol(),PERIOD_D1,1);
  689. end_Time = iTime(Symbol(),PERIOD_D1,0);
  690. }
  691. else
  692. {
  693. start_Time = sessionStart;
  694. end_Time = sessionEnd;
  695. if(TimeCurrent() >= sessionEnd && sessionEnd != 0)
  696. {
  697. start_Time = iTime(Symbol(),PERIOD_D1,0);
  698. end_Time = start_Time + 86400;
  699. }
  700. }
  701. }
  702. else
  703. {
  704. start_Time = iTime(Symbol(),PERIOD_D1,0);
  705. end_Time = iTime(Symbol(),PERIOD_D1,0);
  706. }
  707. if(TimeToStruct(end_Time,edate))
  708. {
  709. edate.hour = newYorkEndHour;
  710. edate.min = newYorkEndMin;
  711. edate.sec = 0;
  712. }
  713. else
  714. Print("Error in Converting Time: ",GetLastError());
  715. newYorkEndTrading = StructToTime(edate);
  716. if(TimeToStruct(start_Time,sdate))
  717. {
  718. sdate.hour = newYorkStartHour;
  719. sdate.min = newYorkStartMin;
  720. sdate.sec = 0;
  721. }
  722. else
  723. Print("Error in Converting Time: ",GetLastError());
  724. newYorkStartTrading = StructToTime(sdate);
  725. sessionStart = newYorkStartTrading;
  726. sessionEnd = newYorkEndTrading;
  727. }
  728. //+------------------------------------------------------------------+
  729. //| |
  730. //+------------------------------------------------------------------+
  731. void setStart_EndTime_modify(bool onInit,string start,string end,datetime & sessionStart,datetime & sessionEnd)
  732. {
  733. int newYorkStartHour = 0, newYorkStartMin = 0, newYorkEndHour = 0, newYorkEndMin = 0;
  734. datetime newYorkStartTrading,newYorkEndTrading;
  735. string time[];
  736. StringSplit(start,':',time);
  737. newYorkStartHour = (int)StringToInteger(time[0]);
  738. newYorkStartMin = (int)StringToInteger(time[1]);
  739. time[0] = "";
  740. time[1] = "";
  741. StringSplit(end,':',time);
  742. newYorkEndHour = (int)StringToInteger(time[0]);
  743. newYorkEndMin = (int)StringToInteger(time[1]);
  744. // Print(" Start Time Hour: ",newYorkStartHour," Start Time Min: ",newYorkStartMin);
  745. // Print(" End Time Hour: ",newYorkEndHour," End Time Min: ",newYorkEndMin);
  746. datetime startDateTime;
  747. MqlDateTime st;
  748. TimeCurrent(st); // get current date
  749. st.hour = newYorkStartHour;
  750. st.min = newYorkStartMin;
  751. st.sec = 0;
  752. startDateTime = StructToTime(st);
  753. datetime endDateTime;
  754. MqlDateTime et;
  755. TimeCurrent(et); // get current date
  756. et.hour = newYorkEndHour;
  757. et.min = newYorkEndMin;
  758. et.sec = 0;
  759. endDateTime = StructToTime(et);
  760. MqlDateTime sdate,edate;
  761. datetime start_Time = 0, end_Time = 0;
  762. if(startDateTime > endDateTime)
  763. {
  764. start_Time = iTime(Symbol(),PERIOD_D1,1);
  765. end_Time = iTime(Symbol(),PERIOD_D1,0);
  766. }
  767. else
  768. {
  769. start_Time = iTime(Symbol(),PERIOD_D1,0);
  770. end_Time = iTime(Symbol(),PERIOD_D1,0);
  771. }
  772. if(TimeToStruct(end_Time,edate))
  773. {
  774. edate.hour = newYorkEndHour;
  775. edate.min = newYorkEndMin;
  776. edate.sec = 0;
  777. }
  778. else
  779. Print("Error in Converting Time: ",GetLastError());
  780. newYorkEndTrading = StructToTime(edate);
  781. if(TimeToStruct(start_Time,sdate))
  782. {
  783. sdate.hour = newYorkStartHour;
  784. sdate.min = newYorkStartMin;
  785. sdate.sec = 0;
  786. }
  787. else
  788. Print("Error in Converting Time: ",GetLastError());
  789. newYorkStartTrading = StructToTime(sdate);
  790. sessionStart = newYorkStartTrading;
  791. sessionEnd = newYorkEndTrading;
  792. }
  793. //+------------------------------------------------------------------+
  794. //| Check Virtual TP/SL for all positions |
  795. //+------------------------------------------------------------------+
  796. void CheckVirtualGlobalTpSl()
  797. {
  798. double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
  799. double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
  800. for(int i=PositionsTotal()-1; i >=0 ; i--)
  801. {
  802. ulong ticket = PositionGetTicket(i);
  803. if(PositionSelectByTicket(ticket))
  804. {
  805. if(PositionGetInteger(POSITION_MAGIC) == magicNo &&
  806. PositionGetString(POSITION_SYMBOL) == _Symbol)
  807. {
  808. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
  809. {
  810. double tp_price = PositionGetDouble(POSITION_PRICE_OPEN) + glTp * 10 * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
  811. double sl_price = PositionGetDouble(POSITION_PRICE_OPEN) - glSl * 10 * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
  812. if(bid >= tp_price || bid <= sl_price)
  813. {
  814. closeAllActiveOrders();
  815. return;
  816. }
  817. }
  818. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  819. {
  820. double tp_price = PositionGetDouble(POSITION_PRICE_OPEN) - glTp * 10 * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
  821. double sl_price = PositionGetDouble(POSITION_PRICE_OPEN) + glSl * 10 * SymbolInfoDouble(_Symbol, SYMBOL_POINT);
  822. if(ask <= tp_price || ask >= sl_price)
  823. {
  824. closeAllActiveOrders();
  825. return;
  826. }
  827. }
  828. }
  829. }
  830. }
  831. }
  832. //+------------------------------------------------------------------+
  833. //| |
  834. //+------------------------------------------------------------------+
  835. void CheckDailyDrawdown()
  836. {
  837. if(!UseDailyDrawdownLimit)
  838. return;
  839. double equity = AccountInfoDouble(ACCOUNT_EQUITY);
  840. double drawdown = g_dailyStartBalance - equity;
  841. if(drawdown >= DailyDrawdownAmount)
  842. {
  843. Print("Daily Drawdown Limit Hit: ", drawdown, " >= ", DailyDrawdownAmount);
  844. closeAllActiveOrders();
  845. }
  846. }
  847. //+------------------------------------------------------------------+
  848. //| |
  849. //+------------------------------------------------------------------+
  850. void markClosedOrder(datetime eaTime)
  851. {
  852. HistorySelect(eaTime, TimeCurrent());
  853. for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
  854. {
  855. ulong dealTicket = HistoryDealGetTicket(i);
  856. long dealMagic = HistoryDealGetInteger(dealTicket, DEAL_MAGIC);
  857. if(dealMagic != magicNo && dealMagic != 0)
  858. continue;
  859. if(HistoryDealGetString(dealTicket, DEAL_SYMBOL) == Symbol())
  860. {
  861. //Print("Condition 2 ",HistoryDealGetInteger(dealTicket, DEAL_ENTRY)," HistoryDealsTotal(): ",HistoryDealsTotal());
  862. if(HistoryDealGetInteger(dealTicket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
  863. {
  864. //Print("deal out close: ",dealTicket);
  865. long dealType = HistoryDealGetInteger(dealTicket, DEAL_TYPE);
  866. if(dealType != DEAL_TYPE_BUY && dealType != DEAL_TYPE_SELL)
  867. continue;
  868. double profit = HistoryDealGetDouble(dealTicket, DEAL_PROFIT);
  869. profit = NormalizeDouble(profit, 2);
  870. string lineName = "TradeLine_" + (string)dealTicket;
  871. if(ObjectFind(0, lineName) >= 0)
  872. continue;
  873. ulong entryDeal = findEntryDeal(dealTicket);
  874. if(entryDeal == 0)
  875. continue;
  876. datetime openTime = (datetime)HistoryDealGetInteger(entryDeal, DEAL_TIME);
  877. double openPrice = HistoryDealGetDouble(entryDeal, DEAL_PRICE);
  878. datetime closeTime = (datetime)HistoryDealGetInteger(dealTicket, DEAL_TIME);
  879. double closePrice = HistoryDealGetDouble(dealTicket, DEAL_PRICE);
  880. createTrendLine(lineName, openTime, openPrice, closeTime, closePrice, dealType, profit);
  881. PrintFormat("Trend line created for closed trade #%I64u | Profit: %.2f", dealTicket, profit);
  882. }
  883. }
  884. }
  885. }
  886. //+------------------------------------------------------------------+
  887. //| |
  888. //+------------------------------------------------------------------+
  889. void createTrendLine(string name,
  890. datetime openTime, double openPrice,
  891. datetime closeTime, double closePrice,
  892. long dealType, double profit)
  893. {
  894. if(ObjectFind(0, name) >= 0)
  895. return;
  896. if(!ObjectCreate(0, name, OBJ_TREND, 0, openTime, openPrice, closeTime, closePrice))
  897. {
  898. Print("Error creating trend line: ", GetLastError());
  899. return;
  900. }
  901. ObjectSetInteger(0, name, OBJPROP_WIDTH, tradeLineThickness);
  902. ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_SOLID);
  903. ObjectSetInteger(0, name, OBJPROP_RAY, false);
  904. color lineColor = (dealType == DEAL_TYPE_BUY) ? clrRed : clrBlue;
  905. ObjectSetInteger(0, name, OBJPROP_COLOR, lineColor);
  906. createProfitLabel(name + "_label", openTime, openPrice, closeTime, closePrice, dealType, profit);
  907. }
  908. //+------------------------------------------------------------------+
  909. //| |
  910. //+------------------------------------------------------------------+
  911. void createProfitLabel(string name,
  912. datetime openTime, double openPrice,
  913. datetime closeTime, double closePrice,
  914. long dealType, double profit)
  915. {
  916. if(ObjectFind(0, name) >= 0)
  917. return;
  918. datetime middleTime = openTime + (closeTime - openTime) / 2;
  919. double midPrice = (openPrice + closePrice) / 2;
  920. if(!ObjectCreate(0, name, OBJ_TEXT, 0, middleTime, midPrice))
  921. {
  922. Print("Error creating profit label: ", GetLastError());
  923. return;
  924. }
  925. string profitText = "$" + DoubleToString(profit, 2);
  926. ObjectSetString(0, name, OBJPROP_TEXT, profitText);
  927. ObjectSetInteger(0, name, OBJPROP_FONTSIZE, dollarFontSize);
  928. ObjectSetInteger(0, name, OBJPROP_COLOR, dollarFontColor);
  929. ObjectSetInteger(0, name, OBJPROP_ANCHOR, ANCHOR_TOP);
  930. ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
  931. }
  932. //+------------------------------------------------------------------+
  933. //| |
  934. //+------------------------------------------------------------------+
  935. ulong findEntryDeal(ulong closeDeal)
  936. {
  937. string symbol = HistoryDealGetString(closeDeal, DEAL_SYMBOL);
  938. long positionID = HistoryDealGetInteger(closeDeal, DEAL_POSITION_ID);
  939. int dealOutCount = 0;
  940. for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
  941. {
  942. ulong deal = HistoryDealGetTicket(i);
  943. if(HistoryDealGetInteger(deal, DEAL_POSITION_ID) == positionID)
  944. {
  945. if(HistoryDealGetInteger(deal, DEAL_ENTRY) == DEAL_ENTRY_OUT)
  946. {
  947. dealOutCount++;
  948. }
  949. }
  950. }
  951. if(dealOutCount < 2)
  952. {
  953. for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
  954. {
  955. ulong deal = HistoryDealGetTicket(i);
  956. if(HistoryDealGetInteger(deal, DEAL_POSITION_ID) == positionID &&
  957. HistoryDealGetInteger(deal, DEAL_ENTRY) == DEAL_ENTRY_IN &&
  958. HistoryDealGetString(deal, DEAL_SYMBOL) == symbol)
  959. return deal;
  960. //Print("Deal: ", deal);
  961. }
  962. }
  963. else
  964. {
  965. for(int i = 0; i < HistoryDealsTotal(); i++)
  966. {
  967. ulong deal = HistoryDealGetTicket(i);
  968. if(HistoryDealGetInteger(deal, DEAL_POSITION_ID) == positionID &&
  969. HistoryDealGetInteger(deal, DEAL_ENTRY) == DEAL_ENTRY_OUT)
  970. {
  971. return deal;
  972. }
  973. //Print("Deal: ", deal);
  974. }
  975. }
  976. return 0;
  977. }
  978. //+------------------------------------------------------------------+
  979. //| |
  980. //+------------------------------------------------------------------+
  981. void DrawArrow(string name, datetime time, double price, color clr, int arrow)
  982. {
  983. if(ObjectFind(0, name) == -1)
  984. {
  985. ObjectCreate(0, name, OBJ_ARROW, 0, time, price);
  986. ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
  987. ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
  988. ObjectSetInteger(0, name, OBJPROP_ARROWCODE, arrow);
  989. }
  990. }
  991. //+------------------------------------------------------------------+
  992. //| |
  993. //+------------------------------------------------------------------+
  994. void DrawVirtualBuyOpen(double openPrice)
  995. {
  996. datetime t = TimeCurrent();
  997. string name = "VBUY_OPEN_" + IntegerToString(t);
  998. // DrawArrow(name, t, openPrice, clrLime, 233);
  999. ObjectCreate(0,name,OBJ_ARROW_BUY,0,TimeCurrent(),openPrice);
  1000. }
  1001. //+------------------------------------------------------------------+
  1002. //| |
  1003. //+------------------------------------------------------------------+
  1004. void DrawVirtualBuyClose(double closePrice)
  1005. {
  1006. datetime t = TimeCurrent();
  1007. string name = "VBUY_CLOSE_" + IntegerToString(t);
  1008. // DrawArrow(name, t, closePrice, clrRed, 234);
  1009. ObjectCreate(0,name,OBJ_ARROW_SELL,0,TimeCurrent(),closePrice);
  1010. }
  1011. //+------------------------------------------------------------------+
  1012. //| |
  1013. //+------------------------------------------------------------------+
  1014. void DrawDottedTrendline(string name, datetime time1, double price1, datetime time2, double price2, color clr)
  1015. {
  1016. // Delete if already exists
  1017. if(ObjectFind(0, name) != -1)
  1018. ObjectDelete(0, name);
  1019. // Create the trendline
  1020. if(!ObjectCreate(0, name, OBJ_TREND, 0, time1, price1, time2, price2))
  1021. Print("Error creating trendline: ", GetLastError());
  1022. // Set properties
  1023. ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
  1024. ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DOT); // Dotted line
  1025. ObjectSetInteger(0, name, OBJPROP_WIDTH, 1); // Line width
  1026. }
  1027. //+------------------------------------------------------------------+
  1028. //| |
  1029. //+------------------------------------------------------------------+
  1030. int orderCount()
  1031. {
  1032. int handle = FileOpen(filename, FILE_READ | FILE_COMMON);
  1033. if(handle == INVALID_HANDLE)
  1034. {
  1035. Print("EA=> Handler invalid: orderCount() ", filename," ",GetLastError()," eaType: ",eaType);
  1036. return -1;
  1037. }
  1038. int index = 0;
  1039. while(!FileIsEnding(handle))
  1040. {
  1041. string line = FileReadString(handle);
  1042. // Skip empty line
  1043. if(StringLen(line) < 2)
  1044. continue;
  1045. string parts[];
  1046. int count = StringSplit(line, ',', parts);
  1047. int ticket = (int)StringToInteger(parts[0]);
  1048. int type = (int)StringToInteger(parts[1]);
  1049. int magic = (int)StringToInteger(parts[2]);
  1050. double open_price = StringToDouble(parts[3]);
  1051. double close_price = StringToDouble(parts[4]);
  1052. datetime open_time = StringToTime(parts[5]);
  1053. datetime close_time = StringToTime(parts[6]);
  1054. double sl = StringToDouble(parts[7]);
  1055. double tp = StringToDouble(parts[8]);
  1056. double lotS = StringToDouble(parts[9]);
  1057. double profit = StringToDouble(parts[10]);
  1058. index++;
  1059. }
  1060. FileClose(handle);
  1061. return index;
  1062. }
  1063. //+------------------------------------------------------------------+
  1064. //| |
  1065. //+------------------------------------------------------------------+
  1066. int getTicketByNumber(int id,double & buySl,double & buyTp)
  1067. {
  1068. int handle = FileOpen(filename, FILE_READ | FILE_COMMON);
  1069. if(handle == INVALID_HANDLE)
  1070. {
  1071. Print("EA=> Handler invalid: getTicketByNumber() ", filename," error: ",GetLastError()," eaType: ",eaType);
  1072. return 0;
  1073. }
  1074. int index = 0;
  1075. while(!FileIsEnding(handle))
  1076. {
  1077. string line = FileReadString(handle);
  1078. // Skip empty line
  1079. if(StringLen(line) < 2)
  1080. continue;
  1081. string parts[];
  1082. int count = StringSplit(line, ',', parts);
  1083. int ticket = (int)StringToInteger(parts[0]);
  1084. int type = (int)StringToInteger(parts[1]);
  1085. int magic = (int)StringToInteger(parts[2]);
  1086. double open_price = StringToDouble(parts[3]);
  1087. double close_price = StringToDouble(parts[4]);
  1088. datetime open_time = StringToTime(parts[5]);
  1089. datetime close_time = StringToTime(parts[6]);
  1090. double sl = StringToDouble(parts[7]);
  1091. double tp = StringToDouble(parts[8]);
  1092. double lotS = StringToDouble(parts[9]);
  1093. double profit = StringToDouble(parts[10]);
  1094. if(id == ticket)
  1095. {
  1096. buySl = sl;
  1097. buyTp = tp;
  1098. }
  1099. }
  1100. FileClose(handle);
  1101. return index;
  1102. }
  1103. //+------------------------------------------------------------------+
  1104. //| |
  1105. //+------------------------------------------------------------------+
  1106. void deleteObjects()
  1107. {
  1108. int total = ObjectsTotal(0);
  1109. for(int i = total - 1; i >= 0; i--)
  1110. {
  1111. string name = ObjectName(0, i);
  1112. if(StringFind(name, "VBUY_OPEN_") >= 0 || StringFind(name, "VBUY_CLOSE_") >= 0 || StringFind(name, "Ticket ") >= 0)
  1113. {
  1114. ObjectDelete(0, name);
  1115. }
  1116. }
  1117. }
  1118. //+------------------------------------------------------------------+