/* Generated by EX4-TO-MQ4 decompiler V4.0.223.1 [] Website: http://purebeam.biz E-mail : purebeam@gmail.com */ #property copyright "Copyright © 2006-2009, Mistigri LLC" #property link "http://www.mistigrifx.com" #property show_inputs #include extern bool DisplayClosedTrades = TRUE; extern bool DisplayLiveTrades = TRUE; int start() { string OutputFile; int FileHandle; int MyTicket; int MyOrderOpenTime; int MyOrderType; string MyOrderTypeStr; double MyOrderLots; string MyOrderSymbol; int MyDigits; double MyOrderOpenPrice; double MyOrderStopLoss; double MyOrderTakeProfit; int MyOrderCloseTime; double MyOrderClosePrice; double MyPoint; string MyOrderCommission; string MyOrderSwap; string MyOrderProfit; double MyOrderPips; string MyOrderComment; string MyOrderMagicNumber; string MyOrderOpenDateStr; string MyOrderCloseDateStr; string MyOrderOpenTimeStr; string MyOrderCloseTimeStr; string FileOutputString; if (AccountNumber() != 0 && IsConnected()) { OutputFile = "MSFX-Trades Export-" + DoubleToStr(AccountNumber(), 0) + ".csv"; FileHandle = CreateFileHeader(OutputFile); if (FileHandle < 0) { Alert("Error - COULD NOT CREATE FILE"); return (0); } if (DisplayClosedTrades) { for (int pos = OrdersHistoryTotal() - 1; pos >= 0; pos--) { if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) == TRUE) { MyTicket = OrderTicket(); MyOrderOpenTime = OrderOpenTime(); MyOrderType = OrderType(); MyOrderLots = OrderLots(); MyOrderSymbol = OrderSymbol(); MyDigits = MarketInfo(MyOrderSymbol, MODE_DIGITS); MyOrderOpenPrice = StrToDouble(DoubleToStr(OrderOpenPrice(), MyDigits)); MyOrderStopLoss = StrToDouble(DoubleToStr(OrderStopLoss(), MyDigits)); MyOrderTakeProfit = StrToDouble(DoubleToStr(OrderTakeProfit(), MyDigits)); MyOrderCloseTime = OrderCloseTime(); MyOrderClosePrice = StrToDouble(DoubleToStr(OrderClosePrice(), MyDigits)); MyPoint = MarketInfo(MyOrderSymbol, MODE_POINT); if (MyPoint == 0.001) { MyPoint = 0.01; } else { if (MyPoint == 0.00001) { MyPoint = 0.0001; } } MyOrderCommission = DoubleToStr(OrderCommission(), 2); MyOrderSwap = DoubleToStr(OrderSwap(), 2); MyOrderProfit = DoubleToStr(OrderProfit(), 2); MyOrderPips = 0.0; MyOrderComment = OrderComment(); if (MyOrderComment == "") MyOrderComment = "None"; MyOrderMagicNumber = DoubleToStr(OrderMagicNumber(), 0); MyOrderTypeStr = ""; if (MyOrderType == OP_BUY) { MyOrderTypeStr = "BUY"; MyOrderPips = (MyOrderClosePrice - MyOrderOpenPrice) / MyPoint; } else { if (MyOrderType == OP_SELL) { MyOrderTypeStr = "SELL"; MyOrderPips = (MyOrderOpenPrice - MyOrderClosePrice) / MyPoint; } else { if (MyOrderType == OP_BUYLIMIT) { MyOrderTypeStr = "BUY_LIMIT"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_SELLLIMIT) { MyOrderTypeStr = "SELL_LIMIT"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_BUYSTOP) { MyOrderTypeStr = "BUY_STOP"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_SELLSTOP) { MyOrderTypeStr = "SELL_STOP"; MyOrderPips = 0.0; } else if (MyOrderType == 6) MyOrderTypeStr = "Deposit/WithDrawal"; } } } } } MyOrderOpenDateStr = TimeMonth(MyOrderOpenTime) + "/" + TimeDay(MyOrderOpenTime) + "/" + TimeYear(MyOrderOpenTime); MyOrderCloseDateStr = TimeMonth(MyOrderCloseTime) + "/" + TimeDay(MyOrderCloseTime) + "/" + TimeYear(MyOrderCloseTime); MyOrderOpenTimeStr = TimeHour(MyOrderOpenTime) + ":" + TimeMinute(MyOrderOpenTime) + ":" + TimeSeconds(MyOrderOpenTime); MyOrderCloseTimeStr = TimeHour(MyOrderCloseTime) + ":" + TimeMinute(MyOrderCloseTime) + ":" + TimeSeconds(MyOrderCloseTime); FileOutputString = StringConcatenate(MyTicket, ",", MyOrderOpenDateStr, ",", MyOrderOpenTimeStr, ",", MyOrderTypeStr, ",", MyOrderLots, ",", MyOrderSymbol, ",", DoubleToStr(MyOrderOpenPrice, MyDigits), ",", DoubleToStr(MyOrderStopLoss, MyDigits), ",", DoubleToStr(MyOrderTakeProfit, MyDigits), ",", MyOrderCloseDateStr, ",", MyOrderCloseTimeStr, ",", DoubleToStr(MyOrderClosePrice, MyDigits), ",", MyOrderCommission, ",", MyOrderSwap, ",", MyOrderProfit, ",", MyOrderPips, ",", MyOrderComment, ",", MyOrderMagicNumber, ","); FileWrite(FileHandle, FileOutputString); } } } if (DisplayLiveTrades) { for (pos = OrdersTotal() - 1; pos >= 0; pos--) { if (OrderSelect(pos, SELECT_BY_POS, MODE_TRADES) == TRUE) { MyTicket = OrderTicket(); MyOrderOpenTime = OrderOpenTime(); MyOrderType = OrderType(); MyOrderLots = OrderLots(); MyOrderSymbol = OrderSymbol(); MyDigits = MarketInfo(MyOrderSymbol, MODE_DIGITS); MyOrderOpenPrice = StrToDouble(DoubleToStr(OrderOpenPrice(), MyDigits)); MyOrderStopLoss = StrToDouble(DoubleToStr(OrderStopLoss(), MyDigits)); MyOrderTakeProfit = StrToDouble(DoubleToStr(OrderTakeProfit(), MyDigits)); MyOrderCloseTime = OrderCloseTime(); MyOrderClosePrice = StrToDouble(DoubleToStr(OrderClosePrice(), MyDigits)); MyPoint = MarketInfo(MyOrderSymbol, MODE_POINT); if (MyPoint == 0.001) { MyPoint = 0.01; } else { if (MyPoint == 0.00001) { MyPoint = 0.0001; } } MyOrderCommission = DoubleToStr(OrderCommission(), 2); MyOrderSwap = DoubleToStr(OrderSwap(), 2); MyOrderProfit = DoubleToStr(OrderProfit(), 2); MyOrderPips = 0.0; MyOrderComment = OrderComment(); if (MyOrderComment == "") MyOrderComment = "None"; MyOrderMagicNumber = DoubleToStr(OrderMagicNumber(), 0); MyOrderTypeStr = ""; if (MyOrderType == OP_BUY) { MyOrderTypeStr = "BUY"; MyOrderPips = NormalizeDouble((iClose(MyOrderSymbol, PERIOD_M1, 0) - MyOrderOpenPrice) / MyPoint, 2); } else { if (MyOrderType == OP_SELL) { MyOrderTypeStr = "SELL"; MyOrderPips = NormalizeDouble((MyOrderOpenPrice - iClose(MyOrderSymbol, PERIOD_M1, 0)) / MyPoint, 2); } else { if (MyOrderType == OP_BUYLIMIT) { MyOrderTypeStr = "BUY_LIMIT"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_SELLLIMIT) { MyOrderTypeStr = "SELL_LIMIT"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_BUYSTOP) { MyOrderTypeStr = "BUY_STOP"; MyOrderPips = 0.0; } else { if (MyOrderType == OP_SELLSTOP) { MyOrderTypeStr = "SELL_STOP"; MyOrderPips = 0.0; } else if (MyOrderType == 6) MyOrderTypeStr = "Deposit/WithDrawal"; } } } } } MyOrderOpenDateStr = TimeMonth(MyOrderOpenTime) + "/" + TimeDay(MyOrderOpenTime) + "/" + TimeYear(MyOrderOpenTime); MyOrderCloseDateStr = "OPEN"; MyOrderOpenTimeStr = TimeHour(MyOrderOpenTime) + ":" + TimeMinute(MyOrderOpenTime) + ":" + TimeSeconds(MyOrderOpenTime); MyOrderCloseTimeStr = "OPEN"; FileOutputString = StringConcatenate(MyTicket, ",", MyOrderOpenDateStr, ",", MyOrderOpenTimeStr, ",", MyOrderTypeStr, ",", MyOrderLots, ",", MyOrderSymbol, ",", DoubleToStr(MyOrderOpenPrice, MyDigits), ",", DoubleToStr(MyOrderStopLoss, MyDigits), ",", DoubleToStr(MyOrderTakeProfit, MyDigits), ",", MyOrderCloseDateStr, ",", MyOrderCloseTimeStr, ",", DoubleToStr(MyOrderClosePrice, MyDigits), ",", MyOrderCommission, ",", MyOrderSwap, ",", MyOrderProfit, ",", MyOrderPips, ",", MyOrderComment, ",", MyOrderMagicNumber, ","); FileWrite(FileHandle, FileOutputString); } } } FileClose(FileHandle); } return (0); } int CreateFileHeader(string fName) { string header; int handle = FileOpen(fName, FILE_CSV|FILE_WRITE, ";"); if (handle <= 0) { handle = GetLastError(); Alert("Error Opening File : " + handle); } else { header = "Ticket, Open Date, Open Time, Type, Lots, Symbol, Price, SL, TP, Close Date, Close Time, Close Price, Commission, Swap, Profit , Pips, Comment, MagicNumber"; FileWrite(handle, header); } return (handle); }