거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
스크립트

Lot sizing risk based and also converting the currency of the account - MetaTrader 4용 스크립트

조회수:
15155
평가:
(6)
게시됨:
2020.04.22 20:14
업데이트됨:
2020.05.03 12:19
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

I know you're not going to read everything so I'm saying this at the start : IT'S A SCRIPT !  SO IT GOES TO THE SCRIPT FOLDER

So this is it, the following code is based on the following article https://www.fxtrademaker.com/fx_calculation.htm. I had a lot of jobs where the customer was asking me to add a risk based lot sizing (so that when you loose a trade on a SL, you loose only this particular percentage of your account, and not more based on the specific lot sizing), but I never knew the correct formula. Then I discovered that you had 3 cases. (USD is going to be the main currency used)


    • First case is the "Direct Rate" if you look at the link above you will see it clearly explained. when you have a direct rate that means that for example your account is in USD and you have a currency like XXXUSD so the formula to calculate the lot size is the following : 
    //DIRECT RATES
    if(symbol_currency_right==acc_currency){// so when the right currency is the same as your account currency (XXXUSD) in our example
       lot_size=money_risk/(dix*sl);//then you divide the money that you want to risk by the Point digits times the size of the lot (standard,micro) times the pips of the SL
    }

    • Second case is the "Indirect Rate", it has a type USDXXX just look up the article to know how it is constructed, or analyse the code :
      else if(acc_currency==symbol_currency_left){//GBPXXX
         lot_size=money_risk*Ask/(dix*sl);
         }
      • Last and most complicated case is when the main currency (USD) is not in the symbol at all, you have to pass through a middle currency to convert it correctly so the type would be XXXXXX. The code is a bit more complicated, and an error that I had at the beginning was that the middle symbol wasn't found in the market watch when you tried to get the current price, so first you have to add it
        else if(acc_currency!=symbol_currency_left&&acc_currency!=symbol_currency_right){///XXX XXX
           string symbol_2=StringConcatenate(symbol_currency_left,acc_currency);
           SymbolSelect(symbol_2,true);
           
           double r__2=SymbolInfoDouble(symbol_2,SYMBOL_ASK);
           
           if(r__2==0){
              symbol_2=StringConcatenate(acc_currency,symbol_currency_left);
              SymbolSelect(symbol_2,true);
              r__2=SymbolInfoDouble(symbol_2,SYMBOL_ASK);
              
              }
              
           lot_size=Ask*money_risk/(dix*sl*r__2);
           }

      This code will not work in the strategy tester unless you add a fixed quote of a middle symbol as entry.

      MA HISTOGRAM MA HISTOGRAM

      Trend indicator

      Manual Trading Lightweight Utility Manual Trading Lightweight Utility

      Free utility for manual orders placement.

      MA HISTOGRAM SEPARATE WINDOW MA HISTOGRAM SEPARATE WINDOW

      Trend indicator (separate window)

      Smoothed Bar to Bar Correlation Smoothed Bar to Bar Correlation

      The Correlation Indicator provides a smoothed bar to bar correlation value.