Toute question de débutant, afin de ne pas encombrer le forum. Professionnels, ne passez pas à côté. Nulle part sans toi - 6. - page 451

 
//+------------------------------------------------------------------+
//| supprimer et/ou clôturer un ordre, filtré par le volume.
//---------------------------------------------------------------------
#property show_inputs
//--------------------------------------------------------------------
extern double MinLot = 0.01 ; //lot minimal qui doit être supprimé/fermé
extern double MaxLot = 0.1 ; //lot maximal qui est supprimé/ contourné
extern bool Buy = false ; //supprime/ferme le sens des ordres d'achat
extern bool Sell = false ; //supprime/clôture la direction des ordres de vente
extern bool pending = true ; //supprime les ordres en attente
extern bool market = true ; //clôturer les positions de marché
extern int slippage = 2 ; //slippage du prix à la clôture des positions de marché
//--------------------------------------------------------------------
int start()
{
double SL,TP ;
string txt=StringConcatenate("Script supprimer ou fermer l'ordre, début ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) ;
RefreshRates() ;

bool error=true ;
int Erreur,OT,Ticket,nn ;
double OOP,OL ;
while(true)
{
for (int j = OrdersTotal()-1 ; j >= 0 ; j--)
{
si (OrderSelect(j, SELECT_BY_POS))
{
si ((OrderSymbol() == Symbol())
{
OL = OrderLots() ;
si (OL<MinLot || OL>MaxLot) continuer ;
OT = OrderType() ;
si (!market && OT<2) continuer ;
si (!pending && OT>1) continuer ;
Ticket = OrderTicket() ;
OOP = OrderOpenPrice() ;
si (OT==OP_BUY)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Bid,Digits),slippage,Red) ;
if (error) txt = StringConcatenate(txt,"\nClosed BUY Order",Ticket) ;
sinon txt = StringConcatenate(txt,"\nClosing error ",GetLastError()) ;
}
si (OT==OP_SELL)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,Blue) ;
if (error) txt = StringConcatenate(txt, "SELL order closed",Ticket ;)
sinon txt = StringConcatenate(txt,"\nError ",GetLastError()," close ",Ticket) ;
}
si (OT>1)
{
error=OrderDelete(Ticket) ;
if (error) txt = StringConcatenate(txt,"\nOrderDeleted ",StrOrdersType(OT)," ",Ticket) ;
else txt = StringConcatenate(txt,"\nError ",GetLastError()," removal ",StrOrdersType(OT)," ",Ticket) ;
}
si (!error)
{
Erreur = GetLastError() ;
si (Error<2) continuer ;
si (Error==129)
{ Comment("Prix incorrect ",TimeToStr(TimeCurrent(),TIME_SECONDS)) ;
Dormir (5000) ;
RefreshRates() ;
continuer ;
}
si (Error==146)
{
j++ ;
si (IsTradeContextBusy()) Sleep(2000) ;
continuer ;
}
Comment("Error ",Error," closing order N ",OrderTicket(),
",TimeToStr(TimeCurrent(),TIME_SECONDS)) ;
}
}
}
}
int n=0 ;
for (j = 0 ; j < OrdersTotal() ; j++)
{
si (OrderSelect(j, SELECT_BY_POS))
{
si (OrderSymbol() == Symbol())
{
OL = OrderLots() ;
si (OL<MinLot || OL>MaxLot) continuer ;
OT = OrderType() ;
si (!market && OT<2) continuer ;
si (!pending && OT>1) continuer ;
n++ ;
}
}
}
si (n==0) pause ;
nn++ ;
if (nn>10) {Comment("Failed to close all trades, there is still ",n);break;}
Sleep(1000) ;
RefreshRates() ;
}
Comment(txt,"\nScript a terminé son travail ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)) ;
retour(0) ;
}
//--------------------------------------------------------------------
string StrOrdersType(int t)
{
si (t==OP_BUY) return("Buy") ;
si (t==OP_SELL) return("Sell") ;
si (t==OP_BUYLIMIT) return("BuyLimit") ;
si (t==OP_SELLLIMIT) return("SellLimit") ;
si (t==OP_BUYSTOP) return("BuyStop") ;
si (t==OP_SELLSTOP) return("SellStop") ;
}

