暂无描述

vol_hedge_strategy_mt5.mq5 136KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. //+------------------------------------------------------------------+
  2. //| vol_hedge_strategy_mt5.mq5 |
  3. //| Copyright 2025, MQL Development |
  4. //| https://www.mqldevelopment.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2025, MQL Development"
  7. #property link "https://www.mqldevelopment.com/"
  8. #property version "1.20"
  9. #define MaxOrders 100
  10. #include <Trade\Trade.mqh>
  11. CTrade trade;
  12. //+------------------------------------------------------------------+
  13. //| Expert initialization function |
  14. //+------------------------------------------------------------------+
  15. enum NewsCloseOrder
  16. {
  17. CloseAllRunningOrder=0,
  18. LetTheOrderRun=1,
  19. };
  20. enum selectLine
  21. {
  22. LineOnNewsBar =0,
  23. LineOnNewsStop=1
  24. };
  25. enum selectDay
  26. {
  27. prev, // Previous Day
  28. curr, // Current Day
  29. };
  30. #import "volHedgeNewsFilter.ex5"
  31. //+------------------------------------------------------------------+
  32. //| |
  33. //+------------------------------------------------------------------+
  34. void initiateNews(bool master = false);
  35. int returnNewsStatus(bool High_Impact_News=true
  36. ,int High_Start_Time=60//Stop Trade before high News (min)
  37. ,int High_Stop_Time=15 //Stop Trade after high News (min)
  38. ,bool show_high_line=true//Show verticle Line when high news comes
  39. ,bool Medium_Impact_News=true
  40. ,int Medium_Start_Time=60//Stop Trade before medium News (min)
  41. ,int Medium_Stop_Time=15 //Stop Trade after medium News (min)
  42. ,bool show_medium_line=true//Show verticle Line when medium news comes
  43. ,bool Low_Impact_News=true
  44. ,int Low_Start_Time=60//Stop Trade before low News (min)
  45. ,int Low_Stop_Time=15 //Stop Trade after low News (min)
  46. ,bool show_low_line=true//Show verticle Line when low news comes
  47. ,string symbol=""
  48. ,string expert=""
  49. ,int GMT_Broker_Time=2
  50. ,selectLine sl=0
  51. ,string extraSymbol=""
  52. ,bool isMaster = false
  53. );
  54. bool checkDate(string &lastNewsTitle, string &symbolNews, string &impactNews, string &news1, string &news2, string &news3, datetime &timeRemaining, datetime date,string expertname = "",string symbol = "",string extraSymbol="", int gmt=2,string description_1 = "",int candle = 0);
  55. void PrintStructure();
  56. #import
  57. struct new_trade_store
  58. {
  59. ulong buy_ticket; // Buy Ticket
  60. ulong sell_ticket; // Sell Ticket
  61. string symbol; // Symbol
  62. double price; // Price
  63. double stop_loss_buy; // StopLoss Buy
  64. double take_profit_buy; // TakeProfit Buy
  65. double stop_loss_sell; // StopLoss Sell
  66. double take_profit_sell; // TakeProfit Sell
  67. datetime start_time; // Start time
  68. datetime end_time; // End Time
  69. bool buy_hit_virtual_sl; // Buy Hit Virtual StopLoss
  70. bool sell_hit_virtual_sl; // Sell Hit Virtual StopLoss
  71. new_trade_store()
  72. {
  73. buy_ticket = -1;
  74. sell_ticket = -1;
  75. price = 0;
  76. buy_hit_virtual_sl = false;
  77. sell_hit_virtual_sl = false;
  78. }
  79. };
  80. new_trade_store newTradeStore[MaxOrders];
  81. enum lotcalculator
  82. {
  83. fix, //Fixed Lot Size
  84. rsk, //Risk in Percentage
  85. dollar, // Risk in Dollars
  86. };
  87. enum optionsEaTyp
  88. {
  89. client, // Slave EA
  90. master, // Master EA
  91. };
  92. sinput string string_0 = "<><><><><><> General SETTINGS <><><><><><>"; //__
  93. input int magic_no = 333; // Magic no
  94. input bool useTpSlPips = false; // Use Relative Tp/Sl in Points
  95. input double stopLoss = 1000; // Fixed Stop Loss in Points
  96. input double takeProfit = 1000; // Fixed Take Profit in Points
  97. input bool bothHitsSl = false; // Enable Topped & Tailed Pre-Demand Level
  98. input int maxTrades = 2; // Max Concurrent Trades
  99. input int maxSlippage = 5; // Max Slippage (Points)
  100. input bool enableSpreadFilter = false; // Enable Spread Filter
  101. input double maximumSpread = 10; // Maximum Spread (Points)
  102. input string tradeComment = "Trade Placed"; // Trade Comment Prefix
  103. input string dataFileName = "vol_hedge_data.csv"; // CSV File Name
  104. input bool enableDrawLevels = false; // Draw Levels
  105. input string string_1 = "<><><><><><> Lot Management<><><><><><>"; //__
  106. input lotcalculator lot_calculator = fix; // Lot Size Option
  107. input double lot_amount = 0.1; // Lot Size
  108. input double risk = 0.5; // Risk in Percentage %
  109. input double dollars = 10; // Risk in GBP
  110. input string time_setting = "<><><><><> Time Filter Settings <><><><><>"; //_
  111. input bool enableTimeFilter = false; // Enable Time Filter
  112. input string startTime = "03:00"; // Start Time Session
  113. input string endTime = "09:00"; // End Time Session
  114. input string weekFilterSettings = "<><><><><> Week Filter Settings <><><><><>"; //_
  115. input bool enableWeekFilter = false; // Enable Week Filter (true/false)
  116. input int filterMonthNumber = 9; // Month number to apply week filter (1..12)
  117. input int filterWeekNumber = 2; // Week number of month to block (1..5)
  118. input string monthFilterSettings = "<><><><><> Month Filter Settings <><><><><>"; //_
  119. input bool allowJanuary = true; // Allow Trading in January
  120. input bool allowFebruary = true; // Allow Trading in February
  121. input bool allowMarch = true; // Allow Trading in March
  122. input bool allowApril = true; // Allow Trading in April
  123. input bool allowMay = true; // Allow Trading in May
  124. input bool allowJune = true; // Allow Trading in June
  125. input bool allowJuly = true; // Allow Trading in July
  126. input bool allowAugust = true; // Allow Trading in August
  127. input bool allowSeptember = true; // Allow Trading in September
  128. input bool allowOctober = true; // Allow Trading in October
  129. input bool allowNovember = true; // Allow Trading in November
  130. input bool allowDecember = true; // Allow Trading in December
  131. input string string_0_2 = "<><><><><><> Trailing Setting<><><><><><>"; //__
  132. input bool indivial_trailing = false; // Indiviual Trailing
  133. input double ts_sl = 150; // Trailing Start in Points
  134. input double ts = 50; // Trailing Stop in Points
  135. input string strMA14 ="<><><><><><> BreakEven Settings <><><><><><>";//_
  136. input bool UseBreakEven = false; // Use Break Even
  137. input int breakEvenPoints = 150; // BreakEven Trigger Points
  138. input int breakStopPoint = 50; // BreakEven Above OpenPrice Points
  139. input string news = "<><><><><><> News Settings <><><><><><>"; // News
  140. input NewsCloseOrder newsClose = CloseAllRunningOrder; // On News Action on Running Orders
  141. input optionsEaTyp selectEaType = master; // Select EA Side
  142. input bool High_Impact_News = true; //High Impact News
  143. input int High_Start_Time = 60; //Stop Trade before high News (min)
  144. input int High_Stop_Time = 15; //Stop Trade after high News (min)
  145. input bool show_high_line = true; //Show verticle Line when high news comes
  146. input selectLine Select_News_Line = 0; //News Line
  147. input bool mobileAlert = true; //Mobile Alert
  148. input bool Medium_Impact_News = true; // Medium Impact News
  149. input int Medium_Start_Time = 60; // Stop Trade before medium News (min)
  150. input int Medium_Stop_Time = 15; // Stop Trade after medium News (min)
  151. input bool show_medium_line = true; // Show vertical Line when medium news comes
  152. input bool Low_Impact_News = true; // Low Impact News
  153. input int Low_Start_Time = 60; // Stop Trade before low News (min)
  154. input int Low_Stop_Time = 15; // Stop Trade after low News (min)
  155. input bool show_low_line = true; // Show vertical Line when low news comes
  156. // Global Variables
  157. static double tickCurrentBid = 0;
  158. double tickPreviousBid = 0;
  159. static double tickCurrentAsk = 0;
  160. double tickPreviousAsk = 0;
  161. int newYorkStartTime = 0, newYorkStartMin = 0, newYorkEndHour = 0, newYorkEndMin = 0;
  162. datetime newYorkStartTrading = 0, newYorkEndTrading = 0;
  163. int GMT_Broker_Time = +2; // GMT_Broker_Time Time of your Broker
  164. int gmt = 0; // GMT_Broker_Time Time of your Broker
  165. string Lname="newsLabel3";
  166. double levelsAre[];
  167. selectDay newYorkSessionDay = curr; // Select Day for Start Time
  168. //+------------------------------------------------------------------+
  169. //| |
  170. //+------------------------------------------------------------------+
  171. int OnInit()
  172. {
  173. //---
  174. Print(" OnInIt. ");
  175. trade.SetExpertMagicNumber(magic_no);
  176. trade.SetDeviationInPoints(maxSlippage);
  177. trade.SetTypeFilling(ORDER_FILLING_IOC);
  178. trade.LogLevel(LOG_LEVEL_ALL);
  179. trade.SetAsyncMode(false);
  180. if(!MQLInfoInteger(MQL_TESTER))
  181. {
  182. loadNewTradeStoreFile();
  183. }
  184. int filehandle = FileOpen(dataFileName, FILE_READ | FILE_CSV | FILE_COMMON | FILE_ANSI);
  185. if(filehandle != INVALID_HANDLE)
  186. {
  187. Print(" Valid Handler. ");
  188. while(!FileIsEnding(filehandle))
  189. {
  190. string orderToRead = FileReadString(filehandle);
  191. string orderData[];
  192. //Print("Data: ", OrderToRead);
  193. StringSplit(orderToRead, StringGetCharacter(",",0), orderData);
  194. Print("Array Size: ", ArraySize(orderData));
  195. Print(" Order is: ", orderToRead);
  196. for(int i = 0 ; i < ArraySize(orderData) ; i++)
  197. {
  198. Print(" Order Data: ", orderData[i], " i: ", i);
  199. }
  200. if(ArraySize(orderData) >= 8)
  201. {
  202. if(orderData[0] == Symbol())
  203. {
  204. // store into local variables first (trim if needed)
  205. ulong buy_ticket_local = (ulong)-1; // keep -1 as per your convention
  206. ulong sell_ticket_local = (ulong)-1;
  207. string symbol_local = orderData[0];
  208. double price_local = StringToDouble(orderData[1]);
  209. double sl_buy_local = StringToDouble(orderData[2]);
  210. double tp_buy_local = StringToDouble(orderData[3]);
  211. double sl_sell_local = StringToDouble(orderData[4]);
  212. double tp_sell_local = StringToDouble(orderData[5]);
  213. // if your CSV has extra fields (tp2,tp3, etc.) parse here as needed
  214. datetime start_local = StringToTime(orderData[6]);
  215. datetime end_local = StringToTime(orderData[7]);
  216. if(orderData[6] == "0" || orderData[6] == NULL)
  217. {
  218. start_local = 0;
  219. }
  220. if(orderData[7] == "0" || orderData[7] == NULL)
  221. {
  222. end_local = 0;
  223. }
  224. ArrayResize(levelsAre,ArraySize(levelsAre)+1);
  225. levelsAre[ArraySize(levelsAre) - 1] = price_local;
  226. // OPTIONAL: only add when price == 0:
  227. // if(MathAbs(price_local) > 1e-9) { Print("Skipped: price != 0"); continue; }
  228. bool buy_virtual_tp_hit = true;
  229. bool sell_virtual_tp_hit = true;
  230. if(bothHitsSl)
  231. {
  232. buy_virtual_tp_hit = false;
  233. sell_virtual_tp_hit = false;
  234. }
  235. // call the single-responsibility function that writes into struct array
  236. if(!level_present(price_local))
  237. {
  238. Print(" --------------- Price: ", price_local, " Start Time: ", start_local, " End Time: ", end_local, " --------------------");
  239. addToNewTradeStore(buy_ticket_local, sell_ticket_local,
  240. symbol_local, price_local,
  241. sl_buy_local, tp_buy_local,
  242. sl_sell_local, tp_sell_local,
  243. start_local, end_local,
  244. buy_virtual_tp_hit, sell_virtual_tp_hit);
  245. }
  246. else
  247. {
  248. Print("Level is already Present. Level: ", price_local);
  249. }
  250. }
  251. }
  252. }
  253. FileClose(filehandle);
  254. }
  255. else
  256. {
  257. Print(" InValid Handler. Error: ", GetLastError());
  258. }
  259. struct_level_check();
  260. print_newTradeStore();
  261. string time[];
  262. StringSplit(startTime,':',time);
  263. newYorkStartTime = (int)StringToInteger(time[0]);
  264. newYorkStartMin = (int)StringToInteger(time[1]);
  265. Print("NewYork Start Time Hour: ",newYorkStartTime," Start Time Min: ",newYorkStartMin);
  266. time[0] = "";
  267. time[1] = "";
  268. StringSplit(endTime,':',time);
  269. newYorkEndHour = (int)StringToInteger(time[0]);
  270. newYorkEndMin = (int)StringToInteger(time[1]);
  271. Print("NewYork End Time Hour: ",newYorkEndHour," End Time Min: ",newYorkEndMin);
  272. StringSplit(startTime,':',time);
  273. int newYorkStartHour = (int)StringToInteger(time[0]);
  274. newYorkStartMin = (int)StringToInteger(time[1]);
  275. EventSetMillisecondTimer(500);
  276. time[0] = "";
  277. time[1] = "";
  278. StringSplit(endTime,':',time);
  279. newYorkEndHour = (int)StringToInteger(time[0]);
  280. newYorkEndMin = (int)StringToInteger(time[1]);
  281. datetime startDateTime;
  282. MqlDateTime st;
  283. TimeCurrent(st); // get current date
  284. st.hour = newYorkStartHour;
  285. st.min = newYorkStartMin;
  286. st.sec = 0;
  287. startDateTime = StructToTime(st);
  288. datetime endDateTime;
  289. MqlDateTime et;
  290. TimeCurrent(et); // get current date
  291. et.hour = newYorkEndHour;
  292. et.min = newYorkEndMin;
  293. et.sec = 0;
  294. endDateTime = StructToTime(et);
  295. datetime start_Time = 0, end_Time = 0;
  296. if(startDateTime > endDateTime)
  297. {
  298. Print(" --------------------------- Previous -------------------------------------- ");
  299. newYorkSessionDay = prev;
  300. }
  301. else
  302. {
  303. Print(" --------------------------- Current -------------------------------------- ");
  304. newYorkSessionDay = curr;
  305. }
  306. timeFilter(true);
  307. int timeDifference = (int)TimeCurrent() - (int)TimeGMT();
  308. Print("Time Difference is: ", timeDifference);
  309. if(timeDifference > 0)
  310. {
  311. GMT_Broker_Time = (int)MathRound((double)timeDifference / 3600.0);
  312. }
  313. else
  314. if(timeDifference < 0)
  315. {
  316. GMT_Broker_Time = (int)MathRound((double)timeDifference / 3600.0);
  317. }
  318. else // timeDifference == 0
  319. {
  320. GMT_Broker_Time = 0;
  321. }
  322. Print("Gmt Time: ", TimeGMT(), " Broker Gmt Time: ", GMT_Broker_Time);
  323. gmt = GMT_Broker_Time;
  324. if(!MQLInfoInteger(MQL_TESTER))
  325. {
  326. if(selectEaType == master)
  327. {
  328. initiateNews(true); // change here
  329. }
  330. else
  331. {
  332. initiateNews(false);
  333. }
  334. }
  335. if(enableDrawLevels)
  336. {
  337. drawLevels();
  338. }
  339. //---
  340. return(INIT_SUCCEEDED);
  341. }
  342. //+------------------------------------------------------------------+
  343. //| Expert deinitialization function |
  344. //+------------------------------------------------------------------+
  345. void OnDeinit(const int reason)
  346. {
  347. //---
  348. ObjectsDeleteAll(0, 0, OBJ_HLINE);
  349. if(!MQLInfoInteger(MQL_TESTER))
  350. {
  351. saveNewTradeStoreFile();
  352. }
  353. }
  354. //+------------------------------------------------------------------+
  355. //| Expert tick function |
  356. //+------------------------------------------------------------------+
  357. void OnTick()
  358. {
  359. bool masterSide = false;
  360. if(selectEaType == master)
  361. {
  362. masterSide = true;
  363. }
  364. else
  365. {
  366. masterSide = false;
  367. }
  368. static int status=-1,preStatus=-1;
  369. if(!MQLInfoInteger(MQL_TESTER))
  370. {
  371. status=returnNewsStatus(High_Impact_News
  372. ,High_Start_Time
  373. ,High_Stop_Time
  374. ,show_high_line
  375. ,Medium_Impact_News
  376. ,Medium_Start_Time
  377. ,Medium_Stop_Time
  378. ,show_medium_line
  379. ,Low_Impact_News
  380. ,Low_Start_Time
  381. ,Low_Stop_Time
  382. ,show_low_line
  383. ,Symbol()
  384. ,MQLInfoString(MQL_PROGRAM_NAME)
  385. ,GMT_Broker_Time
  386. ,Select_News_Line
  387. ,"", masterSide
  388. );
  389. if(status==0)
  390. {
  391. mainActivity();
  392. }
  393. if(status==1 || status==2 || status==3)
  394. {
  395. if(newsClose==0)
  396. {
  397. if(orderCount_1(POSITION_TYPE_BUY,magic_no)>0)
  398. closeTrades(POSITION_TYPE_BUY,magic_no);
  399. if(orderCount_1(POSITION_TYPE_SELL,magic_no)>0)
  400. closeTrades(POSITION_TYPE_SELL,magic_no);
  401. }
  402. else
  403. if(newsClose==1)
  404. {
  405. mainActivity();
  406. }
  407. }
  408. if(status!=preStatus)
  409. {
  410. if(status == 0 && preStatus !=- 1)
  411. {
  412. // if(ObjectFind(0,Lname))
  413. {
  414. // ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
  415. ObjectSetString(0,Lname,OBJPROP_TEXT,"");
  416. }
  417. Alert("Trading is start");
  418. if(mobileAlert)
  419. SendNotification("Trading is start");
  420. preStatus=status;
  421. }
  422. else
  423. if(status==1)
  424. {
  425. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
  426. ObjectSetString(0,Lname,OBJPROP_TEXT,"High Impact News");
  427. Alert("Trading Stop due to high impact news");
  428. if(mobileAlert)
  429. SendNotification("Trading Stop due to high impact news");
  430. preStatus=status;
  431. }
  432. else
  433. if(status==2)
  434. {
  435. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrBlue);
  436. ObjectSetString(0,Lname,OBJPROP_TEXT,"Medium Impact News");
  437. Alert("Trading Stop due to medium impact news");
  438. if(mobileAlert)
  439. SendNotification("Trading Stop due to medium impact news");
  440. preStatus=status;
  441. }
  442. else
  443. if(status==3)
  444. {
  445. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrGreen);
  446. ObjectSetString(0,Lname,OBJPROP_TEXT,"Low Impact News");
  447. Alert("Trading Stop due to low impact news");
  448. if(mobileAlert)
  449. SendNotification("Trading Stop due to low impact news");
  450. preStatus=status;
  451. }
  452. }
  453. }
  454. else
  455. {
  456. mainActivity();
  457. }
  458. }
  459. //+------------------------------------------------------------------+
  460. //| |
  461. //+------------------------------------------------------------------+
  462. void mainActivity()
  463. {
  464. //---
  465. if(enableDrawLevels)
  466. {
  467. drawLevels();
  468. }
  469. newBar();
  470. if(indivial_trailing)
  471. {
  472. Individual_Trailing();
  473. }
  474. if(UseBreakEven)
  475. {
  476. breakEven();
  477. }
  478. double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
  479. double Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
  480. if(tickPreviousBid == 0 && tickCurrentBid == 0)
  481. {
  482. tickPreviousBid = Bid;
  483. tickCurrentBid = Bid;
  484. }
  485. else
  486. {
  487. tickPreviousBid = tickCurrentBid;
  488. tickCurrentBid = Bid;
  489. }
  490. if(tickPreviousAsk == 0 && tickCurrentAsk == 0)
  491. {
  492. tickPreviousAsk = Ask;
  493. tickCurrentAsk = Ask;
  494. }
  495. else
  496. {
  497. tickPreviousAsk = tickCurrentAsk;
  498. tickCurrentAsk = Ask;
  499. }
  500. timeFilter(false);
  501. // Comment(" Session Start = ", newYorkStartTrading, " Asian Session End = ", newYorkEndTrading);
  502. if((enableTimeFilter && TimeCurrent() >= newYorkStartTrading && TimeCurrent() <= newYorkEndTrading) || !enableTimeFilter)
  503. {
  504. removeFromStructure();
  505. if(bothHitsSl)
  506. {
  507. virtualSLHitCheck();
  508. }
  509. tradePlacingCheck();
  510. }
  511. }
  512. //+------------------------------------------------------------------+
  513. //+------------------------------------------------------------------+
  514. //| |
  515. //+------------------------------------------------------------------+
  516. bool isTradingAllowedByWeek()
  517. {
  518. if(!enableWeekFilter) // filter disabled -> allow trading
  519. return true;
  520. // validate inputs quickly
  521. if(filterMonthNumber < 1 || filterMonthNumber > 12)
  522. {
  523. PrintFormat("⚠️ filterMonthNumber out of range (%d). Week filter disabled.", filterMonthNumber);
  524. return true;
  525. }
  526. if(filterWeekNumber < 1 || filterWeekNumber > 5)
  527. {
  528. PrintFormat("⚠️ filterWeekNumber out of range (%d). Week filter disabled.", filterWeekNumber);
  529. return true;
  530. }
  531. MqlDateTime t;
  532. TimeToStruct(TimeCurrent(), t); // t.mon (1..12), t.day (1..31)
  533. // if the months don't match, week filter doesn't apply -> allow
  534. if(t.mon != filterMonthNumber)
  535. return true;
  536. // compute week of month: days 1-7 -> week 1, 8-14 -> week 2, etc.
  537. int weekOfMonth = ((t.day - 1) / 7) + 1; // yields 1..5
  538. // if current week equals the filtered week -> block trading (return false)
  539. if(weekOfMonth == filterWeekNumber)
  540. {
  541. return false; // trading NOT allowed this week of the specified month
  542. }
  543. return true; // otherwise allow trading
  544. }
  545. //+------------------------------------------------------------------+
  546. //| |
  547. //+------------------------------------------------------------------+
  548. bool isTradingAllowedByMonth()
  549. {
  550. MqlDateTime t;
  551. TimeToStruct(TimeCurrent(), t);
  552. switch(t.mon)
  553. {
  554. case 1:
  555. return allowJanuary;
  556. case 2:
  557. return allowFebruary;
  558. case 3:
  559. return allowMarch;
  560. case 4:
  561. return allowApril;
  562. case 5:
  563. return allowMay;
  564. case 6:
  565. return allowJune;
  566. case 7:
  567. return allowJuly;
  568. case 8:
  569. return allowAugust;
  570. case 9:
  571. return allowSeptember;
  572. case 10:
  573. return allowOctober;
  574. case 11:
  575. return allowNovember;
  576. case 12:
  577. return allowDecember;
  578. default:
  579. return true; // Safe fallback: allow trading if month invalid
  580. }
  581. }
  582. //+------------------------------------------------------------------+
  583. //| |
  584. //+------------------------------------------------------------------+
  585. bool newBar()
  586. {
  587. static datetime lastbar;
  588. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  589. if(lastbar != curbar)
  590. {
  591. lastbar = curbar;
  592. Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
  593. return (true);
  594. }
  595. else
  596. {
  597. return (false);
  598. }
  599. }
  600. //+------------------------------------------------------------------+
  601. //| |
  602. //+------------------------------------------------------------------+
  603. void closeTrades(int type,int magicno)
  604. {
  605. Print("Total order: ",OrdersTotal());
  606. for(int i= PositionsTotal()-1; i>=0; i--)
  607. {
  608. // Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i," OrdersTotal(): ", OrdersTotal());
  609. ulong ticket = PositionGetTicket(i);
  610. if(PositionSelectByTicket(ticket))
  611. {
  612. if(PositionGetInteger(POSITION_TYPE) == type)
  613. {
  614. if(PositionGetInteger(POSITION_MAGIC) == magicno && PositionGetString(POSITION_SYMBOL) == Symbol())
  615. {
  616. //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
  617. if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
  618. {Print("Problem in closing order order ",PositionGetInteger(POSITION_TICKET)); }
  619. else
  620. {
  621. Print("Order Closed by closeTrades() new filter",PositionGetInteger(POSITION_TICKET));
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. //+------------------------------------------------------------------+
  629. //| |
  630. //+------------------------------------------------------------------+
  631. int orderCount_1(int type,int magic)
  632. {
  633. int count1=0;
  634. for(int i= PositionsTotal()-1; i>=0; i--)
  635. {
  636. // Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i," OrdersTotal(): ", OrdersTotal());
  637. ulong ticket = PositionGetTicket(i);
  638. if(PositionSelectByTicket(ticket))
  639. {
  640. // if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  641. if(PositionGetInteger(POSITION_MAGIC) == magic && PositionGetString(POSITION_SYMBOL) == Symbol())
  642. {
  643. //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
  644. if(PositionGetInteger(POSITION_TYPE) == type)
  645. {
  646. count1++;
  647. }
  648. }
  649. }
  650. }
  651. return count1;
  652. }
  653. //+------------------------------------------------------------------+
  654. //| |
  655. //+------------------------------------------------------------------+
  656. int orderCount(int type)
  657. {
  658. int count = 0;
  659. for(int i= PositionsTotal()-1; i>=0; i--)
  660. {
  661. ulong ticket = PositionGetTicket(i);
  662. if(PositionSelectByTicket(ticket))
  663. {
  664. if(PositionGetInteger(POSITION_MAGIC) == magic_no && PositionGetString(POSITION_SYMBOL) == Symbol())
  665. {
  666. if(PositionGetInteger(POSITION_TYPE) == type)
  667. {
  668. count++;
  669. }
  670. }
  671. }
  672. }
  673. return count;
  674. }
  675. //+------------------------------------------------------------------+
  676. //| |
  677. //+------------------------------------------------------------------+
  678. bool level_present(double priceIs)
  679. {
  680. for(int i = 0 ; i < MaxOrders ; i++)
  681. {
  682. if(newTradeStore[i].price > 0)
  683. {
  684. if(priceIs == newTradeStore[i].price)
  685. {
  686. return true;
  687. }
  688. }
  689. }
  690. return false;
  691. }
  692. //+------------------------------------------------------------------+
  693. //| |
  694. //+------------------------------------------------------------------+
  695. void struct_level_check()
  696. {
  697. for(int i = 0; i < MaxOrders; i++)
  698. {
  699. if(newTradeStore[i].price > 0)
  700. {
  701. bool found = false;
  702. for(int j = 0; j < ArraySize(levelsAre); j++)
  703. {
  704. if(newTradeStore[i].price == levelsAre[j])
  705. {
  706. found = true;
  707. break;
  708. }
  709. }
  710. if(!found)
  711. {
  712. Print("Price not found in levelsAre[] -> index:", i, " | price:", newTradeStore[i].price);
  713. newTradeStore[i].buy_ticket = (ulong)-1;
  714. newTradeStore[i].sell_ticket = (ulong)-1;
  715. bool buy_virtual_tp_hit = true;
  716. bool sell_virtual_tp_hit = true;
  717. if(bothHitsSl)
  718. {
  719. buy_virtual_tp_hit = false;
  720. sell_virtual_tp_hit = false;
  721. }
  722. newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
  723. newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
  724. newTradeStore[i].symbol = "";
  725. newTradeStore[i].price = 0.0;
  726. newTradeStore[i].stop_loss_buy = 0.0;
  727. newTradeStore[i].take_profit_buy = 0.0;
  728. newTradeStore[i].stop_loss_sell = 0.0;
  729. newTradeStore[i].take_profit_sell = 0.0;
  730. newTradeStore[i].start_time = 0;
  731. newTradeStore[i].end_time = 0;
  732. return;
  733. }
  734. }
  735. }
  736. return;
  737. }
  738. //+------------------------------------------------------------------+
  739. //| |
  740. //+------------------------------------------------------------------+
  741. void print_newTradeStore()
  742. {
  743. bool anyPrinted = false;
  744. Print("=== newTradeStore DUMP ===");
  745. for(int i = 0; i < MaxOrders; i++)
  746. {
  747. // only print populated slots (price > 0)
  748. if(newTradeStore[i].price > 0.0)
  749. {
  750. anyPrinted = true;
  751. // convert booleans to readable text
  752. string buyHit = newTradeStore[i].buy_hit_virtual_sl ? "true" : "false";
  753. string sellHit = newTradeStore[i].sell_hit_virtual_sl ? "true" : "false";
  754. // header line for the entry
  755. Print("---- Entry ", i, " ----");
  756. // summary line (symbol, price, times)
  757. Print(" symbol:", newTradeStore[i].symbol,
  758. " | price:", DoubleToString(newTradeStore[i].price, Digits()),
  759. " | start:", IntegerToString(newTradeStore[i].start_time),
  760. " | end:", IntegerToString(newTradeStore[i].end_time));
  761. // ticket line
  762. Print(" tickets -> buy:", newTradeStore[i].buy_ticket,
  763. " | sell:", newTradeStore[i].sell_ticket);
  764. // flags line
  765. Print(" flags -> buy_hit_virtual_sl:", buyHit,
  766. " | sell_hit_virtual_sl:", sellHit,
  767. " | bothHitsSl:", (bothHitsSl ? "true" : "false"));
  768. // SL/TP line
  769. Print(" SL/TP -> buySL:", DoubleToString(newTradeStore[i].stop_loss_buy, Digits()),
  770. " | buyTP:", DoubleToString(newTradeStore[i].take_profit_buy, Digits()),
  771. " | sellSL:", DoubleToString(newTradeStore[i].stop_loss_sell, Digits()),
  772. " | sellTP:", DoubleToString(newTradeStore[i].take_profit_sell, Digits()));
  773. }
  774. }
  775. if(!anyPrinted)
  776. Print(" (no active newTradeStore entries found)");
  777. Print("=== end dump ===");
  778. }
  779. //+------------------------------------------------------------------+
  780. //| |
  781. //+------------------------------------------------------------------+
  782. void addToNewTradeStore(ulong r_buy_ticket, ulong r_sell_ticket,
  783. string r_symbol, double r_price,
  784. double r_stop_loss_buy, double r_take_profit_buy,
  785. double r_stop_loss_sell, double r_take_profit_sell,
  786. datetime r_start_time, datetime r_end_time, bool r_buy_hit_sl, bool r_sell_hit_sl)
  787. {
  788. Print(" Tier 1. ");
  789. for(int i = 0; i < MaxOrders; i++)
  790. {
  791. // treat slot as empty when both tickets are -1 (same convention as constructor)
  792. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  793. {
  794. if(newTradeStore[i].price == 0)
  795. {
  796. newTradeStore[i].buy_ticket = r_buy_ticket;
  797. newTradeStore[i].sell_ticket = r_sell_ticket;
  798. newTradeStore[i].symbol = r_symbol;
  799. newTradeStore[i].price = r_price;
  800. newTradeStore[i].stop_loss_buy = r_stop_loss_buy;
  801. newTradeStore[i].take_profit_buy = r_take_profit_buy;
  802. newTradeStore[i].stop_loss_sell = r_stop_loss_sell;
  803. newTradeStore[i].take_profit_sell = r_take_profit_sell;
  804. newTradeStore[i].start_time = r_start_time;
  805. newTradeStore[i].end_time = r_end_time;
  806. newTradeStore[i].buy_hit_virtual_sl = r_buy_hit_sl;
  807. newTradeStore[i].sell_hit_virtual_sl = r_sell_hit_sl;
  808. Print("Stored -> idx: ", i,
  809. " | Symbol: ", newTradeStore[i].symbol,
  810. " | price: ", DoubleToString(newTradeStore[i].price, Digits()),
  811. " | Sl Buy: ", DoubleToString(newTradeStore[i].stop_loss_buy, Digits()),
  812. " | Tp Buy: ", DoubleToString(newTradeStore[i].take_profit_buy, Digits()),
  813. "\n | Sl Sell: ", DoubleToString(newTradeStore[i].stop_loss_sell, Digits()),
  814. " | Tp Sell: ", DoubleToString(newTradeStore[i].take_profit_sell, Digits()),
  815. " | start: ", TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS),
  816. " | end: ", TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS),
  817. " | Buy Virtal Sl Hit: ", newTradeStore[i].buy_hit_virtual_sl,
  818. " | Sell Virtual Sl Hit: ", newTradeStore[i].sell_hit_virtual_sl);
  819. break;
  820. }
  821. }
  822. }
  823. }
  824. //+------------------------------------------------------------------+
  825. //| |
  826. //+------------------------------------------------------------------+
  827. void tradePlacingCheck()
  828. {
  829. for(int i = 0; i < MaxOrders; i++)
  830. {
  831. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  832. {
  833. if(newTradeStore[i].price > 0)
  834. {
  835. if((TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time) || (newTradeStore[i].start_time == 0 || newTradeStore[i].end_time == 0))
  836. {
  837. if(newTradeStore[i].buy_hit_virtual_sl == true && newTradeStore[i].sell_hit_virtual_sl == true)
  838. {
  839. double levelPriceIs = newTradeStore[i].price;
  840. if((tickPreviousBid > levelPriceIs && tickCurrentBid < levelPriceIs) ||
  841. (tickPreviousBid < levelPriceIs && tickCurrentBid > levelPriceIs))
  842. {
  843. Print(" ------------------- Level Crossed. Level is: ", levelPriceIs, " -------------------- ");
  844. if(isTradingAllowedByWeek())
  845. {
  846. if(isTradingAllowedByMonth())
  847. {
  848. if((enableSpreadFilter && spreadFilter()) || !enableSpreadFilter)
  849. {
  850. ulong buyTicket = -1, sellTicket = -1;
  851. if(countLiveTrades() < maxTrades)
  852. {
  853. buyTicket = placeBuyTrade(newTradeStore[i].stop_loss_buy, newTradeStore[i].take_profit_buy);
  854. sellTicket = placeSellTrade(newTradeStore[i].stop_loss_sell, newTradeStore[i].take_profit_sell);
  855. newTradeStore[i].buy_ticket = buyTicket;
  856. newTradeStore[i].sell_ticket = sellTicket;
  857. }
  858. }
  859. }
  860. }
  861. }
  862. }
  863. }
  864. }
  865. }
  866. }
  867. }
  868. //+------------------------------------------------------------------+
  869. //| |
  870. //+------------------------------------------------------------------+
  871. void draw_lines(string name, datetime dateTime, double price, color selectColor, long lineStyle)
  872. {
  873. if(!ObjectCreate(0, name, OBJ_HLINE, 0, dateTime, price))
  874. {
  875. Print(" Error in creating ", name," : ","line: "," ",GetLastError());
  876. }
  877. else
  878. {
  879. ObjectSetInteger(0, name, OBJPROP_COLOR, selectColor);
  880. ObjectSetInteger(0, name, OBJPROP_STYLE, lineStyle);
  881. }
  882. }
  883. //+------------------------------------------------------------------+
  884. //| |
  885. //+------------------------------------------------------------------+
  886. void drawLevels()
  887. {
  888. for(int i = 0; i < MaxOrders; i++)
  889. {
  890. if(newTradeStore[i].price > 0)
  891. {
  892. if((TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time) || (newTradeStore[i].start_time == 0 || newTradeStore[i].end_time == 0))
  893. {
  894. if(ObjectFind(0, "level" + (string)newTradeStore[i].price) < 0)
  895. {
  896. draw_lines("level" + (string)newTradeStore[i].price, TimeCurrent(), newTradeStore[i].price, clrAqua, STYLE_SOLID);
  897. }
  898. }
  899. else
  900. {
  901. if(ObjectFind(0, "level" + (string)newTradeStore[i].price) >= 0)
  902. {
  903. ObjectDelete(0, "level" + (string)newTradeStore[i].price);
  904. }
  905. }
  906. }
  907. }
  908. }
  909. //+------------------------------------------------------------------+
  910. //| |
  911. //+------------------------------------------------------------------+
  912. ulong placeBuyTrade(double stoploss, double takeprofit)
  913. {
  914. double buySL = 0, buyTp=0;
  915. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  916. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  917. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  918. if(useTpSlPips)
  919. {
  920. if(stopLoss != 0)
  921. {
  922. buySL = Ask - (stopLoss * Point());
  923. }
  924. if(takeProfit != 0)
  925. {
  926. buyTp = Ask + (takeProfit * Point());
  927. }
  928. }
  929. else
  930. {
  931. if(stoploss > 0)
  932. {
  933. buySL = stoploss;
  934. }
  935. if(takeprofit > 0)
  936. {
  937. buyTp = takeprofit;
  938. }
  939. }
  940. double distance = MathAbs((Ask - buySL) / Point());
  941. if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getLot(distance),Ask,buySL,buyTp,tradeComment+" Buy"))
  942. {
  943. Print("Buy Trade Placed: ",trade.ResultOrder());
  944. return trade.ResultOrder();
  945. }
  946. else
  947. {
  948. Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
  949. return -1;
  950. }
  951. return -1;
  952. }
  953. //+------------------------------------------------------------------+
  954. //| |
  955. //+------------------------------------------------------------------+
  956. ulong placeSellTrade(double stoploss, double takeprofit)
  957. {
  958. double sellSL = 0, sellTp = 0;
  959. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  960. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  961. if(useTpSlPips)
  962. {
  963. if(stopLoss != 0)
  964. {
  965. sellSL = Bid + (stopLoss * Point());
  966. }
  967. if(takeProfit != 0)
  968. {
  969. sellTp = Bid - (takeProfit * Point());
  970. }
  971. }
  972. else
  973. {
  974. if(stoploss > 0)
  975. {
  976. sellSL = stoploss;
  977. }
  978. if(takeprofit > 0)
  979. {
  980. sellTp = takeprofit;
  981. }
  982. }
  983. double distance = MathAbs((Bid - sellSL) / Point());
  984. if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getLot(distance),Bid,sellSL,sellTp,tradeComment+ " Sell"))
  985. {
  986. Print("Sell Trade PLaced: ",trade.ResultOrder());
  987. return trade.ResultOrder();
  988. }
  989. else
  990. {
  991. Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
  992. return -1;
  993. }
  994. return -1;
  995. }
  996. //+------------------------------------------------------------------+
  997. //| |
  998. //+------------------------------------------------------------------+
  999. double getLot(double stop_loss)
  1000. {
  1001. Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
  1002. Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
  1003. double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
  1004. ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
  1005. // Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
  1006. double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
  1007. // pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
  1008. // pipvalue=
  1009. pipvalue = pipvalue / 10;
  1010. double lotSize = lot_amount;
  1011. if(lot_calculator == rsk || lot_calculator == dollar) //calculating risk
  1012. {
  1013. double riskamount = 0;
  1014. if(lot_calculator == rsk)
  1015. {
  1016. riskamount = (risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
  1017. }
  1018. if(lot_calculator == dollar)
  1019. {
  1020. riskamount = dollars;
  1021. }
  1022. double pipvalue_required=riskamount/stop_loss;
  1023. lotSize = pipvalue_required/pipvalue;
  1024. //sl=riskamount/pipValuelot
  1025. int roundDigit=0;
  1026. double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
  1027. while(step<1)
  1028. {
  1029. roundDigit++;
  1030. step=step*10;
  1031. }
  1032. Print("Round Digits:",roundDigit);
  1033. lotSize = NormalizeDouble(lotSize,roundDigit);
  1034. //
  1035. }
  1036. Print("Lot Size: ",lotSize);
  1037. if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
  1038. {
  1039. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  1040. }
  1041. else
  1042. if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
  1043. {
  1044. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  1045. }
  1046. //---
  1047. return lotSize;
  1048. }
  1049. //+------------------------------------------------------------------+
  1050. //| |
  1051. //+------------------------------------------------------------------+
  1052. void timeFilter(bool onInit)
  1053. {
  1054. MqlDateTime sdate,edate;
  1055. datetime start_Time = 0, end_Time = 0;
  1056. if(newYorkSessionDay == prev)
  1057. {
  1058. if(onInit)
  1059. {
  1060. start_Time = iTime(Symbol(),PERIOD_D1,1);
  1061. end_Time = iTime(Symbol(),PERIOD_D1,0);
  1062. }
  1063. else
  1064. {
  1065. start_Time = newYorkStartTrading;
  1066. end_Time = newYorkEndTrading;
  1067. if(TimeCurrent() >= newYorkEndTrading && newYorkEndTrading != 0)
  1068. {
  1069. start_Time = iTime(Symbol(),PERIOD_D1,0);
  1070. end_Time = start_Time + 86400;
  1071. }
  1072. }
  1073. }
  1074. else
  1075. {
  1076. start_Time = iTime(Symbol(),PERIOD_D1,0);
  1077. end_Time = iTime(Symbol(),PERIOD_D1,0);
  1078. }
  1079. if(TimeToStruct(end_Time,edate))
  1080. {
  1081. edate.hour = newYorkEndHour;
  1082. edate.min = newYorkEndMin;
  1083. edate.sec = 0;
  1084. }
  1085. else
  1086. Print("Error in Converting Time: ",GetLastError());
  1087. newYorkEndTrading = StructToTime(edate);
  1088. if(TimeToStruct(start_Time,sdate))
  1089. {
  1090. sdate.hour = newYorkStartTime;
  1091. sdate.min = newYorkStartMin;
  1092. sdate.sec = 0;
  1093. }
  1094. else
  1095. Print("Error in Converting Time: ",GetLastError());
  1096. newYorkStartTrading = StructToTime(sdate);
  1097. // if(onInit)
  1098. //Print("NewYork Start Time ",newYorkStartTrading,"End Date: ",newYorkEndTrading);
  1099. //Print("Edate: ",edate.hour," ",edate.min," Sdate: ",sdate.hour," ",sdate.min);
  1100. }
  1101. //+------------------------------------------------------------------+
  1102. //| |
  1103. //+------------------------------------------------------------------+
  1104. void removeFromStructure()
  1105. {
  1106. for(int i = 0 ; i < MaxOrders ; i++)
  1107. {
  1108. bool isBuyPresent=false, isSellPresent=false;
  1109. if(newTradeStore[i].buy_ticket != -1 && newTradeStore[i].sell_ticket != -1)
  1110. {
  1111. for(int j = PositionsTotal()-1; j>=0; j--)
  1112. {
  1113. ulong ticket = PositionGetTicket(j);
  1114. if(PositionSelectByTicket(ticket))
  1115. {
  1116. if(ticket == newTradeStore[i].buy_ticket)
  1117. {
  1118. isBuyPresent=true;
  1119. }
  1120. }
  1121. }
  1122. for(int j = PositionsTotal()-1; j>=0; j--)
  1123. {
  1124. ulong ticket = PositionGetTicket(j);
  1125. if(PositionSelectByTicket(ticket))
  1126. {
  1127. if(ticket == newTradeStore[i].sell_ticket)
  1128. {
  1129. isSellPresent = true;
  1130. }
  1131. }
  1132. }
  1133. if(!isBuyPresent && !isSellPresent)
  1134. {
  1135. Print("Buy/Sell Ticket is closed so removed from struct. Buy Ticket: ", newTradeStore[i].buy_ticket, " Sell Ticket: ", newTradeStore[i].sell_ticket);
  1136. newTradeStore[i].buy_ticket = (ulong)-1;
  1137. newTradeStore[i].sell_ticket = (ulong)-1;
  1138. bool buy_virtual_tp_hit = true;
  1139. bool sell_virtual_tp_hit = true;
  1140. if(bothHitsSl)
  1141. {
  1142. buy_virtual_tp_hit = false;
  1143. sell_virtual_tp_hit = false;
  1144. }
  1145. newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
  1146. newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
  1147. //newTradeStore[i].symbol = "";
  1148. //newTradeStore[i].price = 0.0;
  1149. //newTradeStore[i].stop_loss = 0.0;
  1150. //newTradeStore[i].take_profit = 0.0;
  1151. //newTradeStore[i].start_time = 0;
  1152. //newTradeStore[i].end_time = 0;
  1153. }
  1154. }
  1155. }
  1156. }
  1157. //+------------------------------------------------------------------+
  1158. //| |
  1159. //+------------------------------------------------------------------+
  1160. void virtualSLHitCheck()
  1161. {
  1162. for(int i = 0 ; i < MaxOrders ; i++)
  1163. {
  1164. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  1165. {
  1166. if(TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time)
  1167. {
  1168. double buy_sl = 0, sell_sl = 0;
  1169. //if(!useTpSlPips)
  1170. // {
  1171. buy_sl = newTradeStore[i].stop_loss_buy;
  1172. sell_sl = newTradeStore[i].stop_loss_sell;
  1173. // }
  1174. //else
  1175. // {
  1176. // buy_sl = stopLoss != 0 ? newTradeStore[i].price - (stopLoss * Point()) : 0;
  1177. // sell_sl = stopLoss != 0 ? newTradeStore[i].price + (stopLoss * Point()) : 0;
  1178. // }
  1179. if(newTradeStore[i].buy_hit_virtual_sl == false)
  1180. {
  1181. if((tickPreviousBid < buy_sl && tickCurrentBid > buy_sl))
  1182. {
  1183. newTradeStore[i].buy_hit_virtual_sl = true;
  1184. Print(" Buy Virtual Sl Hit. newTradeStore[i].buy_hit_virtual_sl: ", newTradeStore[i].buy_hit_virtual_sl, " Order Price is: ", newTradeStore[i].price, " Stop Loss Price is: ", buy_sl, " Time Virtual Sl Hit is: ", TimeCurrent());
  1185. }
  1186. }
  1187. if(newTradeStore[i].sell_hit_virtual_sl == false)
  1188. {
  1189. if((tickPreviousAsk > sell_sl && tickCurrentAsk < sell_sl))
  1190. {
  1191. newTradeStore[i].sell_hit_virtual_sl = true;
  1192. Print(" Sell Virtual Sl Hit. newTradeStore[i].sell_hit_virtual_sl: ", newTradeStore[i].sell_hit_virtual_sl, " Order Price is: ", newTradeStore[i].price, " Stop Loss Price is: ", sell_sl, " Time Virtual Sl Hit is: ", TimeCurrent());
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. //+------------------------------------------------------------------+
  1200. //| |
  1201. //+------------------------------------------------------------------+
  1202. int countLiveTrades()
  1203. {
  1204. int count = 0;
  1205. for(int i = 0; i < PositionsTotal(); i++)
  1206. {
  1207. ulong ticket = PositionGetTicket(i);
  1208. if(PositionSelectByTicket(ticket))
  1209. {
  1210. if(PositionGetInteger(POSITION_MAGIC) == magic_no)
  1211. {
  1212. if(PositionGetString(POSITION_SYMBOL) == Symbol())
  1213. {
  1214. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  1215. {
  1216. count++;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. return count;
  1223. }
  1224. //+------------------------------------------------------------------+
  1225. //| |
  1226. //+------------------------------------------------------------------+
  1227. bool spreadFilter()
  1228. {
  1229. long spreadIs = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
  1230. if(spreadIs > maximumSpread)
  1231. {
  1232. return false;
  1233. }
  1234. return true;
  1235. }
  1236. //+------------------------------------------------------------------+
  1237. //| |
  1238. //+------------------------------------------------------------------+
  1239. void breakEven()
  1240. {
  1241. for(int i = PositionsTotal()-1; i>=0; i--)
  1242. {
  1243. ulong ticket = PositionGetTicket(i);
  1244. string symbol=PositionGetSymbol(i);
  1245. double mySL = 0,newSL = 0;
  1246. double SymbolTickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
  1247. ////Print("ticket ",ticket," Symbol : ",symbol);
  1248. if(PositionSelectByTicket(ticket))
  1249. {
  1250. if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC) == magic_no)
  1251. {
  1252. if(isCounterpartOpen(ticket))
  1253. {
  1254. // counterpart still open -> skip trailing for this position
  1255. continue;
  1256. }
  1257. //========================================================Buy Condition=========================================================================
  1258. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
  1259. {
  1260. mySL = PositionGetDouble(POSITION_PRICE_OPEN) + (breakEvenPoints * SymbolTickSize);
  1261. if(SymbolInfoDouble(Symbol(),SYMBOL_BID) >= mySL && PositionGetDouble(POSITION_PRICE_OPEN) > PositionGetDouble(POSITION_SL))
  1262. {
  1263. newSL= PositionGetDouble(POSITION_PRICE_OPEN) + (breakStopPoint * SymbolTickSize);
  1264. if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
  1265. {
  1266. Print("Buy Order BreakEven Successfully ");
  1267. }
  1268. else
  1269. {
  1270. Print("Error in BreakEven Buy Position ",GetLastError());
  1271. }
  1272. }
  1273. }
  1274. //=======================================================Sell condition ===============================================================
  1275. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  1276. {
  1277. mySL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakEvenPoints * SymbolTickSize);
  1278. if(SymbolInfoDouble(Symbol(),SYMBOL_ASK) <= mySL && PositionGetDouble(POSITION_SL) > PositionGetDouble(POSITION_PRICE_OPEN))
  1279. {
  1280. newSL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakStopPoint * SymbolTickSize);
  1281. if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
  1282. {
  1283. Print("Order Sell BreakEven Successfully ");
  1284. }
  1285. else
  1286. {
  1287. Print("Error in BreakEven Sell Position ",GetLastError());
  1288. }
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. //+------------------------------------------------------------------+
  1296. //| |
  1297. //+------------------------------------------------------------------+
  1298. bool isCounterpartOpen(ulong ticket)
  1299. {
  1300. // scan stored pairs
  1301. for(int k=0; k<MaxOrders; k++)
  1302. {
  1303. // check if this ticket is the buy side in the pair
  1304. if(newTradeStore[k].buy_ticket == ticket)
  1305. {
  1306. ulong other = newTradeStore[k].sell_ticket;
  1307. if(other <= 0)
  1308. return false; // no counterpart recorded -> treat as closed
  1309. // check if counterpart ticket exists in current positions
  1310. for(int p = PositionsTotal()-1; p >= 0; p--)
  1311. {
  1312. ulong t = PositionGetTicket(p);
  1313. if(t == other)
  1314. return true; // counterpart still open
  1315. }
  1316. return false; // counterpart not found -> closed
  1317. }
  1318. // check if this ticket is the sell side in the pair
  1319. if(newTradeStore[k].sell_ticket == ticket)
  1320. {
  1321. ulong other = newTradeStore[k].buy_ticket;
  1322. if(other <= 0)
  1323. return false; // no counterpart recorded -> treat as closed
  1324. for(int p = PositionsTotal()-1; p >= 0; p--)
  1325. {
  1326. ulong t = PositionGetTicket(p);
  1327. if(t == other)
  1328. return true; // counterpart still open
  1329. }
  1330. return false; // counterpart not found -> closed
  1331. }
  1332. }
  1333. // ticket not found in the stored pairs -> treat as no counterpart open
  1334. return false;
  1335. }
  1336. //+------------------------------------------------------------------+
  1337. //| |
  1338. //+------------------------------------------------------------------+
  1339. void Individual_Trailing()
  1340. {
  1341. int openedpositions;
  1342. double mySL,myResult;
  1343. openedpositions=PositionsTotal();
  1344. if((openedpositions>0))
  1345. {
  1346. int totalorders=PositionsTotal();
  1347. for(int i=0; i<totalorders; i++) // scan all orders and positions. ..
  1348. {
  1349. ulong ticket = PositionGetTicket(i);
  1350. if(PositionSelectByTicket(ticket))
  1351. {
  1352. if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC) == magic_no) // only look if mygrid and symbol. ..
  1353. {
  1354. if(isCounterpartOpen(ticket))
  1355. {
  1356. // counterpart still open -> skip trailing for this position
  1357. continue;
  1358. }
  1359. double SymbolAsk = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_ASK);
  1360. double SymbolBid = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_BID);
  1361. int SymbolDigits = (int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL), SYMBOL_DIGITS);
  1362. double SymbolTickSize = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE);
  1363. int type= (int)PositionGetInteger(POSITION_TYPE);
  1364. if(type==POSITION_TYPE_BUY) // its a long position
  1365. {
  1366. mySL=NormalizeDouble(SymbolAsk-(ts*SymbolTickSize),Digits()); // new SL
  1367. double startSl=PositionGetDouble(POSITION_PRICE_OPEN)+(ts_sl*SymbolTickSize);
  1368. if(PositionGetDouble(POSITION_SL) != mySL)
  1369. if(mySL>PositionGetDouble(POSITION_SL) && SymbolAsk>=startSl)
  1370. {
  1371. myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrGreen);
  1372. if(!myResult)
  1373. {
  1374. Print(" Buy Trade Trailing Error: ",GetLastError());
  1375. }
  1376. }
  1377. }
  1378. if(type==POSITION_TYPE_SELL)
  1379. {
  1380. mySL=NormalizeDouble(SymbolBid+(ts*SymbolTickSize),Digits()); // new SL
  1381. double startSlSell=PositionGetDouble(POSITION_PRICE_OPEN)-(ts_sl*SymbolTickSize);
  1382. if(PositionGetDouble(POSITION_SL) != mySL)
  1383. if(((mySL<PositionGetDouble(POSITION_SL)) || (PositionGetDouble(POSITION_SL)<SymbolTickSize)) && SymbolBid<=startSlSell)
  1384. {
  1385. myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrRed);
  1386. if(!myResult)
  1387. {
  1388. Print(" Sell Trade Trailing Error: ",GetLastError());
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. //+------------------------------------------------------------------+
  1398. //| |
  1399. //+------------------------------------------------------------------+
  1400. void saveNewTradeStoreFile()
  1401. {
  1402. // don't run in strategy tester
  1403. if(MQLInfoInteger(MQL_TESTER))
  1404. return;
  1405. string file_name = "new_trade_store_updated.csv";
  1406. int fileHandle = FileOpen(file_name,
  1407. FILE_WRITE | FILE_CSV | FILE_COMMON |
  1408. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_READ);
  1409. if(fileHandle == INVALID_HANDLE)
  1410. {
  1411. PrintFormat("saveNewTradeStoreFile() -> Cannot open file '%s'. Error: %d", file_name, GetLastError());
  1412. return;
  1413. }
  1414. // header (optional) - comment out if you don't want header
  1415. //string header = "buy_ticket,sell_ticket,symbol,price,stop_loss,take_profit,start_time,end_time,buy_hit_virtual_sl,sell_hit_virtual_sl\r\n";
  1416. //FileWriteString(fileHandle, header);
  1417. for(int i = 0; i < MaxOrders; i++)
  1418. {
  1419. if(newTradeStore[i].buy_ticket != -1 && newTradeStore[i].sell_ticket != -1)
  1420. {
  1421. // decide whether this slot has useful data:
  1422. // you can tweak this condition as you prefer (symbol != "" is simple)
  1423. bool slotPopulated = (StringLen(newTradeStore[i].symbol) > 0)
  1424. || (newTradeStore[i].price != 0.0)
  1425. || (newTradeStore[i].start_time != 0);
  1426. if(!slotPopulated)
  1427. continue;
  1428. // convert values to strings
  1429. string buyTicketStr = IntegerToString((long)newTradeStore[i].buy_ticket);
  1430. string sellTicketStr = IntegerToString((long)newTradeStore[i].sell_ticket);
  1431. string priceStr = DoubleToString(newTradeStore[i].price, Digits());
  1432. string slBuyStr = DoubleToString(newTradeStore[i].stop_loss_buy, Digits());
  1433. string tpBuyStr = DoubleToString(newTradeStore[i].take_profit_buy, Digits());
  1434. string slSellStr = DoubleToString(newTradeStore[i].stop_loss_sell, Digits());
  1435. string tpSellStr = DoubleToString(newTradeStore[i].take_profit_sell, Digits());
  1436. string startTimeStr = (newTradeStore[i].start_time != 0) ? TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS) : "";
  1437. string endTimeStr = (newTradeStore[i].end_time != 0) ? TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS) : "";
  1438. string buyHitStr = ""; // IntegerToString(newTradeStore[i].buy_hit_virtual_sl ? 1 : 0);
  1439. string sellHitStr = ""; // IntegerToString(newTradeStore[i].sell_hit_virtual_sl ? 1 : 0);
  1440. if(newTradeStore[i].buy_hit_virtual_sl == true)
  1441. {
  1442. buyHitStr = "true";
  1443. }
  1444. else
  1445. {
  1446. buyHitStr = "false";
  1447. }
  1448. if(newTradeStore[i].sell_hit_virtual_sl == true)
  1449. {
  1450. sellHitStr = "true";
  1451. }
  1452. else
  1453. {
  1454. sellHitStr = "false";
  1455. }
  1456. // build CSV line and write
  1457. string line = buyTicketStr + "," + sellTicketStr + "," +
  1458. newTradeStore[i].symbol + "," +
  1459. priceStr + "," + slBuyStr + "," + tpBuyStr + "," +
  1460. slSellStr + "," + tpSellStr + "," +
  1461. startTimeStr + "," + endTimeStr + "," +
  1462. buyHitStr + "," + sellHitStr + "\r\n";
  1463. FileWriteString(fileHandle, line);
  1464. }
  1465. }
  1466. FileClose(fileHandle);
  1467. PrintFormat("saveNewTradeStoreFile() -> saved to '%s'.", file_name);
  1468. }
  1469. //+------------------------------------------------------------------+
  1470. //| |
  1471. //+------------------------------------------------------------------+
  1472. void loadNewTradeStoreFile()
  1473. {
  1474. if(MQLInfoInteger(MQL_TESTER))
  1475. return;
  1476. string file_name = "new_trade_store_updated.csv";
  1477. int fileHandle = FileOpen(file_name,
  1478. FILE_READ | FILE_CSV | FILE_COMMON |
  1479. FILE_SHARE_READ | FILE_SHARE_WRITE);
  1480. if(fileHandle == INVALID_HANDLE)
  1481. {
  1482. Print("loadNewTradeStoreFile() -> Cannot open file '", file_name, "'. Error: ", GetLastError());
  1483. return;
  1484. }
  1485. // reset defaults
  1486. for(int j = 0; j < MaxOrders; j++)
  1487. {
  1488. newTradeStore[j].buy_ticket = (ulong)-1;
  1489. newTradeStore[j].sell_ticket = (ulong)-1;
  1490. newTradeStore[j].symbol = "";
  1491. newTradeStore[j].price = 0.0;
  1492. newTradeStore[j].stop_loss_buy = 0.0;
  1493. newTradeStore[j].take_profit_buy = 0.0;
  1494. newTradeStore[j].stop_loss_sell = 0.0;
  1495. newTradeStore[j].take_profit_sell = 0.0;
  1496. newTradeStore[j].start_time = 0;
  1497. newTradeStore[j].end_time = 0;
  1498. newTradeStore[j].buy_hit_virtual_sl = false;
  1499. newTradeStore[j].sell_hit_virtual_sl = false;
  1500. }
  1501. int idx = 0;
  1502. while(!FileIsEnding(fileHandle) && idx < MaxOrders)
  1503. {
  1504. string line = FileReadString(fileHandle);
  1505. if(StringLen(line) == 0)
  1506. continue;
  1507. string tokens[];
  1508. int total = StringSplit(line, ',', tokens);
  1509. if(total >= 12)
  1510. {
  1511. if((ulong)tokens[0] != -1 && (ulong)tokens[1] != -1)
  1512. {
  1513. newTradeStore[idx].buy_ticket = (ulong)tokens[0];
  1514. newTradeStore[idx].sell_ticket = (ulong)tokens[1];
  1515. newTradeStore[idx].symbol = tokens[2];
  1516. newTradeStore[idx].price = StringToDouble(tokens[3]);
  1517. newTradeStore[idx].stop_loss_buy = StringToDouble(tokens[4]);
  1518. newTradeStore[idx].take_profit_buy = StringToDouble(tokens[5]);
  1519. newTradeStore[idx].stop_loss_sell = StringToDouble(tokens[6]);
  1520. newTradeStore[idx].take_profit_sell = StringToDouble(tokens[7]);
  1521. string sStart = tokens[8];
  1522. string sEnd = tokens[9];
  1523. newTradeStore[idx].start_time = (StringLen(sStart) > 0) ? StringToTime(sStart) : 0;
  1524. newTradeStore[idx].end_time = (StringLen(sEnd) > 0) ? StringToTime(sEnd) : 0;
  1525. bool bHit = false;
  1526. bool sHit = false;
  1527. if(tokens[10] == "true")
  1528. {
  1529. bHit = true;
  1530. }
  1531. else
  1532. {
  1533. bHit = false;
  1534. }
  1535. if(tokens[11] == "true")
  1536. {
  1537. sHit = true;
  1538. }
  1539. else
  1540. {
  1541. sHit = false;
  1542. }
  1543. newTradeStore[idx].buy_hit_virtual_sl = bHit;
  1544. newTradeStore[idx].sell_hit_virtual_sl = sHit;
  1545. // --- simple Print instead of PrintFormat ---
  1546. Print(
  1547. "Loaded newTradeStore[", idx, "]:",
  1548. " buy_ticket=", newTradeStore[idx].buy_ticket,
  1549. " sell_ticket=", newTradeStore[idx].sell_ticket,
  1550. " symbol=", newTradeStore[idx].symbol,
  1551. " price=", DoubleToString(newTradeStore[idx].price, Digits()),
  1552. " \n sl buy=", DoubleToString(newTradeStore[idx].stop_loss_buy, Digits()),
  1553. " tp buy=", DoubleToString(newTradeStore[idx].take_profit_buy, Digits()),
  1554. " sl sell=", DoubleToString(newTradeStore[idx].stop_loss_sell, Digits()),
  1555. " tp sell=", DoubleToString(newTradeStore[idx].take_profit_sell, Digits()),
  1556. " start=", (newTradeStore[idx].start_time != 0 ? TimeToString(newTradeStore[idx].start_time, TIME_DATE|TIME_SECONDS) : ""),
  1557. " end=", (newTradeStore[idx].end_time != 0 ? TimeToString(newTradeStore[idx].end_time, TIME_DATE|TIME_SECONDS) : ""),
  1558. " buyHit=", newTradeStore[idx].buy_hit_virtual_sl,
  1559. " sellHit=", newTradeStore[idx].sell_hit_virtual_sl
  1560. );
  1561. idx++;
  1562. }
  1563. }
  1564. else
  1565. {
  1566. Print("loadNewTradeStoreFile(): skipping malformed line (tokens=", total, "): ", line);
  1567. }
  1568. }
  1569. FileClose(fileHandle);
  1570. Print("loadNewTradeStoreFile() -> loaded ", idx, " entries from '", file_name, "'.");
  1571. }
  1572. //+------------------------------------------------------------------+
  1573. //| |
  1574. //+------------------------------------------------------------------+
  1575. //+------------------------------------------------------------------+