Please help, how to calculate the SL in MM

 


Dear Sir,
Sorry, I'm very newbie in forex, I hope someone helps me.

I'll open a trading position, its lotsize 3% of FreeMargin. The algorithm is like this:


----------------------------------------------------------------------------------------------------------------------------------------------------------
RefreshRates ();
double MinLot = MarketInfo (Symbol (), MODE_MINLOT); / / Min number of lots
double FreeMargin = AccountFreeMargin ();
double OneLot = MarketInfo (Symbol (), MODE_MARGINREQUIRED
double step = MarketInfo (Symbol (), MODE_LOTSTEP);
double Lots = MathFloor (Free * 0.03/OneLot/Step) * Step;
-----------------------------------------------------------------------------------------------------------------------------------------------------------

My question is, how do the calculation to obtain the position of SL, so if there is loss, the balance is reduced no more than 3%.
Can anyone help me?

Thank you.

 

As an acknowledged newbie you need to understand what you are doing before trying to code it. What you have posted would seem to be somebody else's code (?)

Margin required and possible loss on a position are unrelated. The margin is how much you have to "put up" as security. This depends on the leverage to which your account is set. This has really nothing at all to do with how much you will lose if the position goes bad. The first thing to decide is how much in money you are prepared to lose on this trade. The second thing is how many pips the stop loss should be set from the current market position (trading strategy). Now you can calculate the position size.


Start here

http://www.babypips.com/school/

 
dabbler:

As an acknowledged newbie you need to understand what you are doing before trying to code it. What you have posted would seem to be somebody else's code (?)

Margin required and possible loss on a position are unrelated. The margin is how much you have to "put up" as security. This depends on the leverage to which your account is set. This has really nothing at all to do with how much you will lose if the position goes bad. The first thing to decide is how much in money you are prepared to lose on this trade. The second thing is how many pips the stop loss should be set from the current market position (trading strategy). Now you can calculate the position size.


Start here

http://www.babypips.com/school/



Thank you for your explanation. But before I learn more in school babypips, may I ask again based on your explanation of that?

My question:
a. To secure the balance so that if there is loss, the fund lost no more than 3%, is the above algorithm is correct?.

b. Because you say That margin required and possible loss on a position are unrelated, so if the market moves in the direction that we do not want, while SL is very far away from the open price, the maximum loss is equal to the margin. In contrast, if the SL is not far away, meaning that SL is reached first, so loss is equal to SL. Is that right?

Sorry, the above questions may be very easy for most people, but I'm still a newbie.

Thank you very much.
 
Here ya go.....Link.
 
Jo_NewbieFx:

Thank you for your explanation. But before I learn more in school babypips, may I ask again based on your explanation of that?

My question:
a. To secure the balance so that if there is loss, the fund lost no more than 3%, is the above algorithm is correct?.

b. Because you say That margin required and possible loss on a position are unrelated, so if the market moves in the direction that we do not want, while SL is very far away from the open price, the maximum loss is equal to the margin. In contrast, if the SL is not far away, meaning that SL is reached first, so loss is equal to SL. Is that right?

Sorry, the above questions may be very easy for most people, but I'm still a newbie.

Thank you very much.

a. To secure the balance so that if there is loss, the fund lost no more than 3%, is the above algorithm is correct?.

No, it does not contain the stop loss so clearly it is wrong.

b ...That margin required and possible loss on a position are unrelated, so if the market moves in the direction that we do not want, while SL is very far away from the open price, the maximum loss is equal to the margin

No, you do not lose the margin you can lose the whole account if your stop loss is infinite. In theory when your account is so low that you can no longer support the margin you will get stopped out. But over the weekend a gap could occur (and often does) and then your account can go negative. That is why brokers ask about your finances and skill before opening accounts. You can lose MORE than the account balance if you are careless.

 
dabbler:

The second thing is how many pips the stop loss should be set from the current market position (trading strategy).

I think that is what the OP is asking how to calculate . . .

To: Jo_NewbieFx

to calculate your position (lot size) based on risk (%age of FreeMargin/Account Size) you need 2 pieces of information, your risk in currency, this is easily calculated, and the position of your SL

on the other hand if you are using a fixed potion size (in lots) and you want to calculate the position of the SL then you need your risk in currency and the position size (in lots)

What you cannot do is work out your SL position and your position size . . . you need to know one of them.

 
Jo_NewbieFx:
My question is, how do the calculation to obtain the position of SL, so if there is loss, the balance is reduced no more than 3%.
You got it backwards. Contract Size - MQL4 forum
 

The question of MM is usually asking for Lots. If you want the know the Stop_Loss then something like this. Limited Tested.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int Stop_Loss(
/*
    Returns the Stop_Loss In Integer_Pips Format.
*/
    double  Lot_Size,
    double  Switch,
    double  Flexable
){
    double AE=AccountEquity(); double AB=AccountBalance();
    switch(Switch){
        case 'e':   if(Switch=='e'){/*Based Upon Equity*/
                        double Risk_Amount=AE*Flexable*_2Pct;
                        int Result=Risk_Amount/(Pip_Values*Lot_Size);
                        return(Result);
                    }
        case 'b':   if(Switch=='b'){/*Based Upon Balance*/
                               Risk_Amount=AB*Flexable*_2Pct;
                               Result=Risk_Amount/(Pip_Values*Lot_Size);
                        return(Result);
                    }
}   }

For example of Usage, see attached.

Files:
help_2.mqh  8 kb
 
WHRoeder:
You got it backwards. Contract Size - MQL4 forum

I would like to endorse the correctness of WHR's linked post above, and specifically the quote

"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"

If you pick a random Lotsize and set your stop according to your account size that is not a sound way to trade. This is what I was talking about when I said

"The second thing is how many pips the stop loss should be set from the current market position (trading strategy)"

People set stops around support/resistance areas, using moving averages, using parabolic SAR, all sorts, back tested to fit within a strategy.

 
dabbler:

I would like to endorse the correctness of WHR's linked post above, and specifically the quote

"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"

If you pick a random Lotsize and set your stop according to your account size that is not a sound way to trade. This is what I was talking about when I said

"The second thing is how many pips the stop loss should be set from the current market position (trading strategy)"

People set stops around support/resistance areas, using moving averages, using parabolic SAR, all sorts, back tested to fit within a strategy.

You're not going to get me to Dis-agree with WHRoeder. However Stop_Loss and Money-Management is NOT a one-size-fits-all. Some people use a Margin-Call or Stop-Out as the Stop_Loss. For Some-People the Opposite-Logic which opened the trade should be the Best location to close the trade. Example: Open when MACD Cross-Above 0.....Close when MACD Cross-Below 0 <--- but there's no way of knowing when and where this may happen.

You yourself within this link provided an example where the weekend gap can surpass a stop-loss level; However, I would never use a broker who makes me liable for Negative accounts. Give your Opinions and thats fine. Don't treat the matter like it's Gospel which everyone should follow. IMO, if someone have 10k in the account then they should be willing to lose 10k. As the old saying goes "Don't trade money you cannot afford to lose".

 

Dear All
Thank you for the quick reponse and enthusiasm from all friends in this forum. I will learn the direction from all of you, but because of time constraints in primary job, I can not learn it and give comment immediately.

However, I am very happy if there are another friends help to solve and give comment about this problem.
Once again, thank you very much.

Reason: