Fonctions utiles de KimIV - page 5

 

Merci de votre acceptation... ;)

Qu'est-ce que AND, OR, NOT
n'est pas difficile à comprendre, je suis juste intéressé par ces petites choses dans le code et leurs utilisations.

Ou, par exemple, ceci :
- la condition a est EGAL à b est facile à mettre en œuvre a==b
- Mais la condition a est INÉGALE à b est difficile à mettre en œuvre...

Désolé de remettre sur le tapis les notions de base, mais ceci sera probablement utile à de nombreux débutants...

Voici un code prêt à l'emploi avec des conditions d'entraînement au combat. :)
Il a tout... de la définition et de la disposition des champs à l'écriture du programmeur...
https://www.mql5.com/ru/forum/51521

 
kombat писал (а):
- Mais la condition a est INÉGALE à b pose déjà des difficultés...
a!=b;
 
Il me semble, Igor, que tu t'es un peu écarté du sujet et que tu es parti dans des explications.
Si je peux me permettre, je voudrais suggérer une fonction qui affiche tout ce qui se trouve dans le raccourci de la barre des tâches.
Je l'utilise pour surveiller les performances des EA au travail sans ouvrir le terminal (beaucoup de regards indiscrets).
il peut aussi être utile dans d'autres cas.

//----------- Fonction de visualisation de la barre des tâches -------------------------------------
void ProfMT(string X)
{
int hwnd1 = WindowHandle(Symbol(), Period()) ;
int hwnd_parent1 = 0 ;
while ( !IsStopped())
{
hwnd1= GetParent(hwnd1) ;
if (hwnd1 == 0) break ;
hwnd_parent1 = hwnd1 ;
}
if (hwnd_parent1 != 0) SetWindowTextA(hwnd_parent1,X) ;
}
Merci.
 

Et voilà... Où peut-on apprendre la vérité aussi rapidement que dans un forum... ;)

Merci ! Et désolé de m'être écarté du sujet.
Je vais essayer de poser plus de questions dans le fil de discussion sur les livres...

 

La fonction OpenPosition() pour le testeur.

Conçu pour ouvrir des positions - opérations commerciales consistant à acheter ou à vendre au prix du marché. Cette fonction est universelle et multidevise, permettant d'ouvrir des positions pour n'importe quel symbole, et pas seulement pour le symbole actuel. Par exemple, un EA peut être exécuté sur le graphique EURUSD, et trader USDCAD.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия  : 13.06.2007                                                      |
//|  Описание : Открытие позиции. Версия функции для тестов на истории.        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" - текущий символ)                   |
//|    op - операция                                                           |
//|    ll - лот                                                                |
//|    sl - уровень стоп                                                       |
//|    tp - уровень тейк                                                       |
//|    mn - MagicNumber                                                        |
//+----------------------------------------------------------------------------+
void OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int mn=0) {
  color  clOpen;
  double pp;
  int    err, ticket;
 
  if (sy=="") sy=Symbol();
  if (op==OP_BUY) {
    pp=MarketInfo(sy, MODE_ASK); clOpen=clOpenBuy;
  } else {
    pp=MarketInfo(sy, MODE_BID); clOpen=clOpenSell;
  }
  ticket=OrderSend(sy, op, ll, pp, Slippage, sl, tp, "", mn, 0, clOpen);
  if (ticket<0) {
    err=GetLastError();
    Print("Error(",err,") open ",GetNameOP(op),": ",ErrorDescription(err));
    Print("Ask=",Ask," Bid=",Bid," sy=",sy," ll=",ll,
          " pp=",pp," sl=",sl," tp=",tp," mn=",mn);
  }
}
 

