J'ai écrit un code qui, lorsqu'un ordre ferme tous les autres ordres en attente, mais le problème est que j'ai écrit 4 ordres 2, 3, 4, 5. Ainsi, lorsque les prochains ordres en attente 6, 7, 8, etc. sont ouverts, ils ne doivent pas être fermés. Les nombres d'ordres surlignés en rouge doivent être changés en ordres que tous les ordres en attente seront fermés.
J'ai écrit un code qui, lorsqu'un ordre ferme tous les autres ordres en attente, mais le problème est que j'ai écrit 4 ordres 2, 3, 4, 5. Ainsi, lorsque les prochains ordres en attente 6, 7, 8, etc. sont ouverts, ils ne doivent pas être fermés. Les numéros des ordres marqués en rouge doivent être changés en ordres pour lesquels tous les ordres en attente seront fermés.
Tout d'abord, nous vérifions dans la boucle si la position a été récemment fermée ou non, pour laquelle nous aurons besoin de OrdersHistoryTotal. Où nous vérifions l'heure de fermeture de la position OrderCloseTime, si elle est supérieure à la dernière dans la variable, alors nous bouclons sur tous les OrdersTotal ouverts. Et fermez-les.
P.S. Insérez le code en utilisant Alt+S ou la touche
Par exemple, ceci
// retrieving info from trade historyint i,accTotal=OrdersHistoryTotal();
for(i=0;i<accTotal;i++)
{
//---- check selection resultif(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
break;
}
// работа с ордером ...
}
externstring TimeStart = "04:00"; //Время начала контрольного периодаexternstring TimeEnd = "09:00"; //Время окончания контрольного периодаexternstring TimeCloseOrder = "23:30";//Время в которое происходит закрытие всех ордеровexterndouble LOT = 0.1;
externint Magic = 777;
externdouble K_martin = 2;
externbool No_Loss = true;
int slippage = 3;
double marga,Lot,SL,TP;
int tip,Orders,tipOrders,TradeDey;
//-------------------------------------------------------------------+int init()
{
if (Digits==5 || Digits==3) slippage = 30;
}
int start()
{
datetime Time_Start = StrToTime(StringConcatenate(Day(),".",Month(),".",Year()," ",TimeStart, ":00"));
datetime Time_End = StrToTime(StringConcatenate(Day(),".",Month(),".",Year()," ",TimeEnd, ":00"));
datetime Time_CloseOrder = StrToTime(StringConcatenate(Day(),".",Month(),".",Year()," ",TimeCloseOrder,":00"));
if (Time_CloseOrder>Time_End) if (CurTime()>=Time_CloseOrder) CLOSEORDERS();
int tip;
if (Orders>OrdersTotal()) tip=CloseOrder();
Orders=OrdersTotal();
if (ORDERS(0)==0 && tip==0 && (CurTime()<Time_CloseOrder || Time_CloseOrder<=Time_End) && TradeDey!=TimeDay(CurTime()))
{
int BarStart = iBarShift(NULL,0,Time_Start,false);
int BarEnd = iBarShift(NULL,0,Time_End ,false);
double Max_Price=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,BarStart-BarEnd,BarEnd));
double Min_Price=iLow (NULL,0,iLowest (NULL,0,MODE_LOW, BarStart-BarEnd,BarEnd));
if (TimeCurrent()>Time_End && ObjectFind("bar0"+Time_End)==-1)
{
ObjectCreate("bar0"+Time_End, OBJ_RECTANGLE, 0, 0,0, 0,0);
ObjectSet ("bar0"+Time_End, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet ("bar0"+Time_End, OBJPROP_COLOR, Blue);
ObjectSet ("bar0"+Time_End, OBJPROP_BACK, true);
ObjectSet ("bar0"+Time_End, OBJPROP_TIME1 ,Time_Start);
ObjectSet ("bar0"+Time_End, OBJPROP_PRICE1,Max_Price);
ObjectSet ("bar0"+Time_End, OBJPROP_TIME2 ,Time_End);
ObjectSet ("bar0"+Time_End, OBJPROP_PRICE2,Min_Price);
}
if (Bid>Max_Price) OrderSend(Symbol(),OP_BUY,LOT,Bid,slippage,Min_Price,
NormalizeDouble(Ask + Max_Price-Min_Price,Digits),"BreakdownLevel",Magic,Blue);
if (Bid<Min_Price) OrderSend(Symbol(),OP_SELL,LOT,Bid,slippage,Max_Price,
NormalizeDouble(Bid - Max_Price+Min_Price,Digits),"BreakdownLevel",Magic,Blue);
return;
}
if (No_Loss) No_Loss();
if (tip==1 && TradeDey!=TimeDay(CurTime()))
{
Lot=Lot*K_martin;
if (tipOrders==0) OrderSend(Symbol(),OP_SELL,Lot,Bid,slippage,SL,TP,"Nevalyashka",Magic,Blue);
if (tipOrders==1) OrderSend(Symbol(),OP_BUY ,Lot,Ask,slippage,SL,TP,"Nevalyashka",Magic,Blue);
}
return(0);
}
//-------------------------------------------------------------------+int CloseOrder()
{
string txt;
double loss;
int i=OrdersHistoryTotal()-1;
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
tipOrders=OrderType();
Lot=OrderLots();
loss = MathAbs(OrderProfit()/MarketInfo(Symbol(),MODE_TICKVALUE)/Lot/K_martin);
if (tipOrders==0)
{
TP=NormalizeDouble(Bid - loss*Point,Digits);
SL=NormalizeDouble(Ask + loss*Point,Digits);
}
if (tipOrders==1)
{
SL=NormalizeDouble(Bid - loss*Point,Digits);
TP=NormalizeDouble(Ask + loss*Point,Digits);
}
if (OrderClosePrice()==OrderTakeProfit() || OrderProfit()>=0) TradeDey=TimeDay(CurTime());
if (OrderClosePrice()==OrderStopLoss()) return(1);
}
}
return(0);
}
//+-----------------------------------------------------------------+int ORDERS(int tip)
{
int N_Sell,N_Buy;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol()==Symbol() && Magic==OrderMagicNumber())
{
if (OrderType()==OP_BUY ) N_Buy++;
if (OrderType()==OP_SELL) N_Sell++;
}
}
}
if (tip== 0) return(N_Buy+N_Sell);
if (tip== 1) return(N_Buy);
if (tip==-1) return(N_Sell);
}
//-------------------------------------------------------------------+void No_Loss()
{
int tip;
double TP,OOP;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS)==true)
{
tip = OrderType();
if (tip<2 && OrderSymbol()==Symbol())
{
if (OrderMagicNumber()!=Magic) continue;
TP = OrderTakeProfit();
OOP = OrderOpenPrice();
if (tip==0) //Bay
{
if (OrderStopLoss()>OrderOpenPrice()+Ask-Bid) return;
if ((TP-OOP)/2+OOP<=Bid)
OrderModify(OrderTicket(),OOP,NormalizeDouble(OOP+Ask-Bid,Digits),TP,0,White);
}
if (tip==1) //Sell
{
if (OrderStopLoss()<OrderOpenPrice()-Ask+Bid) return;
if (OOP-(OOP-TP)/2>=Ask)
OrderModify(OrderTicket(),OOP,NormalizeDouble(OOP-Ask+Bid,Digits),TP,0,White);
}
}
}
}
}
//------------------------------------------------------------------+void CLOSEORDERS()
{
bool error;
int err;
while (true)
{ error=true;
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol()!=Symbol()||Magic!=OrderMagicNumber()) continue;
if (OrderType()==OP_BUY)
error=OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
if (OrderType()==OP_SELL)
error=OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
if (!error) {err++;Sleep(2000);RefreshRates();}
if (error || err >5) return;
}
}
//-------------------------------------------------------------------+
Voici une question, un problème avec les takeprofits et les stoplosses, pour une raison quelconque les TP et SL changent, sur les ordres ouverts avec un lot augmenté, lui-même . Et cela augmente les lots, mais la fermeture par TP ne permet pas de restituer le montant des pertes. Pourquoi ça arrive, qu'est-ce qui ne va pas ?
Bonjour, je n'ai pas écrit la fonction. Le robot écrit une erreur à la position de départ 0 incorrecte pour la fonction ArraySort. Je vous serais reconnaissant si vous pouviez m'aider à le réparer et m'expliquer la fonction.
void MaxMinProfit()
{
int i, N, MaxTic, MinTic;
double MinProf=0, MaxProf=0, OP, g, a[][2];
string MinSym, MaxSym;
ArrayResize(a, 0);
for (i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if (OrderType()==OP_SELL || OrderType()==OP_BUY )
{
OP = NormalizeDouble(OrderProfit()+OrderSwap()+OrderCommission(),2);
if (MinProf>OP)
{
MinProf=OP;
MinTic=OrderTicket();
MinSym=OrderSymbol();
}
if (OP>0)
{
N++;
ArrayResize(a, N);
a[N-1][0]=OP;
a[N-1][1]=OrderTicket();
}
}
}
}
ArraySort(a, WHOLE_ARRAY, 0, MODE_DESCEND);//MODE_ASCEND);for (i=0; i<Level; i++)
{
g+=a[i][0];
//int ti=a[i-2][1];
}
if(MinProf <0 && (g+MinProf)>=ProcMax)
{
for (i=0; i<Level; i++)
{
if (OrderSelect(a[i][1], SELECT_BY_TICKET, MODE_TRADES))
{
//Alert(a[i][1]);if (OrderType()== OP_BUY)
{
OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), Slip, CLR_NONE);
}
if (OrderType()== OP_SELL)
{
OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), Slip, CLR_NONE);
}
}
}
if (OrderSelect(MinTic, SELECT_BY_TICKET, MODE_TRADES))
{
if (OrderType()== OP_BUY)
{
OrderClose(MinTic, OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), Slip, CLR_NONE);
}
if (OrderType()== OP_SELL)
{
OrderClose(MinTic, OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), Slip, CLR_NONE);
}
}}
return;
}
Si vous n'avez pas de compte, veuillez vous inscrire
Autorisez l'utilisation de cookies pour vous connecter au site Web MQL5.com.
Veuillez activer les paramètres nécessaires dans votre navigateur, sinon vous ne pourrez pas vous connecter.
Vous êtes connecté. L'authentification à deux facteurs a été désactivée. Configurez-la à nouveau et scannez un nouveau code QR, ou continuez avec l'authentification à deux facteurs désactivée.
J'ai écrit un code qui, lorsqu'un ordre ferme tous les autres ordres en attente, mais le problème est que j'ai écrit 4 ordres 2, 3, 4, 5. Ainsi, lorsque les prochains ordres en attente 6, 7, 8, etc. sont ouverts, ils ne doivent pas être fermés. Les nombres d'ordres surlignés en rouge doivent être changés en ordres que tous les ordres en attente seront fermés.
void start(){
//----
double Take1 = Ask+20 *Point ;
double Take2 = Ask+0 *Point ;
double Take3 = Ask-20 *Point ;
double Take4 = Ask-40 *Point ;
double Take5 = Ask-60 *Point ;
double Stop = Bid-StopLoss *Point ;
si(OrdersTotal()==0){
OrderSend(Symbol(),0,0.01,Ask,30,Stop,Take1,",0,0,CLR_NONE) ;
OrderSend(Symbol(),2,0.02,Ask-20*Point,30,Stop,Take2,"",0,0,CLR_NONE) ;
OrderSend(Symbol(),2,0.04,Ask-40*Point,30,Stop,Take3,",0,0,CLR_NONE) ;
OrderSend(Symbol(),2,0.08,Ask-60*Point,30,Stop,Take4,",0,0,CLR_NONE) ;
OrderSend(Symbol(),2,0.16,Ask-80*Point,30,Stop,Take5,"",0,0,CLR_NONE) ;
}
si(OrdersTotal()==4)
{
OrdreSuppression(2) ;
}
si(OrdersTotal()==3)
{
OrdreSuppression(3) ;
}
si(OrdersTotal()==2)
{
OrdreSuppression(4) ;
}
si(OrdersTotal()==1)
{
OrdreSuppression(5) ;
retour(0) ;
}
J'ai écrit un code qui, lorsqu'un ordre ferme tous les autres ordres en attente, mais le problème est que j'ai écrit 4 ordres 2, 3, 4, 5. Ainsi, lorsque les prochains ordres en attente 6, 7, 8, etc. sont ouverts, ils ne doivent pas être fermés. Les numéros des ordres marqués en rouge doivent être changés en ordres pour lesquels tous les ordres en attente seront fermés.
Tout d'abord, nous vérifions dans la boucle si la position a été récemment fermée ou non, pour laquelle nous aurons besoin de OrdersHistoryTotal. Où nous vérifions l'heure de fermeture de la position OrderCloseTime, si elle est supérieure à la dernière dans la variable, alors nous bouclons sur tous les OrdersTotal ouverts. Et fermez-les.
P.S. Insérez le code en utilisant Alt+S ou la touche

Par exemple, ceci
Voici la condition if(OrdersTotal()==0). Mais comment écrire la condition s'il y a zéro baie?
Si (OP_BUY==0)
Si (OP_BUY==0)