0
votes

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

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?

1

1 Answers

2
votes

Welcome to MQL4! First question is about the account currency - if it is USD (or something else not EUR) - you have to make such convertion. Ok, let me describe what to do with the EUR balance. You can compute lot size based on the stoploss - in such a case you can get tick value using MarketInfo(_Symbol,MODE_TICKVALUE). But you must know the price level where to exit (stoploss), whether it is 1 pips or 100 pips. Let us think that is 100 ticks (which is equal to 10 pips of 5-digit broker). Then, your lot size is
double lot = AmountToMaxLoss / (MarketInfor(_Symbol, MODE_TICKVALUE) * stoploss), then you have to normalize the result:

double lot_step=MarketInfo(_Symbol, MODE_LOTSTEP); double result = lot_step * NormalizeDouble(lot / lot_step, 0); then check that result > MarketInfo(_Symbol, MODE_MINLOT). About takeprofit - it might be a strange approach to wait for your takeprofit target in the currency instead of the price level but if you need - the way is same.