//+------------------------------------------------------------------+
//| ExBB.mq4 |
//| Copyright 2015, AM2 |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, AM2"
#property link "."
#property description "BBands expert advisor"
//--- Inputs
extern double Lots = 0.1; // лот
extern int StopLoss = 5000; // лось
extern int TakeProfit = 5000; // язь
extern int Shift = 0; // сдвиг
extern int Slip = 30; // слипаж
//----
extern int Length = 20; // период BB
extern int Deviation = 2; // отклонение ВВ
extern int Magic = 20; // магик
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void OpenPos()
{
int res;
//--- get Ind
double BBBlue=iCustom(Symbol(),0,"BBands_Stop_v1",Length,Deviation,0,Shift);
double BBRed=iCustom(Symbol(),0,"BBands_Stop_v1",Length,Deviation,1,Shift);
double BBBlue2=iCustom(Symbol(),0,"BBands_Stop_v1",Length,Deviation,0,Shift+1);
double BBRed2=iCustom(Symbol(),0,"BBands_Stop_v1",Length,Deviation,1,Shift+1);
//--- sell conditions
if(BBRed>0 && BBBlue2>0)
{
res=OrderSend(Symbol(),OP_SELL,Lots,NormalizeDouble(Bid,Digits),
Slip,NormalizeDouble(Bid+StopLoss*Point,Digits),
NormalizeDouble(Bid-TakeProfit*Point,Digits),"",Magic,0,Red);
return;
}
//--- buy conditions
if(BBBlue>0 && BBRed2>0)
{
res=OrderSend(Symbol(),OP_BUY,Lots,NormalizeDouble(Ask,Digits),
Slip,NormalizeDouble(Ask-StopLoss*Point,Digits),
NormalizeDouble(Ask+TakeProfit*Point,Digits),"",Magic,0,Blue);
return;
}
//---
}
//+------------------------------------------------------------------+
//| OnTick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(t!=Time[0])
{
OpenPos();
t=Time[0];
}
}
//+------------------------------------------------------------------+