Проблема с ордерами так и осталась!!!
//+------------------------------------------------------------------+
//| ProBoy.mq4 |
//| Copyright 2024, AM2 |
//| https://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, AM2"
#property link "https://www.forexsystems.biz"
#property version "1.00"
#property strict
//--- Inputs
extern double Lots = 0.1; // лот
extern double KLot = 2; // умножение лота
extern double Profit = 11; // профит
extern int StopLoss = 0; // лось
extern int TakeProfit = 0; // язь
extern int Slip = 30; // реквот
extern int Magic = 123; // магик
datetime t=0;
double high_price,low_price;
//+------------------------------------------------------------------+
//| 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)
{
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,lot,NormalizeDouble(price,_Digits),Slip,sl,tp,"",Magic,0,clr);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
{
bool cl=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))
{
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 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 || (OrderType()<2 && type==-1))
count++;
}
}
}
return(count);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int FindOrderType()
{
int oticket,ticketNumber=0,type=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
oticket=OrderTicket();
if(oticket>ticketNumber)
{
ticketNumber=oticket;
type=OrderType();
}
}
}
}
return(type);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double AllProfit()
{
double profit=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)
profit+=OrderProfit()+OrderSwap()+OrderCommission();
}
}
}
return(profit);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DelOrder()
{
bool del=1;
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());
}
}
}
return;
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(AllProfit()>Profit && Profit>0)
{
CloseAll();
DelOrder();
}
//------------------------------------------------
if(CountTrades()>0 && CountTrades(5)<1 && CountTrades(4)<1)
{
if(FindOrderType()==1)
PutOrder(4,high_price,Lots*2);
if(FindOrderType()==0)
PutOrder(5,low_price,Lots*2);
}
//------------------------------------------------
if(t!=Time[0])
{
if(CountTrades()<1 && Close[1]>Open[1] && Close[2]<Open[2] && Close[3]<Open[3])
{
high_price=Ask;
low_price=Low[1];
PutOrder(0,Ask,Lots);
PutOrder(5,Low[1],Lots*2);
}
if(CountTrades()<1 && Close[1]<Open[1] && Close[2]>Open[2] && Close[3]>Open[3])
{
high_price=High[1];
low_price=Bid;
PutOrder(1,Bid,Lots);
PutOrder(4,High[1],Lots*2);
}
t=Time[0];
}
Comment("\n Profit: ",AllProfit(),
"\n CountTrades: ",CountTrades());
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
kvashnin007