//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
double PercentProfitTrades = 0;
if (TesterStatistics(STAT_PROFIT_TRADES) > 0)
PercentProfitTrades = TesterStatistics(STAT_PROFIT_TRADES) / TesterStatistics(STAT_TRADES) * 100;
if (PercentProfitTrades >= TesterMinPercentProfitTrades)
return(NormalizeDouble((TesterStatistics(STAT_PROFIT) / TesterStatistics(STAT_EQUITY_DD)), 1));
else return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Профит всех ордеров в пунктах по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
double lt=0;
double tt=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
lt+=OrderLots();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
lt+=OrderLots();
}
}
}
}
tt=pr/lt/10 ;
return(tt);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>TrailingStop*Point)
{
if(OrderStopLoss()<Bid-TrailingStop*Point)
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void BU()
{
bool m;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
if(CountTrades()>0) DelOrder();
double lo=iLow(NULL,PERIOD_D1,0);
double hi=iHigh(NULL,PERIOD_D1,0);
if((CountTrades()<1) || (CountTrades()<Max && (FindLastBuyPrice(Magic)-Ask)/Point>=Delta))
{
PutOrder(0,Ask);
}
if((CountTrades()<1) || (CountTrades()<Max && (Bid-FindLastSellPrice(Magic))/Point>=Delta))
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
double PercentProfitTrades = 0;
if (TesterStatistics(STAT_PROFIT_TRADES) > 0)
PercentProfitTrades = TesterStatistics(STAT_PROFIT_TRADES) / TesterStatistics(STAT_TRADES) * 100;
if (PercentProfitTrades >= TesterMinPercentProfitTrades)
return(NormalizeDouble((TesterStatistics(STAT_PROFIT) / TesterStatistics(STAT_EQUITY_DD)), 1));
else return(0);
}
//+------------------------------------------------------------------+
//| ProBoyDay_v_axe44.mq4 |
//| Copyright 2019, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, axe44"
#property link "http://www.forexsystems.biz"
#property version "2.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int Max = 20; // сколько ордеров
extern int StopLoss = 70; // лось
extern int TakeProfit = 200; // язь
extern int Delta = 10; // расстояние от уровня
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 200; // трал
extern int Slip = 0; // реквот
extern int Magic = 123; // магик
extern int TesterMinPercentProfitTrades=50;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
{
int r=0;
color clr=Green;
double sl=0,tp=0;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0) break;
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
break;
}
}
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double FindLastBuyPrice(int magic)
{
int oticket,ticketNumber=0;
double oprice=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
oprice=OrderOpenPrice();
}
}
}
}
return(oprice);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double FindLastSellPrice(int magic)
{
int oticket,ticketNumber=0;
double oprice=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
oprice=OrderOpenPrice();
}
}
}
}
return(oprice);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
int CountOrders(int type)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()>1) del=OrderDelete(OrderTicket());
}
}
}
}
axe44