enum test {Balance, Equity, Sortino};
extern test Sharp_Ratio = Balance;
double equity[], equitymin[];
void OnTick()
{
//=== БЛОК ЗАПИСИ ЭКВИТИ ДЛЯ СТАТИСТИКИ ================================================================
if (TimeDay(Time[0])!=TimeDay(Time[1]) && (IsTesting() || IsOptimization())) //день закончился? тогда записываем информацию о состоянии счёта на конец дня в массив
{
ArrayResize(equity,ArraySize(equity)+1);
ArrayResize(equitymin,ArraySize(equitymin)+1);
equity[ArraySize(equity)-1] = AccountEquity();
equitymin[ArraySize(equitymin)-1] = AccountEquity();
if(AccountEquity()<equitymin[ArraySize(equitymin)-1]) equitymin[ArraySize(equitymin)-1] = AccountEquity();
}
}
double OnTester()
{
int startSize = 0;
double orders[];
double plus[];
double Sharp;
double depo = TesterStatistics(STAT_INITIAL_DEPOSIT);
double avprofit =0;
// = (TesterStatistics(STAT_GROSS_PROFIT)+TesterStatistics(STAT_GROSS_LOSS))/TesterStatistics(STAT_TRADES)/depo;
double std = 0;
double high = 0;
double low = 0;
double loss = 0;
double profit = 0;
double mae = 0;
double losses = 0, profits = 0;
//---- Учет закрытых ордеров -------------------------------------------------------------------------------------
for(int i=0;i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i, SELECT_BY_POS ,MODE_HISTORY) == false) continue;
if(OrderSelect(i, SELECT_BY_POS ,MODE_HISTORY) == true && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
if(OrderCloseTime() > 0)
{
startSize+=1;
ArrayResize(orders, startSize);
if(Sharp_Ratio == 0)
{
orders[startSize-1] = (OrderProfit()+OrderSwap()+OrderCommission())/depo;
}
}
ArraySetAsSeries(orders,true);
avprofit = iMAOnArray(orders,0,ArraySize(orders)-1,0,0,0);
std = iStdDevOnArray(orders,0,ArraySize(orders)-1,0,0,0);
}
if(Sharp_Ratio == 1)
{
ArrayResize(orders,ArraySize(equitymin));
for(int i = 1; i<ArraySize(equitymin); i++)
{
orders[i] = equitymin[i]/equitymin[i-1]-1;
}
ArraySetAsSeries(orders,true);
avprofit = iMAOnArray(orders,0,ArraySize(orders)-1,0,0,0);
std = iStdDevOnArray(orders,0,ArraySize(orders)-1,0,0,0);
}
if(Sharp_Ratio == 2)
{
ArrayResize(orders,ArraySize(equity));
ArrayResize(plus,ArraySize(equity));
for(int i = 1; i<ArraySize(equity); i++)
{
plus[i] = MathLog10(equity[i]/equity[i-1]);
orders[i] = MathLog10(equitymin[i]/equity[i-1]);
}
ArraySetAsSeries(orders,true);
ArraySetAsSeries(plus,true);
avprofit = iMAOnArray(plus,0,ArraySize(orders)-1,0,0,0);
std = iStdDevOnArray(orders,0,ArraySize(orders)-1,0,0,0);
}
if(std!=0)Sharp = NormalizeDouble(avprofit/std,5);
else Sharp = 0;
Print("Average profit "+DoubleToStr(avprofit*depo,3)+"$ "+DoubleToStr(avprofit*100,3)+"%, StdDev "+DoubleToStr(std*depo,3)+"$ "+DoubleToStr(std*100,3)+"%");
return(Sharp);
}