# Orders are in the air(Backtesting) / EA opens an order, while the conditions are not true!

19

Hello,

iam starting to write my first EA. But since the beginning, there's a strange behavior of my EA.

Ok my first problem is, that orders are opened in the air, while there is no trend..

and my second problem is, the order is opened while the conditions are FALSE!!

void TechnicalAnalysis2x13()
{
if ((iSAR(NULL, PERIOD_M15,0.02,0.02,1) < Ask) && (iRSI(NULL, PERIOD_M15,7,PRICE_CLOSE,1) < 30))
{
IfOrderDoesNotExist8();

}
}

void IfOrderDoesNotExist8()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}

if (exists == false)
{

}
}

{
if (BuyStoploss5 == 0) SL = 0;
if (BuyTakeprofit5 == 0) TP = 0;
int ticket = -1;
if (true)
else
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}

}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}

The value of

Hope you can help me!

Thank you

1401

Have you tried reversing the logic? Sometimes it helps.

You could try other part also since I think it is just logic problems and nothing much.

What I see is just common logic mistakes.

19

Iam sitting here for hours and can't find a mistake..

I have attached the SourceCode, so maybe someone can have a look inside and tell me what's wrong with it.

The Function is very easy.

Open a buy position if the SAR Indicator is below the market price and RSI is below 30.

Open a sell position if the SAR Indicator is above the market price and RSI is above 70.

Thank you!

DoJo
Files:
dojo_1.mq4 5 kb
1047

The code is too complicated, symplify it

{
if ((iRSI(0,15,7,0,1) < 30)&& (iRSI(0,15,7,0,0) < 30) &&
{
int ticket = -1;
if ( ticket == -1) ticket = OrderSend(Symbol(), OP_BUY, BuyLots5, Ask, 4, 0, 0,   "My Expert", 1, 0, Blue);
} }
1401

Simplification usually will not do any good unless the code is working like it should.

Once it is working, then you can start optimizing the code to make it more efficient. :)

Always happen to me by the way.

1047

I think the EA is working the way it should :

https://charts.mql5.com/4/492/eurusd-m15-fxpro-financial-services.png

It is programmed for 15 Mn indicator, check TF, it should be 15 Mn or below : 5 Mn or 1Mn.

I agree deymacro, but often, one has to symplify the code to find where is the problem, and for us, the reader, it's easier to understand if the code is easy to read, be lazy ... :-)

Moderator
9641

Make sure that the SAR settings on the chart are the same as in the EA

if ((iSAR(NULL, PERIOD_M15,0.02,0.02,1) < Ask) && (iRSI(NULL, PERIOD_M15,7,PRICE_CLOSE,1) < 30))

I bet the SAR on your chart is 0.02,0.2 .

2584

DoJo:

Iam sitting here for hours and can't find a mistake..

I have attached the SourceCode, so maybe someone can have a look inside and tell me what's wrong with it.

The Function is very easy.

Open a buy position if the SAR Indicator is below the market price and RSI is below 30.

Open a sell position if the SAR Indicator is above the market price and RSI is above 70.

Thank you!

DoJo

You should at least attempt basic debugging before you ask others to do it for you. Use Print().

if ((iSAR(NULL, PERIOD_M15,0.02,0.02,1) < Ask) && (iRSI(NULL, PERIOD_M15,7,PRICE_CLOSE,1) < 30))
{
Print("iSAR = ",iSAR(NULL, PERIOD_M15,0.02,0.02,1));
Print("iRSI = ",iRSI(NULL, PERIOD_M15,7,PRICE_CLOSE,1));

IfOrderDoesNotExist8();
}
Moderator
31185

DoJo:

Hello,

iam starting to write my first EA. But since the beginning, there's a strange behavior of my EA.

Ok my first problem is, that orders are opened in the air, while there is no trend..

...

Thank you

Chart is drawn from bid price. Your buy order is open from Ask price. You are running the Strategy Tester with current spread on week end. Which seems to be around 20 pips.
Moderator
9641

angevoyageur:
Chart is drawn from bid price. Your buy order is open from Ask price. You are running the Strategy Tester with current spread on week end. Which seems to be around 20 pips.

I didn't notice the dates on the chart.

I wish that people would actually make it clear when they are referring to a test and not live charts.

2584

Come on now GumRai they all know you have psychic powers to mind read them, no point pretending ;)

12