Normaliser une quantité de lots lors d'un passage d'ordre

Présentation, Développement, Améliorations et Ressources pour les Stratégies de Trading Automatique.

Modérateur : Administrateurs

Message
Auteur
Avatar de l’utilisateur
Pierre8r
Membre assidu
Messages : 276
Inscription : 28 sept. 2013, 07:54

Normaliser une quantité de lots lors d'un passage d'ordre

#1 Message par Pierre8r »

Bonjour,

Je cherche une fonction pour normaliser une quantité de lots lors d'un passage d'ordre.
Avec vous ça quelque part ?
Si je dois la développer moi-meme je pense me baser sur MODE_MINLOT et MODE_LOTSTEP

Code : Tout sélectionner

   
Print("Minimum permitted amount of a lot=",MarketInfo(Symbol(),MODE_MINLOT));
Print("Step for changing lots=",MarketInfo(Symbol(),MODE_LOTSTEP));

neo-13
Professionnel certifié
Messages : 427
Inscription : 28 févr. 2015, 17:53

Re: Normaliser une quantité de lots lors d'un passage d'ordr

#2 Message par neo-13 »

Salut,
désolé, je ne comprends pas la question.
Je ne sais pas si c'est ça que tu cherches, mais j'ai une fonction qui en fonction d'une valeur du pip définie, calcule la quantité correspondante.
ex: si je veux une valeur de 0.3€/pip, alors grâce à une fonction qui prend en compte ce paramètre, et quelque soit la paire tradée (gbp/usd, usc/cad, ...) la fonction renvoi la quantité à acheter de sorte que le pip vaudra 0.3 €.

+2p
-2n

Avatar de l’utilisateur
Pierre8r
Membre assidu
Messages : 276
Inscription : 28 sept. 2013, 07:54

Re: Normaliser une quantité de lots lors d'un passage d'ordr

#3 Message par Pierre8r »

neo-13 a écrit :Salut,
désolé, je ne comprends pas la question.
Je ne sais pas si c'est ça que tu cherches, mais j'ai une fonction qui en fonction d'une valeur du pip définie, calcule la quantité correspondante.
ex: si je veux une valeur de 0.3€/pip, alors grâce à une fonction qui prend en compte ce paramètre, et quelque soit la paire tradée (gbp/usd, usc/cad, ...) la fonction renvoi la quantité à acheter de sorte que le pip vaudra 0.3 €.

+2p
-2n
Salut,
Ta fonction à l'air intéressante, mais ce n'est pas ce que je cherche pour le moment.

Avatar de l’utilisateur
Pierre8r
Membre assidu
Messages : 276
Inscription : 28 sept. 2013, 07:54

Re: Normaliser une quantité de lots lors d'un passage d'ordr

#4 Message par Pierre8r »

J'ai codé quelque chose qui semble me satisfaire pour le moment.

Code : Tout sélectionner

//+------------------------------------------------------------------+
//|                                             spNormalizedLots.mq4 |
//|                                   Copyright 2015, Pierre Rougier |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Pierre Rougier"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---

   Print("Minimum permitted amount of a lot=",MarketInfo(Symbol(),MODE_MINLOT));
   Print("Step for changing lots=",MarketInfo(Symbol(),MODE_LOTSTEP));

   Print("NormalizeLots(Symbol(),0.0001) :",NormalizeLots(Symbol(),0.0001));
   Print("NormalizeLots(Symbol(),0.001) :",NormalizeLots(Symbol(),0.001));
   Print("NormalizeLots(Symbol(),0.01) :",NormalizeLots(Symbol(),0.01));
   Print("NormalizeLots(Symbol(),0.014) :",NormalizeLots(Symbol(),0.014));
   Print("NormalizeLots(Symbol(),0.016) :",NormalizeLots(Symbol(),0.016));
   Print("NormalizeLots(Symbol(),0.01999) :",NormalizeLots(Symbol(),0.01999));
   Print("NormalizeLots(Symbol(),0.02) :",NormalizeLots(Symbol(),0.02));
   Print("NormalizeLots(Symbol(),0.1) :",NormalizeLots(Symbol(),0.1));
   Print("NormalizeLots(Symbol(),1.0) :",NormalizeLots(Symbol(),1.0));

  }
//+------------------------------------------------------------------+
double NormalizeLots(string symbol,double lots)
  {
   double  LotStep=MarketInfo(symbol,MODE_LOTSTEP);
   Print("lots :",lots,"-- LotStep :",LotStep,"-- (MathRound(lots/LotStep)) :",(MathRound(lots/LotStep)),"-- (MathRound(lots/LotStep))*LotStep :",(MathRound(lots/LotStep))*LotStep);
   return((MathRound(lots/LotStep))*LotStep);
  }
//+------------------------------------------------------------------+
2015.04.05 15:59:22.941 Script spNormalizedLots SILVER,H1: removed
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: uninit reason 0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),1.0) :1.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :1.0-- LotStep :0.01-- (MathRound(lots/LotStep)) :100.0-- (MathRound(lots/LotStep))*LotStep :1.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.1) :0.1
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.1-- LotStep :0.01-- (MathRound(lots/LotStep)) :10.0-- (MathRound(lots/LotStep))*LotStep :0.1
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.02) :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.02-- LotStep :0.01-- (MathRound(lots/LotStep)) :2.0-- (MathRound(lots/LotStep))*LotStep :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.01999) :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.01999-- LotStep :0.01-- (MathRound(lots/LotStep)) :2.0-- (MathRound(lots/LotStep))*LotStep :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.016) :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.016-- LotStep :0.01-- (MathRound(lots/LotStep)) :2.0-- (MathRound(lots/LotStep))*LotStep :0.02
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.014) :0.01
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.014-- LotStep :0.01-- (MathRound(lots/LotStep)) :1.0-- (MathRound(lots/LotStep))*LotStep :0.01
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.01) :0.01
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.01-- LotStep :0.01-- (MathRound(lots/LotStep)) :1.0-- (MathRound(lots/LotStep))*LotStep :0.01
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.001) :0.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.001-- LotStep :0.01-- (MathRound(lots/LotStep)) :0.0-- (MathRound(lots/LotStep))*LotStep :0.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: NormalizeLots(Symbol(),0.0001) :0.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: lots :0.0001-- LotStep :0.01-- (MathRound(lots/LotStep)) :0.0-- (MathRound(lots/LotStep))*LotStep :0.0
2015.04.05 15:59:22.941 spNormalizedLots SILVER,H1: Step for changing lots=0.01
2015.04.05 15:59:22.931 spNormalizedLots SILVER,H1: Minimum permitted amount of a lot=0.01
2015.04.05 15:59:22.931 spNormalizedLots SILVER,H1: initialized
2015.04.05 15:59:22.931 Script Normalized\spNormalizedLots SILVER,H1: loaded successfully

Zechatdoc
Membre assidu
Messages : 143
Inscription : 14 janv. 2014, 23:51

Re: Normaliser une quantité de lots lors d'un passage d'ordr

#5 Message par Zechatdoc »

Salut Pierrot,

Voici mon code à moi.
Mais franchement, je ne sais plus pourquoi j'avais fait de cette façon, je sais pas s'il n'y avait pas un soucis avec le MODE_LOTSTEP dans certaines circonstances...

Code : Tout sélectionner

double CSymbole::NormaliseVolume(double d)
{ //Arrondi dessous
   double res = NormalizeDouble(d,GetNbDigitsVolume());
   if(res>d) res-=GetMinLot();
   return res;
}
double CSymbole::GetMinLot()
{
   return MarketInfo(_symbol,MODE_MINLOT);
}

int CSymbole::GetNbDigitsVolume()
{
   if(this._digitsVol!=-1) return this._digitsVol;
    double minlot=GetMinLot();
   string s = DoubleToString(minlot);
   s=CChaine::Supprime0ADroite(s);
   char c='.';
   s=CChaine::Droite(s,c);
   _digitsVol=CChaine::Taille(s);
   return _digitsVol;
}

Répondre