# Heiken Ashi EA Backtest going in loss

19

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.

#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 isSell = false;

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

}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 )

{

}

if(TotalOrdersCount()>0){

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

{

if(isSell){

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

}

}

}

}

int TotalOrdersCount()

{

int result=0;

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

{

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
• 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...
Moderator
106689