enum test
{
res_mfe = 0, // RES/MFE
mfe_mae = 1, // MFE/MAE
res_mae = 2, // RES/MAE
};
input test OnTesterMod = 0;
int BAR;
double MAE,MFE, RES, Qex, Qen, Qua;
void OnTick()
{
Quality();
}
void Quality()
{
int bar;
double op,cp, mae, mfe, QEntry,QExit, atr,res;
int ot,oc;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic)
{
cp = OrderClosePrice();
op = OrderOpenPrice();
oc = iBarShift(_Symbol,_Period,OrderCloseTime());
ot = iBarShift(_Symbol,_Period,OrderOpenTime());
if(oc==1)
{
if(OrderType()==OP_BUY) { mae = (op-iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,ot-oc,oc)));
if(mae<0) mae = 0;
mfe = (iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,ot-oc,oc))-op);
if(mfe<0)mfe=0;
res = (cp-op);
if(res > 0) QEntry = 1/(1+mae/(res)); else QEntry = 0;
if(mfe >0 && res>0) QExit = (res)/mfe; else QExit = 0;
// Print("QEntry "+DoubleToStr(QEntry,2)+" QExit "+DoubleToStr(QExit,2));
if(mfe>0 && mae>0)Print((res/mfe)*(mfe/mae));
MFE += mfe;
MAE += mae;
Qex += QExit;
Qen += QEntry;
RES += res;
BAR += ot-oc;
if(MAE>0)Qua += MFE/MAE;}
if(OrderType()==OP_SELL){ res = (op-cp);
mfe = (op-iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,ot-oc,oc)));
if(mfe<0) mfe=0;
mae = (iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,ot-oc,oc))-op);
if(mae<0) mae = 0;
if(res > 0)QEntry = 1/(1+mae/(res)); else QEntry = 0;
if(mfe >0 && res>0) QExit = (res)/mfe; else QExit = 0;
if(mfe>0 && mae>0)Print((res/mfe)*(mfe/mae));
MFE += mfe;
MAE += mae;
Qex += QExit;
Qen += QEntry;
RES += res;
BAR += ot-oc;
if(MAE>0)Qua += MFE/MAE;}
}
}
}
}
double OnTester()
{
int a, c= 0;
double trades = TesterStatistics(STAT_TRADES);
double sharp_ = TesterStatistics(STAT_SHARPE_RATIO);
double profit = TesterStatistics(STAT_PROFIT);
double depo = TesterStatistics(STAT_INITIAL_DEPOSIT);
double DD = TesterStatistics(STAT_EQUITY_DDREL_PERCENT);
//if(trades<MinTrades) a = 1/c;
Print("MAE "+DoubleToStr(MAE/trades,3)+" MFE "+DoubleToStr(MFE/trades,3)+" RES "+DoubleToStr(RES/trades,3)+" QEntry "+DoubleToStr(MFE/MAE,3)+" QExit "+DoubleToStr(RES/MFE,3)+" Bars "+DoubleToStr(BAR/trades,3));
if(OnTesterMod == res_mae) return(RES/MAE);
if(OnTesterMod == res_mfe) return(RES/MFE);
if(OnTesterMod == mfe_mae) return(MFE/MAE);
}