No Description

vol_hedge_strategy_mt5.mq5 136KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697
  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. //---
  336. return(INIT_SUCCEEDED);
  337. }
  338. //+------------------------------------------------------------------+
  339. //| Expert deinitialization function |
  340. //+------------------------------------------------------------------+
  341. void OnDeinit(const int reason)
  342. {
  343. //---
  344. ObjectsDeleteAll(0, 0, OBJ_HLINE);
  345. if(!MQLInfoInteger(MQL_TESTER))
  346. {
  347. saveNewTradeStoreFile();
  348. }
  349. }
  350. //+------------------------------------------------------------------+
  351. //| Expert tick function |
  352. //+------------------------------------------------------------------+
  353. void OnTick()
  354. {
  355. bool masterSide = false;
  356. if(selectEaType == master)
  357. {
  358. masterSide = true;
  359. }
  360. else
  361. {
  362. masterSide = false;
  363. }
  364. static int status=-1,preStatus=-1;
  365. if(!MQLInfoInteger(MQL_TESTER))
  366. {
  367. status=returnNewsStatus(High_Impact_News
  368. ,High_Start_Time
  369. ,High_Stop_Time
  370. ,show_high_line
  371. ,Medium_Impact_News
  372. ,Medium_Start_Time
  373. ,Medium_Stop_Time
  374. ,show_medium_line
  375. ,Low_Impact_News
  376. ,Low_Start_Time
  377. ,Low_Stop_Time
  378. ,show_low_line
  379. ,Symbol()
  380. ,MQLInfoString(MQL_PROGRAM_NAME)
  381. ,GMT_Broker_Time
  382. ,Select_News_Line
  383. ,"", masterSide
  384. );
  385. if(status==0)
  386. {
  387. mainActivity();
  388. }
  389. if(status==1 || status==2 || status==3)
  390. {
  391. if(newsClose==0)
  392. {
  393. if(orderCount_1(POSITION_TYPE_BUY,magic_no)>0)
  394. closeTrades(POSITION_TYPE_BUY,magic_no);
  395. if(orderCount_1(POSITION_TYPE_SELL,magic_no)>0)
  396. closeTrades(POSITION_TYPE_SELL,magic_no);
  397. }
  398. else
  399. if(newsClose==1)
  400. {
  401. mainActivity();
  402. }
  403. }
  404. if(status!=preStatus)
  405. {
  406. if(status == 0 && preStatus !=- 1)
  407. {
  408. // if(ObjectFind(0,Lname))
  409. {
  410. // ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
  411. ObjectSetString(0,Lname,OBJPROP_TEXT,"");
  412. }
  413. Alert("Trading is start");
  414. if(mobileAlert)
  415. SendNotification("Trading is start");
  416. preStatus=status;
  417. }
  418. else
  419. if(status==1)
  420. {
  421. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
  422. ObjectSetString(0,Lname,OBJPROP_TEXT,"High Impact News");
  423. Alert("Trading Stop due to high impact news");
  424. if(mobileAlert)
  425. SendNotification("Trading Stop due to high impact news");
  426. preStatus=status;
  427. }
  428. else
  429. if(status==2)
  430. {
  431. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrBlue);
  432. ObjectSetString(0,Lname,OBJPROP_TEXT,"Medium Impact News");
  433. Alert("Trading Stop due to medium impact news");
  434. if(mobileAlert)
  435. SendNotification("Trading Stop due to medium impact news");
  436. preStatus=status;
  437. }
  438. else
  439. if(status==3)
  440. {
  441. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrGreen);
  442. ObjectSetString(0,Lname,OBJPROP_TEXT,"Low Impact News");
  443. Alert("Trading Stop due to low impact news");
  444. if(mobileAlert)
  445. SendNotification("Trading Stop due to low impact news");
  446. preStatus=status;
  447. }
  448. }
  449. }
  450. else
  451. {
  452. mainActivity();
  453. }
  454. }
  455. //+------------------------------------------------------------------+
  456. //| |
  457. //+------------------------------------------------------------------+
  458. void mainActivity()
  459. {
  460. //---
  461. if(enableDrawLevels)
  462. {
  463. drawLevels();
  464. }
  465. newBar();
  466. if(indivial_trailing)
  467. {
  468. Individual_Trailing();
  469. }
  470. if(UseBreakEven)
  471. {
  472. breakEven();
  473. }
  474. double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
  475. double Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
  476. if(tickPreviousBid == 0 && tickCurrentBid == 0)
  477. {
  478. tickPreviousBid = Bid;
  479. tickCurrentBid = Bid;
  480. }
  481. else
  482. {
  483. tickPreviousBid = tickCurrentBid;
  484. tickCurrentBid = Bid;
  485. }
  486. if(tickPreviousAsk == 0 && tickCurrentAsk == 0)
  487. {
  488. tickPreviousAsk = Ask;
  489. tickCurrentAsk = Ask;
  490. }
  491. else
  492. {
  493. tickPreviousAsk = tickCurrentAsk;
  494. tickCurrentAsk = Ask;
  495. }
  496. timeFilter(false);
  497. // Comment(" Session Start = ", newYorkStartTrading, " Asian Session End = ", newYorkEndTrading);
  498. if((enableTimeFilter && TimeCurrent() >= newYorkStartTrading && TimeCurrent() <= newYorkEndTrading) || !enableTimeFilter)
  499. {
  500. removeFromStructure();
  501. if(bothHitsSl)
  502. {
  503. virtualSLHitCheck();
  504. }
  505. tradePlacingCheck();
  506. }
  507. }
  508. //+------------------------------------------------------------------+
  509. //+------------------------------------------------------------------+
  510. //| |
  511. //+------------------------------------------------------------------+
  512. bool isTradingAllowedByWeek()
  513. {
  514. if(!enableWeekFilter) // filter disabled -> allow trading
  515. return true;
  516. // validate inputs quickly
  517. if(filterMonthNumber < 1 || filterMonthNumber > 12)
  518. {
  519. PrintFormat("⚠️ filterMonthNumber out of range (%d). Week filter disabled.", filterMonthNumber);
  520. return true;
  521. }
  522. if(filterWeekNumber < 1 || filterWeekNumber > 5)
  523. {
  524. PrintFormat("⚠️ filterWeekNumber out of range (%d). Week filter disabled.", filterWeekNumber);
  525. return true;
  526. }
  527. MqlDateTime t;
  528. TimeToStruct(TimeCurrent(), t); // t.mon (1..12), t.day (1..31)
  529. // if the months don't match, week filter doesn't apply -> allow
  530. if(t.mon != filterMonthNumber)
  531. return true;
  532. // compute week of month: days 1-7 -> week 1, 8-14 -> week 2, etc.
  533. int weekOfMonth = ((t.day - 1) / 7) + 1; // yields 1..5
  534. // if current week equals the filtered week -> block trading (return false)
  535. if(weekOfMonth == filterWeekNumber)
  536. {
  537. return false; // trading NOT allowed this week of the specified month
  538. }
  539. return true; // otherwise allow trading
  540. }
  541. //+------------------------------------------------------------------+
  542. //| |
  543. //+------------------------------------------------------------------+
  544. bool isTradingAllowedByMonth()
  545. {
  546. MqlDateTime t;
  547. TimeToStruct(TimeCurrent(), t);
  548. switch(t.mon)
  549. {
  550. case 1:
  551. return allowJanuary;
  552. case 2:
  553. return allowFebruary;
  554. case 3:
  555. return allowMarch;
  556. case 4:
  557. return allowApril;
  558. case 5:
  559. return allowMay;
  560. case 6:
  561. return allowJune;
  562. case 7:
  563. return allowJuly;
  564. case 8:
  565. return allowAugust;
  566. case 9:
  567. return allowSeptember;
  568. case 10:
  569. return allowOctober;
  570. case 11:
  571. return allowNovember;
  572. case 12:
  573. return allowDecember;
  574. default:
  575. return true; // Safe fallback: allow trading if month invalid
  576. }
  577. }
  578. //+------------------------------------------------------------------+
  579. //| |
  580. //+------------------------------------------------------------------+
  581. bool newBar()
  582. {
  583. static datetime lastbar;
  584. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  585. if(lastbar != curbar)
  586. {
  587. lastbar = curbar;
  588. Print(" ---------------------- New Bar :: ---------------------- ",lastbar);
  589. return (true);
  590. }
  591. else
  592. {
  593. return (false);
  594. }
  595. }
  596. //+------------------------------------------------------------------+
  597. //| |
  598. //+------------------------------------------------------------------+
  599. void closeTrades(int type,int magicno)
  600. {
  601. Print("Total order: ",OrdersTotal());
  602. for(int i= PositionsTotal()-1; i>=0; i--)
  603. {
  604. // Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i," OrdersTotal(): ", OrdersTotal());
  605. ulong ticket = PositionGetTicket(i);
  606. if(PositionSelectByTicket(ticket))
  607. {
  608. if(PositionGetInteger(POSITION_TYPE) == type)
  609. {
  610. if(PositionGetInteger(POSITION_MAGIC) == magicno && PositionGetString(POSITION_SYMBOL) == Symbol())
  611. {
  612. //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
  613. if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
  614. {Print("Problem in closing order order ",PositionGetInteger(POSITION_TICKET)); }
  615. else
  616. {
  617. Print("Order Closed by closeTrades() new filter",PositionGetInteger(POSITION_TICKET));
  618. }
  619. }
  620. }
  621. }
  622. }
  623. }
  624. //+------------------------------------------------------------------+
  625. //| |
  626. //+------------------------------------------------------------------+
  627. int orderCount_1(int type,int magic)
  628. {
  629. int count1=0;
  630. for(int i= PositionsTotal()-1; i>=0; i--)
  631. {
  632. // Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i," OrdersTotal(): ", OrdersTotal());
  633. ulong ticket = PositionGetTicket(i);
  634. if(PositionSelectByTicket(ticket))
  635. {
  636. // if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  637. if(PositionGetInteger(POSITION_MAGIC) == magic && PositionGetString(POSITION_SYMBOL) == Symbol())
  638. {
  639. //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
  640. if(PositionGetInteger(POSITION_TYPE) == type)
  641. {
  642. count1++;
  643. }
  644. }
  645. }
  646. }
  647. return count1;
  648. }
  649. //+------------------------------------------------------------------+
  650. //| |
  651. //+------------------------------------------------------------------+
  652. int orderCount(int type)
  653. {
  654. int count = 0;
  655. for(int i= PositionsTotal()-1; i>=0; i--)
  656. {
  657. ulong ticket = PositionGetTicket(i);
  658. if(PositionSelectByTicket(ticket))
  659. {
  660. if(PositionGetInteger(POSITION_MAGIC) == magic_no && PositionGetString(POSITION_SYMBOL) == Symbol())
  661. {
  662. if(PositionGetInteger(POSITION_TYPE) == type)
  663. {
  664. count++;
  665. }
  666. }
  667. }
  668. }
  669. return count;
  670. }
  671. //+------------------------------------------------------------------+
  672. //| |
  673. //+------------------------------------------------------------------+
  674. bool level_present(double priceIs)
  675. {
  676. for(int i = 0 ; i < MaxOrders ; i++)
  677. {
  678. if(newTradeStore[i].price > 0)
  679. {
  680. if(priceIs == newTradeStore[i].price)
  681. {
  682. return true;
  683. }
  684. }
  685. }
  686. return false;
  687. }
  688. //+------------------------------------------------------------------+
  689. //| |
  690. //+------------------------------------------------------------------+
  691. void struct_level_check()
  692. {
  693. for(int i = 0; i < MaxOrders; i++)
  694. {
  695. if(newTradeStore[i].price > 0)
  696. {
  697. bool found = false;
  698. for(int j = 0; j < ArraySize(levelsAre); j++)
  699. {
  700. if(newTradeStore[i].price == levelsAre[j])
  701. {
  702. found = true;
  703. break;
  704. }
  705. }
  706. if(!found)
  707. {
  708. Print("Price not found in levelsAre[] -> index:", i, " | price:", newTradeStore[i].price);
  709. newTradeStore[i].buy_ticket = (ulong)-1;
  710. newTradeStore[i].sell_ticket = (ulong)-1;
  711. bool buy_virtual_tp_hit = true;
  712. bool sell_virtual_tp_hit = true;
  713. if(bothHitsSl)
  714. {
  715. buy_virtual_tp_hit = false;
  716. sell_virtual_tp_hit = false;
  717. }
  718. newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
  719. newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
  720. newTradeStore[i].symbol = "";
  721. newTradeStore[i].price = 0.0;
  722. newTradeStore[i].stop_loss_buy = 0.0;
  723. newTradeStore[i].take_profit_buy = 0.0;
  724. newTradeStore[i].stop_loss_sell = 0.0;
  725. newTradeStore[i].take_profit_sell = 0.0;
  726. newTradeStore[i].start_time = 0;
  727. newTradeStore[i].end_time = 0;
  728. return;
  729. }
  730. }
  731. }
  732. return;
  733. }
  734. //+------------------------------------------------------------------+
  735. //| |
  736. //+------------------------------------------------------------------+
  737. void print_newTradeStore()
  738. {
  739. bool anyPrinted = false;
  740. Print("=== newTradeStore DUMP ===");
  741. for(int i = 0; i < MaxOrders; i++)
  742. {
  743. // only print populated slots (price > 0)
  744. if(newTradeStore[i].price > 0.0)
  745. {
  746. anyPrinted = true;
  747. // convert booleans to readable text
  748. string buyHit = newTradeStore[i].buy_hit_virtual_sl ? "true" : "false";
  749. string sellHit = newTradeStore[i].sell_hit_virtual_sl ? "true" : "false";
  750. // header line for the entry
  751. Print("---- Entry ", i, " ----");
  752. // summary line (symbol, price, times)
  753. Print(" symbol:", newTradeStore[i].symbol,
  754. " | price:", DoubleToString(newTradeStore[i].price, Digits()),
  755. " | start:", IntegerToString(newTradeStore[i].start_time),
  756. " | end:", IntegerToString(newTradeStore[i].end_time));
  757. // ticket line
  758. Print(" tickets -> buy:", newTradeStore[i].buy_ticket,
  759. " | sell:", newTradeStore[i].sell_ticket);
  760. // flags line
  761. Print(" flags -> buy_hit_virtual_sl:", buyHit,
  762. " | sell_hit_virtual_sl:", sellHit,
  763. " | bothHitsSl:", (bothHitsSl ? "true" : "false"));
  764. // SL/TP line
  765. Print(" SL/TP -> buySL:", DoubleToString(newTradeStore[i].stop_loss_buy, Digits()),
  766. " | buyTP:", DoubleToString(newTradeStore[i].take_profit_buy, Digits()),
  767. " | sellSL:", DoubleToString(newTradeStore[i].stop_loss_sell, Digits()),
  768. " | sellTP:", DoubleToString(newTradeStore[i].take_profit_sell, Digits()));
  769. }
  770. }
  771. if(!anyPrinted)
  772. Print(" (no active newTradeStore entries found)");
  773. Print("=== end dump ===");
  774. }
  775. //+------------------------------------------------------------------+
  776. //| |
  777. //+------------------------------------------------------------------+
  778. void addToNewTradeStore(ulong r_buy_ticket, ulong r_sell_ticket,
  779. string r_symbol, double r_price,
  780. double r_stop_loss_buy, double r_take_profit_buy,
  781. double r_stop_loss_sell, double r_take_profit_sell,
  782. datetime r_start_time, datetime r_end_time, bool r_buy_hit_sl, bool r_sell_hit_sl)
  783. {
  784. Print(" Tier 1. ");
  785. for(int i = 0; i < MaxOrders; i++)
  786. {
  787. // treat slot as empty when both tickets are -1 (same convention as constructor)
  788. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  789. {
  790. if(newTradeStore[i].price == 0)
  791. {
  792. newTradeStore[i].buy_ticket = r_buy_ticket;
  793. newTradeStore[i].sell_ticket = r_sell_ticket;
  794. newTradeStore[i].symbol = r_symbol;
  795. newTradeStore[i].price = r_price;
  796. newTradeStore[i].stop_loss_buy = r_stop_loss_buy;
  797. newTradeStore[i].take_profit_buy = r_take_profit_buy;
  798. newTradeStore[i].stop_loss_sell = r_stop_loss_sell;
  799. newTradeStore[i].take_profit_sell = r_take_profit_sell;
  800. newTradeStore[i].start_time = r_start_time;
  801. newTradeStore[i].end_time = r_end_time;
  802. newTradeStore[i].buy_hit_virtual_sl = r_buy_hit_sl;
  803. newTradeStore[i].sell_hit_virtual_sl = r_sell_hit_sl;
  804. Print("Stored -> idx: ", i,
  805. " | Symbol: ", newTradeStore[i].symbol,
  806. " | price: ", DoubleToString(newTradeStore[i].price, Digits()),
  807. " | Sl Buy: ", DoubleToString(newTradeStore[i].stop_loss_buy, Digits()),
  808. " | Tp Buy: ", DoubleToString(newTradeStore[i].take_profit_buy, Digits()),
  809. "\n | Sl Sell: ", DoubleToString(newTradeStore[i].stop_loss_sell, Digits()),
  810. " | Tp Sell: ", DoubleToString(newTradeStore[i].take_profit_sell, Digits()),
  811. " | start: ", TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS),
  812. " | end: ", TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS),
  813. " | Buy Virtal Sl Hit: ", newTradeStore[i].buy_hit_virtual_sl,
  814. " | Sell Virtual Sl Hit: ", newTradeStore[i].sell_hit_virtual_sl);
  815. break;
  816. }
  817. }
  818. }
  819. }
  820. //+------------------------------------------------------------------+
  821. //| |
  822. //+------------------------------------------------------------------+
  823. void tradePlacingCheck()
  824. {
  825. for(int i = 0; i < MaxOrders; i++)
  826. {
  827. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  828. {
  829. if(newTradeStore[i].price > 0)
  830. {
  831. if((TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time) || (newTradeStore[i].start_time == 0 || newTradeStore[i].end_time == 0))
  832. {
  833. if(newTradeStore[i].buy_hit_virtual_sl == true && newTradeStore[i].sell_hit_virtual_sl == true)
  834. {
  835. double levelPriceIs = newTradeStore[i].price;
  836. if((tickPreviousBid > levelPriceIs && tickCurrentBid < levelPriceIs) ||
  837. (tickPreviousBid < levelPriceIs && tickCurrentBid > levelPriceIs))
  838. {
  839. Print(" ------------------- Level Crossed. Level is: ", levelPriceIs, " -------------------- ");
  840. if(isTradingAllowedByWeek())
  841. {
  842. if(isTradingAllowedByMonth())
  843. {
  844. if((enableSpreadFilter && spreadFilter()) || !enableSpreadFilter)
  845. {
  846. ulong buyTicket = -1, sellTicket = -1;
  847. if(countLiveTrades() < maxTrades)
  848. {
  849. buyTicket = placeBuyTrade(newTradeStore[i].stop_loss_buy, newTradeStore[i].take_profit_buy);
  850. sellTicket = placeSellTrade(newTradeStore[i].stop_loss_sell, newTradeStore[i].take_profit_sell);
  851. newTradeStore[i].buy_ticket = buyTicket;
  852. newTradeStore[i].sell_ticket = sellTicket;
  853. }
  854. }
  855. }
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. }
  863. }
  864. //+------------------------------------------------------------------+
  865. //| |
  866. //+------------------------------------------------------------------+
  867. void draw_lines(string name, datetime dateTime, double price, color selectColor, long lineStyle)
  868. {
  869. if(!ObjectCreate(0, name, OBJ_HLINE, 0, dateTime, price))
  870. {
  871. Print(" Error in creating ", name," : ","line: "," ",GetLastError());
  872. }
  873. else
  874. {
  875. ObjectSetInteger(0, name, OBJPROP_COLOR, selectColor);
  876. ObjectSetInteger(0, name, OBJPROP_STYLE, lineStyle);
  877. }
  878. }
  879. //+------------------------------------------------------------------+
  880. //| |
  881. //+------------------------------------------------------------------+
  882. void drawLevels()
  883. {
  884. for(int i = 0; i < MaxOrders; i++)
  885. {
  886. if(newTradeStore[i].price > 0)
  887. {
  888. if((TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time) || (newTradeStore[i].start_time == 0 || newTradeStore[i].end_time == 0))
  889. {
  890. if(ObjectFind(0, "level" + (string)newTradeStore[i].price) < 0)
  891. {
  892. draw_lines("level" + (string)newTradeStore[i].price, TimeCurrent(), newTradeStore[i].price, clrAqua, STYLE_SOLID);
  893. }
  894. }
  895. else
  896. {
  897. if(ObjectFind(0, "level" + (string)newTradeStore[i].price) >= 0)
  898. {
  899. ObjectDelete(0, "level" + (string)newTradeStore[i].price);
  900. }
  901. }
  902. }
  903. }
  904. }
  905. //+------------------------------------------------------------------+
  906. //| |
  907. //+------------------------------------------------------------------+
  908. ulong placeBuyTrade(double stoploss, double takeprofit)
  909. {
  910. double buySL = 0, buyTp=0;
  911. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  912. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  913. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  914. if(useTpSlPips)
  915. {
  916. if(stopLoss != 0)
  917. {
  918. buySL = Ask - (stopLoss * Point());
  919. }
  920. if(takeProfit != 0)
  921. {
  922. buyTp = Ask + (takeProfit * Point());
  923. }
  924. }
  925. else
  926. {
  927. if(stoploss > 0)
  928. {
  929. buySL = stoploss;
  930. }
  931. if(takeprofit > 0)
  932. {
  933. buyTp = takeprofit;
  934. }
  935. }
  936. double distance = MathAbs((Ask - buySL) / Point());
  937. if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getLot(distance),Ask,buySL,buyTp,tradeComment+" Buy"))
  938. {
  939. Print("Buy Trade Placed: ",trade.ResultOrder());
  940. return trade.ResultOrder();
  941. }
  942. else
  943. {
  944. Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
  945. return -1;
  946. }
  947. return -1;
  948. }
  949. //+------------------------------------------------------------------+
  950. //| |
  951. //+------------------------------------------------------------------+
  952. ulong placeSellTrade(double stoploss, double takeprofit)
  953. {
  954. double sellSL = 0, sellTp = 0;
  955. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  956. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  957. if(useTpSlPips)
  958. {
  959. if(stopLoss != 0)
  960. {
  961. sellSL = Bid + (stopLoss * Point());
  962. }
  963. if(takeProfit != 0)
  964. {
  965. sellTp = Bid - (takeProfit * Point());
  966. }
  967. }
  968. else
  969. {
  970. if(stoploss > 0)
  971. {
  972. sellSL = stoploss;
  973. }
  974. if(takeprofit > 0)
  975. {
  976. sellTp = takeprofit;
  977. }
  978. }
  979. double distance = MathAbs((Bid - sellSL) / Point());
  980. if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getLot(distance),Bid,sellSL,sellTp,tradeComment+ " Sell"))
  981. {
  982. Print("Sell Trade PLaced: ",trade.ResultOrder());
  983. return trade.ResultOrder();
  984. }
  985. else
  986. {
  987. Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
  988. return -1;
  989. }
  990. return -1;
  991. }
  992. //+------------------------------------------------------------------+
  993. //| |
  994. //+------------------------------------------------------------------+
  995. double getLot(double stop_loss)
  996. {
  997. Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
  998. Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
  999. double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
  1000. ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
  1001. // Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
  1002. double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
  1003. // pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
  1004. // pipvalue=
  1005. pipvalue = pipvalue / 10;
  1006. double lotSize = lot_amount;
  1007. if(lot_calculator == rsk || lot_calculator == dollar) //calculating risk
  1008. {
  1009. double riskamount = 0;
  1010. if(lot_calculator == rsk)
  1011. {
  1012. riskamount = (risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
  1013. }
  1014. if(lot_calculator == dollar)
  1015. {
  1016. riskamount = dollars;
  1017. }
  1018. double pipvalue_required=riskamount/stop_loss;
  1019. lotSize = pipvalue_required/pipvalue;
  1020. //sl=riskamount/pipValuelot
  1021. int roundDigit=0;
  1022. double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
  1023. while(step<1)
  1024. {
  1025. roundDigit++;
  1026. step=step*10;
  1027. }
  1028. Print("Round Digits:",roundDigit);
  1029. lotSize = NormalizeDouble(lotSize,roundDigit);
  1030. //
  1031. }
  1032. Print("Lot Size: ",lotSize);
  1033. if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
  1034. {
  1035. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  1036. }
  1037. else
  1038. if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
  1039. {
  1040. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  1041. }
  1042. //---
  1043. return lotSize;
  1044. }
  1045. //+------------------------------------------------------------------+
  1046. //| |
  1047. //+------------------------------------------------------------------+
  1048. void timeFilter(bool onInit)
  1049. {
  1050. MqlDateTime sdate,edate;
  1051. datetime start_Time = 0, end_Time = 0;
  1052. if(newYorkSessionDay == prev)
  1053. {
  1054. if(onInit)
  1055. {
  1056. start_Time = iTime(Symbol(),PERIOD_D1,1);
  1057. end_Time = iTime(Symbol(),PERIOD_D1,0);
  1058. }
  1059. else
  1060. {
  1061. start_Time = newYorkStartTrading;
  1062. end_Time = newYorkEndTrading;
  1063. if(TimeCurrent() >= newYorkEndTrading && newYorkEndTrading != 0)
  1064. {
  1065. start_Time = iTime(Symbol(),PERIOD_D1,0);
  1066. end_Time = start_Time + 86400;
  1067. }
  1068. }
  1069. }
  1070. else
  1071. {
  1072. start_Time = iTime(Symbol(),PERIOD_D1,0);
  1073. end_Time = iTime(Symbol(),PERIOD_D1,0);
  1074. }
  1075. if(TimeToStruct(end_Time,edate))
  1076. {
  1077. edate.hour = newYorkEndHour;
  1078. edate.min = newYorkEndMin;
  1079. edate.sec = 0;
  1080. }
  1081. else
  1082. Print("Error in Converting Time: ",GetLastError());
  1083. newYorkEndTrading = StructToTime(edate);
  1084. if(TimeToStruct(start_Time,sdate))
  1085. {
  1086. sdate.hour = newYorkStartTime;
  1087. sdate.min = newYorkStartMin;
  1088. sdate.sec = 0;
  1089. }
  1090. else
  1091. Print("Error in Converting Time: ",GetLastError());
  1092. newYorkStartTrading = StructToTime(sdate);
  1093. // if(onInit)
  1094. //Print("NewYork Start Time ",newYorkStartTrading,"End Date: ",newYorkEndTrading);
  1095. //Print("Edate: ",edate.hour," ",edate.min," Sdate: ",sdate.hour," ",sdate.min);
  1096. }
  1097. //+------------------------------------------------------------------+
  1098. //| |
  1099. //+------------------------------------------------------------------+
  1100. void removeFromStructure()
  1101. {
  1102. for(int i = 0 ; i < MaxOrders ; i++)
  1103. {
  1104. bool isBuyPresent=false, isSellPresent=false;
  1105. if(newTradeStore[i].buy_ticket != -1 && newTradeStore[i].sell_ticket != -1)
  1106. {
  1107. for(int j = PositionsTotal()-1; j>=0; j--)
  1108. {
  1109. ulong ticket = PositionGetTicket(j);
  1110. if(PositionSelectByTicket(ticket))
  1111. {
  1112. if(ticket == newTradeStore[i].buy_ticket)
  1113. {
  1114. isBuyPresent=true;
  1115. }
  1116. }
  1117. }
  1118. for(int j = PositionsTotal()-1; j>=0; j--)
  1119. {
  1120. ulong ticket = PositionGetTicket(j);
  1121. if(PositionSelectByTicket(ticket))
  1122. {
  1123. if(ticket == newTradeStore[i].sell_ticket)
  1124. {
  1125. isSellPresent = true;
  1126. }
  1127. }
  1128. }
  1129. if(!isBuyPresent && !isSellPresent)
  1130. {
  1131. Print("Buy/Sell Ticket is closed so removed from struct. Buy Ticket: ", newTradeStore[i].buy_ticket, " Sell Ticket: ", newTradeStore[i].sell_ticket);
  1132. newTradeStore[i].buy_ticket = (ulong)-1;
  1133. newTradeStore[i].sell_ticket = (ulong)-1;
  1134. bool buy_virtual_tp_hit = true;
  1135. bool sell_virtual_tp_hit = true;
  1136. if(bothHitsSl)
  1137. {
  1138. buy_virtual_tp_hit = false;
  1139. sell_virtual_tp_hit = false;
  1140. }
  1141. newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
  1142. newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
  1143. //newTradeStore[i].symbol = "";
  1144. //newTradeStore[i].price = 0.0;
  1145. //newTradeStore[i].stop_loss = 0.0;
  1146. //newTradeStore[i].take_profit = 0.0;
  1147. //newTradeStore[i].start_time = 0;
  1148. //newTradeStore[i].end_time = 0;
  1149. }
  1150. }
  1151. }
  1152. }
  1153. //+------------------------------------------------------------------+
  1154. //| |
  1155. //+------------------------------------------------------------------+
  1156. void virtualSLHitCheck()
  1157. {
  1158. for(int i = 0 ; i < MaxOrders ; i++)
  1159. {
  1160. if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
  1161. {
  1162. if(TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time)
  1163. {
  1164. double buy_sl = 0, sell_sl = 0;
  1165. if(!useTpSlPips)
  1166. {
  1167. buy_sl = newTradeStore[i].stop_loss_buy;
  1168. sell_sl = newTradeStore[i].stop_loss_sell;
  1169. }
  1170. else
  1171. {
  1172. buy_sl = stopLoss != 0 ? newTradeStore[i].price - (stopLoss * Point()) : 0;
  1173. sell_sl = stopLoss != 0 ? newTradeStore[i].price + (stopLoss * Point()) : 0;
  1174. }
  1175. if(newTradeStore[i].buy_hit_virtual_sl == false)
  1176. {
  1177. if((tickPreviousBid < buy_sl && tickCurrentBid > buy_sl))
  1178. {
  1179. newTradeStore[i].buy_hit_virtual_sl = true;
  1180. 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());
  1181. }
  1182. }
  1183. if(newTradeStore[i].sell_hit_virtual_sl == false)
  1184. {
  1185. if((tickPreviousAsk > sell_sl && tickCurrentAsk < sell_sl))
  1186. {
  1187. newTradeStore[i].sell_hit_virtual_sl = true;
  1188. 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());
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. }
  1195. //+------------------------------------------------------------------+
  1196. //| |
  1197. //+------------------------------------------------------------------+
  1198. int countLiveTrades()
  1199. {
  1200. int count = 0;
  1201. for(int i = 0; i < PositionsTotal(); i++)
  1202. {
  1203. ulong ticket = PositionGetTicket(i);
  1204. if(PositionSelectByTicket(ticket))
  1205. {
  1206. if(PositionGetInteger(POSITION_MAGIC) == magic_no)
  1207. {
  1208. if(PositionGetString(POSITION_SYMBOL) == Symbol())
  1209. {
  1210. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  1211. {
  1212. count++;
  1213. }
  1214. }
  1215. }
  1216. }
  1217. }
  1218. return count;
  1219. }
  1220. //+------------------------------------------------------------------+
  1221. //| |
  1222. //+------------------------------------------------------------------+
  1223. bool spreadFilter()
  1224. {
  1225. long spreadIs = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
  1226. if(spreadIs > maximumSpread)
  1227. {
  1228. return false;
  1229. }
  1230. return true;
  1231. }
  1232. //+------------------------------------------------------------------+
  1233. //| |
  1234. //+------------------------------------------------------------------+
  1235. void breakEven()
  1236. {
  1237. for(int i = PositionsTotal()-1; i>=0; i--)
  1238. {
  1239. ulong ticket = PositionGetTicket(i);
  1240. string symbol=PositionGetSymbol(i);
  1241. double mySL = 0,newSL = 0;
  1242. double SymbolTickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
  1243. ////Print("ticket ",ticket," Symbol : ",symbol);
  1244. if(PositionSelectByTicket(ticket))
  1245. {
  1246. if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC) == magic_no)
  1247. {
  1248. if(isCounterpartOpen(ticket))
  1249. {
  1250. // counterpart still open -> skip trailing for this position
  1251. continue;
  1252. }
  1253. //========================================================Buy Condition=========================================================================
  1254. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
  1255. {
  1256. mySL = PositionGetDouble(POSITION_PRICE_OPEN) + (breakEvenPoints * SymbolTickSize);
  1257. if(SymbolInfoDouble(Symbol(),SYMBOL_BID) >= mySL && PositionGetDouble(POSITION_PRICE_OPEN) > PositionGetDouble(POSITION_SL))
  1258. {
  1259. newSL= PositionGetDouble(POSITION_PRICE_OPEN) + (breakStopPoint * SymbolTickSize);
  1260. if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
  1261. {
  1262. Print("Buy Order BreakEven Successfully ");
  1263. }
  1264. else
  1265. {
  1266. Print("Error in BreakEven Buy Position ",GetLastError());
  1267. }
  1268. }
  1269. }
  1270. //=======================================================Sell condition ===============================================================
  1271. if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
  1272. {
  1273. mySL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakEvenPoints * SymbolTickSize);
  1274. if(SymbolInfoDouble(Symbol(),SYMBOL_ASK) <= mySL && PositionGetDouble(POSITION_SL) > PositionGetDouble(POSITION_PRICE_OPEN))
  1275. {
  1276. newSL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakStopPoint * SymbolTickSize);
  1277. if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
  1278. {
  1279. Print("Order Sell BreakEven Successfully ");
  1280. }
  1281. else
  1282. {
  1283. Print("Error in BreakEven Sell Position ",GetLastError());
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. }
  1291. //+------------------------------------------------------------------+
  1292. //| |
  1293. //+------------------------------------------------------------------+
  1294. bool isCounterpartOpen(ulong ticket)
  1295. {
  1296. // scan stored pairs
  1297. for(int k=0; k<MaxOrders; k++)
  1298. {
  1299. // check if this ticket is the buy side in the pair
  1300. if(newTradeStore[k].buy_ticket == ticket)
  1301. {
  1302. ulong other = newTradeStore[k].sell_ticket;
  1303. if(other <= 0)
  1304. return false; // no counterpart recorded -> treat as closed
  1305. // check if counterpart ticket exists in current positions
  1306. for(int p = PositionsTotal()-1; p >= 0; p--)
  1307. {
  1308. ulong t = PositionGetTicket(p);
  1309. if(t == other)
  1310. return true; // counterpart still open
  1311. }
  1312. return false; // counterpart not found -> closed
  1313. }
  1314. // check if this ticket is the sell side in the pair
  1315. if(newTradeStore[k].sell_ticket == ticket)
  1316. {
  1317. ulong other = newTradeStore[k].buy_ticket;
  1318. if(other <= 0)
  1319. return false; // no counterpart recorded -> treat as closed
  1320. for(int p = PositionsTotal()-1; p >= 0; p--)
  1321. {
  1322. ulong t = PositionGetTicket(p);
  1323. if(t == other)
  1324. return true; // counterpart still open
  1325. }
  1326. return false; // counterpart not found -> closed
  1327. }
  1328. }
  1329. // ticket not found in the stored pairs -> treat as no counterpart open
  1330. return false;
  1331. }
  1332. //+------------------------------------------------------------------+
  1333. //| |
  1334. //+------------------------------------------------------------------+
  1335. void Individual_Trailing()
  1336. {
  1337. int openedpositions;
  1338. double mySL,myResult;
  1339. openedpositions=PositionsTotal();
  1340. if((openedpositions>0))
  1341. {
  1342. int totalorders=PositionsTotal();
  1343. for(int i=0; i<totalorders; i++) // scan all orders and positions. ..
  1344. {
  1345. ulong ticket = PositionGetTicket(i);
  1346. if(PositionSelectByTicket(ticket))
  1347. {
  1348. if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC) == magic_no) // only look if mygrid and symbol. ..
  1349. {
  1350. if(isCounterpartOpen(ticket))
  1351. {
  1352. // counterpart still open -> skip trailing for this position
  1353. continue;
  1354. }
  1355. double SymbolAsk = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_ASK);
  1356. double SymbolBid = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_BID);
  1357. int SymbolDigits = (int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL), SYMBOL_DIGITS);
  1358. double SymbolTickSize = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE);
  1359. int type= (int)PositionGetInteger(POSITION_TYPE);
  1360. if(type==POSITION_TYPE_BUY) // its a long position
  1361. {
  1362. mySL=NormalizeDouble(SymbolAsk-(ts*SymbolTickSize),Digits()); // new SL
  1363. double startSl=PositionGetDouble(POSITION_PRICE_OPEN)+(ts_sl*SymbolTickSize);
  1364. if(PositionGetDouble(POSITION_SL) != mySL)
  1365. if(mySL>PositionGetDouble(POSITION_SL) && SymbolAsk>=startSl)
  1366. {
  1367. myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrGreen);
  1368. if(!myResult)
  1369. {
  1370. Print(" Buy Trade Trailing Error: ",GetLastError());
  1371. }
  1372. }
  1373. }
  1374. if(type==POSITION_TYPE_SELL)
  1375. {
  1376. mySL=NormalizeDouble(SymbolBid+(ts*SymbolTickSize),Digits()); // new SL
  1377. double startSlSell=PositionGetDouble(POSITION_PRICE_OPEN)-(ts_sl*SymbolTickSize);
  1378. if(PositionGetDouble(POSITION_SL) != mySL)
  1379. if(((mySL<PositionGetDouble(POSITION_SL)) || (PositionGetDouble(POSITION_SL)<SymbolTickSize)) && SymbolBid<=startSlSell)
  1380. {
  1381. myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrRed);
  1382. if(!myResult)
  1383. {
  1384. Print(" Sell Trade Trailing Error: ",GetLastError());
  1385. }
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. //+------------------------------------------------------------------+
  1394. //| |
  1395. //+------------------------------------------------------------------+
  1396. void saveNewTradeStoreFile()
  1397. {
  1398. // don't run in strategy tester
  1399. if(MQLInfoInteger(MQL_TESTER))
  1400. return;
  1401. string file_name = "new_trade_store_updated.csv";
  1402. int fileHandle = FileOpen(file_name,
  1403. FILE_WRITE | FILE_CSV | FILE_COMMON |
  1404. FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_READ);
  1405. if(fileHandle == INVALID_HANDLE)
  1406. {
  1407. PrintFormat("saveNewTradeStoreFile() -> Cannot open file '%s'. Error: %d", file_name, GetLastError());
  1408. return;
  1409. }
  1410. // header (optional) - comment out if you don't want header
  1411. //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";
  1412. //FileWriteString(fileHandle, header);
  1413. for(int i = 0; i < MaxOrders; i++)
  1414. {
  1415. if(newTradeStore[i].buy_ticket != -1 && newTradeStore[i].sell_ticket != -1)
  1416. {
  1417. // decide whether this slot has useful data:
  1418. // you can tweak this condition as you prefer (symbol != "" is simple)
  1419. bool slotPopulated = (StringLen(newTradeStore[i].symbol) > 0)
  1420. || (newTradeStore[i].price != 0.0)
  1421. || (newTradeStore[i].start_time != 0);
  1422. if(!slotPopulated)
  1423. continue;
  1424. // convert values to strings
  1425. string buyTicketStr = IntegerToString((long)newTradeStore[i].buy_ticket);
  1426. string sellTicketStr = IntegerToString((long)newTradeStore[i].sell_ticket);
  1427. string priceStr = DoubleToString(newTradeStore[i].price, Digits());
  1428. string slBuyStr = DoubleToString(newTradeStore[i].stop_loss_buy, Digits());
  1429. string tpBuyStr = DoubleToString(newTradeStore[i].take_profit_buy, Digits());
  1430. string slSellStr = DoubleToString(newTradeStore[i].stop_loss_sell, Digits());
  1431. string tpSellStr = DoubleToString(newTradeStore[i].take_profit_sell, Digits());
  1432. string startTimeStr = (newTradeStore[i].start_time != 0) ? TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS) : "";
  1433. string endTimeStr = (newTradeStore[i].end_time != 0) ? TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS) : "";
  1434. string buyHitStr = ""; // IntegerToString(newTradeStore[i].buy_hit_virtual_sl ? 1 : 0);
  1435. string sellHitStr = ""; // IntegerToString(newTradeStore[i].sell_hit_virtual_sl ? 1 : 0);
  1436. if(newTradeStore[i].buy_hit_virtual_sl == true)
  1437. {
  1438. buyHitStr = "true";
  1439. }
  1440. else
  1441. {
  1442. buyHitStr = "false";
  1443. }
  1444. if(newTradeStore[i].sell_hit_virtual_sl == true)
  1445. {
  1446. sellHitStr = "true";
  1447. }
  1448. else
  1449. {
  1450. sellHitStr = "false";
  1451. }
  1452. // build CSV line and write
  1453. string line = buyTicketStr + "," + sellTicketStr + "," +
  1454. newTradeStore[i].symbol + "," +
  1455. priceStr + "," + slBuyStr + "," + tpBuyStr + "," +
  1456. slSellStr + "," + tpSellStr + "," +
  1457. startTimeStr + "," + endTimeStr + "," +
  1458. buyHitStr + "," + sellHitStr + "\r\n";
  1459. FileWriteString(fileHandle, line);
  1460. }
  1461. }
  1462. FileClose(fileHandle);
  1463. PrintFormat("saveNewTradeStoreFile() -> saved to '%s'.", file_name);
  1464. }
  1465. //+------------------------------------------------------------------+
  1466. //| |
  1467. //+------------------------------------------------------------------+
  1468. void loadNewTradeStoreFile()
  1469. {
  1470. if(MQLInfoInteger(MQL_TESTER))
  1471. return;
  1472. string file_name = "new_trade_store_updated.csv";
  1473. int fileHandle = FileOpen(file_name,
  1474. FILE_READ | FILE_CSV | FILE_COMMON |
  1475. FILE_SHARE_READ | FILE_SHARE_WRITE);
  1476. if(fileHandle == INVALID_HANDLE)
  1477. {
  1478. Print("loadNewTradeStoreFile() -> Cannot open file '", file_name, "'. Error: ", GetLastError());
  1479. return;
  1480. }
  1481. // reset defaults
  1482. for(int j = 0; j < MaxOrders; j++)
  1483. {
  1484. newTradeStore[j].buy_ticket = (ulong)-1;
  1485. newTradeStore[j].sell_ticket = (ulong)-1;
  1486. newTradeStore[j].symbol = "";
  1487. newTradeStore[j].price = 0.0;
  1488. newTradeStore[j].stop_loss_buy = 0.0;
  1489. newTradeStore[j].take_profit_buy = 0.0;
  1490. newTradeStore[j].stop_loss_sell = 0.0;
  1491. newTradeStore[j].take_profit_sell = 0.0;
  1492. newTradeStore[j].start_time = 0;
  1493. newTradeStore[j].end_time = 0;
  1494. newTradeStore[j].buy_hit_virtual_sl = false;
  1495. newTradeStore[j].sell_hit_virtual_sl = false;
  1496. }
  1497. int idx = 0;
  1498. while(!FileIsEnding(fileHandle) && idx < MaxOrders)
  1499. {
  1500. string line = FileReadString(fileHandle);
  1501. if(StringLen(line) == 0)
  1502. continue;
  1503. string tokens[];
  1504. int total = StringSplit(line, ',', tokens);
  1505. if(total >= 12)
  1506. {
  1507. if((ulong)tokens[0] != -1 && (ulong)tokens[1] != -1)
  1508. {
  1509. newTradeStore[idx].buy_ticket = (ulong)tokens[0];
  1510. newTradeStore[idx].sell_ticket = (ulong)tokens[1];
  1511. newTradeStore[idx].symbol = tokens[2];
  1512. newTradeStore[idx].price = StringToDouble(tokens[3]);
  1513. newTradeStore[idx].stop_loss_buy = StringToDouble(tokens[4]);
  1514. newTradeStore[idx].take_profit_buy = StringToDouble(tokens[5]);
  1515. newTradeStore[idx].stop_loss_sell = StringToDouble(tokens[6]);
  1516. newTradeStore[idx].take_profit_sell = StringToDouble(tokens[7]);
  1517. string sStart = tokens[8];
  1518. string sEnd = tokens[9];
  1519. newTradeStore[idx].start_time = (StringLen(sStart) > 0) ? StringToTime(sStart) : 0;
  1520. newTradeStore[idx].end_time = (StringLen(sEnd) > 0) ? StringToTime(sEnd) : 0;
  1521. bool bHit = false;
  1522. bool sHit = false;
  1523. if(tokens[10] == "true")
  1524. {
  1525. bHit = true;
  1526. }
  1527. else
  1528. {
  1529. bHit = false;
  1530. }
  1531. if(tokens[11] == "true")
  1532. {
  1533. sHit = true;
  1534. }
  1535. else
  1536. {
  1537. sHit = false;
  1538. }
  1539. newTradeStore[idx].buy_hit_virtual_sl = bHit;
  1540. newTradeStore[idx].sell_hit_virtual_sl = sHit;
  1541. // --- simple Print instead of PrintFormat ---
  1542. Print(
  1543. "Loaded newTradeStore[", idx, "]:",
  1544. " buy_ticket=", newTradeStore[idx].buy_ticket,
  1545. " sell_ticket=", newTradeStore[idx].sell_ticket,
  1546. " symbol=", newTradeStore[idx].symbol,
  1547. " price=", DoubleToString(newTradeStore[idx].price, Digits()),
  1548. " \n sl buy=", DoubleToString(newTradeStore[idx].stop_loss_buy, Digits()),
  1549. " tp buy=", DoubleToString(newTradeStore[idx].take_profit_buy, Digits()),
  1550. " sl sell=", DoubleToString(newTradeStore[idx].stop_loss_sell, Digits()),
  1551. " tp sell=", DoubleToString(newTradeStore[idx].take_profit_sell, Digits()),
  1552. " start=", (newTradeStore[idx].start_time != 0 ? TimeToString(newTradeStore[idx].start_time, TIME_DATE|TIME_SECONDS) : ""),
  1553. " end=", (newTradeStore[idx].end_time != 0 ? TimeToString(newTradeStore[idx].end_time, TIME_DATE|TIME_SECONDS) : ""),
  1554. " buyHit=", newTradeStore[idx].buy_hit_virtual_sl,
  1555. " sellHit=", newTradeStore[idx].sell_hit_virtual_sl
  1556. );
  1557. idx++;
  1558. }
  1559. }
  1560. else
  1561. {
  1562. Print("loadNewTradeStoreFile(): skipping malformed line (tokens=", total, "): ", line);
  1563. }
  1564. }
  1565. FileClose(fileHandle);
  1566. Print("loadNewTradeStoreFile() -> loaded ", idx, " entries from '", file_name, "'.");
  1567. }
  1568. //+------------------------------------------------------------------+
  1569. //| |
  1570. //+------------------------------------------------------------------+
  1571. //+------------------------------------------------------------------+