
Андрей, сделаешь?это будет уже другой заказ
Все ТЗ там
Но потом он все отыграет, когда начнется безоткатный тренд
//+------------------------------------------------------------------+
//| UpDn.mq4 |
//| Copyright 2020, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // торговый объем ордера
extern int StopLoss = 0; // лось
extern int TakeProfit = 50; // язь
extern int Step = 70; // шаг
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
double p=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
p=Bid;
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;
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,Lots,NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CountTrades(int type=-1)
{
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 || type==-1)
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| Результат последней сделки |
//+------------------------------------------------------------------+
int LastDealResult()
{
int result=0;
if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()>0)
{
result=1;//tp
}
if(OrderProfit()<0)
{
result=2;//sl
}
}
}
return(result);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(LastDealResult()==1 && CountTrades()>1)
CloseAll();
if(Bid-p>Step*_Point)
{
PutOrder(0,Ask);
p=Bid;
}
if(p-Bid>Step*_Point)
{
PutOrder(1,Bid);
p=Bid;
}
Comment("\n Trades: ",CountTrades());
}
//+------------------------------------------------------------------+
Придумал, как избавиться от висяков. При срабатывании тейка нужно закрывать все открытые ордера
Сделайте так, чтобы советник торговал независимо от цен открытия и открытых ордеров. То есть, торговал постоянно.
1. открытие по сигналу
2. трал всех ордеров
3. закрытие по сигналу
4. закрытие по общему профиту
5. закрытие по тейку серии
6. реверс
7. в индикатор добавлены буферы стрелок
AM2