# EA open a position late (For beginners)

Do you have a trading signal? Publish it in your blog as well!
10
2014.09.11 02:18
`Hi im new in this forum and i can not do than the EA buy in the open the candlestick, therefore very expensive purchase and sell very cheap`
```
```
```//+------------------------------------------------------------------+
//|                                              Ichimoku-Simple.mq4 |
//|                                     David Ricardo Balaguera Mesa |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "David Ricardo Balaguera Mesa"
#property version   "1.00"

extern int  Tenkan=8;
extern int  Kinjun=22;
extern int  SenkouB=44;
extern int  ShiftCloud=10;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#define MAGICMA  2
int CalculateCurrentOrders(string symbol)
{
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_SELL) sells++;
}
}
//--- return orders volume
if(sells>0)       return(sells);
return 0;
}

void CheckForOpen()
{
double t,k,sa,sb,open,close,resb,e,e2,ress=0;
bool    res=false;

//--- get info
e=GetLastError();
t=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_TENKANSEN,0,0); //Valor Tenkan
k=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_KIJUNSEN,1,0);//Valor Kinjun
sa=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_SENKOUSPANA,5,0);//Valor senkou A

sb=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_SENKOUSPANB,6,0);//Valor Senkou B

close=iClose( Symbol() , PERIOD_M15 , 1);
open=iOpen (Symbol() , PERIOD_M15 , 1);
//e2=GetLastError();
//--- sell conditions
if(k<sa && k<sb && close<sa && close<sb)
{
while(ress==-1)
{
ress=OrderSend(Symbol(),OP_SELL,0.01,Bid,2,0,0,"",MAGICMA,Red);

}

}
if(k>sa && k>sb && close>sa && close>sb)
{
do
{
} while(resb==-1);

}
//---
}

void CheckForClose()
{
double t,k,sa,sb,close,a;
//--- go trading only for first tiks of new bar

t=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_TENKANSEN,0,0); //Valor Tenkan
k=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_KIJUNSEN,1,0);//Valor Kinjun
sa=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_SENKOUSPANA,2,0);//Valor senkou A
sb=iCustom(Symbol(),Period(),"Ichimoku2",Tenkan,Kinjun,SenkouB,ShiftCloud,MODE_SENKOUSPANB,3,0);//Valor Senkou B
close=iClose( Symbol() , PERIOD_M15 , 1);
//---
for(int i=0;i<OrdersTotal();i++)
{
if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
//--- check order type

// e=GetLastError();

{

//if(k<sa && k<sb && close<sa && close<sb)OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
if((k<=sa && k>=sb && close<=sa && close>=sb) || (k>=sa && k<=sb && close>=sa && close<=sb) || (k<=sa && k>=sb && close<=sa && close<=sb)||(k>=sa && k<=sb && close<=sa && close<=sb) ||(k<=sa && k<=sb && close<=sa && close<=sb) )
{
OrderClose(OrderTicket(),0.01,Bid,2,White);

}

break;
}
if(OrderType()==OP_SELL)
{
if((k<=sa && k>=sb && close<=sa && close>=sb) || (k>=sa && k<=sb && close>=sa && close<=sb) || (k<=sa && k>=sb && close>=sa && close>=sb)||(k>=sa && k<=sb && close>=sa && close>=sb) ||(k>=sa && k>=sb && close>=sa && close>=sb)  )
{
//while(res==false)
//{x
//}
}
break;
}
}
//---
}
int OnInit()
{
//---

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

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
return;
//--- calculate open orders by current symbol

if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else                                    CheckForClose();

}
//+------------------------------------------------------------------+
```
/