Browse Source

Revert "Merge branch 'development/entry-conditions' of huzaifa.hayat/vol_hedge_strategy_mt5 into master"

This reverts commit c3118be8f665b6b24b80ba25d3eb51764c1ef521, reversing
changes made to d64edb0f380d84356fb30156e7c57ab3d2843fe7.
WajeehSaqib-MQL 9 months ago
parent
commit
cd59a8eb55

+ 0 - 2
data/vol_hedge_data.csv

@@ -1,2 +0,0 @@
-EURUSDm,1.08384,1000,1000,2023.03.22 02:05:25,2023.03.24 02:05:25
-EURUSDm,1.08734,400,400,2023.03.30 00:00:00,2023.04.04 02:05:25

BIN
library/volHedgeNewsFilter.ex5


+ 0 - 964
library/volHedgeNewsFilter.mq5

@@ -1,964 +0,0 @@
-//+------------------------------------------------------------------+
-//|                                                   newsFilter.mq5 |
-//|                                      Copyright 2021, MQLDEV Ltd. |
-//|                                           https://www.mqldev.com |
-//+------------------------------------------------------------------+
-#property library
-#property copyright "Copyright 2021, MQLDEV Ltd."
-#property link      "https://www.mqldev.com"
-#property version   "1.00"
-#include <Trade\Trade.mqh>
-CTrade trade;
-
-//+------------------------------------------------------------------+
-//| My function                                                      |
-//+------------------------------------------------------------------+
-// int MyCalculator(int value,int value2) export
-//   {
-//    return(value+value2);
-//   }
-//+------------------------------------------------------------------+
-
-#import  "Wininet.dll"
-int InternetOpenW(string,int,string,string,int);
-int InternetConnectW(int,string,int,string,string,int,int,int);
-int HttpRequestW(int,string,string,int,string,int,string,int);
-int InternetOpenUrlW(int,string,string,int,int,int);
-int InternetReadFile(int,uchar &sBuffer[],int,int &OneInt);
-int InternetCloseHandle(int);
-bool DeleteUrlCacheEntryW(string);
-#import
-
-#import "kernel32.dll"
-int GetLastError(void);
-#import
-//+------------------------------------------------------------------+
-//| My function                                                      |
-//+------------------------------------------------------------------+
-// int MyCalculator(int value,int value2) export
-//   {
-//    return(value+value2);
-//   }
-//+------------------------------------------------------------------+
-datetime previous_time;
-datetime expiry=D'2021.10.16 12:30:27';
-string matchExpert="vol_hedge_strategy_mt5";
-string matchExpert2="Vol_Hedge_Strategy_Mt5";
-string fileName="test1"+MQLInfoString(MQL_PROGRAM_NAME)+Symbol()+IntegerToString(Period())+".xml";
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-enum selectLine
-  {
-   LineOnNewsBar =0,
-   LineOnNewsStop=1
-  };
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-struct newsEvent
-  {
-   string            title;
-   string            country;
-   string            date;
-   string            time;
-   string            impact;
-                     newsEvent()
-     {
-      title="";
-      country="";
-      date="";
-      time="";
-      impact="";
-     }
-  };
-
-const int newsSize=300;
-newsEvent ns[300];
-datetime lastNews;
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void initiateNews() export
-  {
-   lastNews=TimeCurrent();
-   updateNews();
-   fillNewsStruct();
-   Print("The Symbol is:",Symbol()," and timeperiod:",Period()," and file name is:"+fileName);
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-//int OnInit()
-//  {
-////---
-//   bool check = MQLInfoInteger(MQL_DLLS_ALLOWED);
-//   Print("DLL: ",check);
-//   Alert("Enable");
-//   return(INIT_SUCCEEDED);
-//  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int returnNewsStatus(bool highFlag=true
-                                   ,int high_impact_value=60//Stop Trade before high News (min)
-                     ,int end_impact_value=15 //Stop Trade after high News (min)
-
-                     ,bool show_high_line=true//Show verticle Line when high news comes
-                     ,bool mediumFlag=true
-                     ,int medium_impact_high=60//Stop Trade before medium News (min)
-                     ,int medium_impact_low=15 //Stop Trade after medium News (min)
-
-                     ,bool show_medium_line=true//Show verticle Line when medium news comes
-                     ,bool lowFlag=true
-                     ,int low_impact_high=60//Stop Trade before low News (min)
-                     ,int low_impact_low=15 //Stop Trade after low News (min)
-
-                     ,bool show_low_line=true//Show verticle Line when low news comes
-                     ,string symbol=""
-                     ,string expertname=""
-                     ,int gmt=2
-                     ,selectLine sl=0
-                     ,string extraSymbol=""
-                    ) export
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-  {
-   int newsStatus=0;
-//Print("TImeCurrent:"+TimeCurrent()+"expiry:"+expiry);
-//"Trend Gridder(22)" || expertname=="TG NEWS" || expertname=="TG News"
-//"tylergabor"
-//((  expertname=="TG NEWS" || expertname=="TG News" || expertname=="Bandit" || expertname=="BANDIT" || expertname=="bandit" || expertname=="TG NEWS" || expertname=="TG News" || expertname=="C-Storm" || expertname=="C-STORM" || expertname=="c-storm" || (expertname=="C-StormV1.1" || (StringFind(chkexpert,"tyler")!=-1) || (StringFind(chkexpert,"hullincash")!=-1) ||(StringFind(chkexpert,"pk5000")!=-1) )))// && TimeCurrent()<expiry)
-
-   string chkexpert=expertname;
-// Print("chkexpert ",chkexpert);
-//   StringToLower(chkexpe/rt);
-
-   if(Validate())
-     {
-      if(TimeDayMQL4(TimeCurrent())!=TimeDayMQL4(lastNews))
-        {
-         updateNews();
-         fillNewsStruct();
-         lastNews=TimeCurrent();
-         Print("News Function is calling and updating by "+symbol);
-        }
-      int index=0;
-      string sym=symbol;
-      string metals=sym;
-      StringToLower(metals);
-      StringToLower(extraSymbol);
-      //Print("---------------------Metals:"+metals+ " and symbol:"+ns[index].country," and extraSymbol:",extraSymbol);
-      //Print("checking metal:"+(StringFind("Nymex-J",sym,0)!=-1) +" and metal is:"+sym );
-      //Print("country:"+ns[index].country+" and check "+StringFind("JPYAUD",ns[index].country,0)!=-1))
-      //Start working here
-      while(index<newsSize)
-        {
-         // Print("Inside the currency:"+index+ " currency"+ns[index].country+ " and curent demanding symbol:"+metals + "nstime:"+ns[index].time);
-
-         if((StringFind(sym,ns[index].country,0)!=-1) || ((metals=="wticrude." || metals=="usoil" || metals=="crude"  || metals=="crude" || metals=="usousd" || metals=="wticousd"  || (StringFind(metals,"nymex",0)!=-1) || (StringFind(metals,"WTICrude",0)!=-1) || (StringFind(metals,extraSymbol,0)!=-1)) &&((StringFind("USD",ns[index].country,0)!=-1) || (StringFind("CAD",ns[index].country,0)!=-1))))
-           {
-            //  Print("Inside the currency:"+index+ " currency"+ns[index].country+ " and curent demanding symbol:"+metals + "nstime:"+ns[index].time);
-
-            //     int low_time;
-            //    int high_time;
-            datetime ulow_time,uhigh_time;
-
-            //    int time_in_seconds;
-            datetime utime_in_seconds;
-            //this is the current broker time
-            //     time_in_seconds=(TimeHour(iTime(symbol,0,0))*60*60)+(TimeMinute(iTime(symbol,0,0))*60);
-            //  Print("nsDate:"+ns[index].date);
-            utime_in_seconds=TimeCurrent();
-
-            string chngdt=changeDateFormate(ns[index].date);
-            //     string Date1=TimeToStr(TimeCurrent(),TIME_DATE);
-
-            datetime updatedDateTime=StringToTime(chngdt+" 00:00:00");
-            updatedDateTime+=NsTimeInSeconds(ns[index].time);
-
-            //   Print("updateTime1+nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
-
-            //  string updatedTime=TimeToStr(updatedDateTime,TIME_MINUTES);
-            updatedDateTime+=((gmt)*3600);
-
-            //  Print("updateTime 2 +nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
-            //     string Today1=TimeToStr(updatedDateTime,TIME_DATE);
-
-            //   string times=Time24Conversion(ns[index].time);
-            datetime temp2;
-            temp2=updatedDateTime;
-            // Print("chngDate:"+chngdt);
-            //  Print("Time in Seconds:"+time_in_seconds);
-            //  Print("temp2:"+temp2);
-            // Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
-
-            if(ns[index].impact=="High" && highFlag)
-              {
-
-               //  low_time=NsTimeInSeconds(ns[index].time)-(high_impact_value*60);
-               //high_time=NsTimeInSeconds(ns[index].time)+(end_impact_value*60);
-               ulow_time=updatedDateTime-(high_impact_value*60);
-               uhigh_time=updatedDateTime+(end_impact_value*60);
-               //    Print("High least:"+low_time+" high highest:"+high_time);
-               //     Print("Date1:"+Date1+" today1:"+Today1);
-               //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-               //  Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
-
-               //  Print("----------HighNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
-               if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-                 {
-
-                  //flag=true;
-                  newsStatus=1;
-                  if(temp2!=previous_time)
-                    {
-                     if(show_high_line==true)
-                       {
-                        Print("Inside high alert");
-                        datetime lineTime=TimeCurrent();
-                        if(sl==0)
-                           lineTime=updatedDateTime;
-
-                        ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
-                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
-
-                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrRed);
-                        ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
-                       }
-                     previous_time=temp2;
-                    }
-
-                  break;
-                 }
-              }
-
-            //medium impact
-            else
-               if(ns[index].impact=="Medium" && mediumFlag)
-                 {
-                  // low_time=NsTimeInSeconds(ns[index].time)-(medium_impact_high*60);
-                  // high_time=NsTimeInSeconds(ns[index].time)+(medium_impact_high*60);
-                  ulow_time=updatedDateTime-(medium_impact_high*60);
-                  uhigh_time=updatedDateTime+(medium_impact_low*60);
-
-                  // Print("medium least:"+low_time+" medium highest:"+high_time);
-                  //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-
-                  //  Print("----------MediumNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
-
-                  if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-
-                    {
-                     //StopTrading(); //Close Current Orders Buy/Sell
-                     // flag=true;
-                     //     Print("Inside high alert");
-                     newsStatus=2;
-                     if(temp2!=previous_time)
-                       {
-                        if(show_medium_line==true)
-                          {
-                           datetime lineTime=TimeCurrent();
-                           if(sl==0)
-                              lineTime=updatedDateTime;
-
-                           ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
-                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
-
-                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrGreen);
-                           ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
-
-                          }
-                        previous_time=temp2;
-                       }
-                     break;
-                    }
-                 }
-               else
-                  if(ns[index].impact=="Low" && lowFlag)
-                    {
-                     ///    low_time=NsTimeInSeconds(ns[index].time)-(low_impact_high*60);
-                     //   high_time=NsTimeInSeconds(ns[index].time)+(low_impact_high*60);
-                     //Print("low least:"+low_time+" low highest:"+high_time);
-                     //   Print("In low impact and currency is:"+ns[index].country);
-                     ulow_time=updatedDateTime-(low_impact_high*60);
-                     uhigh_time=(updatedDateTime)+(low_impact_low*60);
-
-                     // if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-
-                     //    Print("-------Low news Now dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);//+" low time in min:"+low_impact_low);
-
-                     if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-
-                       {
-                        //StopTrading(); //Close Current Orders Buy/Sell
-                        // flag=true;
-                        //    Print("Inside high alert");
-                        //  Print("updateDateTime:"+updatedDateTime);
-                        newsStatus=3;
-                        // Print("Temp2"+temp2);
-                        if(temp2!=previous_time)
-                          {
-                           if(show_low_line==true)
-                             {
-                              datetime lineTime=TimeCurrent();
-                              if(sl==0)
-                                 lineTime=updatedDateTime;
-
-                              //  Print("s1:"+sl+ " lineTime:"+lineTime );
-                              //  Print("nsDate:"+ns[index].date+" nstime:"+ns[index].time+ "Sym:"+ns[index].country );
-                              ObjectCreate(0,"VLine"+TimeToString(lineTime),OBJ_VLINE,0,lineTime,0);
-                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_STYLE,STYLE_DOT);
-
-                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_COLOR,clrBlue);
-                              ObjectSetInteger(0,"VLine"+TimeToString(lineTime),OBJPROP_WIDTH,1);
-
-                             }
-                           previous_time=temp2;
-                          }
-                        break;
-                       }
-                    }
-            //
-           }//Close Country Symbol if
-         index++;
-        }
-
-     }
-   else
-     {
-      //  Print("exprtName:"+chkexpert+"stringfind:"+IntegerToString((StringFind(chkexpert,"FX Ekspert Ghost Trader"))));
-      Print("Validation Error");
-     }
-   return newsStatus;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-string AlphaNumeric(string istr)
-  {
-   string other="Aa";
-   string ostr = "";
-   for(int i=0; i<StringLen(istr); i++)
-     {
-      string s=StringSubstr(istr,i,1);
-      if((s>="A" && s<="Z" && StringFind(other,"A")>=0)
-         || (s >= "a" && s <= "z" && StringFind(other,"a") >= 0)
-         || (s >= "0" && s <= "9" && StringFind(other,"1") >= 0)
-         || (s==":")
-         || (s=="-")
-         || (s=="0")
-         || (s=="1")
-         || (s=="2")
-         || (s=="3")
-         || (s=="4")
-         || (s=="5")
-         || (s=="6")
-         || (s=="7")
-         || (s=="8")
-         || (s=="9")
-         || StringFind(other,s)>=0)
-         ostr=ostr+s;
-     }
-   return(ostr);
-  }
-//+------------------------------------------------------------------+
-//| ChartEvent function                                              |
-//+------------------------------------------------------------------+
-
-//+------------------------------------------------------------------+
-void fillNewsStruct()
-  {
-   int file_handle=FileOpen(fileName,FILE_READ|FILE_ANSI);
-
-   if(file_handle!=INVALID_HANDLE)
-     {
-      PrintFormat("%s file is available for reading",fileName);
-      //PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
-      //--- additional variables
-      int    str_size;
-      string str ;
-      //--- read data from the file
-      int n=0;
-      Print("n:",n);
-      while(!FileIsEnding(file_handle))
-        {
-
-         // Print("n:",n);
-         //--- find out how many symbols are used for writing the time
-
-         str_size=FileReadInteger(file_handle,INT_VALUE);
-         Print("size:",str_size);
-
-         //--- read the string
-         str=FileReadString(file_handle,str_size);
-         Print("Printing what is inside the n :",str);
-
-         if(StringFind(str,"<title>",0)!=-1)
-           {
-            StringReplace(str,"<title>","");
-            StringReplace(str,"</title>","");
-            str=AlphaNumeric(str);
-            ns[n].title=str;
-            //Print("title ",ns[n].title);
-           }
-         else
-            if(StringFind(str,"<country>",0)!=-1)
-              {
-               StringReplace(str,"<country>","");
-               StringReplace(str,"</country>","");
-               str=AlphaNumeric(str);
-               ns[n].country=str;
-               //Print("country ",ns[n].country);
-
-              }
-            else
-               if(StringFind(str,"<date>",0)!=-1)
-                 {
-                  StringReplace(str,"<date>","");
-                  StringReplace(str,"</date>","");
-                  StringReplace(str,"CDATA","");
-                  str=AlphaNumeric(str);
-                  ns[n].date=str;
-                  // Print("date ",ns[n].date);
-                 }
-               else
-                  if(StringFind(str,"<time>",0)!=-1)
-                    {
-                     StringReplace(str,"<time>","");
-                     StringReplace(str,"</time>","");
-                     StringReplace(str,"CDATA","");
-                     str=AlphaNumeric(str);
-                     ns[n].time=str;
-                     //  Print("time ",ns[n].time);
-                    }
-                  else
-                     if(StringFind(str,"<impact>",0)!=-1)
-                       {
-                        StringReplace(str,"<impact>","");
-                        StringReplace(str,"</impact>","");
-                        StringReplace(str,"CDATA","");
-                        str=AlphaNumeric(str);
-                        ns[n].impact=str;
-                        //   Print("impact ",ns[n].impact);
-
-                        n++;
-                       }
-         //--- print the string
-         //   PrintFormat(str);
-
-        }
-      //--- close the file
-      FileClose(file_handle);
-      PrintFormat("Data is read, %s file is closed",fileName);
-     }
-   else
-      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError());
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void updateNews()
-  {
-   string cookie=NULL,strNews;
-   string reqheaders="User-Agent: Mozilla/4.0\r\n";
-   char post[],result[];
-   int res;
-//http://www.forexfactory.com/ffcal_week_this.xml
-   string url="https://cdn-nfs.faireconomy.media/ff_calendar_thisweek.xml";
-   url="https://nfs.faireconomy.media/ff_calendar_thisweek.xml";
-   ResetLastError();
-   int timeout=5000;
-//res=WebRequest("GET",url,reqheaders,timeout,post,result,headers);
-   res=InternetGetFile(url,strNews);
-
-   StringToCharArray(strNews,result);
-   if(res==-1)
-     {
-      Print("Error in WebRequest. Error code  =",GetLastError());
-      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
-      MessageBox("Add the address '"+url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
-     }
-   else
-     {
-      //--- Load successfully
-      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
-      //--- Save the data to a file
-      int filehandle=FileOpen(fileName,FILE_WRITE|FILE_BIN);
-      //--- Checking errors
-      if(filehandle!=INVALID_HANDLE)
-        {
-         //--- Save the contents of the result[] array to a file
-         FileWriteArray(filehandle,result,0,ArraySize(result));
-         //--- Close the file
-         FileClose(filehandle);
-        }
-      else
-         Print("Error in FileOpen. Error code=",GetLastError());
-     }
-
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int NsTimeInSeconds(string str)
-  {
-   int temp=0;
-   datetime temp0=StringToTime(str);
-   int _hour=TimeHourMQL4(temp0);
-   int _minute=TimeMinuteMQL4(temp0);
-   if(str[StringLen(str)-2]=='p' && _hour!=12)
-     {
-
-      _hour=_hour+12;
-
-     }
-   if((str[StringLen(str)-2]=='a') && _hour==12)
-      _hour=0;
-   temp=temp+(_hour*3600);
-   temp=temp+(_minute*60);
-   return temp;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-string Time24Conversion(string time)
-  {
-   string hour,t_mode,min;
-   int count=0;
-   bool fl=false;
-   for(int i=0; i<StringLen(time); i++)
-     {
-      if(count==0 && (StringSubstr(time,i,1)!=":"))
-         hour=hour+StringSubstr(time,i,1);
-      else
-         if(StringSubstr(time,i,1)==":")
-           {
-            count++;
-            i++;
-           }
-      if(count==1 && (StringSubstr(time,i,1)!="a" && StringSubstr(time,i,1)!="p" && StringSubstr(time,i,1)!="m"))
-         min=min+StringSubstr(time,i,1);
-      if(StringSubstr(time,i,1)=="a")
-         t_mode="a";
-      else
-         if(StringSubstr(time,i,1)=="p")
-            t_mode="p";
-     }
-   long h=StringToInteger(hour);
-   if(t_mode=="p")
-      h=h+12;
-   string final_time=IntegerToString(h)+":"+min;
-   return final_time;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-string changeDateFormate(string date)
-  {
-
-   string str[],result="";
-   StringSplit(date,'-',str);
-// Print("Str0:"+str[0]+" str1:"+str[1]+" str2:"+str[2]);
-   result=str[2]+"."+str[0]+"."+str[1];
-// Print("result:"+result);
-   return result;
-
-  }
-//+------------------------------------------------------------------+
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-datetime NsDate(string str)
-  {
-   string month=StringSubstr(str,0,2);
-   string day=StringSubstr(str,3,2);
-   string year = StringSubstr(str,6,4);
-   string date = year+"."+month+"."+day;
-   datetime date_time=StringToTime(date);
-   return date_time;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-datetime NsDateTime(string date,string time)
-  {
-   datetime t1 = NsDate(date);
-   datetime t2 = NsTimeInSeconds(time);
-   datetime t3 = t1+t2;
-   return t3;
-  }
-//+------------------------------------------------------------------+
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-bool Validate() export
-  {
-//      if(MQLInfoString(MQL_PROGRAM_NAME)=="AProxAlert")
-
-   string chkexpert=MQLInfoString(MQL_PROGRAM_NAME);
-//Print("Calling Expert: ",chkexpert);
-   StringToLower(chkexpert);
-   if((StringFind(chkexpert,matchExpert)!=-1) || chkexpert=="news" || (StringFind(chkexpert,matchExpert2)!=-1))
-     {
-      // Print("Calling Expert: ",chkexpert);
-      //string  content;
-      // string request="http://www.verifymysystem.com/";
-      // InternetGetFile(request,content);
-      return true;
-     }
-   return false;
-  }
-//+------------------------------------------------------------------+
-//+------------------------------------------------------------------+
-//+ Main function which returns Windows error code                   +
-//+------------------------------------------------------------------+
-int InternetGetFile(string url,string &content)
-  {
-//--- Init
-   content=NULL;
-
-//--- Create connection
-   int httpconnect=0;
-   int httprequest=0;
-   int httpopen=Wininet::InternetOpenW("InternetGetFileMQL",0," "," ",0);
-   int e=kernel32::GetLastError();
-   if(e==0)
-     {
-      bool flag=Wininet::DeleteUrlCacheEntryW(url);
-      httprequest=Wininet::InternetOpenUrlW(httpopen,url,NULL,0,16|10,0);
-      e=kernel32::GetLastError();
-      if(e==0)
-        {
-         //--- Define buffers
-         uchar ch[512];
-         string temp="";
-
-         //--- Retrieve data from file
-         int cnt=0;
-         while(Wininet::InternetReadFile(httprequest,ch,512,cnt))
-           {
-            //e=kernel32::GetLastError();
-            if(cnt<=0)
-               break;
-            temp=temp+CharArrayToString(ch,0,cnt);
-           }
-         //--- Store result
-         content=temp;
-        }
-     }
-
-//--- Close connection
-   if(httprequest>0)
-      InternetCloseHandle(httprequest);
-   if(httpopen>0)
-      InternetCloseHandle(httpopen);
-
-//--- Get out and return error code
-   return(e);
-  }
-//+------------------------------------------------------------------+
-//+ Macro function which returns content directly                    +
-//+------------------------------------------------------------------+
-string InternetGetFile(string url)
-  {
-   string content=NULL;
-   int e=InternetGetFile(url,content);
-   return content;
-  }
-//+------------------------------------------------------------------+
-void closeTrades(ENUM_POSITION_TYPE type,int magic)
-  {
-   Print("in close trade function : ",PositionsTotal());
-   for(int i=PositionsTotal()-1; i>=0; i--)
-     {
-      ulong ticket = PositionGetTicket(i);
-      string symbol=PositionGetSymbol(i);
-      Print("ticket ",ticket," Symbol : ",symbol);
-
-      if(PositionSelectByTicket(ticket))
-        {
-         Print("1");
-         if(PositionGetString(POSITION_SYMBOL)==symbol  && PositionGetInteger(POSITION_MAGIC) == magic && PositionGetInteger(POSITION_TYPE)==type)
-           {
-            Print("2");
-            if((PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)||(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL))
-              {
-               if(!trade.PositionClose(ticket))
-                 {
-                  Print("Problem in closing order buy", GetLastError());
-                 }
-               else
-                 {
-                  Print("Buy Order closed");
-                 }
-              }
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//+------------------------------------------------------------------+
-int orderCount(ENUM_POSITION_TYPE type,int magic_no)
-  {
-   int count=0;
-   for(int i=0; i<PositionsTotal(); i++)
-     {
-      ulong ticket = PositionGetTicket(i);
-      PositionSelectByTicket(ticket);
-      if(PositionGetInteger(POSITION_MAGIC)== magic_no && PositionGetSymbol(POSITION_SYMBOL)==Symbol() &&  PositionGetInteger(POSITION_TYPE) == type)
-        {
-         count++;
-        }
-     }
-// Print("Order count" + count);
-   return count;
-  }
-//+-----------
-//+------------------------------------------------------------------+
-void deleteFileNews()export
-  {
-   if(FileIsExist(fileName))
-      if(FileDelete(fileName))
-        {
-         Print("File:"+fileName+" deleted");
-        }
-
-  }
-//+------------------------------------------------------------------+
-string returnUpCommingNews(bool highFlag=true,
-                           int high_impact_value=60//Stop Trade before high News (min)
-                                 ,int end_impact_value=15 //Stop Trade after high News (min)
-
-                           ,bool mediumFlag=true
-                           ,int medium_impact_high=60//Stop Trade before medium News (min)
-                           ,int medium_impact_low=15 //Stop Trade after medium News (min)
-                           ,bool lowFlag=true
-                           ,int low_impact_high=60//Stop Trade before low News (min)
-                           ,int low_impact_low=15 //Stop Trade after low News (min)
-
-                           ,string symbol=""
-                           ,string expertname=""
-                           ,int gmt=2
-
-                          ) export
-  {
-   int newsStatus=0;
-   string content="No News";
-//Print("TImeCurrent:"+TimeCurrent()+"expiry:"+expiry);
-//"Trend Gridder(22)" || expertname=="TG NEWS" || expertname=="TG News"
-//"tylergabor"
-//((  expertname=="TG NEWS" || expertname=="TG News" || expertname=="Bandit" || expertname=="BANDIT" || expertname=="bandit" || expertname=="TG NEWS" || expertname=="TG News" || expertname=="C-Storm" || expertname=="C-STORM" || expertname=="c-storm" || (expertname=="C-StormV1.1" || (StringFind(chkexpert,"tyler")!=-1) || (StringFind(chkexpert,"hullincash")!=-1) ||(StringFind(chkexpert,"pk5000")!=-1) )))// && TimeCurrent()<expiry)
-
-// string chkexpert=expertname;
-// StringToLower(chkexpert);
-   if(Validate())
-     {
-
-      if(TimeDayMQL4(TimeCurrent())!=TimeDayMQL4(lastNews))
-        {
-         //updateNews();
-         fillNewsStruct();
-         lastNews=TimeCurrent();
-         Print("News Function is calling and updating by "+symbol);
-        }
-      int index=0;
-      string sym=symbol;
-      string metals=sym;
-      StringToLower(metals);
-      // StringToLower(extraSymbol);
-      //Print("---------------------Metals:"+metals+ " and symbol:"+ns[index].country," and extraSymbol:",extraSymbol);
-      //Print("checking metal:"+(StringFind("Nymex-J",sym,0)!=-1) +" and metal is:"+sym );
-      //Print("country:"+ns[index].country+" and check "+StringFind("JPYAUD",ns[index].country,0)!=-1))
-      //Start working here
-      while(index<newsSize)
-        {
-         Print("Inside the currency:",index, " currency:",ns[index].country," and curent demanding symbol:",metals, " nstime:",ns[index].time);
-
-         if((StringFind(sym,ns[index].country,0)!=-1))// || ((metals=="wticrude." || metals=="usoil" || metals=="crude"  || metals=="crude" || metals=="usousd" || metals=="wticousd"  || (StringFind(metals,"nymex",0)!=-1) || (StringFind(metals,"WTICrude",0)!=-1) || (StringFind(metals,extraSymbol,0)!=-1)) &&((StringFind("USD",ns[index].country,0)!=-1) || (StringFind("CAD",ns[index].country,0)!=-1))))
-           {
-            Print("Inside the currency:",index, " currency",ns[index].country, " and curent demanding symbol:",metals, "nstime:",ns[index].time);
-
-            //     int low_time;
-            //    int high_time;
-            datetime ulow_time,uhigh_time;
-
-            //    int time_in_seconds;
-            datetime utime_in_seconds;
-            //this is the current broker time
-            //     time_in_seconds=(TimeHour(iTime(symbol,0,0))*60*60)+(TimeMinute(iTime(symbol,0,0))*60);
-            //  Print("nsDate:"+ns[index].date);
-            utime_in_seconds=TimeCurrent();
-
-            string chngdt=changeDateFormate(ns[index].date);
-            //     string Date1=TimeToString(TimeCurrent(),TIME_DATE);
-
-            datetime updatedDateTime=StringToTime(chngdt+" 00:00:00");
-            updatedDateTime+=NsTimeInSeconds(ns[index].time);
-
-            //   Print("updateTime1+nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
-
-            //  string updatedTime=TimeToString(updatedDateTime,TIME_MINUTES);
-            updatedDateTime+=((gmt)*3600);
-
-            //  Print("updateTime 2 +nsTime:"+updatedDateTime+ "currency:"+ns[index].country);
-            //     string Today1=TimeToString(updatedDateTime,TIME_DATE);
-
-            //   string times=Time24Conversion(ns[index].time);
-            datetime temp2;
-            temp2=updatedDateTime;
-            // Print("chngDate:"+chngdt);
-            //  Print("Time in Seconds:"+time_in_seconds);
-            //  Print("temp2:"+temp2);
-            Print("------------Index:",index," updated Date Time:",updatedDateTime);
-
-            if(ns[index].impact=="High" && highFlag)
-              {
-
-               //  low_time=NsTimeInSeconds(ns[index].time)-(high_impact_value*60);
-               //high_time=NsTimeInSeconds(ns[index].time)+(end_impact_value*60);
-               ulow_time=updatedDateTime-(high_impact_value*60);
-               uhigh_time=updatedDateTime+(end_impact_value*60);
-               //    Print("High least:"+low_time+" high highest:"+high_time);
-               //     Print("Date1:"+Date1+" today1:"+Today1);
-               //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-               //  Print("------------Index:"+index+" updated Date Time:"+updatedDateTime);
-
-               //  Print("----------HighNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
-               if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-                 {
-
-                  //flag=true;
-                  newsStatus=1;
-                  if(temp2!=previous_time)
-                    {
-
-                     Print("Inside high alert");
-
-                     content=ns[index].title;
-
-
-                     previous_time=temp2;
-                    }
-
-                  break;
-                 }
-              }
-
-            //medium impact
-            else
-               if(ns[index].impact=="Medium" && mediumFlag)
-                 {
-                  // low_time=NsTimeInSeconds(ns[index].time)-(medium_impact_high*60);
-                  // high_time=NsTimeInSeconds(ns[index].time)+(medium_impact_high*60);
-                  ulow_time=updatedDateTime-(medium_impact_high*60);
-                  uhigh_time=updatedDateTime+(medium_impact_low*60);
-
-                  // Print("medium least:"+low_time+" medium highest:"+high_time);
-                  //  if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-
-                  //  Print("----------MediumNews dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);
-
-                  if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-
-                    {
-                     //StopTrading(); //Close Current Orders Buy/Sell
-                     // flag=true;
-                     //     Print("Inside high alert");
-                     newsStatus=2;
-                     if(temp2!=previous_time)
-                       {
-
-                        content=ns[index].title;
-
-
-                        previous_time=temp2;
-                       }
-                     break;
-                    }
-                 }
-               else
-                  if(ns[index].impact=="Low" && lowFlag)
-                    {
-                     ///    low_time=NsTimeInSeconds(ns[index].time)-(low_impact_high*60);
-                     //   high_time=NsTimeInSeconds(ns[index].time)+(low_impact_high*60);
-                     //Print("low least:"+low_time+" low highest:"+high_time);
-                     //   Print("In low impact and currency is:"+ns[index].country);
-                     ulow_time=updatedDateTime-(low_impact_high*60);
-                     uhigh_time=(updatedDateTime)+(low_impact_low*60);
-
-                     // if(Date1==Today1 && (time_in_seconds>=low_time && time_in_seconds<=high_time))
-
-                     //    Print("-------Low news Now dateTime:"+utime_in_seconds+" lowOfNews:"+ulow_time+" highOfnews:"+uhigh_time);//+" low time in min:"+low_impact_low);
-
-                     if(utime_in_seconds>=ulow_time && utime_in_seconds<=uhigh_time)
-
-                       {
-                        //StopTrading(); //Close Current Orders Buy/Sell
-                        // flag=true;
-                        //    Print("Inside high alert");
-                        //  Print("updateDateTime:"+updatedDateTime);
-                        newsStatus=3;
-                        // Print("Temp2"+temp2);
-                        if(temp2!=previous_time)
-                          {
-                           content=ns[index].title;
-
-                           previous_time=temp2;
-                          }
-                        break;
-                       }
-                    }
-            //
-           }//Close Country Symbol if
-         index++;
-        }
-
-     }
-   else
-     {
-      //  Print("exprtName:"+chkexpert+"stringfind:"+IntegerToString((StringFind(chkexpert,"FX Ekspert Ghost Trader"))));
-      Print("Validation Error");
-     }
-   return content;
-  }
-//+------------------------------------------------------------------+
-int TimeDayMQL4(datetime date)
-  {
-   MqlDateTime tm;
-   TimeToStruct(date,tm);
-   return(tm.day);
-  }
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int TimeHourMQL4(datetime date)
-  {
-   MqlDateTime tm;
-   TimeToStruct(date,tm);
-   return(tm.hour);
-  }
-
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int TimeMinuteMQL4(datetime date)
-  {
-   MqlDateTime tm;
-   TimeToStruct(date,tm);
-   return(tm.min);
-  }
-//+------------------------------------------------------------------+

BIN
vol_hedge_strategy_mt5.ex5


+ 0 - 1309
vol_hedge_strategy_mt5.mq5

@@ -1,1309 +0,0 @@
-//+------------------------------------------------------------------+
-//|                                       vol_hedge_strategy_mt5.mq5 |
-//|                                  Copyright 2025, MQL Development |
-//|                                  https://www.mqldevelopment.com/ |
-//+------------------------------------------------------------------+
-#property copyright "Copyright 2025, MQL Development"
-#property link      "https://www.mqldevelopment.com/"
-#property version   "1.00"
-#define MaxOrders 100
-#include <Trade\Trade.mqh>
-CTrade  trade;
-//+------------------------------------------------------------------+
-//| Expert initialization function                                   |
-//+------------------------------------------------------------------+
-enum NewsCloseOrder
-  {
-   CloseAllRunningOrder=0,
-   LetTheOrderRun=1,
-  };
-enum selectLine
-  {
-   LineOnNewsBar =0,
-   LineOnNewsStop=1
-  };
-
-#import "volHedgeNewsFilter.ex5"
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void initiateNews();
-int returnNewsStatus(bool High_Impact_News=true
-                     ,int High_Start_Time=60//Stop Trade before high News (min)
-                     ,int High_Stop_Time=15 //Stop Trade after high News (min)
-                     ,bool show_high_line=true//Show verticle Line when high news comes
-
-                     ,bool Medium_Impact_News=true
-                     ,int Medium_Start_Time=60//Stop Trade before medium News (min)
-                     ,int Medium_Stop_Time=15 //Stop Trade after medium News (min)
-                     ,bool show_medium_line=true//Show verticle Line when medium news comes
-
-                     ,bool Low_Impact_News=true
-                     ,int Low_Start_Time=60//Stop Trade before low News (min)
-                     ,int Low_Stop_Time=15 //Stop Trade after low News (min)
-                     ,bool show_low_line=true//Show verticle Line when low news comes
-
-                     ,string symbol=""
-                     ,string expert=""
-                     ,int GMT_Broker_Time=2
-                     ,selectLine sl=0
-                     ,string extraSymbol=""
-                    );
-void initiateNews();
-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);
-void PrintStructure();
-#import
-
-struct new_trade_store
-  {
-   ulong             buy_ticket;            // Buy Ticket
-   ulong             sell_ticket;           // Sell Ticket
-   string            symbol;                // Symbol
-   double            price;                 // Price
-   double            stop_loss;             // StopLoss
-   double            take_profit;           // TakeProfit
-   datetime          start_time;            // Start time
-   datetime          end_time;              // End Time
-   bool              buy_hit_virtual_sl;    // Buy Hit Virtual StopLoss
-   bool              sell_hit_virtual_sl;   // Sell Hit Virtual StopLoss
-
-                     new_trade_store()
-     {
-      buy_ticket = -1;
-      sell_ticket = -1;
-      price = 0;
-      buy_hit_virtual_sl = false;
-      sell_hit_virtual_sl = false;
-     }
-
-  };
-new_trade_store newTradeStore[MaxOrders];
-
-enum lotcalculator
-  {
-   fix, //Fixed Lot Size
-   rsk, //Risk Percentage
-   dollar, // Risk in Dollars
-  };
-
-sinput       string                  string_0                   = "<><><><><><> General SETTINGS <><><><><><>";   //__
-input        int                     magic_no                   = 333;             // Magic no
-input        bool                    bothHitsSl                 = false;           // Open after Both Hits StopLoss
-input        int                     maxTrades                  = 2;               // Max Concurrent Trades
-input        int                     maxSlippage                = 5;               // Max Slippage
-input        bool                    enableSpreadFilter         = false;           // Enable Spread Filter
-input        double                  maximumSpread              = 10;              // Maximum Spread
-input        string                  dataFileName               = "vol_hedge_data.csv"; // Data File Name
-
-input        string                  string_1                   = "<><><><><><> Lot Management<><><><><><>";   //__
-input        lotcalculator           lot_calculator             = fix;             // Lot Size Option
-input        double                  lot_amount                 = 0.1;             // Lot Size
-input        double                  risk                       = 0.5;             // Risk in Percentage %
-input        double                  dollars                    = 10;              // Risk in GBP
-
-input        string                  string_2                   = "<><><><><><> Time Filter Setting <><><><><><> ";//_
-input        bool                    enableTimeSession          = false;           // Enable Time Session
-input        string                  start_time_session         = "01:00";         // Start Session
-input        string                  end_time_session           = "23:59";         // End Session
-
-input        string                  string_0_2                 = "<><><><><><> Trailing Setting<><><><><><>";   //__
-input        bool                    indivial_trailing          = false;           // Indiviual Trailing
-input        double                  ts_sl                      = 15;              // Trailing Start in Pips
-input        double                  ts                         = 5;               // Trailing Stop in Pips
-
-input        string                  strMA14                    ="<><><><><><> BreakEven Settings <><><><><><>";//_
-input        bool                    UseBreakEven               = false;           // Use Break Even
-input        int                     breakEvenPoints            = 15;              // BreakEven Trigger Pips
-input        int                     breakStopPoint             = 5;               // BreakEven Above OpenPrice Pips
-
-input        string                  news                       = "<><><><><><> News Settings <><><><><><>";         // News
-input        NewsCloseOrder          newsClose                  = CloseAllRunningOrder; // On News Action on Running Orders
-input        bool                    High_Impact_News           = true;                 //High Impact News
-input        int                     High_Start_Time            = 60;                   //Stop Trade before high News (min)
-input        int                     High_Stop_Time             = 15;                   //Stop Trade after high News (min)
-input        bool                    show_high_line             = true;                 //Show verticle Line when high news comes
-input        selectLine              Select_News_Line           = 0;                    //News Line
-input        bool                    mobileAlert                = true;                 //Mobile Alert
-input        bool                    Medium_Impact_News         = false;                // Medium Impact News
-input        int                     Medium_Start_Time          = 60;                   // Stop Trade before medium News (min)
-input        int                     Medium_Stop_Time           = 15;                   // Stop Trade after medium News (min)
-input        bool                    show_medium_line           = false;                // Show vertical Line when medium news comes
-input        bool                    Low_Impact_News            = false;                // Low Impact News
-input        int                     Low_Start_Time             = 60;                   // Stop Trade before low News (min)
-input        int                     Low_Stop_Time              = 15;                   // Stop Trade after low News (min)
-input        bool                    show_low_line              = false;                // Show vertical Line when low news comes
-
-// Global Variables
-static double tickCurrentBid = 0;
-double tickPreviousBid = 0;
-static double tickCurrentAsk = 0;
-double tickPreviousAsk = 0;
-datetime startSessionTime, endSessionTime;
-int GMT_Broker_Time = +2; // GMT_Broker_Time Time of your Broker
-int                     gmt                        = 0;                   // GMT_Broker_Time Time of your Broker
-string Lname="newsLabel3";
-double levelsAre[];
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int OnInit()
-  {
-//---
-   Print(" OnInIt. ");
-   trade.SetExpertMagicNumber(magic_no);
-   trade.SetDeviationInPoints(maxSlippage);
-   trade.SetTypeFilling(ORDER_FILLING_IOC);
-   trade.LogLevel(LOG_LEVEL_ALL);
-   trade.SetAsyncMode(false);
-
-   if(!MQLInfoInteger(MQL_TESTER))
-     {
-      loadNewTradeStoreFile();
-     }
-
-   int filehandle = FileOpen(dataFileName, FILE_READ | FILE_CSV | FILE_COMMON | FILE_ANSI);
-   if(filehandle != INVALID_HANDLE)
-     {
-      Print(" Valid Handler. ");
-      while(!FileIsEnding(filehandle))
-        {
-         string orderToRead = FileReadString(filehandle);
-         string orderData[];
-         //Print("Data: ", OrderToRead);
-         StringSplit(orderToRead, StringGetCharacter(",",0), orderData);
-         Print("Array Size: ", ArraySize(orderData));
-         Print(" Order is: ", orderToRead);
-         for(int i = 0 ; i < ArraySize(orderData) ; i++)
-           {
-            Print(" Order Data: ", orderData[i], " i: ", i);
-           }
-
-         if(ArraySize(orderData) >= 6)
-           {
-            if(orderData[0] == Symbol())
-              {
-               // store into local variables first (trim if needed)
-               ulong  buy_ticket_local  = (ulong)-1; // keep -1 as per your convention
-               ulong  sell_ticket_local = (ulong)-1;
-               string symbol_local      = orderData[0];
-               double price_local       = StringToDouble(orderData[1]);
-               double sl_local          = StringToDouble(orderData[2]);
-               double tp_local          = StringToDouble(orderData[3]);
-               // if your CSV has extra fields (tp2,tp3, etc.) parse here as needed
-               datetime start_local     = StringToTime(orderData[4]);
-               datetime end_local       = StringToTime(orderData[5]);
-
-               ArrayResize(levelsAre,ArraySize(levelsAre)+1);
-               levelsAre[ArraySize(levelsAre) - 1] = price_local;
-
-               // OPTIONAL: only add when price == 0:
-               // if(MathAbs(price_local) > 1e-9) { Print("Skipped: price != 0"); continue; }
-               bool buy_virtual_tp_hit = true;
-               bool sell_virtual_tp_hit = true;
-               if(bothHitsSl)
-                 {
-                  buy_virtual_tp_hit = false;
-                  sell_virtual_tp_hit = false;
-                 }
-
-               // call the single-responsibility function that writes into struct array
-               if(!level_present(price_local))
-                 {
-                  addToNewTradeStore(buy_ticket_local, sell_ticket_local,
-                                     symbol_local, price_local,
-                                     sl_local, tp_local,
-                                     start_local, end_local,
-                                     buy_virtual_tp_hit, sell_virtual_tp_hit);
-                 }
-               else
-                 {
-                  Print("Level is already Present. Level: ", price_local);
-                 }
-              }
-           }
-        }
-      FileClose(filehandle);
-     }
-   else
-     {
-      Print(" InValid Handler. Error: ", GetLastError());
-     }
-
-   struct_level_check();
-
-   timeFilter(true,start_time_session, end_time_session, startSessionTime, endSessionTime);
-   Print(" Session Start  = ", startSessionTime,  " Asian  Session End = ", endSessionTime);
-
-   int timeDifference = (int)TimeCurrent() - (int)TimeGMT();
-   Print("Time Difference is: ", timeDifference);
-
-   if(timeDifference > 0)
-     {
-      GMT_Broker_Time = (int)MathRound((double)timeDifference / 3600.0);
-     }
-   else
-      if(timeDifference < 0)
-        {
-         GMT_Broker_Time = (int)MathRound((double)timeDifference / 3600.0);
-        }
-      else // timeDifference == 0
-        {
-         GMT_Broker_Time = 0;
-        }
-
-   Print("Gmt Time: ", TimeGMT(), " Broker Gmt Time: ", GMT_Broker_Time);
-   gmt = GMT_Broker_Time;
-
-   if(!MQLInfoInteger(MQL_TESTER))
-     {
-      initiateNews(); // change here
-     }
-
-//---
-   return(INIT_SUCCEEDED);
-  }
-//+------------------------------------------------------------------+
-//| Expert deinitialization function                                 |
-//+------------------------------------------------------------------+
-void OnDeinit(const int reason)
-  {
-//---
-   if(!MQLInfoInteger(MQL_TESTER))
-     {
-      saveNewTradeStoreFile();
-     }
-  }
-//+------------------------------------------------------------------+
-//| Expert tick function                                             |
-//+------------------------------------------------------------------+
-void OnTick()
-  {
-   static int status=-1,preStatus=-1;
-   if(!MQLInfoInteger(MQL_TESTER))
-     {
-      status=returnNewsStatus(High_Impact_News
-                              ,High_Start_Time
-                              ,High_Stop_Time
-
-                              ,show_high_line
-                              ,Medium_Impact_News
-                              ,Medium_Start_Time
-                              ,Medium_Stop_Time
-
-                              ,show_medium_line
-                              ,Low_Impact_News
-                              ,Low_Start_Time
-                              ,Low_Stop_Time
-
-                              ,show_low_line
-                              ,Symbol()
-                              ,MQLInfoString(MQL_PROGRAM_NAME)
-                              ,GMT_Broker_Time
-                              ,Select_News_Line
-                              ,""
-                             );
-     }
-   else
-      status=0;
-
-   if(status==0)
-     {
-      mainActivity();
-     }
-   if(status==1 || status==2 || status==3)
-     {
-      if(newsClose==0)
-        {
-         if(orderCount_1(POSITION_TYPE_BUY,magic_no)>0)
-            closeTrades(POSITION_TYPE_BUY,magic_no);
-         if(orderCount_1(POSITION_TYPE_SELL,magic_no)>0)
-            closeTrades(POSITION_TYPE_SELL,magic_no);
-        }
-      else
-         if(newsClose==1)
-           {
-            if((orderCount_1(POSITION_TYPE_BUY,magic_no)>0) || (orderCount_1(POSITION_TYPE_SELL,magic_no)>0))
-              {
-               mainActivity();
-              }
-           }
-
-     }
-   if(status!=preStatus)
-     {
-      if(status==0 && preStatus!=-1)
-        {
-         // if(ObjectFind(0,Lname))
-           {
-
-            // ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
-            ObjectSetString(0,Lname,OBJPROP_TEXT,"");
-           }
-         Alert("Trading is start");
-         if(mobileAlert)
-            SendNotification("Trading is start");
-
-         preStatus=status;
-        }
-      else
-         if(status==1)
-           {
-            ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
-            ObjectSetString(0,Lname,OBJPROP_TEXT,"High Impact News");
-            Alert("Trading Stop due to high impact news");
-
-            if(mobileAlert)
-               SendNotification("Trading Stop due to high impact news");
-
-            preStatus=status;
-           }
-         else
-            if(status==2)
-              {
-               ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrBlue);
-               ObjectSetString(0,Lname,OBJPROP_TEXT,"Medium Impact News");
-               Alert("Trading Stop due to medium impact news");
-
-               if(mobileAlert)
-                  SendNotification("Trading Stop due to medium impact news");
-
-               preStatus=status;
-              }
-            else
-               if(status==3)
-                 {
-                  ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrGreen);
-                  ObjectSetString(0,Lname,OBJPROP_TEXT,"Low Impact News");
-                  Alert("Trading Stop due to low impact news");
-
-                  if(mobileAlert)
-                     SendNotification("Trading Stop due to low impact news");
-
-                  preStatus=status;
-                 }
-     }
-   else
-     {
-      mainActivity();
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void mainActivity()
-  {
-//---
-   if(indivial_trailing)
-     {
-      Individual_Trailing();
-     }
-   if(UseBreakEven)
-     {
-      breakEven();
-     }
-   double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
-   double Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
-
-   if(tickPreviousBid == 0 && tickCurrentBid == 0)
-     {
-      tickPreviousBid = Bid;
-      tickCurrentBid  = Bid;
-     }
-   else
-     {
-      tickPreviousBid = tickCurrentBid;
-      tickCurrentBid  = Bid;
-     }
-
-   if(tickPreviousAsk == 0 && tickCurrentAsk == 0)
-     {
-      tickPreviousAsk = Ask;
-      tickCurrentAsk  = Ask;
-     }
-   else
-     {
-      tickPreviousAsk = tickCurrentAsk;
-      tickCurrentAsk  = Ask;
-     }
-
-// Print(" Time is: ", TimeCurrent());
-   timeFilter(false,start_time_session, end_time_session, startSessionTime, endSessionTime);
-// Comment(" Session Start  = ", startSessionTime,  " Asian  Session End = ", endSessionTime);
-   if((!enableTimeSession) || (enableTimeSession && TimeCurrent() >= startSessionTime && TimeCurrent() <= endSessionTime))
-     {
-      removeFromStructure();
-      if(bothHitsSl)
-        {
-         virtualSLHitCheck();
-        }
-      tradePlacingCheck();
-     }
-  }
-//+------------------------------------------------------------------+
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void closeTrades(int type,int magicno)
-  {
-   Print("Total order: ",OrdersTotal());
-   for(int i= PositionsTotal()-1; i>=0; i--)
-     {
-      //  Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i,"  OrdersTotal(): ", OrdersTotal());
-      ulong ticket = PositionGetTicket(i);
-      if(PositionSelectByTicket(ticket))
-        {
-         if(PositionGetInteger(POSITION_TYPE) == type)
-           {
-            if(PositionGetInteger(POSITION_MAGIC) == magicno && PositionGetString(POSITION_SYMBOL) == Symbol())
-              {
-               //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
-               if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
-                 {Print("Problem in closing order order ",PositionGetInteger(POSITION_TICKET)); }
-               else
-                 {
-                  Print("Order Closed by closeTrades() new filter",PositionGetInteger(POSITION_TICKET));
-                 }
-              }
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int orderCount_1(int type,int magic)
-  {
-   int count1=0;
-   for(int i= PositionsTotal()-1; i>=0; i--)
-     {
-      //  Print(" Selection: ",OrderSelect(i,SELECT_BY_POS)," i: ",i,"  OrdersTotal(): ", OrdersTotal());
-      ulong ticket = PositionGetTicket(i);
-      if(PositionSelectByTicket(ticket))
-        {
-         //   if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
-         if(PositionGetInteger(POSITION_MAGIC) == magic && PositionGetString(POSITION_SYMBOL) == Symbol())
-           {
-            //trade.PositionClose(PositionGetInteger(POSITION_TICKET))
-            if(PositionGetInteger(POSITION_TYPE) == type)
-              {
-               count1++;
-              }
-           }
-        }
-     }
-   return count1;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int orderCount(int type)
-  {
-   int count = 0;
-   for(int i= PositionsTotal()-1; i>=0; i--)
-     {
-      ulong ticket = PositionGetTicket(i);
-
-      if(PositionSelectByTicket(ticket))
-        {
-         if(PositionGetInteger(POSITION_MAGIC) == magic_no && PositionGetString(POSITION_SYMBOL) == Symbol())
-           {
-            if(PositionGetInteger(POSITION_TYPE) == type)
-              {
-               count++;
-              }
-           }
-        }
-     }
-   return count;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-bool level_present(double priceIs)
-  {
-   for(int i = 0 ; i < MaxOrders ; i++)
-     {
-      if(newTradeStore[i].price > 0)
-        {
-         if(priceIs == newTradeStore[i].price)
-           {
-            return true;
-           }
-        }
-     }
-   return false;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void struct_level_check()
-  {
-   for(int i = 0; i < MaxOrders; i++)
-     {
-      if(newTradeStore[i].price > 0)
-        {
-         bool found = false;
-
-         for(int j = 0; j < ArraySize(levelsAre); j++)
-           {
-            if(newTradeStore[i].price == levelsAre[j])
-              {
-               found = true;
-               break;
-              }
-           }
-
-         if(!found)
-           {
-            Print("Price not found in levelsAre[] -> index:", i, " | price:", newTradeStore[i].price);
-            newTradeStore[i].buy_ticket  = (ulong)-1;
-            newTradeStore[i].sell_ticket = (ulong)-1;
-            bool buy_virtual_tp_hit = true;
-            bool sell_virtual_tp_hit = true;
-            if(bothHitsSl)
-              {
-               buy_virtual_tp_hit = false;
-               sell_virtual_tp_hit = false;
-              }
-            newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
-            newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
-            newTradeStore[i].symbol      = "";
-            newTradeStore[i].price       = 0.0;
-            newTradeStore[i].stop_loss   = 0.0;
-            newTradeStore[i].take_profit = 0.0;
-            newTradeStore[i].start_time  = 0;
-            newTradeStore[i].end_time    = 0;
-            return;
-           }
-        }
-     }
-
-   return;
-  }
-
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void addToNewTradeStore(ulong r_buy_ticket, ulong r_sell_ticket,
-                        string r_symbol, double r_price,
-                        double r_stop_loss, double r_take_profit,
-                        datetime r_start_time, datetime r_end_time, bool r_buy_hit_sl, bool r_sell_hit_sl)
-  {
-   Print(" Tier 1. ");
-   for(int i = 0; i < MaxOrders; i++)
-     {
-      // treat slot as empty when both tickets are -1 (same convention as constructor)
-      if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
-        {
-         if(newTradeStore[i].price == 0)
-           {
-            newTradeStore[i].buy_ticket  = r_buy_ticket;
-            newTradeStore[i].sell_ticket = r_sell_ticket;
-            newTradeStore[i].symbol      = r_symbol;
-            newTradeStore[i].price       = r_price;
-            newTradeStore[i].stop_loss   = r_stop_loss;
-            newTradeStore[i].take_profit = r_take_profit;
-            newTradeStore[i].start_time  = r_start_time;
-            newTradeStore[i].end_time    = r_end_time;
-            newTradeStore[i].buy_hit_virtual_sl = r_buy_hit_sl;
-            newTradeStore[i].sell_hit_virtual_sl = r_sell_hit_sl;
-
-            Print("Stored -> idx: ", i,
-                  " | Symbol: ", newTradeStore[i].symbol,
-                  " | price: ", DoubleToString(newTradeStore[i].price, Digits()),
-                  " | sl: ", DoubleToString(newTradeStore[i].stop_loss, Digits()),
-                  " | tp: ", DoubleToString(newTradeStore[i].take_profit, Digits()),
-                  " | start: ", TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS),
-                  " | end: ", TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS),
-                  " | Buy Virtal Sl Hit: ", newTradeStore[i].buy_hit_virtual_sl,
-                  " | Sell Virtual Sl Hit: ", newTradeStore[i].sell_hit_virtual_sl);
-            break;
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void tradePlacingCheck()
-  {
-   for(int i = 0; i < MaxOrders; i++)
-     {
-      if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
-        {
-         if(newTradeStore[i].price > 0)
-           {
-            if(TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time)
-              {
-               if(newTradeStore[i].buy_hit_virtual_sl == true && newTradeStore[i].sell_hit_virtual_sl == true)
-                 {
-                  double levelPriceIs = newTradeStore[i].price;
-                  if((tickPreviousBid > levelPriceIs && tickCurrentBid < levelPriceIs) ||
-                     (tickPreviousBid < levelPriceIs && tickCurrentBid > levelPriceIs))
-                    {
-                     if(countLiveTrades() < maxTrades)
-                       {
-                        if((enableSpreadFilter && spreadFilter()) || !enableSpreadFilter)
-                          {
-                           ulong buyTicket = placeBuyTrade(newTradeStore[i].stop_loss, newTradeStore[i].take_profit);
-                           ulong sellTicket = placeSellTrade(newTradeStore[i].stop_loss, newTradeStore[i].take_profit);
-
-                           newTradeStore[i].buy_ticket = buyTicket;
-                           newTradeStore[i].sell_ticket = sellTicket;
-                          }
-                       }
-                    }
-                 }
-              }
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-ulong placeBuyTrade(double stoploss, double takeprofit)
-  {
-
-   double buySL = 0, buyTp=0;
-//openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
-   double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
-   double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
-
-   if(stoploss != 0)
-     {
-      buySL = Ask - (stoploss * Point());
-     }
-   if(takeprofit != 0)
-     {
-      buyTp = Ask + (takeprofit * Point());
-     }
-
-   double distance = MathAbs((Ask - buySL) / Point());
-   if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getLot(distance),Ask,buySL,buyTp,"Buy Trade Placed"))
-     {
-      Print("Buy Trade Placed: ",trade.ResultOrder());
-      return trade.ResultOrder();
-     }
-   else
-     {
-      Print("Error in placing Buy: "+Symbol()+"  ",GetLastError());
-      return -1;
-     }
-   return -1;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-ulong placeSellTrade(double stoploss, double takeprofit)
-  {
-
-   double sellSL = 0, sellTp = 0;
-   double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
-   double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
-
-   if(stoploss != 0)
-     {
-      sellSL = Bid + (stoploss * Point());
-     }
-   if(takeprofit != 0)
-     {
-      sellTp = Bid - (takeprofit * Point());
-     }
-   double distance = MathAbs((Bid - sellSL) / Point());
-   if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getLot(distance),Bid,sellSL,sellTp,"Sell Trade Placed"))
-     {
-      Print("Sell Trade PLaced: ",trade.ResultOrder());
-      return trade.ResultOrder();
-     }
-   else
-     {
-      Print("Error in placing Sell: "+Symbol()+"  ",GetLastError());
-      return -1;
-     }
-   return -1;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-double getLot(double stop_loss)
-  {
-   Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
-   Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
-   double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
-                    ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
-// Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
-   double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
-// pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
-// pipvalue=
-   pipvalue = pipvalue / 10;
-   double lotSize = lot_amount;
-   if(lot_calculator == rsk || lot_calculator == dollar) //calculating risk
-     {
-      double riskamount = 0;
-      if(lot_calculator == rsk)
-        {
-         riskamount = (risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
-        }
-      if(lot_calculator == dollar)
-        {
-         riskamount = dollars;
-        }
-      double pipvalue_required=riskamount/stop_loss;
-      lotSize = pipvalue_required/pipvalue;
-      //sl=riskamount/pipValuelot
-      int roundDigit=0;
-      double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
-
-      while(step<1)
-        {
-         roundDigit++;
-         step=step*10;
-        }
-      Print("Round Digits:",roundDigit);
-      lotSize = NormalizeDouble(lotSize,roundDigit);
-      //
-     }
-   Print("Lot Size: ",lotSize);
-
-   if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
-     {
-      lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
-     }
-   else
-      if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
-        {
-         lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
-        }
-
-//---
-   return lotSize;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void timeFilter(bool onInit,string startTime,string endTime,datetime & sessionStart,datetime & sessionEnd)
-  {
-   int newYorkStartHour = 0, newYorkStartMin = 0, newYorkEndHour = 0, newYorkEndMin = 0;
-
-   datetime newYorkStartTrading,newYorkEndTrading;
-
-   string time[];
-   StringSplit(startTime,':',time);
-   newYorkStartHour = (int)StringToInteger(time[0]);
-   newYorkStartMin  = (int)StringToInteger(time[1]);
-
-   EventSetMillisecondTimer(500);
-   time[0] = "";
-   time[1] = "";
-   StringSplit(endTime,':',time);
-   newYorkEndHour = (int)StringToInteger(time[0]);
-   newYorkEndMin  = (int)StringToInteger(time[1]);
-
-// Print(" Start Time Hour: ",newYorkStartHour,"  Start Time Min: ",newYorkStartMin);
-// Print(" End Time Hour: ",newYorkEndHour,"  End Time Min: ",newYorkEndMin);
-
-
-   datetime startDateTime;
-   MqlDateTime st;
-   TimeCurrent(st); // get current date
-   st.hour   = newYorkStartHour;
-   st.min    = newYorkStartMin;
-   st.sec    = 0;
-   startDateTime = StructToTime(st);
-
-
-   datetime endDateTime;
-   MqlDateTime et;
-   TimeCurrent(et); // get current date
-   et.hour   = newYorkEndHour;
-   et.min    = newYorkEndMin;
-   et.sec    = 0;
-   endDateTime = StructToTime(et);
-
-
-   MqlDateTime sdate,edate;
-   datetime start_Time = 0, end_Time = 0;
-   if(startDateTime > endDateTime)
-     {
-      if(onInit)
-        {
-         start_Time = iTime(Symbol(),PERIOD_D1,1);
-         end_Time = iTime(Symbol(),PERIOD_D1,0);
-        }
-      else
-        {
-         start_Time = sessionStart;
-         end_Time = sessionEnd;
-         if(TimeCurrent() >= sessionEnd && sessionEnd != 0)
-           {
-            start_Time = iTime(Symbol(),PERIOD_D1,0);
-            end_Time = start_Time + 86400;
-           }
-        }
-     }
-   else
-     {
-      start_Time = iTime(Symbol(),PERIOD_D1,0);
-      end_Time = iTime(Symbol(),PERIOD_D1,0);
-     }
-
-   if(TimeToStruct(end_Time,edate))
-     {
-      edate.hour = newYorkEndHour;
-      edate.min  = newYorkEndMin;
-      edate.sec  = 0;
-     }
-   else
-      Print("Error in Converting Time: ",GetLastError());
-   newYorkEndTrading = StructToTime(edate);
-
-   if(TimeToStruct(start_Time,sdate))
-     {
-      sdate.hour = newYorkStartHour;
-      sdate.min  = newYorkStartMin;
-      sdate.sec  = 0;
-     }
-   else
-      Print("Error in Converting Time: ",GetLastError());
-   newYorkStartTrading = StructToTime(sdate);
-
-   sessionStart = newYorkStartTrading;
-   sessionEnd   = newYorkEndTrading;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void removeFromStructure()
-  {
-   for(int i = 0 ; i < MaxOrders ; i++)
-     {
-      bool isBuyPresent=false, isSellPresent=false;
-      if(newTradeStore[i].buy_ticket != -1 && newTradeStore[i].sell_ticket != -1)
-        {
-         for(int j = PositionsTotal()-1; j>=0; j--)
-           {
-            ulong ticket = PositionGetTicket(j);
-            if(PositionSelectByTicket(ticket))
-              {
-               if(ticket == newTradeStore[i].buy_ticket)
-                 {
-                  isBuyPresent=true;
-                 }
-              }
-           }
-
-         for(int j = PositionsTotal()-1; j>=0; j--)
-           {
-            ulong ticket = PositionGetTicket(j);
-            if(PositionSelectByTicket(ticket))
-              {
-               if(ticket == newTradeStore[i].sell_ticket)
-                 {
-                  isSellPresent = true;
-                 }
-              }
-           }
-
-         if(!isBuyPresent && !isSellPresent)
-           {
-            Print("Buy/Sell Ticket is closed so removed from struct. Buy Ticket: ", newTradeStore[i].buy_ticket, " Sell Ticket: ", newTradeStore[i].sell_ticket);
-            newTradeStore[i].buy_ticket  = (ulong)-1;
-            newTradeStore[i].sell_ticket = (ulong)-1;
-            bool buy_virtual_tp_hit = true;
-            bool sell_virtual_tp_hit = true;
-            if(bothHitsSl)
-              {
-               buy_virtual_tp_hit = false;
-               sell_virtual_tp_hit = false;
-              }
-            newTradeStore[i].buy_hit_virtual_sl = buy_virtual_tp_hit;
-            newTradeStore[i].sell_hit_virtual_sl = sell_virtual_tp_hit;
-            //newTradeStore[i].symbol      = "";
-            //newTradeStore[i].price       = 0.0;
-            //newTradeStore[i].stop_loss   = 0.0;
-            //newTradeStore[i].take_profit = 0.0;
-            //newTradeStore[i].start_time  = 0;
-            //newTradeStore[i].end_time    = 0;
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void virtualSLHitCheck()
-  {
-   for(int i = 0 ; i < MaxOrders ; i++)
-     {
-      if(newTradeStore[i].buy_ticket == -1 && newTradeStore[i].sell_ticket == -1)
-        {
-         if(TimeCurrent() > newTradeStore[i].start_time && TimeCurrent() < newTradeStore[i].end_time)
-           {
-            double buy_sl = newTradeStore[i].price - (newTradeStore[i].stop_loss * Point());
-            double sell_sl = newTradeStore[i].price + (newTradeStore[i].stop_loss * Point());
-            if(newTradeStore[i].buy_hit_virtual_sl == false)
-              {
-               if((tickPreviousBid < buy_sl && tickCurrentBid > buy_sl))
-                 {
-                  newTradeStore[i].buy_hit_virtual_sl = true;
-                  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());
-                 }
-              }
-            if(newTradeStore[i].sell_hit_virtual_sl == false)
-              {
-               if((tickPreviousAsk > sell_sl && tickCurrentAsk < sell_sl))
-                 {
-                  newTradeStore[i].sell_hit_virtual_sl = true;
-                  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());
-                 }
-              }
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-int countLiveTrades()
-  {
-   int count = 0;
-
-   for(int i = 0; i < PositionsTotal(); i++)
-     {
-      ulong ticket = PositionGetTicket(i);
-      if(PositionSelectByTicket(ticket))
-        {
-         if(PositionGetInteger(POSITION_MAGIC) == magic_no)
-           {
-            if(PositionGetString(POSITION_SYMBOL) == Symbol())
-              {
-               if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY || PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
-                 {
-                  count++;
-                 }
-              }
-           }
-        }
-     }
-   return count;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-bool spreadFilter()
-  {
-   long spreadIs = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
-   if(spreadIs > maximumSpread)
-     {
-      return false;
-     }
-   return true;
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void breakEven()
-  {
-   for(int i = PositionsTotal()-1; i>=0; i--)
-     {
-      ulong ticket = PositionGetTicket(i);
-      string symbol=PositionGetSymbol(i);
-      double mySL = 0,newSL = 0;
-      double SymbolTickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
-      ////Print("ticket ",ticket," Symbol : ",symbol);
-      if(PositionSelectByTicket(ticket))
-        {
-         if(PositionGetString(POSITION_SYMBOL)==Symbol()  && PositionGetInteger(POSITION_MAGIC) == magic_no)
-           {
-            //========================================================Buy Condition=========================================================================
-            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
-              {
-               mySL = PositionGetDouble(POSITION_PRICE_OPEN) + (breakEvenPoints* 10 * SymbolTickSize);
-               if(SymbolInfoDouble(Symbol(),SYMBOL_BID) >= mySL && PositionGetDouble(POSITION_PRICE_OPEN) > PositionGetDouble(POSITION_SL))
-                 {
-                  newSL= PositionGetDouble(POSITION_PRICE_OPEN) + (breakStopPoint* 10 * SymbolTickSize);
-                  if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
-                    {
-
-                     Print("Buy Order BreakEven Successfully ");
-                    }
-                  else
-                    {
-                     Print("Error in BreakEven Buy Position ",GetLastError());
-                    }
-                 }
-              }
-            //=======================================================Sell condition  ===============================================================
-            if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
-              {
-               mySL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakEvenPoints* 10 * SymbolTickSize);
-               if(SymbolInfoDouble(Symbol(),SYMBOL_ASK) <= mySL && PositionGetDouble(POSITION_SL) > PositionGetDouble(POSITION_PRICE_OPEN))
-                 {
-                  newSL = PositionGetDouble(POSITION_PRICE_OPEN) - (breakStopPoint* 10 * SymbolTickSize);
-
-                  if(trade.PositionModify(ticket,newSL,PositionGetDouble(POSITION_TP)))
-                    {
-                     Print("Order Sell BreakEven Successfully ");
-                    }
-                  else
-                    {
-                     Print("Error in BreakEven Sell Position ",GetLastError());
-                    }
-                 }
-              }
-           }
-        }
-
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void Individual_Trailing()
-  {
-   int openedpositions;
-   double mySL,myResult;
-
-   openedpositions=PositionsTotal();
-   if((openedpositions>0))
-     {
-      int totalorders=PositionsTotal();
-      for(int i=0; i<totalorders; i++) // scan all orders and positions. ..
-        {
-         ulong ticket = PositionGetTicket(i);
-         if(PositionSelectByTicket(ticket))
-           {
-            if(PositionGetString(POSITION_SYMBOL)==Symbol()  && PositionGetInteger(POSITION_MAGIC) ==magic_no) // only look if mygrid and symbol. ..
-              {
-
-               double SymbolAsk           = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_ASK);
-               double SymbolBid           = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_BID);
-               int SymbolDigits           = (int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL), SYMBOL_DIGITS);
-               double SymbolTickSize      = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE);
-               int type= (int)PositionGetInteger(POSITION_TYPE);
-
-               if(type==POSITION_TYPE_BUY) // its a long position
-                 {
-                  mySL=NormalizeDouble(SymbolAsk-(ts*SymbolTickSize*10),Digits()); // new SL
-                  double startSl=PositionGetDouble(POSITION_PRICE_OPEN)+(ts_sl*SymbolTickSize*10);
-                  if(PositionGetDouble(POSITION_SL) != mySL)
-                     if(mySL>PositionGetDouble(POSITION_SL) && SymbolAsk>=startSl)
-                       {
-                        myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrGreen);
-                        if(!myResult)
-                          {
-                           Print(" Buy Trade Trailing Error: ",GetLastError());
-                          }
-                       }
-                 }
-               if(type==POSITION_TYPE_SELL)
-                 {
-                  mySL=NormalizeDouble(SymbolBid+(ts*SymbolTickSize*10),Digits()); // new SL
-                  double startSlSell=PositionGetDouble(POSITION_PRICE_OPEN)-(ts_sl*SymbolTickSize*10);
-                  if(PositionGetDouble(POSITION_SL) != mySL)
-                     if(((mySL<PositionGetDouble(POSITION_SL)) || (PositionGetDouble(POSITION_SL)<SymbolTickSize)) && SymbolBid<=startSlSell)
-                       {
-                        myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrRed);
-                        if(!myResult)
-                          {
-                           Print(" Sell Trade Trailing Error: ",GetLastError());
-                          }
-                       }
-                 }
-              }
-           }
-        }
-     }
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void saveNewTradeStoreFile()
-  {
-// don't run in strategy tester
-   if(MQLInfoInteger(MQL_TESTER))
-      return;
-
-   string file_name = "new_trade_store.csv";
-   int fileHandle = FileOpen(file_name,
-                             FILE_WRITE | FILE_CSV | FILE_COMMON |
-                             FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_READ);
-   if(fileHandle == INVALID_HANDLE)
-     {
-      PrintFormat("saveNewTradeStoreFile() -> Cannot open file '%s'. Error: %d", file_name, GetLastError());
-      return;
-     }
-
-// header (optional) - comment out if you don't want header
-//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";
-//FileWriteString(fileHandle, header);
-
-   for(int i = 0; i < MaxOrders; i++)
-     {
-      // decide whether this slot has useful data:
-      // you can tweak this condition as you prefer (symbol != "" is simple)
-      bool slotPopulated = (StringLen(newTradeStore[i].symbol) > 0)
-                           || (newTradeStore[i].price != 0.0)
-                           || (newTradeStore[i].start_time != 0);
-
-      if(!slotPopulated)
-         continue;
-
-      // convert values to strings
-      string buyTicketStr  = IntegerToString((long)newTradeStore[i].buy_ticket);
-      string sellTicketStr = IntegerToString((long)newTradeStore[i].sell_ticket);
-      string priceStr      = DoubleToString(newTradeStore[i].price, _Digits);
-      string slStr         = DoubleToString(newTradeStore[i].stop_loss, _Digits);
-      string tpStr         = DoubleToString(newTradeStore[i].take_profit, _Digits);
-
-      string startTimeStr  = (newTradeStore[i].start_time != 0) ? TimeToString(newTradeStore[i].start_time, TIME_DATE|TIME_SECONDS) : "";
-      string endTimeStr    = (newTradeStore[i].end_time   != 0) ? TimeToString(newTradeStore[i].end_time, TIME_DATE|TIME_SECONDS)   : "";
-
-      string buyHitStr  = ""; // IntegerToString(newTradeStore[i].buy_hit_virtual_sl  ? 1 : 0);
-      string sellHitStr = ""; // IntegerToString(newTradeStore[i].sell_hit_virtual_sl ? 1 : 0);
-
-      if(newTradeStore[i].buy_hit_virtual_sl == true)
-        {
-         buyHitStr = "true";
-        }
-      else
-        {
-         buyHitStr = "false";
-        }
-
-      if(newTradeStore[i].sell_hit_virtual_sl == true)
-        {
-         sellHitStr = "true";
-        }
-      else
-        {
-         sellHitStr = "false";
-        }
-
-      // build CSV line and write
-      string line = buyTicketStr + "," + sellTicketStr + "," +
-                    newTradeStore[i].symbol + "," +
-                    priceStr + "," + slStr + "," + tpStr + "," +
-                    startTimeStr + "," + endTimeStr + "," +
-                    buyHitStr + "," + sellHitStr + "\r\n";
-
-      FileWriteString(fileHandle, line);
-     }
-
-   FileClose(fileHandle);
-   PrintFormat("saveNewTradeStoreFile() -> saved to '%s'.", file_name);
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-void loadNewTradeStoreFile()
-  {
-   if(MQLInfoInteger(MQL_TESTER))
-      return;
-
-   string file_name = "new_trade_store.csv";
-   int fileHandle = FileOpen(file_name,
-                             FILE_READ | FILE_CSV | FILE_COMMON |
-                             FILE_SHARE_READ | FILE_SHARE_WRITE);
-   if(fileHandle == INVALID_HANDLE)
-     {
-      Print("loadNewTradeStoreFile() -> Cannot open file '", file_name, "'. Error: ", GetLastError());
-      return;
-     }
-
-// reset defaults
-   for(int j = 0; j < MaxOrders; j++)
-     {
-      newTradeStore[j].buy_ticket           = (ulong)-1;
-      newTradeStore[j].sell_ticket          = (ulong)-1;
-      newTradeStore[j].symbol               = "";
-      newTradeStore[j].price                = 0.0;
-      newTradeStore[j].stop_loss            = 0.0;
-      newTradeStore[j].take_profit          = 0.0;
-      newTradeStore[j].start_time           = 0;
-      newTradeStore[j].end_time             = 0;
-      newTradeStore[j].buy_hit_virtual_sl   = false;
-      newTradeStore[j].sell_hit_virtual_sl  = false;
-     }
-
-   int idx = 0;
-   while(!FileIsEnding(fileHandle) && idx < MaxOrders)
-     {
-      string line = FileReadString(fileHandle);
-      if(StringLen(line) == 0)
-         continue;
-
-      string tokens[];
-      int total = StringSplit(line, ',', tokens);
-
-      if(total >= 10)
-        {
-         newTradeStore[idx].buy_ticket  = (ulong)tokens[0];
-         newTradeStore[idx].sell_ticket = (ulong)tokens[1];
-         newTradeStore[idx].symbol      = tokens[2];
-         newTradeStore[idx].price       = StringToDouble(tokens[3]);
-         newTradeStore[idx].stop_loss   = StringToDouble(tokens[4]);
-         newTradeStore[idx].take_profit = StringToDouble(tokens[5]);
-
-         string sStart = tokens[6];
-         string sEnd   = tokens[7];
-         newTradeStore[idx].start_time = (StringLen(sStart) > 0) ? StringToTime(sStart) : 0;
-         newTradeStore[idx].end_time   = (StringLen(sEnd)   > 0) ? StringToTime(sEnd)   : 0;
-
-         bool bHit = false;
-         bool sHit = false;
-
-         if(tokens[8] == "true")
-           {
-            bHit = true;
-           }
-         else
-           {
-            bHit = false;
-           }
-
-         if(tokens[9] == "true")
-           {
-            sHit = true;
-           }
-         else
-           {
-            sHit = false;
-           }
-
-         newTradeStore[idx].buy_hit_virtual_sl  = bHit;
-         newTradeStore[idx].sell_hit_virtual_sl = sHit;
-
-         // --- simple Print instead of PrintFormat ---
-         Print(
-            "Loaded newTradeStore[", idx, "]:",
-            " buy_ticket=", newTradeStore[idx].buy_ticket,
-            " sell_ticket=", newTradeStore[idx].sell_ticket,
-            " symbol=", newTradeStore[idx].symbol,
-            " price=", DoubleToString(newTradeStore[idx].price, _Digits),
-            " \n sl=", DoubleToString(newTradeStore[idx].stop_loss, _Digits),
-            " tp=", DoubleToString(newTradeStore[idx].take_profit, _Digits),
-            " start=", (newTradeStore[idx].start_time != 0 ? TimeToString(newTradeStore[idx].start_time, TIME_DATE|TIME_SECONDS) : ""),
-            " end=", (newTradeStore[idx].end_time   != 0 ? TimeToString(newTradeStore[idx].end_time,   TIME_DATE|TIME_SECONDS) : ""),
-            " buyHit=", newTradeStore[idx].buy_hit_virtual_sl,
-            " sellHit=", newTradeStore[idx].sell_hit_virtual_sl
-         );
-
-         idx++;
-        }
-      else
-        {
-         Print("loadNewTradeStoreFile(): skipping malformed line (tokens=", total, "): ", line);
-        }
-     }
-
-   FileClose(fileHandle);
-   Print("loadNewTradeStoreFile() -> loaded ", idx, " entries from '", file_name, "'.");
-  }
-//+------------------------------------------------------------------+
-//|                                                                  |
-//+------------------------------------------------------------------+
-
-//+------------------------------------------------------------------+