#property copyright "0ll"
#property strict
input double lot = 0.1;
input int SmoothPeriod = 5;
input int SmoothMethod = 1;
input int TP = 0;
input int SL = 0;
input int Magic = 24011;
int OnInit()
{
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { }
int idir = -1, odir = -1, ocnt = 0;
double opl = 0, bufBuy, bufSell, bufBuy2, bufSell2;
void OnTick()
{
if (!NewBar()) return;
ordCount();
bufBuy = iCustom(NULL,0,"Market\\volution",SmoothPeriod,SmoothMethod,0,1,1);
bufBuy2 = iCustom(NULL,0,"Market\\volution",SmoothPeriod,SmoothMethod,0,1,2);
bufSell = iCustom(NULL,0,"Market\\volution",SmoothPeriod,SmoothMethod,0,2,1);
bufSell2 = iCustom(NULL,0,"Market\\volution",SmoothPeriod,SmoothMethod,0,2,2);
idir = -1;
if (bufBuy == bufSell && bufBuy2 == EMPTY_VALUE && bufSell2 != EMPTY_VALUE) idir = OP_BUY;
if (bufBuy == bufSell && bufBuy2 != EMPTY_VALUE && bufSell2 == EMPTY_VALUE) idir = OP_SELL;
// if (odir >= 0 && opl > 2)ordClose(odir);
if (idir == 1 - odir)
{
ordClose(odir);
}
if (idir >= 0 && odir < 0) ordOpen(idir);
}
//+------------------------------------------------------------------+
void ordOpen(int dir)
{
int tik=-1;
tik = OrderSend(_Symbol,dir,lot,(dir==OP_BUY?Ask:Bid),10,0,0,"Check_Indi",Magic,0,(dir==OP_BUY?Blue:Red));
if (tik > 0)
{
odir = dir; ocnt = 1;
OrderSelect(tik, SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),(dir==OP_BUY?Bid-SL*_Point:Ask+SL*_Point),(dir==OP_BUY?Bid+TP*_Point:Ask-TP*_Point),0);
}
}
void ordClose(int dir)
{
if (OrderClose(OrderTicket(),OrderLots(), (dir==OP_BUY?Bid:Ask),10, Gray)) { odir = -1; ocnt = 0; opl = 0; }
}
void ordCount()
{
int no;
odir = -1; ocnt = 0; opl = 0;
for (no=0; no < OrdersTotal(); no++) //Сбор инфы об открытых ордерах
{
if (!OrderSelect(no, SELECT_BY_POS, MODE_TRADES)) continue;
if (!(OrderSymbol()== _Symbol && OrderMagicNumber() == Magic)) continue;
odir = OrderType();
ocnt++;
opl += OrderProfit()+OrderCommission()+OrderSwap();
}
}
bool NewBar()
{
static datetime new_Bar;
if (new_Bar == Time[1]) return(false); //Если бар не закрыт - выход
new_Bar = Time[1];
return(true);
}