로트 크기는 어떻게 계산합니까? - 페이지 2

 
Ais wrote >>
Hello.
Correct code must be able to produce any valid result.
Examples.




Best regards,
Ais.

귀하가 제공한 답변(.01 이내)을 성공적으로 복제했으며 ald.MinimalMargin의 값에 대해 한 가지 질문이 있습니다.

내 IBFX 표준 계정을 사용하면 내 ald.MinimalMargin은 GBPJPY 및 EURUSD 모두에 대해 항상 $10이지만 금액은 다양합니다(예: 185.785 또는 147.6).

귀하의 최소 마진 금액은 다양하지만 제 마진 금액은 달라지지 않는 이유가 무엇인지 아십니까?

 

귀하의 ald.OperationVolume 금액(.01 이내)을 복제했으며 한 가지 질문이 있습니다.

계정에서 계산이 실행되면 ald.MinimalMargin이 달라집니다.

내 IBFX 표준 계정에서 계산을 실행할 때 ald.MinimalMargin은 항상 $10입니다.

질문: 왜 그런지 아세요?

다음은 IDFX 표준 계정을 사용하는 내 시스템의 경고 값입니다. ald.MinimalMargin = 10 USD입니다.

aas.Symbol = GBPJPY
aad.VAR한도 = 3155 USD
aai.VARPoints = 50점
aai.명령 = 0

처리:
ald.MinimalMargin = 10 USD
ald.MinimalPoint = 0.0942 USD
ali.PositionPoints = 106포인트
aai.VARPoints = 50점
ald.VARPositions = 0.4717 위치
aad.VAR한도 = 3155 USD
ald.PositionLimit = 6688.6 USD
ald.VolumeLimit = 6.6886랏
ald.VolumeStep = 0.01랏
ald.NominalMargin = 1000 여백 필요 (이 줄을 삽입했습니다)
ald.MinimalVolume = 0.01랏

산출:
ald.OperationVolume = 6.68

 
Hello.
According to MQL4 documentation "MODE_LOTSIZE" must return "Lot size in the base currency".
However, some brokers indicate "MODE_LOTSIZE" as "Lot size in the account currency".
In this case, "MODE_MARGINREQUIRED" means 1 lot size in the account currency divided by constant "AccountLeverage ()".

Thank you for effective collaboration.
Best regards,
Ais.
 
Hello.
The revised sample of the operation volume computing:

double avd.OperationVolume    ;

double avd.VARLimit  = 200.00 ;
int    avi.VARPoints = 50     ;

//<init>
int    init
 (//<0>
){//<1>
 
avd.OperationVolume = amd.OperationVolume ( Symbol () , avd.VARLimit , avi.VARPoints ) ;

}//</init> 

//<amd.OperationVolume>
double amd.OperationVolume
 (//<3>
       string aas.Symbol    ,
       double aad.VARLimit  ,
       int    aai.VARPoints
){//<31>

double ald.VolumeStep      = MarketInfo ( aas.Symbol , MODE_LOTSTEP        )                        ;
double ald.MinimalVolume   = MarketInfo ( aas.Symbol , MODE_MINLOT         )                        ;
double ald.NominalLot      = MarketInfo ( aas.Symbol , MODE_LOTSIZE        )                        ;
double ald.NominalMargin   = MarketInfo ( aas.Symbol , MODE_MARGINREQUIRED )                        ;
double ald.NominalTick     = MarketInfo ( aas.Symbol , MODE_TICKVALUE      )                        ;
double ald.QuoteTick       = MarketInfo ( aas.Symbol , MODE_TICKSIZE       )                        ;
double ald.QuotePoint      = MarketInfo ( aas.Symbol , MODE_POINT          )                        ;

double ald.MinimalMargin   = ald.NominalMargin       * ald.MinimalVolume                            ;
double ald.MinimalTick     = ald.NominalTick         * ald.MinimalVolume                            ;
double ald.MinimalPoint    = ald.MinimalTick         * ald.QuotePoint    / ald.QuoteTick            ;
int    ali.PositionPoints  = MathRound               ( ald.MinimalMargin / ald.MinimalPoint )       ;

double ald.VARPositions    = aai.VARPoints * 1.0     / ali.PositionPoints                           ;
double ald.MarginLimit     = avd.VARLimit            / ald.VARPositions                             ;
double ald.VolumeLimit     = ald.MarginLimit         / ald.NominalMargin                            ;
 
double ald.OperationVolume = 0                                                                      ;

if   ( ald.VolumeLimit    >= ald.MinimalVolume )
     { int ali.Steps       = MathFloor ( ( ald.VolumeLimit - ald.MinimalVolume ) / ald.VolumeStep ) ;
       ald.OperationVolume = ald.MinimalVolume + ald.VolumeStep * ali.Steps                         ; }

string als.LotMeasure      , als.BaseCurrency                                                       ;

if   ( AccountLeverage () != NormalizeDouble ( ald.NominalLot / ald.NominalMargin , 1 ) )
     { als.BaseCurrency    = StringSubstr    ( aas.Symbol , 0 , 3 )                                 ;
       als.LotMeasure      = als.BaseCurrency                                                       ; }
else   als.LotMeasure      = AccountCurrency ()                                                     ;

Alert  ( " "                                                                                      ) ;
Alert  ( "ald.OperationVolume = " , ald.OperationVolume , " " , "lots"                            ) ;
Alert  ( "Output :"                                                                               ) ;
Alert  ( " "                                                                                      ) ;
Alert  ( "ald.MinimalVolume   = " , ald.MinimalVolume   , " " , "lots"                            ) ;
Alert  ( "ald.VolumeStep      = " , ald.VolumeStep      , " " , "lots"                            ) ;
Alert  ( "ald.VolumeLimit     = " , ald.VolumeLimit     , " " , "lots"                            ) ;
Alert  ( "ald.MarginLimit     = " , ald.MarginLimit     , " " , AccountCurrency ()                ) ;
Alert  ( "aad.VARLimit        = " , aad.VARLimit        , " " , AccountCurrency ()                ) ;
Alert  ( "ald.VARPositions    = " , ald.VARPositions    , " " , "positions"                       ) ;
Alert  ( "aai.VARPoints       = " , aai.VARPoints       , " " , "points"                          ) ;
Alert  ( "ali.PositionPoints  = " , ali.PositionPoints  , " " , "points"                          ) ;
Alert  ( "ald.MinimalPoint    = " , ald.MinimalPoint    , " " , AccountCurrency ()                ) ;
Alert  ( "ald.MinimalMargin   = " , ald.MinimalMargin   , " " , AccountCurrency ()                ) ;
Alert  ( "ald.NominalMargin   = " , ald.NominalMargin   , " " , AccountCurrency ()                ) ;
Alert  ( "ald.NominalLot      = " , ald.NominalLot      , " " , als.LotMeasure                    ) ;
Alert  ( "Processing :"                                                                           ) ;
Alert  ( " "                                                                                      ) ;
Alert  ( "aai.VARPoints       = " , aai.VARPoints       , " " , "points"                          ) ;
Alert  ( "aad.VARLimit        = " , aad.VARLimit        , " " , AccountCurrency ()                ) ;
Alert  ( "aas.Symbol          = " , aas.Symbol                                                    ) ;
Alert  ( "Input :"                                                                                ) ;
Alert  ( " "                                                                                      ) ;
Alert  ( "AccountLeverage ()  = " , AccountLeverage ()                                            ) ;
Alert  ( "AccountCurrency ()  = " , AccountCurrency ()                                            ) ;
 
return ( ald.OperationVolume )                                                                      ;

}//</amd.OperationVolume>
 



Best regards,
Ais.
 
로트 크기의 계산은 허용 가능한 최대 손실의 계산입니다. 위험은 공개 가격 - 초기 손절매(매수: Ask-SL, 매도: SL-Bid)입니다. 최대 손실은 위험에 핍당 손실을 곱한 값입니다. 그것은 당신이 계정 잔액 의 2%가 되기를 원하는 것입니다. 여백과 관련이 없습니다. 오픈 및 스톱 위치를 파악한 다음 로트 크기를 따릅니다.
 //+------------------------------------------------------------------+
//| Lot size computation.                                            |
//+------------------------------------------------------------------+
double   LotSize( double SLpoints){
/*double    TEF.value,                          // Import from ComputeTEF
//double    at.risk;                            // Export to init/start
//bool      need2refresh;                       // Import from RelTradeContext
//int       op.code; // -1/OP_BUY/OP_SELL       // Import from setDIR */
     /* This function computes the lot size for a trade.
     * Explicit inputs are SL relative to bid/ask (E.G. SL=30*points,)
     * Implicit inputs are the MM mode, the MM multiplier, count currently
     * filled orders by all EA's vs this EA/pair/period count and history.
     * Implicit inputs are all used to reduce available balance the maximum
     * dollar risk allowed. StopLoss determines the maximum dollar risk possible
     * per lot. Lots=maxRisk/maxRiskPerLot
     **************************************************************************/
     if (need2refresh)   Refresh();
     /*++++ Compute lot size based on account balance and MM mode*/ {
     double   ab  = AccountBalance();
     switch (Money.Management.F0M1G2){
     case MMMODE_FIXED:
        at.risk = Money.Management.Multiplier;
         break ;
     case MMMODE_MODERATE:
         // See https://www.mql5.com/en/articles/1526 Fallacies, Part 1: Money
         // Management is Secondary and Not Very Important.       // %used/trade=
        at.risk = MathSqrt (Money.Management.Multiplier * ab)/ab; // ~const rate.
        at.risk = MathSqrt (Money.Management.Multiplier * ab
                            * MathPow ( 1 - at.risk, OrdersTotal () ));
         break ;
     case MMMODE_GEOMETRICAL:
        at.risk = Money.Management.Multiplier * ab *
                 MathPow ( 1 - Money.Management.Multiplier, OrdersTotal ());
         break ;
    }
     double   maxLossPerLot   = SLpoints * PointValuePerLot(),
     /* Number of lots wanted = at.risk / maxLossPerLot rounded/truncated to
     * nearest lotStep size.
     *
     * However, the broker doesn't care about the at.risk/account balance. They
     * care about margin. Margin used=lots used*marginPerLot and that must be
     * less than free margin available. */
            marginFree      = AccountFreeMargin(),
            marginPerLot    = MarketInfo( Symbol (), MODE_MARGINREQUIRED ),
     // So I use, the lesser of either.
            size = MathMin (marginFree / marginPerLot, at.risk / maxLossPerLot),
            minLot  = MarketInfo( Symbol (), MODE_MINLOT),
            LotStep = MarketInfo( Symbol (), MODE_LOTSTEP);
     /*---- Compute lot size based on account balance and MM mode*/ }
     double   adjFact = IfD( MathMin ( 1 , TEF.value), 1 , TEF.Enable01);
     while (true){   // Adjust for broker, test for margin, combine with TEF
        size =   MathFloor (size/LotStep)*LotStep;
         if (size < minLot){ // Insufficient margin.
             Print (
             "LotSize(SL=" , DoubleToStr(SLpoints/pips2dbl, Digits .pips), ")=" ,
            size, " [risk=" , at.risk, AccountCurrency(),     "/" , maxLossPerLot,
                     ", margin=" ,    marginFree,             "/" , marginPerLot,
                     ", MMM=" ,       Money.Management.F0M1G2, "x" ,
                    Money.Management.Multiplier,
                     ", ExtraOO=" ,   OrdersTotal (),
                 "]" );
            size= 0 ; break ;  }
         /* size<minLot should be sufficient, but the tester was generating error
         * 134 even when marginFree should have been OK. So I also use
         * AccountFreeMarginCheck which aggrees with the tester.
         * https://forum.mql4.com/35056 */
         double AFMC = AccountFreeMarginCheck( Symbol (), op.code, size);
         /**/ if (AFMC < 0 )      size *= 0.95 ;
         else if (adjFact < 1 ){  size  = MathMax (minLot,size*adjFact);adjFact= 1 ;}
         else break ; // We're good to go.
    }
    at.risk = size * maxLossPerLot;                     // Export for Comment
     return (size);
}   // LotSize
double PointValuePerLot() { // Value in account currency of a Point of Symbol.
     /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147)
     * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip.
     * IBFX demo/mini       EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000
     * IBFX demo/standard   EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE =100,000
     *                                  $1.00/point or $10.00/pip.
     *
     * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the
     * same value as MODE_POINT (or Point for the current symbol), however, an
     * example of where to use MODE_TICKSIZE would be as part of a ratio with
     * MODE_TICKVALUE when performing money management calculations which need
     * to take account of the pair and the account currency. The reason I use
     * this ratio is that although TV and TS may constantly be returned as
     * something like 7.00 and 0.00001 respectively, I've seen this
     * (intermittently) change to 14.00 and 0.00002 respectively (just example
     * tick values to illustrate). */
     return (  MarketInfo( Symbol (), MODE_TICKVALUE)
           / MarketInfo( Symbol (), MODE_TICKSIZE) ); // Not Point.
}

 

포럼에 이 코드를 계속해서 게시하고 있으며 이 경우에는 그렇게 하기 위해 2년 된 스레드를 네크로 처리했으며 계정의 명칭이 카운터 통화인 통화 쌍 에 대해서만 정확합니다. 통화 쌍.

(계정 명칭이 USD이고 통화 쌍 EURUSD인 경우 코드는 정확하지만 USDJPY, EURJPY 등의 경우에는 잘못됨)

나는 이것을 계속 지적하고, 당신은 그것을 계속 무시합니다.

 

WHRoeder , 계정 명칭 또는 카운터 통화에 관계없이 모든 통화 쌍에 유효한 이 코드의 업데이트된 버전이 있습니까?


감사해요.

 
내가 아는 한 여기에서 그의 최신 전체 기본 코드 컬렉션을 찾을 수 있습니다. 첨부 파일이 있는 그의 게시물까지 아래로 스크롤합니다.
 
  1. roy7 :
    WHRoeder , 계정 명칭 또는 카운터 통화에 관계없이 모든 통화 쌍에 유효한 이 코드의 업데이트된 버전이 있습니까?

    해당 코드는 모든 쌍에 유효합니다.
     return (  MarketInfo( Symbol (), MODE_TICKVALUE)
          / MarketInfo( Symbol (), MODE_TICKSIZE) ); // Not Point.
    모든 쌍의 한 틱에 대한 계정 통화 변경을 반환합니다. 정류장이 너무 커서 tickValue가 크게 변경되지 않는 한 변경이 필요하지 않습니다(IE 2000 pip SL.).
  2. 1005필립 2010.09.18 17:29
    나는 이것을 계속 지적하고, 당신은 그것을 계속 무시합니다.
    당신이 렸기 때문입니다.
  3. 외환코더 2011.06.01 06:42
    내가 아는 한 여기에서 그의 최신 전체 기본 코드 컬렉션을 찾을 수 있습니다. 첨부 파일이 있는 그의 게시물까지 아래로 스크롤합니다.
    자동 스크롤
 

고맙습니다!