if(Open[1]-Close[1]>0)
{
if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point && Close[1]-Low[1]<High[1]-Open[1]) return(true);
}
//+------------------------------------------------------------------+
//| PinBar.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 35; // трал
extern int Expiration = 10; // истечение ордера в часах
extern int Delta = 100; // дельта
extern int Body = 30; // тело
extern int Nouse = 100; // нос
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Простой трал |
//+------------------------------------------------------------------+
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;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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); else sl=High[1];
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); else sl=Low[1];
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool buy()
{
if(Open[1]-Close[1]>0)
{
if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool sell()
{
if(Open[1]-Close[1]>0)
{
if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
{
if(CountOrders(4)<1 && buy()) PutOrder(4,High[1]+Delta*Point);
if(CountOrders(5)<1 && sell()) PutOrder(5,Low[1]-Delta*Point);
t=Time[0];
}
if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Bablos.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
extern int StopLoss = 500; // лось
extern int TakeProfit = 10; // язь
extern int Delta = 10; // расстояние для отложек
extern int Spread = 10; // спред
extern int Vol = 40; // волатильность
extern int Slip = 0; // реквот
extern int StartHour = 0; // час начала торговли
extern int StartMin = 30; // минута начала торговли
extern int EndHour = 23; // час окончания торговли
extern int EndMin = 30; // минута окончания торговли
extern int StopTrade = 0; // 1-остановка после закрытия всех ордеров
extern int Magic1 = 111; // магик 1
extern int Magic2 = 222; // магик 2
extern double Lots = 0.1; // лот
extern string SoundTake = "ok.wav"; // звук тейк
extern string SoundTrade="expert.wav"; // звук остановка
int cycle=0;
datetime t=0;
bool trade=true;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0,int mb=0,int he=0,int me=0)
{
datetime db, de; // Время начала и окончания работы
int hc; // Часы текущего времени торгового сервера
db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)hb+":"+(string)mb);
de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)he+":"+(string)me);
hc=TimeHour(TimeCurrent());
if(db>=de)
{
if(hc>=he) de+=24*60*60; else db-=24*60*60;
}
if(TimeCurrent()>=db && TimeCurrent()<=de) return(True);
else return(False);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,int magic)
{
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,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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())
{
if(OrderType()==type) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Подсчет позиций |
//+------------------------------------------------------------------+
int CountTrades(int ot=-1)
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==0 && (ot==0 || ot==-1)) count++;
if(OrderType()==1 && (ot==1 || ot==-1)) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ModifyOrders(int magic)
{
double all=0,tp=0,sl=0;
double 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()==OP_BUY || OrderType()==OP_SELL)
{
all+=OrderOpenPrice()*OrderLots();
count+=OrderLots();
}
}
}
}
if(count>0) all=NormalizeDouble(all/count,Digits);
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)
{
tp=NormalizeDouble(all+TakeProfit*Point,Digits);
sl=NormalizeDouble(all-StopLoss*Point,Digits);
if(OrderStopLoss()!=sl || OrderTakeProfit()!=tp)
bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
if(OrderType()==OP_SELL)
{
tp=NormalizeDouble(all-TakeProfit*Point,Digits);
sl=NormalizeDouble(all+StopLoss*Point,Digits);
if(OrderStopLoss()!=sl || OrderTakeProfit()!=tp)
bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Mode()
{
bool m;
double oop=0,sl=0,tp=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==2)
{
if((Ask-OrderOpenPrice()>Delta*Point) || (Ask-OrderOpenPrice()<Delta*Point))
{
oop=NormalizeDouble(Ask-Delta*Point,Digits);
if(StopLoss>0) sl=NormalizeDouble(oop-StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(oop+TakeProfit*Point,Digits);
if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
}
}
if(OrderType()==3)
{
if((OrderOpenPrice()-Bid>Delta*Point) || (OrderOpenPrice()-Bid<Delta*Point))
{
oop=NormalizeDouble(Bid+Delta*Point,Digits);
if(StopLoss>0) sl=NormalizeDouble(oop+StopLoss*Point,Digits);
if(TakeProfit>0) tp=NormalizeDouble(oop-TakeProfit*Point,Digits);
if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double vol=MathAbs((Open[0]-Close[0])/Point);
double spread=MarketInfo(NULL,MODE_SPREAD);
if(cycle>0 && CountTrades()<1 && StopTrade>0) trade=false;
if(trade==False)
{
PlaySound(SoundTrade);
Alert("SoundTrade");
}
if(cycle>0 && (CountTrades(0)<1 || CountTrades(0)<1))
{
PlaySound(SoundTake);
Alert("SoundTake");
}
if(trade)
{
if(vol>Vol && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin) && spread<=Spread)
{
if(t!=Time[0])
{
if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Magic1);
if(CountOrders(2)<1) PutOrder(2,Ask-Delta*Point,Magic2);
t=Time[0];
}
}
if(CountOrders(0)>0) ModifyOrders(Magic2);
if(CountOrders(1)>0) ModifyOrders(Magic1);
Mode();
if(CountTrades()>0) cycle++;
}
Comment("\n Trades: ",CountTrades(),
"\n Vol: ",NormalizeDouble(vol,1),
"\n Spread: ",spread,
"\n Cycle: ",cycle,
"\n Trade: ",trade);
}
//+------------------------------------------------------------------+
Просьба переделать написанный вами советник
//+------------------------------------------------------------------+
//| PinBar.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int BULevel = 0; // уровень БУ
extern int BUPoint = 30; // пункты БУ
extern int TrailingStop = 35; // трал
extern int Expiration = 10; // истечение ордера в часах
extern int Delta = 100; // дельта
extern int Body = 30; // тело
extern int Nouse = 100; // нос
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Простой трал |
//+------------------------------------------------------------------+
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;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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); else sl=High[1];
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); else sl=Low[1];
if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
}
r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool buy()
{
if(Open[1]-Close[1]>0)
{
if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool sell()
{
if(Open[1]-Close[1]>0)
{
if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(BULevel>0) BU();
if(TrailingStop>0) Trailing();
if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
{
if(buy() || sell())
{
if(CountOrders(4)<1) PutOrder(4,High[1]+Delta*Point);
if(CountOrders(5)<1) PutOrder(5,Low[1]-Delta*Point);
t=Time[0];
}
}
if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
}
//+------------------------------------------------------------------+
По моему заказчик просил о трёх рыночных ордерах по сигналу
а в этом коде как и было ставиться один рыночный и один отложенный
for(int i=1;i<=3;i++)
Андрей в советнике нет функции перевод в безубыток.
//+------------------------------------------------------------------+
//| PinBar.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 50; // лось
extern int TakeProfit = 70; // язь
extern int TrailingStop = 35; // трал
extern int Expiration = 10; // истечение ордера в часах
extern int Delta = 100; // дельта
extern int Body = 30; // тело
extern int Nouse = 100; // нос
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Простой трал |
//+------------------------------------------------------------------+
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 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,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
return;
}
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу |
//+------------------------------------------------------------------+
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());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool buy()
{
if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool sell()
{
if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
return(false);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TrailingStop>0) Trailing();
if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
{
if(buy() || sell())
{
if(CountOrders(4)<1) PutOrder(4,High[1]+Delta*Point);
if(CountOrders(5)<1) PutOrder(5,Low[1]-Delta*Point);
t=Time[0];
}
}
if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
}
//+------------------------------------------------------------------+
AM2