Trading Robots for MetaTrader 4

Special Offer!

Time Left to Buy:

Up to 25% OFF

Shopping cart

Name Price
Total 112 $
Netsrac Correlation Trader 112 $
Proceed to checkout

MetaTrader 4

Top Rated Products MT4

999 $749 $ AI Gen XII MT4
Denis Kurnev
3.66667 5 3 Product
999 $749 $ Nmt5
Liang Qi Quan
4.5 5 2 Product
2 199 $1 649 $ Ak47tutu
Dian Zhou
4.5 5 2 Product

Optimal F Service

optimal-f-service-logo-200x200-6529
400 $300 $

Free updates are included

We accept crypto: BTC, ETH, BCH and more...

30-Day Money Back Guarantee
100% Guarantee of Originality

Information

Utilities
MetaTrader 5
Semen Racheev
1.0
10

Overview

Optimal F Service

  • Application Type: Service
  • Application Functions: Calculation of the optimal fraction and trade volume to achieve maximum growth of the equity curve, based on the results of previous trades.

About this app

Capital management is the most crucial and often underestimated component of any trading system. Proper capital management can enhance—and sometimes significantly improve—the performance of your trading algorithm.
This application automatically calculates the optimal fraction and trade volume using the algorithm proposed by Ralph Vince in his book "The Mathematics of Money Management" to achieve maximum geometric growth of the account balance. This point exists and is unique for any trading system, which is why it is essential to know it. In your trading systems, you must never use a trade size exceeding the optimal value!

Capital management algorithms are NOT designed for mathematically losing systems based on averaging, martingale, or similar strategies. Such systems will be filtered out by the application before any calculations, as the optimal fraction and trade volume for these systems are always equal to zero. Capital management algorithms can improve results ONLY for mathematically profitable trading systems (those with a positive mathematical expectation). Therefore, this service is recommended ONLY for professionals who understand what they are doing.
Additionally, the algorithm does not account for correlation (dependencies) between simultaneously operating systems. For the algorithm to work effectively, a well-diversified set of trading systems is necessary.

How to use

Parameters:
  • LOG_LEVEL - The logging level for the Experts section of the terminal. DEBUG provides the most detailed information, while ERROR logs the minimum.
  • MAGIC_LIST - A comma-separated list of system identifiers (Magic Numbers) that operate simultaneously and require calculation.
  • TRADE_FILES_PATH - The path to the directory containing files with the results of previous trades (relative to <Data folder>/MQL5/Files/ ).
  • OUTPUT_FILE_PATH - The path to the file where the calculation results will be saved (relative to <Data folder>/MQL5/Files/ ).
  • WORK_PERIOD - The frequency of recalculations in seconds.
  • BALANCE_MATRIX_PERIOD - The period over which results are aggregated, with calculations based on this aggregated period rather than on each individual trade.

Before the first launch, each trading system must be tested in the strategy tester for the period up to the present moment. It is recommended to select a timeframe that includes at least 100 trades. Then, using the Test Trade Saver Script and following the instructions, extract the result files from the testing files (*.tst) in the required format.

If the trading system has already been used in the terminal and there are positions in the history with the specified MAGIC, you must set a different CUSTOM_MAGIC_NUMBER parameter in the script!

Next, to ensure that the data files are regularly updated and remain current, you need to run the Trade Saver Service following the provided instructions.
Thus, after the initial data export from tests using the Trade Saver Script, the Trade Saver Service continuously updates the files with new data as it becomes available, while the Optimal F Service regularly calculates and writes new values to the results file

Algorithm

  1. Extract the list of systems requiring calculation from the MAGIC_LIST parameter.
  2. Use text files named <MAGIC>.csv in the format <MAGIC>,<POSITION_CLOSE_TIME>,<LOTS>,<RESULT_$> containing the results of previous trades from the directory specified by TRADE_FILES_PATH. Construct a matrix for the balance curve function, where each value a[i][j] represents the result of trading system i for period j.
  3. Check each system for at least one negative period in its results. If a system has no negative periods, exclude it from further calculations (such systems must be removed).
  4. Evaluate the mathematical expectation of each system. If a system has no positive expected value, exclude it from further calculations (such systems must be removed).
  5. Determine the error margin required to compute the trading volume with a precision of 0.01.
  6. For each remaining system, calculate its optimal fraction.
  7. Divide the current balance into equal parts for the remaining systems. For each system and its allocated balance, calculate the trade volume in lots corresponding to the optimal fraction.
  8. Write the results to the text file specified by OUTPUT_FILE_PATH in the format <MAGIC>,<BIGGEST_LOSS>,<OPTIMAL_F>,<OPTIMAL_LOTS>.

Links and references

  • Ralph Vince - The Mathematics of Money Management: Risk Analysis Techniques for Traders (ISBN-13  978-0471547389)

For developers

you can use the following class to integrate the results into your trading systems:
    #include "OptimalFResultsLoader.mqh"
       // create loader
       COptimalFResultsLoader* optimalFResultsLoader = new COptimalFResultsLoader("/SRProject/results.csv");
       // print all fields for magic = '1111'
       Print(optimalFResultsLoader.getOptimalFFor(1111), " ",
             optimalFResultsLoader.getBiggestLossFor(1111), " ", 
             optimalFResultsLoader.getOptimalLotsFor(1111));
       // delete loader from memory
       delete(optimalFResultsLoader);


    //+------------------------------------------------------------------+
    //|                                        OptimalFResultsLoader.mqh |
    //|                                                   Semyon Racheev |
    //|                                                                  |
    //+------------------------------------------------------------------+
    #property copyright "Semyon Racheev"
    #property link      ""
    #property version   "1.00"
    
    #include <Files\FileTxt.mqh>
    
    class COptimalFResultsLoader
      {
    private:
       const string name_;
       const uchar delimiter_;
       const ushort separator_;
       const string srcFilePath_; 
                         bool checkStringForOptimalFResultsDeserializing(string &inputStr[]) const;
                         ushort calculateCharCode(const uchar separator) const;
    public:
                         COptimalFResultsLoader(const string srcFilePath, uchar separator);
                        ~COptimalFResultsLoader();
                         double getOptimalLotsFor(const ulong magicNumber) const;
                         double getOptimalFFor(const ulong magicNumber) const;
                         double getBiggestLossFor(const ulong magicNumber) const;
      };
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    COptimalFResultsLoader::COptimalFResultsLoader(const string srcFilePath = "/SRProject/results.csv", uchar separator = ','):name_("OptimalFResultsLoader"),
    srcFilePath_(srcFilePath), delimiter_(separator), separator_(calculateCharCode(separator))
      {  
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    COptimalFResultsLoader::~COptimalFResultsLoader()
      {
      }
    //+------------------public------------------------------------------+
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COptimalFResultsLoader::getOptimalLotsFor(const ulong inputMagicNumber) const
      {
       double rsl = 0.0;
       CFileTxt* file = new CFileTxt();
       int fileHandle = file.Open(srcFilePath_,FILE_READ|FILE_UNICODE|FILE_CSV);
       while (!FileIsEnding(fileHandle))
        {
         string readString = file.ReadString(); 
         
         string str[];
         StringSplit(readString, separator_, str);
         if (checkStringForOptimalFResultsDeserializing(str))
          {
           if (inputMagicNumber == (ulong)StringToInteger(str[0]))
            {
             rsl = StringToDouble(str[3]);
            }
          }
        }   
       file.Close();
       delete(file);
       return(rsl);  
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COptimalFResultsLoader::getOptimalFFor(const ulong inputMagicNumber) const
      {
       double rsl = 0.0;
       CFileTxt* file = new CFileTxt();
       int fileHandle = file.Open(srcFilePath_,FILE_READ|FILE_UNICODE|FILE_CSV);
       while (!FileIsEnding(fileHandle))
        {
         string readString = file.ReadString(); 
         
         string str[];
         StringSplit(readString, separator_, str);
         if (checkStringForOptimalFResultsDeserializing(str))
          {
           if (inputMagicNumber == (ulong)StringToInteger(str[0]))
            {
             rsl = StringToDouble(str[2]);
            }
          }
        }   
       file.Close();
       delete(file);
       return(rsl);  
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    double COptimalFResultsLoader::getBiggestLossFor(const ulong inputMagicNumber) const
      {
       double rsl = 0.0;
       CFileTxt* file = new CFileTxt();
       int fileHandle = file.Open(srcFilePath_,FILE_READ|FILE_UNICODE|FILE_CSV);
       while (!FileIsEnding(fileHandle))
        {
         string readString = file.ReadString(); 
         
         string str[];
         StringSplit(readString, separator_, str);
         if (checkStringForOptimalFResultsDeserializing(str))
          {
           if (inputMagicNumber == (ulong)StringToInteger(str[0]))
            {
             rsl = StringToDouble(str[1]);
            }
          }
        }   
       file.Close();
       delete(file);
       return(rsl);  
      }
    //+---------------------private--------------------------------------+
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    bool COptimalFResultsLoader::checkStringForOptimalFResultsDeserializing(string &inputStr[]) const
      {
       if (ArraySize(inputStr) < 4)
        {
         return(false);
        }
       return(true);
      }
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    ushort COptimalFResultsLoader::calculateCharCode(const uchar separator) const
      {
       string str = CharToString(separator);
       return(StringGetCharacter(str,0));
      }
    //+------------------------------------------------------------------+


    Recently Viewed

    111 $83 $ Trends Engine
    Maryna Shulzhenko
    399 $299 $ Goldminer AI MT5
    Ruben Octavio Gonzalez Aviles
    149 $112 $ Malaysian SNR Levels
    Matthias Horst Pieroth
    200 $150 $ Pivot meter
    Theophane Dohou
    Results 1 - 4 of 4

    30-Day Money Back Guarantee

    If for any reason you do not like the purchased program, you can request a refund within 30 days from the date of purchase. You can also make an exchange for any other product at an equal cost or by paying the difference.
    Simply send a request for refund or exchange with your order number by email: [email protected].
    Refund requests received more than 30 days after purchase will be rejected.

    Email Us Now! Support is available 24/7
    by Email: [email protected]

    Do You Need Help?
    Click Here To Start Live Chat

    Contact Us

    Image

    Search