Простой шаблон для эксперта для реала с инструкцией: www.opentraders.ru/downloads/1096/
//+------------------------------------------------------------------+
//| FL.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 1; // умножение лота
extern double MaxLot = 5; // максимальный лот
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 300; // трал
extern int Slip = 30; // реквот
extern int Count = 5; // максимальное количество позиций
extern int CloseOn = 0; // 1-закрытие по сигналу
extern int Shift = 1; // сдвиг
extern int Magic = 123; // магик
extern string IndName = "FL01";
datetime t=0;
//+------------------------------------------------------------------+
//| 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;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 OpenPos()
{
double up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
if(Open[1]<dn && Close[1]>dn)
{
PutOrder(0,Ask);
}
if(Open[1]>up && Close[1]<up)
{
PutOrder(1,Bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ClosePos()
{
double up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
//---
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(Close[0]>up)
{
if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slip,White))
Print("OrderClose error ",GetLastError());
}
}
if(OrderType()==OP_SELL)
{
if(Close[1]<dn)
{
if(!OrderClose(OrderTicket(),OrderLots(),Ask,Slip,White))
Print("OrderClose error ",GetLastError());
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double Lot()
{
double lot=Lots;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0)
{
lot=OrderLots()*KLot;
}
}
if(lot>MaxLot)lot=Lots;
return(lot);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,Green);
return;
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && OrderOpenPrice()<OrderStopLoss())
{
m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Green);
return;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double up = iCustom(NULL,0,IndName,1,Shift);
double dn = iCustom(NULL,0,IndName,2,Shift);
if(CountTrades()<=Count && t!=Time[0])
{
OpenPos();
t=Time[0];
}
else if(CloseOn>0) ClosePos();
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
Comment("\n UP: ",up,
"\n DN: ",dn);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Copyright © 2014, Khlystov Vladimir |
//| http://cmillion.narod.ru |
//+------------------------------------------------------------------+
//#property copyright "Copyright © 2014, cmillion@narod.ru"
//#property link "http://cmillion.ru"
//#property strict
//#property description "Советник торгует на скачках рынка, при этом не использует никакие индикаторы."
//#property description "Идея советника заключается в том, что стоп ордера дискретно времени перемещаются на заданном расстоянии от текущей цены."
//#property description "Если цена достаточно резко поползла в одну сторону, то советник просто не успевает переместить ордер и он становится рыночным."
//#property description "Далее включается тралл ордера."
//--------------------------------------------------------------------
extern int Stoploss = 10, //стоплосс, если 0 то не изменяется
Takeprofit = 50; //тейкпрофит, если 0 то не изменяется
extern int TrailingStop = 10; //длинна тралла, если 0 то нет тралла
extern int TrailingStart = 0; //когда включать тралл, например после достижения 40 п прибыл
extern int StepTrall = 2; //шаг тралла - перемещать стоплосс не ближе чем StepTrall
extern int NoLoss = 0, //перевод в безубыток при заданном кол-ве пунктов прибыли, если 0 то нет перевода в безубыток
MinProfitNoLoss = 0; //минимальная прибыль при переводе вбезубыток
extern int Magic = 77; //магик
extern int Step = 10; //расстояние от цены
extern double Lot = 0.1;
extern int TimeModify = 30; //кол-во секунд раньше которого запрещено изменять ордер
extern int slippage = 30; //Максимально допустимое отклонение цены для рыночных ордеров (ордеров на покупку или продажу).
//--------------------------------------------------------------------
datetime TimeBarB,TimeBarS;
//--------------------------------------------------------------------
int start()
{
ObjectsDeleteAll(0,OBJ_ARROW);
ObjectsDeleteAll(0,OBJ_TREND);
double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
double OSL=0,StLo=0,PriceB=0,PriceS=0,OOP=0,SL=0,TP=0;
int b=0,s=0,TicketB=0,TicketS=0,OT;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
OT=OrderType();
OSL = NormalizeDouble(OrderStopLoss(),Digits);
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
SL=OSL;
if(OT==OP_BUY)
{
b++;
if(OSL<OOP && NoLoss!=0)
{
StLo=NormalizeDouble(OOP+MinProfitNoLoss*Point,Digits);
if(StLo>OSL && StLo<=NormalizeDouble(Bid-STOPLEVEL*Point,Digits)) SL=StLo;
}
if(TrailingStop>=STOPLEVEL && TrailingStop!=0 && (Bid-OOP)/Point>=TrailingStart)
{
StLo=NormalizeDouble(Bid-TrailingStop*Point,Digits);
if(StLo>=OOP && StLo>OSL+StepTrall*Point) SL=StLo;
}
if(SL>OSL)
{
if(!OrderModify(OrderTicket(),OOP,SL,TP,0,0)) Print("Error ",GetLastError()," Order Modify Buy SL ",OSL,"->",SL);
else Print("Order Buy Modify SL ",OSL,"-",SL);
}
}
if(OT==OP_SELL)
{
s++;
if((OSL>OOP || OSL==0) && NoLoss!=0)
{
StLo=NormalizeDouble(OOP-MinProfitNoLoss*Point,Digits);
if((StLo<OSL || OSL==0) && StLo>=NormalizeDouble(Ask+STOPLEVEL*Point,Digits)) SL=StLo;
}
if(TrailingStop>=STOPLEVEL && TrailingStop!=0 && (OOP-Ask)/Point>=TrailingStart)
{
StLo=NormalizeDouble(Ask+TrailingStop*Point,Digits);
if(StLo<=OOP && (StLo<OSL-StepTrall*Point || OSL==0)) SL=StLo;
}
if((SL<OSL || OSL==0) && SL!=0)
{
if(!OrderModify(OrderTicket(),OOP,SL,TP,0,0)) Print("Error ",GetLastError()," Order Modify Sell SL ",OSL,"->",SL);
else Print("Order Sell Modify SL ",OSL,"-",SL);
}
}
if(OT==OP_BUYSTOP) {PriceB=OOP; TicketB=OrderTicket();}
if(OT==OP_SELLSTOP) {PriceS=OOP; TicketS=OrderTicket();}
}
}
}
if(b+TicketB==0)
{
if(Stoploss>=STOPLEVEL && Stoploss!=0) SL=NormalizeDouble(Bid-Stoploss*Point,Digits); else SL=0;
if(Takeprofit>=STOPLEVEL && Takeprofit!=0) TP=NormalizeDouble(Ask+Takeprofit*Point,Digits); else TP=0;
if(OrderSend(Symbol(),OP_BUYSTOP,Lot,NormalizeDouble(Ask+Step*Point,Digits),slippage,SL,TP,"news",Magic,0,0)!=-1) TimeBarB=TimeCurrent();
}
if(s+TicketS==0)
{
if(Stoploss>=STOPLEVEL && Stoploss!=0) SL=NormalizeDouble(Ask+Stoploss*Point,Digits); else SL=0;
if(Takeprofit>=STOPLEVEL && Takeprofit!=0) TP=NormalizeDouble(Bid-Takeprofit*Point,Digits); else TP=0;
if(OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Bid-Step*Point,Digits),slippage,SL,TP,"news",Magic,0,0)!=-1) TimeBarS=TimeCurrent();
}
if(TicketB!=0)
{
if(TimeBarB<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Ask+Step*Point,Digits)-PriceB)/Point>StepTrall)
{
if(Stoploss>=STOPLEVEL && Stoploss!=0) SL=NormalizeDouble(Bid-Stoploss*Point,Digits); else SL=0;
if(Takeprofit>=STOPLEVEL && Takeprofit!=0) TP=NormalizeDouble(Ask+Takeprofit*Point,Digits); else TP=0;
if(OrderModify(TicketB,NormalizeDouble(Ask+Step*Point,Digits),SL,TP,0,0)) TimeBarB=TimeCurrent();
}
}
if(TicketS!=0)
{
if(TimeBarS<TimeCurrent()-TimeModify && MathAbs(NormalizeDouble(Bid-Step*Point,Digits)-PriceS)/Point>StepTrall)
{
if(Stoploss>=STOPLEVEL && Stoploss!=0) SL=NormalizeDouble(Ask+Stoploss*Point,Digits); else SL=0;
if(Takeprofit>=STOPLEVEL && Takeprofit!=0) TP=NormalizeDouble(Bid-Takeprofit*Point,Digits); else TP=0;
if(OrderModify(TicketS,NormalizeDouble(Bid-Step*Point,Digits),SL,TP,0,0)) TimeBarS=TimeCurrent();
}
}
return(0);
}
//--------------------------------------------------------------------
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
После модификации отложек, сраэу же удалять стрелки, появляющиеся на графике после модификации.
В принципе я практически со все разобрался сам, но стрелки при модификации отложек забивают график и очень трудно найти среди них рыночный ордер.
string name=ObjectName(i);
ObjectDelete(name);
//+------------------------------------------------------------------+
//| IndTrail.mq4 |
//| Copyright 2016, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
input int Buffer=0;
input string IndName="GoFX-3MA-MTF-Non-H1";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int r=0;
bool m;
if(IsTesting() && OrdersTotal()<1)
{
//r = OrderSend(NULL,0,0.1,Ask,30,Ask-500*Point,0,"",0,0,Blue);
r = OrderSend(NULL,1,0.1,Bid,30,Ask+500*Point,0,"",0,0,Red);
}
double StopLevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
double sl=NormalizeDouble(iCustom(NULL,0,IndName,Buffer,0),Digits);
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(sl>OrderOpenPrice() && sl!=OrderStopLoss())
{
if(sl<Bid-StopLevel) m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sl,Digits),OrderTakeProfit(),0,White);
}
}
if(OrderType()==OP_SELL)
{
if(sl<OrderOpenPrice() && sl!=OrderStopLoss())
{
if(sl>Ask+StopLevel) m=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(sl,Digits),OrderTakeProfit(),0,White);
}
}
}
}
}
}
//+------------------------------------------------------------------+
if (OrdTotalBuy()==1) Mnog1 = Mnog;
if (OrdTotalBuy()==2) Mnog1 = Mnog+0.05;
if (OrdTotalBuy()==3) Mnog1 = Mnog+0.1;
if (OrdTotalBuy()==4) Mnog1 = Mnog+0.15;
if(OrdTotalBuy()>0) Mnog1 = Mnog+0.05*(OrdTotalBuy()-1);
AM2