Detected Country () : English
Hidden Stop Loss and Hidden Take Profit EA - codingforex.com

Welcome to CodingForex.Com!

Knowledge portal where you can learn how to create forex indicators and robot.

Click button below to choose level that suite you:

Hidden Stop Loss and Hidden Take Profit EA

Samples [2018-04-10 10:31:46] - by hillzx
Featured Image

There are some forex traders who think that not all brokers are honest, sometimes traders feel that their Stop Loss is always touched just before the price turns in the desired direction, it is often referred to as Stop Loss Hunter.

Stop Loss Hunter issues seem endless because every year there are always cases from some brokers indicated to do so, seen from evidence chart that looks much different between one broker with another broker, candlestick look longer or there is a price of shadow (needle) which is different between brokers.

Some traders then decide not to set Stop Loss in the hope that the broker will not know where the trader actually put Stop Loss. However, the problem of Stop Loss Hunter is often accompanied by widening spreads. At certain events or at certain times, the broker can change the spreads to be larger than usual so Stop Loss will be much easier to be touched.

OK to solve the problem we will create EA which has the following features:

  1. EA will close the transaction based on the hidden Stop Loss price
  2. EA will close the transaction based on the hidden Take Profit price
  3. EA will make Stop Loss and Take Profit bending and dynamic when the broker suddenly changes the spread suddenly, and returns to its original position when the spread returns to a reasonable spread



The first stage we create an external variable to receive input from the user:

extern int Hidden_TP=300; // please change take profit
extern int Hidden_SL=200; // please change the stop loss amount
extern bool Enabled=false; // enabled=True meaning the robot is active
int Slippage = 5;
int vspread;

 

Next create a module to check Stop Loss and Take Profit, each Tick:

void CheckHiddenSLTP() {

int  itotal=OrdersTotal();
 
   for(int cnt=itotal-1;cnt>=0;cnt--) 
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
      {
         if( ( Bid>= (OrderOpenPrice()+(Hidden_TP+vspread)*Point) ) || ( Bid<= (OrderOpenPrice()-(Hidden_SL+vspread)*Point) ) )
         {
             OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
         } 
      }
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
      {
         if( ( Ask<= (OrderOpenPrice()-(Hidden_TP+vspread)*Point) ) || ( Ask>= (OrderOpenPrice()+(Hidden_SL+vspread)*Point) ) )
         {
             OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
         }       
      }  
   }

}

 

Lastly call the module in the main module:

void OnTick()
  {
//---

   if (Enabled) 
   {
      vspread=MarketInfo(Symbol(),MODE_SPREAD);
      CheckHiddenSLTP();
   }
  }

 


hidden

 

Done, if still confused how to type the code, please copy the complete source code here:

//+------------------------------------------------------------------+
//|                                               Hidden SL & TP.mq4 |
//|                                                 hillzx@gmail.com |
//|                                           http://codingforex.com |
//+------------------------------------------------------------------+
#property copyright "hillzx@gmail.com"
#property link      "http://codingforex.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int Hidden_TP=300;
extern int Hidden_SL=200;
extern bool Enabled=false;
int Slippage = 5;
int vspread;

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

   if (Enabled) 
   {
      vspread=MarketInfo(Symbol(),MODE_SPREAD);
      CheckHiddenSLTP();
   }
  }
//+------------------------------------------------------------------+

void CheckHiddenSLTP() {

int  itotal=OrdersTotal();
 
   for(int cnt=itotal-1;cnt>=0;cnt--) 
   {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY)
      {
         if( ( Bid>= (OrderOpenPrice()+(Hidden_TP+vspread)*Point) ) || ( Bid<= (OrderOpenPrice()-(Hidden_SL+vspread)*Point) ) )
         {
             OrderClose( OrderTicket(), OrderLots(), Bid, Slippage, White);
         } 
      }
      
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL)
      {
         if( ( Ask<= (OrderOpenPrice()-(Hidden_TP+vspread)*Point) ) || ( Ask>= (OrderOpenPrice()+(Hidden_SL+vspread)*Point) ) )
         {
             OrderClose( OrderTicket(), OrderLots(), Ask, Slippage, White);
         }       
      }  
   }

}


Let us try, do not forget to share and follow our facebook and our youtube channel, happy trading!


Previous Article

Featured Image

EA AutoClose By Equity




- Provided by HiLLzSoft Studio -