Page 1 of 2 12 LastLast
Results 1 to 10 of 18
 3 Attachment(s)    

Thread: Add a lot management

  1. #1
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default Add a lot management

    Here is the Metatrader code for lot management :

    Code:
    //Money Management sequence
     if (MoneyManagement)
       {
          if (Risk<1 || Risk>100)
          {
             Comment("Invalid Risk Value.");
             return(0);
          }
          else
          {
    Lot=MathFloor((AccountFreeMargin() *AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT )))*MarketInfo(Symbol(),MODE_MINLOT );
          }
       }
    At the top of the expert, add :

    Code:
    extern bool MoneyManagement=True;
    extern double Risk=2;

  2. #2

    Default

    Funyoo,

    I use a similar line of code, except that I use AccountBalance() instead of AccountFreeMargin()*AccountLeverage().

    A couple of users of my EA's have reported issues in running the EA's through InterbankFX's Strategy Tester. With Money Management set to true, the EA always trades fixed lots. It only seems to be IBFX who has this issue and the code seems to work fine with all other brokers.

    I just wonder if it's something that either you or anybody else has come across before.

  3. #3
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by jezzer1961 View Post
    Funyoo,

    I use a similar line of code, except that I use AccountBalance() instead of AccountFreeMargin()*AccountLeverage().

    A couple of users of my EA's have reported issues in running the EA's through InterbankFX's Strategy Tester. With Money Management set to true, the EA always trades fixed lots. It only seems to be IBFX who has this issue and the code seems to work fine with all other brokers.

    I just wonder if it's something that either you or anybody else has come across before.
    Hi jezzer1961,

    I have tested it in strategy tester, and I don't get errors. In demo/live I don't know.

  4. #4

    Default

    OK, thanks Funyoo. This is clearly something that I need to look at in greater detail.

  5. #5

    Default

    Funyoo,

    I think that I have identified the problem here. It is to do with some brokers (such as Alpari) who quote their prices to an extra decimal place.

    As a result, the result which is returned for the size of lot can potentially be out by a factor of 10 depending upon which broker the EA was designed for and which broker it is being used with.

    I think the solution is to replace MarketInfo(Symbol(),MODE_LOTSIZE) with MarketInfo(Symbol(),MODE_TICKVALUE). You would also need to adjust the multiplier and I think you should also normalise the double.

    What do you think?
    Last edited by jezzer1961; 01-18-2009 at 13:31.

  6. #6
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Quote Originally Posted by jezzer1961 View Post
    Funyoo,

    I think that I have identified the problem here. It is to do with some brokers (such as Alpari) who quote their prices to an extra decimal place.

    As a result, the result which is returned for the size of lot can potentially be out by a factor of 10 depending upon which broker the EA was designed for and which broker it is being used with.

    I think the solution is to replace MarketInfo(Symbol(),MODE_LOTSIZE) with MarketInfo(Symbol(),MODE_TICKVALUE). You would also need to adjust the multiplier and I think you should also normalise the double.

    What do you think?
    Hi jezzer1961,

    This is an interesting idea. We should see in demo what is the result.

    I'm using another way with my new template, maybe more simple :

    After extern parameters :

    Code:
    extern double Lots=0.1;//|-----------------------lots size
    extern bool RiskMM=false;//|---------------------risk management
    extern double RiskPercent=1;//|------------------risk percentage
    extern double MinLots=0.01;//|-------------------minlots
    extern double MaxLots=100;//|--------------------maxlots
    After start(){ :

    Code:
    if(RiskMM)CalculateMM();
    At the end of the code :

    Code:
    void CalculateMM()
    {
       double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
       double MaxLots=MarketInfo(Symbol(),MODE_MAXLOT);
       Lots=AccountFreeMargin()/100000*RiskPercent;
       Lots=MathMin(MaxLots,MathMax(MinLots,Lots));
       if(MinLots<0.1)Lots=NormalizeDouble(Lots,2);
       else
       {
         if(MinLots<1)Lots=NormalizeDouble(Lots,1);
         else Lots=NormalizeDouble(Lots,0);
       }
       if(Lots<MinLots)Lots=MinLots;
       if(Lots>MaxLots)Lots=MaxLots;
       return(0);
    }

  7. #7

    Default

    Quote Originally Posted by funyoo View Post
    Hi jezzer1961,

    This is an interesting idea. We should see in demo what is the result.
    Well it certainly does seem to work with different brokers and different symbols in the Strategy Tester, Funyoo, but I'm not fully sure that I understand exactly what each of the different MarketInfo() identifiers actually means in plain English.

    I think that I need to just clear it up in my head properly first.

  8. #8

    Default

    Hello Funyoo,

    I wanted to see for myself what values the MarketInfo() function was returning for some of its different identifiers, so I built the little EA which I have attached to use as a tool. The aim was to use it with some different symbols and different brokers and then compare the results to solve the problem of brokers such as Alpari and IBFX who return different Point values which affects the lot size from broker to broker.

    There is a line of code within the EA which you might find useful yourself for calculating lot sizes. I have experimented with different brokers and it certainly produces a standardised result for the lot size.

    My next problem is one that you might be able to help with please. A 100 point SL or TP with a broker like IBFX or ODL will be the equivalent of 1000 points with Alpari because of their strange Point value. I'm trying to find a way of getting an EA to work universally with different brokers using hard-coded internal SL and TP values without there being a need to alter any external parameters.

    My best idea so far is that the value returned for Digits tends to be an odd number for brokers like Alpari who have the strange tick size and an even number for other brokers like ODL and IBFX. So I am thinking that if I halve the value of Digits, then round this answer down to an integer using MathFloor() and then multiply the answer by 2, I can check the result against the value for Digits and multiply my TP and SL values by a factor of 10 if the result does not equal the value of Digits.

    It's a bit long-winded though and I would think there must be an easier solution.

    Have you any ideas?
    Attached Files Attached Files

  9. #9
    Administrator funyoo's Avatar
    Join Date
    Sep 2008
    Posts
    7,003

    Default

    Hello jezzer1961,

    You're right, it's quite boring to develop a version depending on the broker.

    For the moment, I have only the same idea than you.

    And we have also to take in consideration the number of digits with some pairs that have 4 digits on one broker and 5 on another one, and those that have 2 digits on certain brokers and 3 on the others... There is two kind of pairs.

  10. #10

    Default

    Fortunately Alpari seem to use an odd number of digits (either 3 or 5) exclusively and every instrument that I can think of is quoted conventionally to an even number of digits (either 2 or 4). I'd be interested to know if there are any instruments which aren't conventionally quoted to either 2 or 4 digits, as this would affect the operation of the following piece of code.

    This piece of code should make the EA automatically adjust internal stop-losses, etc for Alpari and will save having to open them up as external parameters.

    Code:
    int HalfDigits,DoubleDigits;
    HalfDigits=MathFloor(MarketInfo(Symbol(),MODE_DIGITS)/2);
    DoubleDigits=HalfDigits*2;
    if(DoubleDigits!=MarketInfo(Symbol(),MODE_DIGITS)) {StopLoss=StopLoss*10; TakeProfit=TakeProfit*10;}
    Is it just Alpari who have this odd point system or are there other brokers who do the same out there too?
    Last edited by jezzer1961; 01-27-2009 at 08:43.

Similar Threads

  1. Management EA
    By best2004 in forum Ideas for expert advisors
    Replies: 5
    Last Post: 12-10-2010, 03:25
  2. Management EA
    By tonycashflow in forum Ideas for expert advisors
    Replies: 0
    Last Post: 11-14-2009, 19:29
  3. Account Management EA?
    By Luther_Blissett in forum Ideas for expert advisors
    Replies: 4
    Last Post: 11-12-2009, 22:06

Tags for this Thread

100, add, alpari, broker, brokers, change, copy, demo, eas, expert, indicators, live, metatrader, money, simple, stop, stoploss, strategy, system, thank you, tool, usd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •