Download MetaTrader 5

PROBLEM WITH CODE

To add comments, please log in or register
Have you published a program in the Market? Place it in your blog as well - the widget will help!
sgtrader
29
sgtrader 2013.11.19 13:12 

Hi everyone, I wrote code as belows for my EA, compilation is Ok but no result appears after back-test in MT4 for long period. So I think I got problem with the code. Can anyone help me to resolve this problem?

Thanks so much!

The code is very simple with 3 terms for trade!

extern double TakeProfit=3.0;

extern double StopLoss=3.0;

extern double Size=0.5;


int start()

{

int total,ticket;

double PreClose_1, PreClose_2,PreMA_1,PreMA_2,RSI, RSI_Pre;




PreClose_1 = iClose(NULL,0,1);

PreClose_2 = iClose(NULL,0,2);

PreMA20_1 = iMA(NULL,0,30,0,MODE_SMA,PRICE_CLOSE,1);

PreMA20_2 = iMA(NULL,0,30,0,MODE_SMA,PRICE_CLOSE,2);

RSI = iRSI(NULL,0,14,PRICE_CLOSE,1);

RSI_Pre = iRSI(NULL,0,14,PRICE_CLOSE,2);


total=OrdersTotal();

         if (total<1)

{

if( PreClose_1*Point < PreMA_1*Point && PreClose_2*Point >= PreMA_2*Point && (RSI*Point)>30 && (RSI*Point)<50)

{

ticket=OrderSend(Symbol(),OP_SELL,Size,Bid,3,0,0,"Sell",12345,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+StopLoss,OrderOpenPrice()-TakeProfit,0,Red);

Print(" Sell Rate : ",OrderOpenPrice());

}

}

else Print("Cannot Sell:",GetLastError());

return(0);

}


if( PreClose_1*Point > PreMA_1*Point && PreClose_2*Point <= PreMA_2*Point && (RSI*Point)>50 && (RSI*Point)<70)

{

ticket=OrderSend(Symbol(),OP_BUY,Size,Ask,3,0,0,"Buy",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss,OrderOpenPrice()+TakeProfit,0,Green);

Print(" Buy Rate : ",OrderOpenPrice());

}

}

else Print("Cannot Buyc:",GetLastError());

return(0);

}


if( RSI_Pre*Point<80 && (RSI*Point)>80 )

{

ticket=OrderSend(Symbol(),OP_BUY,Size,Ask,3,0,0,"Buy",12345,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-StopLoss,OrderOpenPrice()+TakeProfit,0,Green);

Print(" Buy Rate : ",OrderOpenPrice());

}

}

else Print("Cannot Buy:",GetLastError());

return(0);

}

}


return(0);

}
Ubzen
5394
Ubzen 2013.11.19 13:33  
whroeder1
14480
whroeder1 2013.11.19 14:16  
sgtrader: no result appears after back-test in MT4 for long period. So I think I got problem
So start printing out your variable and calculation values and track it down. Should take about 2 minutes.
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.11.19 15:33  
sgtrader:

Hi everyone, I wrote code as belows for my EA, compilation is Ok but no result appears after back-test in MT4 for long period. So I think I got problem with the code. Can anyone help me to resolve this problem?

Thanks so much!

The code is very simple with 3 terms for trade!

Did you OrderSend() not get called ? did it get called and failed ? don't you want to know ? read this: What are Function return values ? How do I use them ?
Keith Watford
Moderator
9614
Keith Watford 2013.11.19 19:21  
if( PreClose_1*Point > PreMA_1*Point && PreClose_2*Point <= PreMA_2*Point && (RSI*Point)>50 && (RSI*Point)<70)

Why *Point?

if( RSI_Pre*Point<80 && (RSI*Point)>80 )

Any RSI value *Point will be less than 1 for most symbols, so the above can never be true

whroeder1
14480
whroeder1 2013.11.19 22:18  
Of course. I wanted the OP to find out for himself.
To add comments, please log in or register