
Нужно чтобы получился тест с почти ровный и немножко в профите.
Еще мартин не работает как нужно местами не увеличивает лот
//+------------------------------------------------------------------+
//| MASafe.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
extern double Lots = 0.1;
extern double KLot = 2;
extern double MaxLot = 5;
extern int StopLoss = 1200;
extern int TakeProfit = 1400;
extern int TrailingStop = 300;
extern int BULevel = 0;
extern int BUPoint = 30;
extern int Slip = 50;
extern int MA1Period = 9;
extern int MA2Period = 22;
extern int Magic = 123;
datetime t=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
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(TrailingStop>0)
{
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;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
double ma11=iMA(NULL,0,MA1Period,0,0,0,1);
double ma21=iMA(NULL,0,MA2Period,0,0,0,1);
double ma12=iMA(NULL,0,MA1Period,0,0,0,2);
double ma22=iMA(NULL,0,MA2Period,0,0,0,2);
//---- buy
if(ma11>ma21 && ma12<ma22)
{
PutOrder(0,Ask);
}
//---- sell
if(ma11<ma21 && ma12>ma22)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| Лот для усреднителя |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);
lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
if(lot<MinimumLot) lot=MinimumLot;
if(lot>MaximumLot) lot=MaximumLot;
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
OpenPos();
t=Time[0];
}
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
}
//+------------------------------------------------------------------+
2017.09.13 20:27:18.377 2017.01.16 19:00:00 cannot open file 'D:\Program Files\Alpari Limited MT4\MQL4\indicators\4D — Range Switch.ex4' [2]
2017.09.13 20:27:18.373 2017.01.16 18:45:00 cannot open file 'D:\Program Files\Alpari Limited MT4\MQL4\indicators\Waddah_Attar_Explosion.ex4' [2]
//+------------------------------------------------------------------+
//| MASafe.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
extern double Lots = 0.1;
extern double KLot = 2;
extern double MaxLot = 5;
extern int StopLoss = 1200;
extern int TakeProfit = 1400;
extern int TrailingStop = 300;
extern int Slip = 50;
extern int MA1Period = 9;
extern int MA2Period = 22;
extern int Magic = 123;
datetime t=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Trailing()
{
bool mod;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
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(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>TrailingStop*Point)
{
if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
{
mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
return;
}
}
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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;
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
double ma11=iMA(NULL,0,MA1Period,0,0,0,1);
double ma21=iMA(NULL,0,MA2Period,0,0,0,1);
double ma12=iMA(NULL,0,MA1Period,0,0,0,2);
double ma22=iMA(NULL,0,MA2Period,0,0,0,2);
//---- buy
if(ma11>ma21 && ma12<ma22)
{
PutOrder(0,Ask);
}
//---- sell
if(ma11<ma21 && ma12>ma22)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| Лот для усреднителя |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);
lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
if(lot<MinimumLot) lot=MinimumLot;
if(lot>MaximumLot) lot=MaximumLot;
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
OpenPos();
t=Time[0];
}
if(TrailingStop!=0) Trailing();
}
//+------------------------------------------------------------------+
Автор Daying Cao, опытный инженер-программист.
AM2