
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I want to set the stop loss for the trade to a particular % of the price.
For making it multiple of the ticks, I used the below code:
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double price = (type == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK) : SymbolInfoDouble(_Symbol, SYMBOL_BID);
double sl = (type == ORDER_TYPE_BUY) ? price * (1-Risk_Per_Trade/2000): price * (1+Risk_Per_Trade/2000);
int digits = Digits();
sl = NormalizeDouble(MathRound(sl/tickValue)*tickValue, digits);
The result is always a large floating point number instead of precison value set as per the digits.
Because of which I get the Invalid stops length 13 error every time
None of the logics to set the precision to specified digits is working.
I even tried to use custom code be multiplying the SL price to MathPow(10, digits), converting the same to long to remove large precision and then diving it back with MathPow(10, digits)
Still, it dont work.
Please suggest
Regards
Vinayak