If you visit Spain again... you know where to contact me

Cheers
//+------------------------------------------------------------------+ //| ESG_tax_history.mq4 //| ESG //| 03/19/2015 //+------------------------------------------------------------------+ #property copyright "ESG" #property version "1.00" #property strict #property script_show_inputs //--- input parameters input datetime startdate = D'2014.01.01 00:00'; input datetime enddate = D'2015.01.01 00:00'; input string filename="tax_statement.csv"; void OnInit() { int i = 0, handle = 0, hstTotal = 0; double positiveProfit = 0, negativeProfit = 0, tmpProfit = 0; string orderType = ""; hstTotal = HistoryTotal(); handle=FileOpen(filename, FILE_WRITE|FILE_CSV,","); if(handle > 0) { FileWrite(handle,"Ticket,Open Time,Type,Lots,Symbol,Price,Stop/Loss,Take Profit,Close Time,Close Price,Commission,Swap,HSTProfit,PositiveProfit,NegativeProfit,Comment"); for(i = 0; i < hstTotal; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) { if (startdate <= OrderCloseTime() && enddate >= OrderCloseTime() && (OrderType() == OP_BUY || OrderType() == OP_SELL)) { if (OrderType() == OP_BUY) orderType = "Buy"; if (OrderType() == OP_SELL) orderType = "Sell"; tmpProfit = OrderProfit() + OrderCommission() + OrderSwap(); if (tmpProfit == 0) { positiveProfit = 0.0; negativeProfit = 0.0; } else { if (tmpProfit > 0) { positiveProfit = tmpProfit; negativeProfit = 0.0; } else { positiveProfit = 0.0; negativeProfit = tmpProfit; } } FileWrite(handle, OrderTicket(), TimeToStr(OrderOpenTime(), TIME_DATE|TIME_MINUTES|TIME_SECONDS), orderType, OrderLots(), OrderSymbol(), DoubleToString(OrderOpenPrice(), Digits()), DoubleToString(OrderStopLoss(), Digits()), DoubleToString(OrderTakeProfit(), Digits()), TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES|TIME_SECONDS), DoubleToString(OrderClosePrice(), Digits()), DoubleToString(OrderCommission(), Digits()), DoubleToString(OrderSwap(), Digits()), DoubleToString(OrderProfit(), Digits()), DoubleToString(positiveProfit, Digits()), DoubleToString(negativeProfit, Digits()), OrderComment()); } } } FileClose(handle); } } //+------------------------------------------------------------------+ void OnStart() { } //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| ESG_tax_history.mq4 //| ESG //| 03/19/2015 //+------------------------------------------------------------------+ #property copyright "ESG" #property version "1.00" #property strict #property script_show_inputs //--- input parameters input datetime startdate = D'2014.01.01 00:00'; input datetime enddate = D'2015.01.01 00:00'; input string filename="tax_statement.csv"; void OnInit() { int i = 0, handle = 0, hstTotal = 0; double positiveProfit = 0, negativeProfit = 0, tmpProfit = 0; string orderType = ""; hstTotal = HistoryTotal(); handle=FileOpen(filename, FILE_WRITE|FILE_CSV,","); if(handle > 0) { FileWrite(handle,"Ticket,Open Time,Type,Lots,Symbol,Price,Stop/Loss,Take Profit,Close Time,Close Price,Commission,Swap,HSTProfit,PositiveProfit,NegativeProfit,Comment"); for(i = 0; i < hstTotal; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true) { if (startdate <= OrderCloseTime() && enddate >= OrderCloseTime() && (OrderType() == OP_BUY || OrderType() == OP_SELL)) { if (OrderType() == OP_BUY) orderType = "Buy"; if (OrderType() == OP_SELL) orderType = "Sell"; tmpProfit = OrderProfit() + OrderCommission() + OrderSwap(); if (tmpProfit == 0) { positiveProfit = 0.0; negativeProfit = 0.0; } else { if (tmpProfit > 0) { positiveProfit = tmpProfit; negativeProfit = 0.0; } else { positiveProfit = 0.0; negativeProfit = tmpProfit; } } FileWrite(handle, OrderTicket(), TimeToStr(OrderOpenTime(), TIME_DATE|TIME_MINUTES|TIME_SECONDS), orderType, OrderLots(), OrderSymbol(), DoubleToString(OrderOpenPrice(), Digits()), DoubleToString(OrderStopLoss(), Digits()), DoubleToString(OrderTakeProfit(), Digits()), TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES|TIME_SECONDS), DoubleToString(OrderClosePrice(), Digits()), DoubleToString(OrderCommission(), Digits()), DoubleToString(OrderSwap(), Digits()), DoubleToString(OrderProfit(), Digits()), DoubleToString(positiveProfit, Digits()), DoubleToString(negativeProfit, Digits()), OrderComment()); } } } FileClose(handle); } } //+------------------------------------------------------------------+ void OnStart() { } //+------------------------------------------------------------------+
Leave a comment: