Hi guys, I hope you doing well. I wrote an EA which is more complicated than this below, But as an example in the below code, I used ADX to get signals, when it's running on real time it works perfectly, But when I want to back test, It doesn't actually works, Then the strategy tester doesn't move at all, I noticed that the problem must be about the code not the MT4, because I can test any other EA in it as well, So i want to know if the problem is about code, and how can I fix it?
Here is the code
I really appreciate your help & your time for solve it, Thanks in advance.
inputint risk=5; //Risk Amount In Percent//+------------------------------------------------------------------+//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnTick()
{
//+------------------------------------------------------------------+//|Lot Calculation |//+------------------------------------------------------------------+double balance=AccountInfoDouble(ACCOUNT_BALANCE);
int leverage=AccountInfoInteger(ACCOUNT_LEVERAGE);
int Currency_Lot=100000;
double balnace_=(balance*risk)/100;
double leverage_=balnace_*leverage;
double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
double lot_=ask*Currency_Lot;
double lot= leverage_/lot_;
lot=NormalizeDouble(lot,2);
//+------------------------------------------------------------------+//|Opening positions |//+------------------------------------------------------------------+if(ADX()=="Signal Buy")
close(2020);
if(ADX()=="Signal Sell")
close(1010);
if(iVolume(Symbol(),PERIOD_CURRENT,0)<=1 && Orders()==0)
{
if(ADX()=="Signal Buy")
int Ticketbuy=OrderSend(Symbol(),OP_BUY,lot,Ask,5,0,0,"We Got a Buy Position",1010,0,clrGreen);
if(ADX()=="Signal Sell")
int Ticketsell=OrderSend(Symbol(),OP_SELL,lot,Bid,5,0,0,"We Got a Sell Position",2020,0,clrRed);
}
}
//+------------------------------------------------------------------+//| Check Adx Signal//+------------------------------------------------------------------+string ADX()
{
double Adx_PDI1= iADX(NULL,PERIOD_CURRENT,14,PRICE_CLOSE,1,1); // DI+ For Candle Number 1double Adx_MDI1= iADX(NULL,PERIOD_CURRENT,14,PRICE_CLOSE,2,1); // DI- For Candle Number 1double Adx_PDI2= iADX(NULL,PERIOD_CURRENT,14,PRICE_CLOSE,1,0); // DI+ For Candle Number 0double Adx_MDI2= iADX(NULL,PERIOD_CURRENT,14,PRICE_CLOSE,2,0); // DI+ For Candle Number 0if(Adx_MDI2>Adx_PDI2 && Adx_MDI1<Adx_PDI1)
{
return("Signal Buy");
}
elseif(Adx_MDI2<Adx_PDI2 && Adx_MDI1>Adx_PDI1)
{
return("Signal Sell");
}
return("No Signal");
}
//+------------------------------------------------------------------+//|Select Positions//+------------------------------------------------------------------+int Orders()
{
int num=0;
for(int i= OrdersTotal()-1; i>=0; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==1010 || OrderMagicNumber()==2020)
num++;
}
}
return(num);
}
//+------------------------------------------------------------------+//|Closing Positions//+------------------------------------------------------------------+void close(int Magic)
{
for(int i= OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic)
bool abc= OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,clrRed);
}
}
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi guys, I hope you doing well. I wrote an EA which is more complicated than this below, But as an example in the below code, I used ADX to get signals, when it's running on real time it works perfectly, But when I want to back test, It doesn't actually works, Then the strategy tester doesn't move at all, I noticed that the problem must be about the code not the MT4, because I can test any other EA in it as well, So i want to know if the problem is about code, and how can I fix it?
Here is the code
I really appreciate your help & your time for solve it, Thanks in advance.