Keine Beschreibung

vol_hedge_strategy_mt5.mq5 136KB

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