Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
When you post code please use the CODE button (Alt-S)!
Thank you.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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)
{
}