Добрый день! Ваш советник AllCandlesHalf получился замечательный помощник.Могли бы Вы внести изменения в алгоритм закрытия ордеров ( закрываем ордера при появлении противоположной стрелки на меньшей " Amplitude ". А так же добавить в настройках «Shift» (бар индикатора)
AllCandlesHalf.zip (1 Kb)
Комментарии (1)
Не понял как сюда загрузить сам файл.
//+------------------------------------------------------------------+
//| AllCandlesHalf.mq4 |
//| Copyright 2021, AM2 |
//| www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright «Copyright 2021, AM2»
#property link «www.forexsystems.biz»
#property version «1.00»
#property strict
extern double Lots = 0.1; // торговый объем
extern int StopLoss = 0; // стоплосс ордера
extern int TakeProfit = 0; // тейкпрофит ордера
extern int Profit = 0; // профит в валюте
extern int BuyProfit = 5; // бай профит в валюте
extern int SellProfit = 5; // селл профит в валюте
extern int Count = 10; // число поз
extern int CloseSig = 1; // закрытие по сигналу
extern int Slip = 30; // проскальзывание ордера
extern int StartHour = 1; // начало торговли
extern int EndHour = 23; // окончание торговли
extern int Magic = 123; // магик
extern string IndName = «HalfTrend-1.02»;
extern int Amplitude = 2;
extern int Amplitude2 = 12;
extern int Shift = 0; // бар индикатора
datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Comment("");
}
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
{
double pr=0;
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))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
if(OrderType()==1 && (ot==1 || ot==-1))
{
pr+=OrderProfit()+OrderCommission()+OrderSwap();
}
}
}
}
return(pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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 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);
}
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
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,0,clr);
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double blu = iCustom(NULL,0,IndName,Amplitude,0,Shift);
double red = iCustom(NULL,0,IndName,Amplitude,1,Shift);
double blu2 = iCustom(NULL,0,IndName,Amplitude2,0,Shift);
double red2 = iCustom(NULL,0,IndName,Amplitude2,1,Shift);
bool buy = blu>0 && blu2>0;
bool sell = red>0 && red2>0;
bool smallAmpIsFirst = (Amplitude<=Amplitude2);
double closeBlu = smallAmpIsFirst? blu: blu2;
double closeRed = smallAmpIsFirst? red: red2;
bool closeBuySignal = closeBlu>0;
bool closeSellSignal = closeRed>0;
if(t!=Time[0])
{
if(AllProfit()>=Profit && Profit>0)
CloseAll();
if(AllProfit(0)>=BuyProfit && BuyProfit>0)
CloseAll(0);
if(AllProfit(1)>=SellProfit && SellProfit>0)
CloseAll(1);
if(CloseSig>0)
{
if(closeBuySignal)
{
CloseAll(1);
}
if(closeSellSignal)
{
CloseAll(0);
}
}
if(Hour()>=StartHour && Hour()<=EndHour && CountTrades()<Count)
{
if(buy)
{
PutOrder(0,Ask);
}
if(sell)
{
PutOrder(1,Bid);
}
}
t=Time[0];
}
Comment("\n Trades: ",CountTrades(),
"\n Profit: ",AllProfit(),
"\n Buy Profit: ",AllProfit(0),
"\n Sell Profit: ",AllProfit(1),
"\n Shift: ",Shift,
"\n Blu: ",blu,
"\n Red: ",red,
"\n Blu2: ",blu2,
"\n Red2: ",red2,
"\n Close Blu: ",closeBlu,
"\n Close Red: ",closeRed);
}
//+------------------------------------------------------------------+ Редактирован: 25 марта 2026, 10:21
5 Kadosh123456789 Сообщений: 14 - Kadosh
Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий