//+------------------------------------------------------------------+
//| Delta.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 Lot1 = 0.1; // лот 1
extern double Lot2 = 0.1; // лот 2
extern int StopLoss1 = 200; // лось 1
extern int StopLoss2 = 200; // лось 2
extern int TakeProfit1 = 300; // язь 1
extern int TakeProfit2 = 300; // язь 2
extern int StartHour = 0; // час начала торговли
extern int Slip = 30; // реквот
extern int Shift = 1; // начальный бар
extern int Count = 9; // конечный бар
extern int Magic = 123; // магик
int counts=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,double lot=0.1,double sl=0,double tp=0)
{
int r=0;
color clr=Green;
if(type==1 || type==3 || type==5)
{
clr=Red;
if(sl>0) sl=NormalizeDouble(price+sl*Point,Digits);
if(tp>0) tp=NormalizeDouble(price-tp*Point,Digits);
}
if(type==0 || type==2 || type==4)
{
clr=Blue;
if(sl>0) sl=NormalizeDouble(price-sl*Point,Digits);
if(tp>0) tp=NormalizeDouble(price+tp*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 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 OneDayDeal()
{
bool result=true;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()<6 && TimeDay(OrderOpenTime())==Day())
{
result=false;//tp
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderType()==0 && (ot==0 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
RefreshRates();
cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(Bars<=MathMax(Shift, Count)+2) return;
int high=iHighest(NULL,0,MODE_HIGH,Count,Shift);
int low=iLowest(NULL,0,MODE_LOW,Count,Shift);
double h=High[high];
double l=Low[low];
if(TimeCurrent()>=StringToTime((string)StartHour+":00") && OrdersTotal()<1 && OneDayDeal())
{
if(Close[Shift]>Close[Count])
{
PutOrder(0,Ask,Lot1,StopLoss1,TakeProfit1);
PutOrder(5,l,Lot2,StopLoss2,TakeProfit2);
}
if(Close[Shift]<Close[Count])
{
PutOrder(1,Bid,Lot1,StopLoss1,TakeProfit1);
PutOrder(4,h,Lot2,StopLoss2,TakeProfit2);
}
}
if(CountTrades()>1) counts=CountTrades();
if(CountTrades()<1)
{
DelOrder();
counts=0;
}
if(counts==2 && CountTrades()<2)
{
CloseAll();
counts=0;
}
Comment("\n Count: ",counts);
}
//+------------------------------------------------------------------+
ошибка array out of range
Kashtan