Price Data Components
Orders Execution
Miscellaneous
0
Views
0
Downloads
0
Favorites
Report_v1
//Report
#property indicator_chart_window
string TEXT[10000000];
int d = 1;
int n;
int y2;
//--------------
int init( )
{
return( 0 );
}
//-------------------
int deinit( )
{
return( 0 );
}
//---------------
int start( )
{
y2++;
if( y2 > 122 )
{
if( y2 > 132 )
{
y2 = 122;
}
int t = OrdersHistoryTotal( );
if( d >= -1 || n != t )
{
n = t;
int i = 0;
int error;
int x1;
double x2;
double x3;
double x4;
int x5;
int x6;
int x7;
int x8;
datetime x9;
double sum = 0;
double sum1 = 0;
double sum2 = 0;
int total = 0;
int total_trade = 0;
int total_buy = 0;
int total_sell = 0;
int Quantity = 0;
string name = "Report "+AccountNumber( ) + ".csv";
int handle = FileOpen( name, FILE_READ | FILE_WRITE, ";" );
if( handle == -1 )
{
error = GetLastError( );
if( error == 4103 )
{
Alert( "Report: Ôàéë ñ èìåíåì \""+name+"\" íå íàéäåí " );
}
else
{
if( error != 0 )
{
Alert( "Report: Êîä îøèáêè "+error+" ïðè ïîïûòêå ñîçäàòü ôàéë \""+name+"\" " );
FileClose( handle );
return( 0 );
}
}
}
else
{
if( handle > 0 )
{
int size = FileSize( handle );
if( size < 28 )
{
string column1= " Order";
string column2 = " Time_Open";
string column3 = " Type";
string column4 = " Size";
string column5 = " Symbol";
string column6 = " Price_Open";
string column7 = " S/L";
string column8 = " T/P";
string column9 = " Time_Close";
string column10 = " Price_Close";
string column11 = " Commission";
string column12 = " Swap";
string column13 = " Profit";
string column14 = " Profit_Ticks";
string column15 = " Sum_Profit";
string column16 = " Sum_Profit_Ticks";
string column17 = " Balance";
string column18 = " Total";
string column19 = " Total_Trades";
string column20 = " Total_Buy";
string column21 = " Total_Sell";
string column22 = " Comment";
Quantity = FileWrite( handle, column1, column2, column3 , column4, column5, column6, column7, column8, column9, column10,
column11, column12, column13, column14, column15, column16, column17, column18, column19, column20, column21, column22 );
if( Quantity < 0 )
{
Alert( "Report: Oøèáêà "+GetLastError( )+" ïðè çàïèñè â ôàéë íàçâàíèé êîëîíîê" );
FileClose( handle );
return( 0 );
}
FileClose( handle );
Quantity = 0;
handle = 0;
} // ãðàíèöà óñëîâèÿ if( size < 28 )
//-----------------------------------------------------------------------
if( ( handle > 0 ) && ( size > 28 ) )
{
while( FileIsEnding( handle ) == false )
{
i++;
TEXT[i] = FileReadString( handle );
if( FileIsEnding( handle ) == true )
{
x1 = StrToDouble( StringTrimLeft( TEXT[i - 22] ) );
x2 = StrToDouble( StringTrimLeft( TEXT[i - 8] ) );
x3 = StrToDouble( StringTrimLeft( TEXT[i - 7] ) );
x4 = StrToDouble( StringTrimLeft( TEXT[i - 6] ) );
x5 = StrToDouble( StringTrimLeft( TEXT[i - 5] ) );
x6 = StrToDouble( StringTrimLeft( TEXT[i - 4] ) );
x7 = StrToDouble( StringTrimLeft( TEXT[i - 3] ) );
x8 = StrToDouble( StringTrimLeft( TEXT[i - 2] ) );
if( size <= 500 )
{
x9 = 0;
}
else
{
if( size > 500 )
{
x9 = StrToTime( StringTrimLeft( TEXT[i - 14] ) );
}
}
break; // âûõîä èç öèêëà while( FileIsEnding( handle ) == false )
} // ãðàíèöà óñëîâèÿ if( FileIsEnding( handle ) == true )
} // ãðàíèöà öèêëà while( FileIsEnding( handle ) == false )
//-----------------------------------------------------------------------
i = 0;
while( i <= t )
{
if( OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ) == true )
{
datetime timeclose = OrderCloseTime( );
if( timeclose > x9 )
{
int cmd = OrderType( );
double profit = OrderProfit( );
double commission = OrderCommission( );
double swap = OrderSwap( );
double open = OrderOpenPrice( );
double close = OrderClosePrice( );
string symbol = OrderSymbol( );
column1 = " " + DoubleToStr( OrderTicket( ), 0 );
column22 = " " + OrderComment( );
column12 = " " + DoubleToStr( swap, 2 );
column11 = " " + DoubleToStr( commission, 2 );
column13 = " " + DoubleToStr( profit, 2 );
column8 = " " + DoubleToStr( OrderTakeProfit( ), 5 );
column7 = " " + DoubleToStr( OrderStopLoss( ), 5 );
column4 = " " + DoubleToStr( OrderLots( ), 2 );
sum2 = sum2 + profit + swap + commission;
column17 = " " + DoubleToStr( sum2 + x4, 2 );
total++;
column18 = " " + DoubleToStr( total + x5, 0 );
column14 = " " + 0;
column15 = " " + DoubleToStr( sum1 + x2, 2 );
column16 = " " + DoubleToStr( sum + x3, 0 );
column19 = " " + DoubleToStr( total_trade + x6, 0 );
column20 = " " + DoubleToStr( total_buy + x7, 0 );
column21 = " " + DoubleToStr( total_sell + x8, 0 );
int k = 0;
if( cmd <= 1 )
{
if( profit >= 0 )
{
k = 1;
}
else
{
if( profit < 0 )
{
k = -1;
}
}
total_trade++;
column19 = " " + DoubleToStr( total_trade + x6, 0 );
sum1 = sum1 + 0 + profit + swap + commission;
column15 = " " + DoubleToStr( sum1 + x2, 2 );
double tick = MarketInfo( symbol, MODE_TICKSIZE );
if( tick != 0 )
{
double df = k * MathAbs( open - close ) / tick;
column14 = " " + DoubleToStr( df, 0 );
sum = sum + 0 + df;
column16 = " " + DoubleToStr( sum + x3, 0 );
}
} // ãðàíèöà óñëîâèÿ if( cmd <= 1 )
//-------------
if( cmd == 0 )
{
column3 = " " + "buy";
total_buy++;
column20 = " " + DoubleToStr( total_buy + x7, 0 );
}
else
{
if( cmd == 1 )
{
column3 = " " + "sell";
total_sell++;
column21 = " " + DoubleToStr( total_sell + x8, 0 );
}
}
//----
if( cmd == 2 )
{
column3 = " " + "buy limit";
}
else
{
if( cmd == 3 )
{
column3 = " " + "sell limit";
}
}
//----
if( cmd == 4 )
{
column3 = " " + "buy stop";
}
else
{
if( cmd == 5 )
{
column3 = " " + "sell stop";
}
}
//-----
FileSeek( handle, 0, SEEK_END );
column9 = " " + TimeToStr( timeclose, TIME_DATE | TIME_MINUTES | TIME_SECONDS );
column2 = " " + TimeToStr( OrderOpenTime( ), TIME_DATE | TIME_MINUTES | TIME_SECONDS );
column6 = " " + DoubleToStr( open, 5 );
column10 = " " + DoubleToStr( close, 5 );
column5 = " " + symbol;
if( cmd == 6 )
{
if( profit > 0 )
{
column3 = " " + "balance";
}
else
{
if( profit < 0 )
{
column3 = " " + "withdrawal";
}
}
column4 = " ";
column5 = " ";
column6 = " ";
column7 = " ";
column8 = " ";
column9 = " ";
column10 = " ";
column11 = " ";
column12 = " ";
column14 = " ";
} // ãðàíèöà óñëîâèÿ if( cmd == 6 )
Quantity = FileWrite( handle, column1, column2, column3 , column4, column5, column6, column7, column8, column9, column10,
column11, column12, column13, column14, column15, column16, column17, column18, column19, column20, column21, column22 );
//---------------------------------------------------
if( Quantity < 0 )
{
Alert( "Report: Êîä îøèáêè ïðè äî çàïèñè â ôàéë ", GetLastError( ) );
FileClose( handle );
return( 0 );
}
//-----------------------------------------------------
} // ãðàíèöà óñëîâèÿ if( timeclose > x9 )
} // ãðàíèöà óñëîâèÿ if( OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ) == true )
i++; // ñ÷åò÷èê öèêëà while( i <= t )
} // ãðàíèöà öèêëà while( i <= t )
FileClose( handle );
} // ãðàíèöà óñëîâèÿ if( ( handle > 0 ) && ( size > 28 ) )
} // ãðàíèöà óñëîâèÿ if( handle == -1 ) else
} // ãðàíèöà óñëîâèÿ if( handle > 0 )
d--;
} // ãðàíèöà óñëîâèÿ if( d >= -1 || n != t )
} // ãðàíèöà óñëîâèÿif if( y2 > 122 )
return( 0 ); // âûõîä èç ñòàðò
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---