//--------------------------------------------------------------------

Que dois-je ajouter ou modifier dans le script pour fermer tous les ordres ouverts pour toutes les paires par taille de lot.

 
Vitek, utilisez le bouton SRC pour insérer le code! Qui a besoin de fouiller dans des gribouillages illisibles ? !
 
pu6ka:
Oui, les prix des demandes ne sont pas visibles, mais ils le sont :)
Dans le visualiseur, vous pouvez appuyer sur pause et sélectionner "Show Ask line" dans les propriétés du graphique et continuer le test. Le graphique des prix dans MT4 est normalement tracé par Bid.

De quoi dépend la qualité des tests et comment l'augmenter au maximum ?
 
Zver4991:

et de quoi dépend la qualité des tests et comment l'améliorer vers le maximum ?
Honnêtement, je ne sais pas. Je n'en ai pas encore eu besoin, regardez sur le site web.
 

Chers professionnels.
Pourriez-vous me dire comment ouvrir une grille d'ordres en attente sans utiliser de cycles ?
Si ce n'est pas difficile, veuillez montrer au moins un exemple grossier d'un tel code,
avec la possibilité de changer le pas et la taille du lot de chaque ordre successif de la grille.

 
Forexman77:
J'ai mis des lignes

au lieu deint Ticket ; des erreurs apparaissent :

'=' - parenthèse carrée gauche attendue pour un tableau('=' - parenthèse carrée gauche, attendue pour un tableau)

'>' - parenthèse carrée gauche attendue pour un tableau ('=' - parenthèse carrée gauche attendue pour un tableau)

'>' - jeton inattendu('>' - jeton inattendu)

')' - affectation attendue('' - affectation attendue )

continue" - "break" ou "continue" utilisé uniquement dans certaines boucles)

et bien d'autres choses encore.


Donc Ticket est toujours utilisé quelque part dans l'ancienne version. Nous devons nettoyer le code...
 
1mql:

Chers professionnels.
Pourriez-vous me dire comment ouvrir une grille d'ordres en attente sans utiliser de boucles ?
Si cela n'est pas difficile, veuillez montrer au moins un exemple approximatif d'un tel code,
Si vous pouvez modifier le pas et la taille du lot de chaque ordre suivant dans la grille.

Oui, en fait, c'est la même chose que dans une boucle... ...mais sans la boucle. Montrez-nous comment vous ouvrez une boucle et expliquez-nous pourquoi vous ne voulez pas utiliser de boucles, car ce que vous essayez d'obtenir n'est pas clair.
 
borilunad:
Vitek, utilisez le bouton SRC pour coller le code ! Qui a besoin de fouiller dans des gribouillages illisibles ?

