Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us

Share your knowledge in the forex community!

Our community is a completely independent place for communication between forex traders and software developers for trading platforms Metatrader 4 and Metatrader 5

Create A New Account
Home/ Questions/Q 2036
Next
In Process
cyberdev
cyberdev

cyberdev

  • 1 Question
  • 3 Answers
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
cyberdev
Asked: December 26, 20202020-12-26T11:36:12+00:00 2020-12-26T11:36:12+00:00In: Forex Expert Advisors

Maximum possible volume for the Deposit

  • 0

There is SYMBOL_VOLUME_MAX
as well

OrderCalcMargin ().
But when checking
SYMBOL_VOLUME_MAX with this function, with a Deposit of $10,000, it turns out that it is impossible to enter the market with this volume
. How do I find out the maximum possible volume to enter the market with a current Deposit?

  • 5 5 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    5 Answers

    • Voted
    • Oldest
    • Recent
    1. cyberdev

      cyberdev

      • 1 Question
      • 3 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      cyberdev
      2020-12-26T11:36:49+00:00Added an answer on December 26, 2020 at 11:36 am

      Experimented with free margin:

      double volumeChecked;
        
        double cutVoluneByFreeMargin(string _symbol, double _volume, int _stopLoss, ENUM_ORDER_TYPE _type) {
          
          volumeChecked = false;
          
          double lotValue = SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_VALUE);
          double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
          
          double maxLot_ = (freeMargin * 0.3 / _stopLoss) / lotValue; / / only works starting from 0.3 from freeMargin
          
          double maxLot = SymbolInfoDouble(_symbol, SYMBOL_VOLUME_MAX);
          
          if(maxLot_ > maxLot)
            maxLot_ = maxLot;
          
          double lot = (_volume <= maxLot_) ? _volume : maxLot_;
          
          / / checking for sufficient funds to enter the market
          MqlTick mqltick;
          SymbolInfoTick(_symbol, mqltick);
          double price;
          switch(_type) {
          case ORDER_TYPE_BUY:
            price = mqltick.ask;
            break;
          case ORDER_TYPE_SELL:
            price = mqltick.bid;
            break;
          default:
            Print(__FUNCTION__," Error! Line:", __LINE__);
            return 0;
          }
          
          double margin;
          
          if(!OrderCalcMargin(_type, _symbol, lot, price, margin)) {
            / / - - - something went wrong
            Print("Error in ",__FUNCTION__," code: ",GetLastError());
            return 0;
          }
      / / - - - if there are not enough funds for the operation
          if(margin > freeMargin) {
            / / - - - report an error and return false
            Print("Not enough money for ",EnumToString(_type)," ", lot," ",_symbol," Error code: ",GetLastError());
            Print("margin: ", margin, " freeMargin: ", freeMargin, " lot: ", lot);
            return 0;
          }
          volumeChecked = true;
          return lot;
        }

      But the function skips the volume calculated with a value of no more than 0.3 * freeMargin

      double maxLot_ = (freeMargin * 0.3 / _stopLoss) / lotValue;

      Why did you get exactly this pattern? Maybe
      maybe I’m calculating the maximum possible lot incorrectly?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. barabashkakvn

      barabashkakvn

      • 8 Questions
      • 171 Answers
      • 0 Best Answers
      • 352 Points
      View Profile
      barabashkakvn
      2020-12-26T11:36:39+00:00Added an answer on December 26, 2020 at 11:36 am

      Mihail Matkovskij:

      I checked the code on the demo account. 

      It turns out that maxLot passes the test on the demo, but in
      in the expert Advisor, on the tester, the message crashes ”

      Not
      enough money
      to make a deal!” and the position with the maxLot volume does not open, though, the Deposit size, as on
      on the tester and on the demo 10000. On the demo, even less is a bit. How can I calculate the maximum possible lot if

      OrderCalcMargin gives a fake?

      In addition to checking

      if(!OrderCalcMargin

      you need to check at least

      if(margin>0.0

      and even better (at least I do tai) – so that margin is enough for another such position.

      Code example: OnInit prints the maximum lot; if the Start parameter is set to “true“,
      it will give a signal to open a position with the specified lot (

      Money management: Lot OR Risk is set to Constant lot, and The value for “Money management” is set
      to 500.0)

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. cyberdev

      cyberdev

      • 1 Question
      • 3 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      cyberdev
      2020-12-26T11:36:33+00:00Added an answer on December 26, 2020 at 11:36 am

      Set checkmoneyfortrade (style= ” background-color:rgb(251, 249, 245); color:rgb(0, 0, 0);”>)>,
      which I do not allow the operation of the OrderSend function (if the data is not checked) gives a message about the lack of funds on the
      Deposit:

      2019.10.06 17:15:02.028 Core 1  2012.05.03 14:53:00   Not enough money for ORDER_TYPE_BUY 500.0 EURUSD Error code: 0
      But the
      Deposit, again, has grown to

      47730.00, with 10000 and here the
      terminal does not miss the volume of 500.0, which corresponds
      to SYMBOL_VOLUME_MAX.
      There are no errors

      – “Error
      code:
      0″, but there are not enough funds on the Deposit. How can this be?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    4. barabashkakvn

      barabashkakvn

      • 8 Questions
      • 171 Answers
      • 0 Best Answers
      • 352 Points
      View Profile
      barabashkakvn
      2020-12-26T11:36:23+00:00Added an answer on December 26, 2020 at 11:36 am

      Article What
      checks should the trading robot pass before publishing in the Market read?

      • Lack of funds for conducting a trading operation
      • Incorrect volumes in trading operations
      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    5. cyberdev

      cyberdev

      • 1 Question
      • 3 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      cyberdev
      2020-12-26T11:36:17+00:00Added an answer on December 26, 2020 at 11:36 am

      I checked the code on the demo account. 

      //+------------------------------------------------------------------+
      //| Script program start function                                    |
      //+------------------------------------------------------------------+
      void OnStart() {
        string symbol = Symbol();
        double maxLot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
        double margin;
        if(!OrderCalcMargin(ORDER_TYPE_BUY, symbol, maxLot, SymbolInfoDouble(symbol, SYMBOL_ASK), margin)) {
          Print("Not enough money to make a deal!");
          // Recalculation of the maximum lot for the current Deposit
          // ...
        }
      }
      //+------------------------------------------------------------------+

      It turns out that on the demo maxLot passes the test, but in the expert
      Advisor, on the tester, the message crashes ”

      Not
      enough money
      to make a deal!” and the position with the maxLot volume does not open, although the Deposit size, both on the tester
      and on the demo, is 10000. On the demo, even less is a bit. How can I calculate the maximum possible lot if

      OrderCalcMargin gives a fake?

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 514
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 921
    • Popular
    • Answers
    • Tags
      • On: December 18, 2020
      • Answers: 16

      How to allow trading at certain times

      • On: December 29, 2020
      • Answers: 16

      Example of implementing the OOP pattern Abstract Factory using MQL5 ...

      • On: December 18, 2020
      • Answers: 15

      EMA with a different formula

      • On: December 29, 2020
      • Answers: 15

      Invitation for algo traders.

      • On: December 29, 2020
      • Answers: 14

      Dear Programmers, do not pass by, help fix the error!

    • atma1
      atma1 added an answer Added activation. Thanks. April 8, 2021 at 6:54 am
    • iks_
      iks_ added an answer Atma1: Good day, dear colleagues. Yesterday I updated VMware to… April 8, 2021 at 6:54 am
    • renat
      renat added an answer Atma1: Good day, dear colleagues. Yesterday I updated VMware to… April 8, 2021 at 6:54 am
    • mvs
      mvs added an answer Renat Fatkhullin: You can not immediately send the received data,… April 8, 2021 at 6:53 am
    • anton_m
      anton_m added an answer Renat Fatkhullin: How much data do you read? You can… April 8, 2021 at 6:53 am
    analytics british company computer developers django employee employer english facebook french google interview javascript language life php proforexea programmer programs pro vsa salary university

    Related Questions

    • atma1

      Yesterday I updated VMware to version 16.1.0 and the product ...

      • 3 Answers
    • anton_m

      It is not possible to read data from the server ...

      • 6 Answers
    • s22aa

      Tell me what the difference is.

      • 2 Answers
    • areedbreen

      on the chart in the tester one yield and in ...

      • 2 Answers
    • 1006293

      A question about the intersection of moving averages in MQL5

      • 3 Answers

    Users

    atma1

    atma1

    • 1 Question
    • 1 Answer
    s22aa

    s22aa

    • 1 Question
    • 1 Answer
    areedbreen

    areedbreen

    • 1 Question
    • 1 Answer

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved