Wie berechne ich die Losgröße? - Seite 2

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




Best regards,
Ais.

Ich habe die von Ihnen gegebenen Antworten erfolgreich dupliziert (innerhalb von .01) und habe eine Frage zu den Werten für ald.MinimalMargin.

Bei meinem IBFX-Standardkonto beträgt meine ald.MinimalMargin immer $10, sowohl für GBPJPY als auch für EURUSD, während Ihre Werte variieren (z.B. 185,785 oder 147,6).

Haben Sie eine Idee, warum Ihre minimalen Margin-Beträge variieren, meine aber nicht?

 

Ich habe Ihre ald.OperationVolume-Beträge dupliziert (bis auf .01) und habe eine Frage.

Wenn die Berechnung auf Ihrem Konto läuft, variiert die ald.MinimalMargin.

Wenn die Berechnung auf meinem IBFX-Standardkonto ausgeführt wird, beträgt die ald.MinimalMargin immer $10.

FRAGE: Haben Sie eine Idee, warum?

Hier sind die Alert-Werte auf meinem System mit dem IBFX-Standardkonto. Beachten Sie, dass ald.MinimalMargin = 10 USD.

aas.Symbol = GBPJPY
aad.VARLimit = 3155 USD
aai.VARPoints = 50 Punkte
aai.Command = 0

Verarbeitung:
ald.MinimalMargin = 10 USD
ald.MinimalPoint = 0.0942 USD
ali.PositionPoints = 106 Punkte
aai.VARPoints = 50 Punkte
ald.VARPositions = 0.4717 Positionen
aad.VARLimit = 3155 USD
ald.PositionLimit = 6688.6 USD
ald.VolumeLimit = 6.6886 lots
ald.VolumeStep = 0.01 lots
ald.NominalMargin = 1000 margin required (ich habe diese Zeile eingefügt)
ald.MinimalVolume = 0.01 lots

Ausgabe:
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.
 
Die Berechnung der Losgröße ist die Berechnung des maximal zulässigen Verlustes. Das Risiko ist der Eröffnungskurs - der anfängliche Stop Loss (Buy: Ask-SL, Sell: SL-Bid) Der maximale Verlust ist das Risiko mal dem Verlust pro Pip. Das ist, was Sie wollen 2% des Kontostandes zu sein. Das hat nichts mit der Marge zu tun. Überlegen Sie sich, wo Ihr Eröffnungskurs und Ihre Stopps liegen werden, dann ergibt sich daraus die Losgröße.
//+------------------------------------------------------------------+
//| 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.
}

 

Sie halten Posting diesen Code immer und immer wieder im Forum, und in diesem Fall Sie thread-necro'ed ein 2yr alten Thread zu tun, und es ist nur richtig für Währungspaare, die das Konto Stückelung als Gegenwährung in das Währungspaar haben.

(Wenn die Kontobezeichnung = USD und das Währungspaar EURUSD ist, dann ist Ihr Code korrekt...aber er ist falsch für USDJPY, EURJPY, etc.)

Ich weise Sie immer wieder darauf hin, und Sie ignorieren es.

 

WHRoeder, haben Sie eine aktualisierte Version dieses Codes, die für alle Währungspaare gültig ist, unabhängig von der Kontostückelung oder Gegenwährung?


Danke!

 
Soweit ich weiß, finden Sie HIER seine neueste vollständige Basiscode-Sammlung. Scrollen Sie nach unten zu seinem Beitrag mit dem Anhang.
 
  1. roy7:
    WHRoeder, haben Sie eine aktualisierte Version dieses Codes, die für alle Währungspaare unabhängig von der Kontostückelung oder Gegenwährung gültig ist?

    Dieser Code IST für jedes Paar gültig.
    return(  MarketInfo(Symbol(), MODE_TICKVALUE)
          / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
    Gibt die Veränderung der Kontowährung für einen Tick des Paares zurück, egal welches Paar. Es sind keine Änderungen erforderlich, es sei denn, Ihre Stops sind so groß, dass sich tickValue signifikant ändert (z.B. 2000 pip SL.)
  2. 1005phillip 2010.09.18 17:29
    Ich weise immer wieder darauf hin, und Sie ignorieren es weiterhin.
    Denn Sie liegen falsch.
  3. ForexCoder 2011.06.01 06:42
    Soweit ich weiß, finden Sie HIER seine letzte vollständige Basiscode-Sammlung. Scrollen Sie runter zu seinem Beitrag mit dem Anhang.
    AutoScroll
 

Ich danke Ihnen!