IS MY EA OKAY

 
HELLO GUYZ, I HAVE BEEN WORKING ON MY FIRST EA AS A NEWBIE TO MQL4. PLS I NEED HELP IN SCRUTINIZING MY EA FOR A GOOD DEVELOPMENT AS IT DOES NOT OPEN TRADES ACCORDING TO THE CONDITIONS. THE META EDITOR SHOWS NO ERROR. PLS GUYS,HELP ME OUT.DO I HAVE ANY BUG IN IT?.......CHINEXEX NB: BELOW IS A COPY OF THE EA
Files:
chinex.mq4  7 kb
 
I had a brief look : a function is defined this way : FunctionName {....... code inside brackets ........} it seems you missused brakets.
int start()
  {
//-------------------------------------------------------------------+
   int cnt,ticket,total;
   double RSI_CURR,RSI_PREV,MA_1,MA_2,STOCHVAL,STOCHSIGN;
//-------------------------------------------------------------------+
  
   RSI_CURR =iRSI(NULL,0,14,PRICE_CLOSE,0);
   RSI_PREV =iRSI(NULL,0,14,PRICE_CLOSE,1);
   MA_1     =iMA (NULL,0,14,0,MODE_EMA,PRICE_CLOSE,0);
   MA_2     =iMA (NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);
   STOCHVAL =iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,0);
   STOCHSIGN=iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_SIGNAL,0);
//-------------------------------------------------------------------+  I THINK YOU MUST CLOSE START HERE BY }
//+------------------------------------------------------------------+
//| Calculate Optimal Lot Size                                       |
//+------------------------------------------------------------------+  
double lot;                                             ....................... TO OPEN A FUNCTION DO NOT PUT ;
                                                        ........................ JUST functionName{.... 
{ ....................... HERE YOU ARE OPENING A ROUTINE CALLED LOT
   double dFreeMargin = AccountFreeMargin()*lot/100;
  
   if (AccountFreeMargin()<(10000*lot))
   {
   Print("we have no money", AccountFreeMargin());
   return(0);
   }

} YOU ARE CLOSING THE FUNCTION LOT                  .............

//------------------------------------------------
   total= OrdersTotal ();           ORDERS BUT NO FUNCTION HAS BEEN OPENED
   if(ticket<0)                   
   {
      Print("ordersend failed with error#",GetLastError());
      return(0);
   }
Hope it will help a bit, no time right now to go further.
 
tanx for your help jac, but i still cannot get the ea working, pls help me out guyz
 
Do not panic. Correct your entire code and resubmit it if still not ok.
(In case you don't know: You can also have a look to the Book on this website, it will guide you thru the basic learnings you need to build a great EA.)
 

ok.. here is the corrrection to my ea

//+------------------------------------------------------------------+
//| CHIFX.mq4 |
//| Copyright © 2008,chinex nig ltd|
//| chinexannex@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, chinex nig ltd"
#property link "chinexannex@yahoo.com"

extern int takeprofit = 30; // the targeted profit in pips
extern int stoploss = 30; // the desired loss in pips
extern int iTrailingStop= 30; // the extended pip gain when the targeted profit is reached
extern int slippage = 3; // the difference between the bid and the ask price is 3 pips
extern double MA_1 = 14; // the moving average for 14 period (long)
extern double MA_2 = 7; // the moving average for 7 period (short)
extern double RS1 = 14; // the relative standard index for 14 periods
extern double S_FAST = 10; // the stochastic value for %k period
extern double S_SLOW = 3; // the stochastic value for slowing period
extern double S_SIGN = 3; // the stochastic value for %d period
extern double lot = 0.01; // the unit size of the contract

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+

int start()
{
//-------------------------------------------------------------------+
int cnt,ticket,total;
double RSI_CURR,RSI_PREV,MA_1,MA_2,STOCHVAL,STOCHSIGN;
//-------------------------------------------------------------------+
RSI_CURR =iRSI(NULL,0,14,PRICE_CLOSE,0);
RSI_PREV =iRSI(NULL,0,14,PRICE_CLOSE,1);
MA_1 =iMA (NULL,0,14,0,MODE_EMA,PRICE_CLOSE,0);
MA_2 =iMA (NULL,0,7,0,MODE_EMA,PRICE_CLOSE,0);
STOCHVAL =iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,0);
STOCHSIGN=iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_SIGNAL,0);

//-------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Calculate Optimal Lot Size |
//+------------------------------------------------------------------+
double dFreeMargin = AccountFreeMargin()*lot/100;
if (AccountFreeMargin()<(10000*lot))
{
Print("we have no money", AccountFreeMargin());
return(0);
}
//+---------------------------------------------------------------+
//| request to close/open long positions
//+---------------------------------------------------------------+
if((STOCHVAL>STOCHSIGN && RSI_CURR>50 && MA_1==MA_2)==true)
{
//---------------------
OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-stoploss*Point,Ask+takeprofit*Point,"bullish",0,0,Blue);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ", OrderOpenPrice());
Print("BUY order closed : ",OrderClosePrice());
Print("BUY order opentime : ", OrderOpenTime());
Print("BUY order closetime: ", OrderCloseTime());
Print("BUY order ticket no: ", OrderTicket());
Print("BUY order print : ", OrderPrint());
}
else
Print("Error opening BUY order : ",GetLastError());
return(0);
}
//---------------------------------------------------------------------

