
//+------------------------------------------------------------------+
//| CloseStop.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 Lots = 0.1; // лот
extern double Koeff = 3; // коэффициент расширения диапазона
extern int StopLoss = 2000; // лось
extern int TakeProfit = 3000; // язь
extern int Expiration = 24; // истечение ордера в часах
extern int MAPeriod = 12; // период МА
extern int Delta = 100; // дельта
extern int Slip = 30; // реквот
extern int Magic = 123456; // магик
datetime t=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)
{
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);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double ma=iMA(NULL,0,MAPeriod,0,0,0,0);
if(CountOrders(0)<1 && CountOrders(1)<1)
{
if(CountOrders(5)<1 && Bid>Low[1] && Bid>ma && (Close[1]>High[1]-(High[1]-Low[1])/Koeff)) PutOrder(5,Low[1]-Delta*Point); //c>h-(h-l)/3 && <h
if(CountOrders(4)<1 && Bid<High[1] && Bid<ma && (Close[1]>High[1]-(High[1]-Low[1])/Koeff)) PutOrder(4,High[1]+Delta*Point);
}
Comment("\n");
}
//+------------------------------------------------------------------+
Отладка это достаточно длительный процесс. Когда будет оплачиваемый заказ или просьба от автора топика, тогда буду смотреть.
AM2