Hi, I'm just finishing my own brand new EA which i build my self and i'm looking for pointer if there is something wrong with it or simplifying it.

 

Now this is my code

{  
   //Sting signals
   string Signal="";
  
   //Moving Average
   double MovingAverage=iMA(_Symbol,0,2000,0,MODE_SMA,PRICE_CLOSE,0);
   
   //CCI
   double CCI=iCCI(_Symbol,0,2000,PRICE_TYPICAL,0);
   
   //Buy Signal with moving average is lower than price close and CCI is higher than zero
   if ((MovingAverage<Close[0])&&(CCI>0))
   {
      //Set the signal variable to buy
      Signal="buy";
   }
   
   //Sell Signal with moving average is higher than price close and CCI is lover than zero
   if ((MovingAverage>Close[0])&&(CCI<0))
   {
      //Set the signal variable to sell
      Signal="sell";
   }

   //Buy 0.3 Lot
   if (Signal=="buy"&&OrdersTotal()==0)
   OrderSend (_Symbol,OP_BUY,0.30,Ask,3,Ask-500*_Point,Ask+3000*_Point,NULL,0,0,Green);
   
   //Sell 0.3 Lot
   if (Signal=="sell"&&OrdersTotal()==0)
   OrderSend (_Symbol,OP_SELL,0.30,Bid,30,Bid+500*_Point,Bid-3000*_Point,NULL,0,0,Green);
   
}

I scrap it from some tutorials in youtube which then i shape as i wish. The point of this EA is that i want to buy when price close above MA and 0 CCI and sell when price below MA and 0 CCI. I also need some help with closing order because i do realize that this system of mine is only to open the order.

 

Although not that important, I feel that it is a good idea to use enums instead of strings.

//+------------------------------------------------------------------+  I normally place enums above the inputs
enum enumSignal
  {
   BuySignal,  //Buy Signal
   SellSignal, //Sell Signal
   NoSignal    //No Signal
  };
//+------------------------------------------------------------------+
//in OnTick
{  
   //String signals--use enum instead
   enumSignal Signal=NoSignal;


   //Buy Signal with moving average is lower than price close and CCI is higher than zero
   if ((MovingAverage<Close[0])&&(CCI>0))
   {
      //Set the signal variable to buy
      Signal=BuySignal;
   }

   
   //Sell Signal with moving average is higher than price close and CCI is lover than zero
   if ((MovingAverage>Close[0])&&(CCI<0))
   {
      //Set the signal variable to sell
      Signal=SellSignal;
   }
   
}

Doing it this way saves having to type the quotes and auto_complete will work with enums in the compiler but not with strings.

I note that you are using values for the current open bar. This can lead to many false signals intrabar and is why the last closed bar is often used.

You may want to use an opposite signal to exit, or simply the opposite condition for either the MA or CCI. If you do opt for this method, it is another good reason to only use closed bars as you could be opening and closing multiple trades in the same bar if using the current bar.

 
Keith Watford:

Although not that important, I feel that it is a good idea to use enums instead of strings.

Doing it this way saves having to type the quotes and auto_complete will work with enums in the compiler but not with strings.

I note that you are using values for the current open bar. This can lead to many false signals intrabar and is why the last closed bar is often used.

You may want to use an opposite signal to exit, or simply the opposite condition for either the MA or CCI. If you do opt for this method, it is another good reason to only use closed bars as you could be opening and closing multiple trades in the same bar if using the current bar.

Hi Keith, thanks for the advice. I will implement it immedietly.

Do you mind if you explain more about this part "I note that you are using values for the current open bar."?

 
Firstian Putra Adi:

Do you mind if you explain more about this part "I note that you are using values for the current open bar."?

You are checking values for the current open bar, that is shift [0].

The values can change every tick while the bar is still open and this could give you false signals. This is why many people prefer to only use closed bars for signals.

 
Keith Watford:

You are checking values for the current open bar, that is shift [0].

The values can change every tick while the bar is still open and this could give you false signals. This is why many people prefer to only use closed bars for signals.

Wait, that isn't closed bars? I thought that is already using closed bars

Do you mind tell me what to change for it uses the closed bars?

 
Firstian Putra Adi:

Wait, that isn't closed bars? I thought that is already using closed bars

Do you mind tell me what to change for it uses the closed bars?

Shift[0] is the current open bar

Shift[1] is the most recent closed  bar

 
Thank you
Reason: