ATR based TP and SL

 

I am trying to implement an ATR based SL and TP. I have run into a dead end though and cant figure out where the mistake is. The code compiles but when i use the ATR SL and TP in the OrderSend() no trades are executed. If i set the TP and SL to a fixed amount of pips then orders are opened. I have tried to return an error code and get error 0, so that doesnt help me much.. Can someone here spot my mistake? 


#property copyright "Jes"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input string               ATR = "ATR Settings";
extern int  ATRPeriod           = 14;
extern double SLATRMultiplier   = 2;
extern double TPATRMultiplier   = 4;



//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   int ticket = 0;

   datetime dtfrom=StringToTime("00:00");
   datetime dttill=StringToTime("08:00");
   int ifrom=iBarShift(NULL,0,dtfrom);
   int itill=iBarShift(NULL,0,dttill);
   int ihighest=iHighest(NULL,0,MODE_HIGH,ifrom-itill,itill+1);
   int ilowest = iLowest(NULL,0,MODE_LOW, ifrom-itill,itill+1);

   double highestPrice=iHigh(NULL,0,ihighest);
   double lowestPrice = iLow(NULL,0,ilowest);


// ATR Stop Loss and Take Profit

// high and low price of previous candle 
   double high = iHigh(NULL,0,1);
   double low  = iLow(NULL,0,1);

// Atr
   double atr = iATR(NULL,0,14,1);

// SL
   double SLsell = NormalizeDouble(high + atr * SLATRMultiplier,Digits);
   double SLbuy = NormalizeDouble(low - atr * SLATRMultiplier,Digits);

//TP
   double TPbuy = NormalizeDouble(high + atr * TPATRMultiplier, Digits);
   double TPsell = NormalizeDouble(low - atr * TPATRMultiplier, Digits);

   if(Close[1] > highestPrice && Open[1] < highestPrice && OrdersTotal()<1) //Buy conditions
     {
    
      ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,90,SLbuy*Point,TPsell*Point,NULL,0); //buying
      if(ticket < 0) Alert("order rejected. Order error: " + GetLastError());
     }
   else
     {
      if(Close[1] < lowestPrice && Open[1] > lowestPrice && OrdersTotal()<1) //sell condidtions
      
         ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,90,SLsell*Point,TPsell*Point,NULL,0);      // selling
         if(ticket < 0) Alert("order rejected. Order error: " + GetLastError());
     }


  }
//+------------------------------------------------------------------+
OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
Before we start developing, let's get acquainted with some features of the OOP, which will be used in this article.  Of course, we will use structures and classes. These are the basics of object oriented languages. A structure is a construction that allows containing a set of variables and functions of different types (except void). A class as...
 
I think it is about first part of your codes 
 
silly me. I simply forgot to add/deduct my SL/TP values from Bid/Ask.. Thanks anyway