dynamic lot size problem help please?

 

what is wrong with my code to open orders of a lot size based on what I want to risk.


                    Print("AccountEquity(): "+AccountEquity() );
                      RiskAmount = Balance*(EquityPercent / 100.0);
                                Print("RiskAmount: "+RiskAmount);
                                 TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
                                Print("TickValue: "+TickValue);
                                if(Point == 0.001 || Point == 0.00001) TickValue *= 10;
                                 LotSize = NormalizeDouble( (RiskAmount/StopLoss)/TickValue,1);
                           Print("TickValue check: "+TickValue);
                      Print("LotSize: "+LotSize);

EquityPercent is an external int. if it is 2, this means I want to risk 2% of my capital.
The problem is that the code risks 2% of $100,000 which is $2000. Somehow I am able to buy 4 lots of GBPUSD using only 50:1 leverage. What is wrong with my code?
 

StopLoss is ?? is it a price ? or is it a number of pips ?

I think your calculation is wrong also . . . try risk/(SL in pips * tickvalue)

 
jeemba2012:

what is wrong with my code to open orders of a lot size based on what I want to risk.


seems nothing wrong. Your sl= 50, correct?

Leverages (whatever their ratios are does not mattter) only directly affect margins calc, nothing to do with tick/pip values, thus, lotting/sizing, as far as I know. ???

 
Tickvalue must be used as a ratio
double  PointValuePerLot(string pair="") {
    /* 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).
     * https://forum.mql4.com/43064#515262 zzuegg reports for non-currency DE30:
     * MarketInfo(Symbol(),MODE_TICKSIZE) returns 0.5
     * MarketInfo(Symbol(),MODE_DIGITS) return 1
     * Point = 0.1
     * Prices to open must be a multiple of ticksize */
    if (pair == "") pair = Symbol();
    return(  MarketInfo(pair, MODE_TICKVALUE)
           / MarketInfo(pair, MODE_TICKSIZE) ); // Not Point.
}
 
RaptorUK:

StopLoss is ?? is it a price ? or is it a number of pips ?

I think your calculation is wrong also . . . try risk/(SL in pips * tickvalue)


my stoploss is # of pips
 
jeemba2012:

my stoploss is # of pips

Excuse my ignorance. I still dont understand. My broker is FxPro. This is the conversation I had with them

For example

Kim: 0.10 lots of GBP/USD with a leverage of 1:50

Kim: will require $311.59 to open a trade

Kim: 1 lot of GBP/USD with a leverage of 1:50 will require $3,115.68

Kim: You can use the margin calculator in the following link

Kim: http://www.fxpro.com/forex-tools

Kim: to calculate this.

If 1 lot of GBPUSD requires $3115.68, How is my code correct buy 4 lots with $2000 with 50:1 leverage?

 
jeemba2012:

Excuse my ignorance. I still dont understand. My broker is FxPro. This is the conversation I had with them

For example

Kim: 0.10 lots of GBP/USD with a leverage of 1:50

Kim: will require $311.59 to open a trade

Kim: 1 lot of GBP/USD with a leverage of 1:50 will require $3,115.68

Kim: You can use the margin calculator in the following link

Kim: http://www.fxpro.com/forex-tools

Kim: to calculate this.

If 1 lot of GBPUSD requires $3115.68, How is my code correct buy 4 lots with $2000 with 50:1 leverage?

1) In the first place, you should have asked that 'Kim' for such a question (minus the code). ......You: "can I possibly buy you 4 lots with 50:1 leverage via account XXXXX? " and see how Kim settles that one out.

If Kim have told you:

2)"Yes". Chances are its not the codes. It's probably your understanding of the business principles behind trade & risk.

3) If Kim said "No", than there is something wrong. Awfully wrong. Maybe it's Kim...

 
diostar:

1) In the first place, you should have asked that 'Kim' for such a question (minus the code). ......You: "can I possibly buy you 4 lots with 50:1 leverage via account XXXXX? " and see how Kim settles that one out.

If Kim have told you:

2)"Yes". Chances are its not the codes. It's probably your understanding of the business principles behind trade & risk.

3) If Kim said "No", than there is something wrong. Awfully wrong. Maybe it's Kim...

I did ask kim and this is how she responded

You are now chatting with 'Kim', May i have your FxPro account number please?

Kim: Hello, how may I assist you?

you: how much GBPUSD lots will $2000 usd buy

Kim: To determine the required margin to place a trade,

Kim: you also need to check your account leverage

you: my leverage is 50:1

Kim: For example

Kim: 0.10 lots of GBP/USD with a leverage of 1:50

Kim: will require $311.59 to open a trade

Kim: 1 lot of GBP/USD with a leverage of 1:50 will require $3,115.68

Kim: You can use the margin calculator in the following link

Kim: http://www.fxpro.com/forex-tools

Kim: to calculate this

you: thanks

Kim: you are most welcome

you: thats all I needed

Kim: please come back anytime you require assistance

Kim: Thank you for chatting, bye for now.

Chat session has been terminated by the site operator.


How can I possibly buy 4 lots with $2000.00 USD

 
jeemba2012:

I did ask kim and this is how she responded

You are now chatting with 'Kim', May i have your FxPro account number please?

Kim: Hello, how may I assist you?

you: how much GBPUSD lots will $2000 usd buy

Kim: To determine the required margin to place a trade,

Kim: you also need to check your account leverage

you: my leverage is 50:1

Kim: For example

Kim: 0.10 lots of GBP/USD with a leverage of 1:50

Kim: will require $311.59 to open a trade

Kim: 1 lot of GBP/USD with a leverage of 1:50 will require $3,115.68

Kim: You can use the margin calculator in the following link

Kim: http://www.fxpro.com/forex-tools

Kim: to calculate this

you: thanks

Kim: you are most welcome

you: thats all I needed

Kim: please come back anytime you require assistance

Kim: Thank you for chatting, bye for now.

Chat session has been terminated by the site operator.


How can I possibly buy 4 lots with $2000.00 USD

This was NOT what I suggest between YOU & KIM. I said you should ask him, rather her, this: "can I possibly buy you 4 lots with 50:1 leverage via account XXXXX? "

Did I or did not suggest that?

Why on earth did you ask her, "how much GBPUSD lots will $2000 usd buy" ???????

What do you expect her to do? Of course, you get that from her, "You can use your own margin calculator". So, are you happy with that?

Look, with all due respect to you, I have to say, I really cant be of much help if you choose this sort of way/approach with Kim. For she can only respond, the way you hook her up with correct/incorrect questions, in the first place or the next opportunity.

Hope you understand and respect from my perspectives, (probably that of Kim as well).

Reason: