
//+------------------------------------------------------------------+
//| Kanal.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // торговый объем ордера
extern double MaxLot = 5; // максимальный торговый объем
extern double KLot = 2; // увеличение лота
extern double Price = 1.19; // цена
extern int StopLoss = 500; // лось
extern int TakeProfit = 200; // язь
extern int Delta = 200; // дельта
extern int BuySell = 0; // 0-buy 1-sell 2-both
extern int Step = 100; // шаг
extern int Slip = 30; // реквот
extern bool MA = false; // фильтр
extern int Magic = 123; // магик
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
{
int r=0;
color clr=clrNONE;
double sl=0,tp=0;
datetime expiration=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 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);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades()
{
int count=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()<2) count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров |
//+------------------------------------------------------------------+
void DelOrder(int type)
{
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()==type) del=OrderDelete(OrderTicket());
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int LastType()
{
int tp=8;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<2) tp=OrderType();
break;
}
}
}
return(tp);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double LastLot()
{
double lt=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) lt=OrderLots();
break;
}
}
}
return(lt);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bid>Price && CountTrades()<1)
{
if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Lots);
if(CountOrders(2)<1) PutOrder(2,Bid-Delta*Point,Lots);
}
if(CountOrders(3)<1)
{
DelOrder(2);
if(CountOrders(2)<1) PutOrder(2,Price-Delta*Point,LastLot()*KLot);
}
if(CountOrders(2)<1)
{
DelOrder(3);
if(CountOrders(3)<1) PutOrder(3,Price+Delta*Point,LastLot()*KLot);
}
Comment("");
}
//+------------------------------------------------------------------+
AM2