if((STOCHVAL<STOCHSIGN && RSI_PREV>RSI_CURR && MA_1==MA_2)==true)
{
//-----------------
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_BUY && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue); // close position
return(0);
}
//-----------------------
Sleep(10000); //disables the EA for 10 seconds

//-------------
if((STOCHVAL<STOCHSIGN && RSI_CURR<50 && MA_1==MA_2)==true)
{
//---------------------
OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+stoploss*Point,Bid-takeprofit*Point,"bearish",0,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
Print("SELL order closed : ",OrderClosePrice());
Print("SELL order opentime : ", OrderOpenTime());
Print("SELL order closetime: ", OrderCloseTime());
Print("SELL order ticket no: ", OrderTicket());
Print("SELL order print : ", OrderPrint());
}
else
Print("Error opening SELL order : ",GetLastError());
return(0);
}
//----------------------------

if((STOCHVAL>STOCHSIGN && RSI_PREV<RSI_CURR && MA_1==MA_2)==true)
{
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_SELL) // long position is opened
{
// should it be closed?
//-----------------
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red); // close position
return(0);
}
//-----------------------
Sleep(10000); //disables the EA for 10 seconds




//+------------------------------------------------------------------------------------+
//| Modify positions - Stoploss based on Trailing stop |
//+------------------------------------------------------------------------------------+
for(int i = 0; i < OrdersTotal(); i++)
{

if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*iTrailingStop)
{
if(OrderStopLoss()<Bid-Point*iTrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*iTrailingStop,OrderTakeProfit(),0,Green);
}
else
{
if(OrderType()==OP_SELL)
{
if(OrderOpenPrice()-Ask > Point*iTrailingStop)
if(OrderStopLoss() > Ask+Point*iTrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*iTrailingStop,OrderTakeProfit(),0,Yellow);
}
}

}}}}}}}}}}}

am i missing something?????????????????????????????????

...........chinexex


























 
Please revise carefully your program. See what I mean in the extract of your code I have commented:
//+---------------------------------------------------------------+
//| request to close/open long positions 
//+---------------------------------------------------------------+ 
if((STOCHVAL>STOCHSIGN && RSI_CURR>50 && MA_1==MA_2)==true)   ('== true' is not needed as the result of a condition is either true or false and if statement is triggered only when condition is true)
{
//---------------------
OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-stoploss*Point,Ask+takeprofit*Point,"bullish",0,0,Blue);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))    what do you want to do if that if is true?
Print("BUY order opened : ", OrderOpenPrice());         because as there is no bracket opened the pgm will only execute this line
Print("BUY order closed : ",OrderClosePrice());   and then the other Prints what ever your if result is
Print("BUY order opentime : ", OrderOpenTime());
Print("BUY order closetime: ", OrderCloseTime());
Print("BUY order ticket no: ", OrderTicket());
Print("BUY order print : ", OrderPrint());
}
else 
Print("Error opening BUY order : ",GetLastError()); 
return(0); 
}
//---------------------------------------------------------------------
When you have more then 1 instruction to execute in a if statement, use brackets.
Advice : arrange your code in order to be readable, you will need it when it will become more complicated. Refer to this exemple to see what I mean : https://book.mql4.com/samples/expert
 

tanx a lot jac 4 ur help. my ea now open orders but it does trail stops and it doesn't open sell position, why?

any advise will do. pls, assist me.

note: below is the edited version of the ea

Files:
test1.mq4  8 kb
 
chinexex wrote >>

tanx a lot jac 4 ur help. my ea now open orders but it does trail stops and it doesn't open sell position, why?

any advise will do. pls, assist me.

note: below is the edited version of the ea

From the look of your EA, you need to sort out your { and }. I don't know how much programming experience in other languages, so forgive me if this is teaching 'Granny to suck eggs'. What you need to remember is that the indentation is not important from the point of view of what gets executed in your code, but the bracketing is... { and } define levels of scope for sections of code for example:

if (condition)

{

line 1;

line 2;

}

is not the same as

if (condition)

line1;

line2;

in the first example, line and and line 2 will be executed, but the second example line 1 will be executed if the condition is true and line 2 will be executed anyway.

I don't have time to go through your code and figure it out, but it will be a good learning experience for you to do this :-)... There are an awful lot of }s at the end of your code and that makes me a bit suspicious that you may have missed some out earlier and just added them at the bottom until your peogram compiled...

All the best

-=naj=-

Reason: