How to calculate lot based on account currency in Metatrader4

 

I am a little bit new in this language, but I have the basics.

I want to trade EUR/USD, and my account is in EUR. I have 1000 EUR in my account.

What I want: open a position with stop loss and take profit.

I want to place an order with 100 euro, and I want to set the stop loss to 10 euros, and set the take profit to 5 euros. But as I see the OrderSend method requires lots for placing the order, and levels for stop loss and take profit.

And my problem is: how to calculate these values based on the euro amounts I want to set?

I searched for some lot-pip-etc calculation on the web, but after all what I tried did not work. This is how I wanted to calculate:

double AmountToTradeInEuro = 100;
double AmountToTakeInEuro = 5;
double AmountToMaxLossInEuro = 10;
double Lots = AmountToTradeInEuro / MarketInfo(Symbol(), MODE_TICKVALUE);
double StopLossLevel = AmountToTakeInEuro / MarketInfo(Symbol(), MODE_TICKVALUE);
double TakeProfitLevel = AmountToMaxLossInEuro / MarketInfo(Symbol(), MODE_TICKVALUE);
OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, StopLossLevel, TakeProfitLevel);

Basically I would like to know how to calculate the Lot for 100 euro and how to calculate the Levels for stoploss and takeprofit.

And are the stoploss and takeprofit levels also lots? Or are they different units?

Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
 
viktoriopablo: Basically I would like to know how to calculate the Lot for 100 euro and how to calculate the Levels for stoploss and takeprofit.
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Can't be done because risk depends on your initial stop loss, lot size, and the value of the pair. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support. Only then can you calculate lot size.
    1. In MT4 code:
      1. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
      2. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                  MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
      3. You must normalize lots properly and check against min and max.
      4. You must also check FreeMargin to avoid stop out
      Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
    2. Use a GUI EA like mine (for MT4): Indicators: 'Money Manager Graphic Tool' indicator by 'takycard' Forum - Page 6
 
whroeder1:
  1. When you post code please use the CODE button (Alt-S)! (For large amounts of code, attach it.) Please edit your (original) post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Can't be done because risk depends on your initial stop loss, lot size, and the value of the pair. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support. Only then can you calculate lot size.
    1. In MT4 code:
      1. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
      2. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                  MODE_TICKVALUE is not reliable on non-fx instruments with many brokers.
      3. You must normalize lots properly and check against min and max.
      4. You must also check FreeMargin to avoid stop out
      Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5=0.1 Lots maximum.
    2. Use a GUI EA like mine (for MT4): Indicators: 'Money Manager Graphic Tool' indicator by 'takycard' Forum - Page  6

Thanks for your comment. Sorry for the code format, I edited it.

So you say that I cannot calculate lot based on the euro amount? Because when I used for example Plus500, I needed to type the amount in euro to trade, for example 100€, and not Lot! And then I set the stoploss to 10€ and takeprofit to 5€.

And it is not really clear that what is the stoploss and takeprofit in the OrderSend() method. I know it is called Level, but what is it actually, what do I need to set there? I guess not 5€ and 10€, I think I need to calculate them somehow if I want the result to be 5€ for takeprofit and 10€ for stoploss.

I can't believe that it is so hard to calculate the lot and the other two based on the result I want in euro.

 
viktoriopablo: So you say that I cannot calculate lot based on the euro amount? Because when I used for example Plus500, I needed to type the amount in euro to trade, for example 100€, and not Lot! And then I set the stoploss to 10€ and takeprofit to 5€.

What you say makes no sense.

  1. How can the risk for a 1 lot trade with a 10 pip SL be the same as a 1 lot trade with a 1000 pip SL? They can't! Risk depends on the stop size and lots.
  2. What does it mean to set a SL to 10? SL is a price level not an amount.
  3. If you place your SL and then set lot size so your risk is 10, then your trade risk is 10 not 100.
  4. It's not hard. Risk depends on stop size and lot size. You must fix two to calculate the third.
Reason: