PROBLEM WITH CODE

 

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);

}
 
 
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.
 
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 ?
 
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

 
Of course. I wanted the OP to find out for himself.