Fonction OpenPosition() en ligne.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 21.03.2008                                                     |
//|  Описание : Открывает позицию и возвращает её тикет.                       |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    op - операция                                                           |
//|    ll - лот                                                                |
//|    sl - уровень стоп                                                       |
//|    tp - уровень тейк                                                       |
//|    mn - MagicNumber                                                        |
//+----------------------------------------------------------------------------+
int OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int mn=0) {
  color    clOpen;
  datetime ot;
  double   pp, pa, pb;
  int      dg, err, it, ticket=0;
  string   lsComm=WindowExpertName()+" "+GetNameTF(Period());
 
  if (sy=="" || sy=="0") sy=Symbol();
  if (op==OP_BUY) clOpen=clOpenBuy; else clOpen=clOpenSell;
  for (it=1; it<=NumberOfTry; it++) {
    if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) {
      Print("OpenPosition(): Остановка работы функции");
      break;
    }
    while (!IsTradeAllowed()) Sleep(5000);
    RefreshRates();
    dg=MarketInfo(sy, MODE_DIGITS);
    pa=MarketInfo(sy, MODE_ASK);
    pb=MarketInfo(sy, MODE_BID);
    if (op==OP_BUY) pp=pa; else pp=pb;
    pp=NormalizeDouble(pp, dg);
    ot=TimeCurrent();
    ticket=OrderSend(sy, op, ll, pp, Slippage, sl, tp, lsComm, mn, 0, clOpen);
    if (ticket>0) {
      if (UseSound) PlaySound(NameFileSound); break;
    } else {
      err=GetLastError();
      if (pa==0 && pb==0) Message("Проверьте в Обзоре рынка наличие символа "+sy);
      // Вывод сообщения об ошибке
      Print("Error(",err,") opening position: ",ErrorDescription(err),", try ",it);
      Print("Ask=",pa," Bid=",pb," sy=",sy," ll=",ll," op=",GetNameOP(op),
            " pp=",pp," sl=",sl," tp=",tp," mn=",mn);
      // Блокировка работы советника
      if (err==2 || err==64 || err==65 || err==133) {
        gbDisabled=True; break;
      }
      // Длительная пауза
      if (err==4 || err==131 || err==132) {
        Sleep(1000*300); break;
      }
      if (err==128 || err==142 || err==143) {
        Sleep(1000*66.666);
        if (ExistPositions(sy, op, mn, ot)) {
          if (UseSound) PlaySound(NameFileSound); break;
        }
      }
      if (err==140 || err==148 || err==4110 || err==4111) break;
      if (err==141) Sleep(1000*100);
      if (err==145) Sleep(1000*17);
      if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
      if (err!=135) Sleep(1000*7.7);
    }
  }
  return(ticket);
}
 

Exemples d'utilisation de la fonction OpenPosition().

1. Acheter 0,1 lot de l'instrument actuel

OpenPosition(NULL, OP_BUY, 0.1);

2. Vendre 0.2 lots d'EURUSD

string sy="EURUSD";
double pa=MarketInfo("EURUSD", MODE_ASK);
double pb=MarketInfo("EURUSD", MODE_BID);
double po=MarketInfo("EURUSD", MODE_POINT);
OpenPosition(sy, OP_SELL, 0.2);

3. Vendre 0.12 lots de USDCAD avec un stop de 20 pips

string sy="USDCAD";
double pa=MarketInfo("USDCAD", MODE_ASK);
double pb=MarketInfo("USDCAD", MODE_BID);
double po=MarketInfo("USDCAD", MODE_POINT);
OpenPosition("USDCAD", OP_SELL, 0.12, pb+20*po);

4. Acheter 0.15 lot de USDJPY avec un stop de 40 pips

string sy="USDJPY";
double pa=MarketInfo("USDJPY", MODE_ASK);
double pb=MarketInfo("USDJPY", MODE_BID);
double po=MarketInfo("USDJPY", MODE_POINT);
OpenPosition("USDJPY", OP_BUY, 0.15, 0, pa+40*po);

5. Vendez 0.1 lot de GBPJPY avec un stop de 23 et un takeaway de 44 pips.

string sy="GBPJPY";
double pa=MarketInfo("GBPJPY", MODE_ASK);
double pb=MarketInfo("GBPJPY", MODE_BID);
double po=MarketInfo("GBPJPY", MODE_POINT);
OpenPosition("GBPJPY", OP_SELL, 0.1, pb+23*po, pb-44*po);
Le trailer est un script pour tester la fonction OpenPosition(). Les 4 premiers exemples sont commentés.
Dossiers :
 
KimIV:

Fonction OpenPosition() en ligne.

//+----------------------------------------------------------------------------+
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 21.03.2008 |
//| Описание : Открывает позицию и возвращает её тикет. |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента (NULL или "" - текущий символ) |
//| op - операция |
//| ll - лот |
//| sl - уровень стоп |
//| tp - уровень тейк |
//| mn - MagicNumber |
//+----------------------------------------------------------------------------+
int OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, int mn=0) {
//-- skip --
string lsComm=WindowExpertName()+" "+GetNameTF(Period());
//-- skip --
Pourquoi ne pas mettre lsComm dans les paramètres de la fonction ? Par exemple, comme ceci :
int OpenPosition(string sy, int op, double ll, double sl=0, double tp=0, string lsComm="", int mn=0) {
color clOpen;
datetime ot;
double pp, pa, pb;
int dg, err, it, ticket=0;

if (lsComm=="" || lsComm=="0") lsComm=WindowExpertName()+" "+GetNameTF(Period());
if (sy=="" || sy=="0") sy=Symbol();
Imho, la "flexibilité" de la fonction s'étend...
 
Lukyanov писал (а):
Pourquoi ne pas mettre lsComm dans les paramètres de la fonction ?
Imho, la "flexibilité" de la fonction s'étend...
Ça ne me dérange pas... Je veux dire que je vous autorise à le faire :-)
 
Je l'ai fait pour moi. Ça pourrait être utile à quelqu'un. :-)
Raison: