Nenhuma descrição

vol_hedge_strategy_mt5.mq5 135KB

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