//+------------------------------------------------------------------+ //| Returns the correct StopLoss relative to StopLevel | //+------------------------------------------------------------------+ double CorrectStopLoss(const string symbol_name,const ENUM_POSITION_TYPE position_type,const int stop_loss) { if(stop_loss==0) return 0; double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT); if(pt==0) return 0; double price=(position_type==POSITION_TYPE_BUY ? SymbolInfoDouble(symbol_name,SYMBOL_ASK) : SymbolInfoDouble(symbol_name,SYMBOL_BID)); int lv=StopLevel(symbol_name),dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS); return (position_type==POSITION_TYPE_BUY ? NormalizeDouble(::fmin(price-lv*pt,price-stop_loss*pt),dg) : NormalizeDouble(::fmax(price+lv*pt,price+stop_loss*pt),dg) ); } //+------------------------------------------------------------------+ //| Checks StopLoss for correctness with respect to StopLevel | //+------------------------------------------------------------------+ bool CheckCorrectStopLoss(const string symbol_name,const ENUM_POSITION_TYPE position_type,const double stop_loss) { if(stop_loss==0) return true; double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT); if(pt==0) return false; double price=(position_type==POSITION_TYPE_BUY ? SymbolInfoDouble(symbol_name,SYMBOL_ASK) : SymbolInfoDouble(symbol_name,SYMBOL_BID)); int lv=StopLevel(symbol_name),dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS); return ( position_type==POSITION_TYPE_BUY ? NormalizeDouble(stop_loss-price- lv*pt,dg)<0 : NormalizeDouble(stop_loss-price+ lv*pt,dg)>0 ); }
Errors highlighted.
fxsaber:
Errors are highlighted.
double price=(position_type==POSITION_TYPE_BUY ? SymbolInfoDouble(symbol_name,SYMBOL_ASK) : SymbolInfoDouble(symbol_name,SYMBOL_BID)); int lv=StopLevel(symbol_name),dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS); return (position_type==POSITION_TYPE_BUY ? NormalizeDouble(::fmin(price-lv*pt,price-stop_loss*pt),dg) : NormalizeDouble(::fmax(price+lv*pt,price+stop_loss*pt),dg) );
What is the error?
Artyom Trishkin:
What's the mistake?
The wrong price is used.
fxsaber:
Justify.
The price is incorrectly used.
Artyom Trishkin:
Justify.
Justify.
OrderSend(_Symbol, OP_BUY, 1, Ask, 100, 0, Bid);
It will work when StopLevel == 0.
Is there a mt4 version?
Great job! Thank you so much!
Easy to use. Top. Great.
Hello there.
I am trying to use your EA, but it get out of with code 1.
It's brazilian IBOV market. covered contracts and real account.
The trailing stops don't seem to adjust as the price moves further away. Is there something I'm missing?
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
TrailingStopAndTake:
Simple trailing of stop loss and take profit orders of open positions.
Author: Scriptor