Code - Optimisation des Lots

Author: Copyright � 2007, GwadaTradeBoy
Code - Optimisation des Lots
0 Views
0 Downloads
0 Favorites
Code - Optimisation des Lots
//+------------------------------------------------------------------+
//|                                 Code - Optimisation des Lots.mq4 |
//|                                  Copyright © 2007, GwadaTradeBoy |
//|                                           gwadatradeboy@yahoo.fr |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, GwadaTradeBoy"
#property link      "gwadatradeboy@yahoo.fr"

//---- Optimisation des Lots
extern bool    AcountIsMini      = false;
extern double  Lots              = 0.1;
extern double  MaximumRisk       = 0.02;
extern double  DecreaseFactor    = 3;
double         lot;
int            orders, losses, spread;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
   {
//----
//---- Expert Advisor
      spread = MarketInfo(Symbol(),MODE_SPREAD);
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
   {
//----
      
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| Calculs preliminaires de l'expert                                |
//+------------------------------------------------------------------+
//********** Calcul de la taille optimale du lot **********//
double LotsOptimized()
   {
      if (AcountIsMini)
         Lots = 0.01;
      lot=Lots;
      orders=HistoryTotal();     // Historique des ordres
      losses=0;                  // Nombre de trade perdants consécutif
/* Selection de la taille du lot */
      lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000,1);
/* Calcul du nombre de perte consecutive */
      if(DecreaseFactor>0)
         {
            for(int i=orders-1;i>=0;i--)
               {
                  if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==False) 
                     { 
                        Print("Erreur dans l historique!"); 
                        break; 
                     }
                  if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) 
                     continue;
         //----
                  if(OrderProfit()>0) 
                     break;
                  if(OrderProfit()<0) 
                     losses++;
               }
            if(losses>1) 
               lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
         }
/* Retour de la taille du lot */
      if(lot<0.1) 
         lot=0.1;
      return(lot);
   }
   
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   {
//----
      
//----
      return(0);
   }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---