Heiken Ashi EA Backtest going in loss

To add comments, please log in or register
Pathmanathan Sujeeve
19
Pathmanathan Sujeeve  

I'm running below EA based on Heiken Ashi indicator. the logic is when 3 continuous green bar then buy, when find first opposite direction bar (in this case red) close the trade. 

The trade opening and closing all getting closed immediately. I don't understand what im doing wrong. Please help me.  

Please see below ea code



#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict


extern int MagicNumber=32001;

extern double Lots =0.1;

extern int Slippage=3;

extern int NoOfMaxOrders=1;


color color1 = Red;

color color2 = White;

color color3 = Red;

color color4 = White;


#define HAHIGH      0

#define HALOW       1

#define HAOPEN      2

#define HACLOSE     3


void OnTick()

  {

  

  double ho1 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HAOPEN, 1);

  double hc1 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HACLOSE, 1);

  double ho2 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HAOPEN, 2);

  double hc2 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HACLOSE, 2);

  double ho3 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HAOPEN, 3);

  double hc3 = iCustom(NULL,Period(),"Heiken Ashi", color1,color2,color3,color4, HACLOSE, 3);

  

  bool isBuy = false;

  bool isSell = false;

 

  if((ho1<hc1) && (ho2<hc2) && (ho3<hc3)){

isBuy=true;

  }else if((ho1>hc1)){

isSell=true;

  }

  

  double MyPoint=Point;

  if(Digits==3 || Digits==5) MyPoint=Point*10;

  

  double TheStopLoss=0;

  double TheTakeProfit=0;

  if( TotalOrdersCount()<NoOfMaxOrders )

  {

     int result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);

  }

  

  if(TotalOrdersCount()>0){

for(int i=0;i<OrdersTotal();i++)

{

if(isSell){

   OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

   OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);

}

}

  }

  

}


int TotalOrdersCount()

{

  int result=0;

  for(int i=0;i<OrdersTotal();i++)

  {

     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

     if (OrderMagicNumber()==MagicNumber) result++;

   }

  return (result);

}


int OnInit()

  {

   return(INIT_SUCCEEDED);

  }


void OnDeinit(const int reason)

  {

      

   

  }

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Any great idea about HEDGING positions...
Sergey Golubev
Moderator
106689
To add comments, please log in or register