//+------------------------------------------------------------------+
//| удаления и/или закрытие ордера, с фильтрацией его по объему |
//---------------------------------------------------------------------
#property show_inputs
//--------------------------------------------------------------------
extern double MinLot = 0.01; //минимальный лот который удаляем/закываем
extern double MaxLot = 0.1; //максимальный лот который удаляем/закываем
extern bool Buy = false; //удалять/закрывать направление buy ордеров
extern bool Sell = false; //удалять/закрывать направление sell ордеров
extern bool pending = true; //удалить отложенные ордера
extern bool market = true ; //закрыть рыночные позиции
extern int slippage = 2; //проскальзывание цены при закрытии рыночных позиций
//--------------------------------------------------------------------
int start()
{
double SL,TP;
string txt=StringConcatenate("Скрипт удаления или закрытие ордера, старт ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
RefreshRates();

bool error=true;
int Error,OT,Ticket,nn;
double OOP,OL;
while(true)
{
for (int j = OrdersTotal()-1; j >= 0; j--)
{
if (OrderSelect(j, SELECT_BY_POS))
{
if ((OrderSymbol() == Symbol()))
{
OL = OrderLots();
if (OL<MinLot || OL>MaxLot) continue;
OT = OrderType();
if (!market && OT<2) continue;
if (!pending && OT>1) continue;
Ticket = OrderTicket();
OOP = OrderOpenPrice();
if (OT==OP_BUY)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Bid,Digits),slippage,Red);
if (error) txt = StringConcatenate(txt,"\nЗакрыт ордер BUY ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка закрытия ",GetLastError());
}
if (OT==OP_SELL)
{
error=OrderClose(Ticket,OrderLots(),NormalizeDouble(Ask,Digits),slippage,Blue);
if (error) txt = StringConcatenate(txt,"\nЗакрыт ордер SELL ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," закрытия ",Ticket);
}
if (OT>1)
{
error=OrderDelete(Ticket);
if (error) txt = StringConcatenate(txt,"\nУдален ордер ",StrOrdersType(OT)," ",Ticket);
else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," удаления ",StrOrdersType(OT)," ",Ticket);
}
if (!error)
{
Error = GetLastError();
if (Error<2) continue;
if (Error==129)
{ Comment("Неправильная цена ",TimeToStr(TimeCurrent(),TIME_SECONDS));
Sleep(5000);
RefreshRates();
continue;
}
if (Error==146)
{
j++;
if (IsTradeContextBusy()) Sleep(2000);
continue;
}
Comment("Ошибка ",Error," закрытия ордера N ",OrderTicket(),
" ",TimeToStr(TimeCurrent(),TIME_SECONDS));
}
}
}
}
int n=0;
for (j = 0; j < OrdersTotal(); j++)
{
if (OrderSelect(j, SELECT_BY_POS))
{
if (OrderSymbol() == Symbol())
{
OL = OrderLots();
if (OL<MinLot || OL>MaxLot) continue;
OT = OrderType();
if (!market && OT<2) continue;
if (!pending && OT>1) continue;
n++;
}
}
}
if (n==0) break;
nn++;
if (nn>10) {Comment("Не удалось закрыть все сделки, осталось еще ",n);break;}
Sleep(1000);
RefreshRates();
}
Comment(txt,"\nСкрипт закончил свою работу ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
return(0);
}
//--------------------------------------------------------------------
string StrOrdersType(int t)
{
if (t==OP_BUY) return("Buy");
if (t==OP_SELL) return("Sell");
if (t==OP_BUYLIMIT) return("BuyLimit");
if (t==OP_SELLLIMIT) return("SellLimit");
if (t==OP_BUYSTOP) return("BuyStop");
if (t==OP_SELLSTOP) return("SellStop");
}
//--------------------------------------------------------------------

Que dois-je ajouter ou modifier pour clôturer tous les ordres ouverts sur toutes les paires par taille de lot.

 
Vitek2010:

Que dois-je ajouter ou modifier pour clôturer tous les ordres ouverts sur toutes les paires par taille de lot.

En dessous du dernier externe :
extern int slippage = 2 ; // slippage du prix lors de la fermeture des positions de marché

insérez-en un autre :
extern bool total_symb = true ; //sur toutes les paires

et sur chaque ligne :
si((OrderSymbol() == Symbol())
и
si(OrderSymbol() == Symbol())

remplacer par celui-ci :
si(OrderSymbol() == Symbol() || total_symb)

Théoriquement, cela devrait fonctionner, vérifiez-le.

 
La question s'est posée, est-il possible d 'écrire un Expert Advisor ou un script, qui serait d'atteindre par exemple une perte de 2% sur le jour fermerait toutes les transactions ?
Raison: