Stop-loss and take-profit settings for buy and sell

 

Hello

I have the following code of which am expecting that on BUY ORDER its sets the SL and TP according to the ASK price and on SELL its sets SL AND TP according to BID PRICE. Everytime i run the bot is report INVALID stops 

 //define Ask, Bid
Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   //brokers settings management
symbolTickSize  = SymbolInfoDouble(Symbol(), SYMBOL_TRADE_TICK_SIZE);
symbolDigits    = (int)SymbolInfoInteger(Symbol(), SYMBOL_DIGITS);
   //money and risk manangemnt 
lot = 0.01;
stopLoss =20; //in points
takeProfit = 50; //in points

   //Take Profits for BUYs
buyTakeProfit = NormalizeDouble(Ask + (takeProfit * symbolTickSize), symbolDigits);
sellTakeProfit = NormalizeDouble(Bid - (takeProfit * symbolTickSize), symbolDigits);
   //Stop Loss for SELLs
buyStopLoss = NormalizeDouble(Ask - (stopLoss* symbolTickSize), symbolDigits);
sellStopLoss = NormalizeDouble(Bid + (stopLoss * symbolTickSize), symbolDigits);
 
Topic has been moved to the section: Expert Advisors and Automated Trading
 

Learn to use the debugger to find where and why you have some problems.

Here are the HowTos:

Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272

Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...