StrategyViewer_v1

Miscellaneous
Uses files from the file systemIt opens Message Boxes to the userIt reads information from a fileIt reads information from a file
0 Views
0 Downloads
0 Favorites
StrategyViewer_v1
ÿþ//recoded from http://tradelikeapro.ru/kak-perenesti-sdelki-iz-myfxbook/

//author ;0A>2 025;

//+------------------------------------------------------------------+

//|                                              StrategyViewer.mq4 |

//|                   Copyright 2006-2015, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

//+------------------------------------------------------------------+



#property show_inputs



extern string fileName= "statement.csv"; //History trading csv file

extern int hourOffset = 0;               //time offset between broker server and MetaTrader

//+------------------------------------------------------------------+

//| script program start function                                    |

//+------------------------------------------------------------------+

int start()

  {

   int count=1;

   int ticket;

   string action;

   double order_lot;

   string order_symbol;

   double comission;

   double swap;

   double profit;

   datetime openTime;

   datetime closeTime;

   int ordType;

   double closePrice;

   double openPrice;  

   string comment;

   double stoploss;

   double takeprofit;

   

   int f= FileOpen(fileName,FILE_READ|FILE_CSV,';');

   if(f == -1)

     {

      int res=GetLastError();

      MessageBox("File open error! "+res,"Error",MB_OK|MB_ICONWARNING);

      return(0);

     }

   FileSeek(f,0,SEEK_SET);



 

//mql5.com Trading history csv file format   

//Time;Type;Volume;Symbol;Price;Time;Price;Commission;Swap;Profit

//2018.01.02 12:39:23;Buy;0.7;USDJPY.;112.142;2018.01.02 21:55:48;112.292;-7;;93.51

//or

//Time;Type;Volume;Symbol;Price;S/L;T/P;Time;Price;Commission;Swap;Profit;Comment

//2018.01.02 10:00:00;Sell;0.10;USDCAD;1.25250;1.27086;1.24486;2018.01.04 08:41:17;1.25201;;-0.29;3.91;

//2018.01.03 21:56:50;Sell Stop;3.20;USDJPY;112.403;114.503;112.003;2018.01.04 08:38:37;112.490;;;;cancelled





//parse header   

   bool hasTicket=false,hasStops=false,hasComment=false;

   while(!FileIsLineEnding(f))

     {

      string s=FileReadString(f);

      if(s=="Ticket")

         hasTicket=true;

      if(s=="S/L" || s=="T/P")

         hasStops=true;

      if(s=="Comment")

         hasComment=true;

     }



   ObjectsDeleteAll();   

   

   while(!FileIsEnding(f))

     {

      if(hasTicket)

        ticket=FileReadNumber(f);

      else

        ticket=count;

      openTime = FileReadDatetime(f) + hourOffset;

      action = FileReadString(f);

      order_lot = FileReadNumber(f);

      order_symbol = FileReadString(f);

      openPrice = FileReadNumber(f);

      if (hasStops)

        stoploss = FileReadNumber(f);

      else

        stoploss = 0.0;

      if (hasStops)

        takeprofit = FileReadNumber(f);

      else

        takeprofit = 0.0;

      closeTime = FileReadDatetime(f) + hourOffset;

      closePrice = FileReadNumber(f);

      comission = FileReadNumber(f);

      swap = FileReadNumber(f);

      profit = FileReadNumber(f);

      if (hasComment)

        comment = FileReadString(f);

      else

        comment = "";

        

      if (StringSubstr(order_symbol,0,6)!=StringSubstr(Symbol(),0,6)) continue;

      if (action == "Balance") continue;

        

      ordType= getOrderTypeFromString(action);

      if(ordType == -1)

        {

         Print("Not supported order type: ",action);

         continue;

        }



      if(ordType>OP_SELL) closePrice=openPrice; // pending orders price not changed



      color c=Blue;

      if(ordType==OP_SELL || ordType==OP_SELLLIMIT || ordType==OP_SELLSTOP)

         c=Red;



      string objName="#"+ticket+" "+action+" "+DoubleToStr(order_lot,2)+" "+StringSubstr(order_symbol,0,6)+" at "+DoubleToStr(openPrice,_Digits);

      ObjectCreate(objName,OBJ_ARROW,0,openTime,openPrice);

      ObjectSet(objName,OBJPROP_COLOR,c);

      ObjectSet(objName,OBJPROP_ARROWCODE,1);

      ObjectSetText(objName,"Lots: "+DoubleToStr(order_lot,2));



      objName="#"+ticket+" "+action+" trendline";

      ObjectCreate(objName,OBJ_TREND,0,openTime,openPrice,closeTime,closePrice);

      ObjectSet(objName,OBJPROP_STYLE,STYLE_DOT);

      ObjectSet(objName,OBJPROP_RAY,false);

      ObjectSet(objName,OBJPROP_COLOR,c);



      objName="#"+ticket+" "+action+" "+DoubleToStr(order_lot,2)+" "+_Symbol+" at "+DoubleToStr(closePrice,_Digits);

      if (comment == "cancelled")

         objName=objName+" "+comment;

      else

         if (comment == "") 

           objName=objName+" close";

         else

           objName=objName+" close at "+comment;

      ObjectCreate(objName,OBJ_ARROW,0,closeTime,closePrice);

      ObjectSet(objName,OBJPROP_COLOR,Goldenrod);

      ObjectSet(objName,OBJPROP_ARROWCODE,3);

      ObjectSetText(objName,"Profit: "+DoubleToStr(profit,2)+"; Commission: "+DoubleToStr(comission,2)+"; Swap: "+DoubleToStr(swap,2));

      //MessageBox(StringConcatenate(open_date, " = ", TimeToStr(openTime, TIME_DATE|TIME_MINUTES), ", ", close_date, " = ", TimeToStr(closeTime, TIME_DATE|TIME_MINUTES)), "", MB_OK);

      //Print(StringConcatenate(open_date, " = ", TimeToStr(openTime, TIME_DATE|TIME_MINUTES), ", ", close_date, " = ", TimeToStr(closeTime, TIME_DATE|TIME_MINUTES)), "", MB_OK);

      

      count++;

     }

   FileClose(f);



   MessageBox("Loaded "+ticket+" orders.","Finish",MB_OK);



//----

   return(0);

  }

//+------------------------------------------------------------------+



int getOrderTypeFromString(string s)

  {

   if(s == "Buy")         return(OP_BUY);

   if(s == "Buy Stop")    return(OP_BUYSTOP);

   if(s == "Buy Limit")   return(OP_BUYLIMIT);



   if(s == "Sell")         return(OP_SELL);

   if(s == "Sell Stop")    return(OP_SELLSTOP);

   if(s == "Sell Limit")   return(OP_SELLLIMIT);



   return(-1);

  }

Comments