I used to trade only forex , and i was using this part of the code to find out how many pips is the stop loss, and if it was more than 300 pip then i entered the trade.
//to find the stop value i use fibonacci.
double SymPoint=0;
if(SymbolInfoInteger(thissymbol,SYMBOL_DIGITS) == 3)
{
SymPoint = 0.01;
}
if(SymbolInfoInteger(thissymbol,SYMBOL_DIGITS) == 4)
{
SymPoint = 0.0001;
}
if(SymbolInfoInteger(thissymbol,SYMBOL_DIGITS) == 5)
{
SymPoint = 0.0001;
}
double pipsdistance=MathAbs(iClose(thissymbol,TF,0) - stop)/SymPoint;
before entering the trade i used the bellow part of the code to make sure that each symbol uses the same amount of margin
double Deposit= 10000;
double division =100000;
double high=AccountInfoDouble(ACCOUNT_BALANCE);
double Lots=high/division;
/// For every trade i want to use 50$ used margin. So x=50double x=50;
double Mgn=0;
if(dir=="buy")
{
if(OrderCalcMargin(ORDER_TYPE_BUY,thissymbol,Lots,SymbolInfoDouble(thissymbol,SYMBOL_ASK),Mgn)==true)
{
}
}
if(dir=="sell")
{
if(OrderCalcMargin(ORDER_TYPE_SELL,thissymbol,Lots,SymbolInfoDouble(thissymbol,SYMBOL_BID),Mgn)==true)
{
}
}
int k=1;
while (Mgn<x)
{
k=k+1;
double x=50*(high/division);
if(dir=="buy")
{
if(OrderCalcMargin(ORDER_TYPE_BUY,thissymbol,Lots,SymbolInfoDouble(thissymbol,SYMBOL_ASK),Mgn)==true)Lots=(high/division)*k;
}
if(dir=="sell")
{
if(OrderCalcMargin(ORDER_TYPE_SELL,thissymbol,Lots,SymbolInfoDouble(thissymbol,SYMBOL_BID),Mgn)==true)Lots=(high/division)*k;
}
}
So now i want to try my expert advisor on cfds too, but i see that the contract size is difrerent (usually 10 ) and it used to be 100,000 on forex.
And i suppose this will affect my lotsize.
So before trying my code, i want to ask how to calculate the pipsdistance the Used Margin (Mgn) and the Lots size on cfds.
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi.
I used to trade only forex , and i was using this part of the code to find out how many pips is the stop loss, and if it was more than 300 pip then i entered the trade.
before entering the trade i used the bellow part of the code to make sure that each symbol uses the same amount of margin
So now i want to try my expert advisor on cfds too, but i see that the contract size is difrerent (usually 10 ) and it used to be 100,000 on forex.
And i suppose this will affect my lotsize.
So before trying my code, i want to ask how to calculate the pipsdistance the Used Margin (Mgn) and the Lots size on cfds.
Thank you.