CCI ver2.3





extern int shortcciperiod=7;
extern int longcciperiod=30;
extern int shortmaperiod=2;
extern int longmaperiod=55;
extern int stoploss=90;
extern int takeprofit=30;
extern int lots=1;


bool notrades;
int tradeconditions;
int trend;
bool enabletrading;
double vol;
int startingbalance;



int magicnumber=1234;


int init() {

startingbalance = AccountBalance() / lots;

tradeconditions = 1;

double shortcci=iCCI(Symbol(),0,shortcciperiod,PRICE_OPEN,0);
double longcci=iCCI(Symbol(),0,longcciperiod,PRICE_OPEN,0);

if (shortcci > 0 && longcci > 0) trend=1;
if (shortcci < 0 && longcci < 0) trend=-1;

int allexpertorders=0;
for (int alltheorders=OrdersTotal(); alltheorders >= 0; alltheorders--) {
   OrderSelect(alltheorders,SELECT_BY_POS,MODE_TRADES);
   if (OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber) allexpertorders++;
   }
   
if (allexpertorders==0) enabletrading=true;
if (allexpertorders > 0) {enabletrading=false; Alert("There are orders from this expert opened...");}

return(0);

}



int start() {

if (enabletrading) {


RefreshRates();

vol = NormalizeDouble(AccountBalance() / startingbalance, 2);


double shortcci=iCCI(Symbol(),0,shortcciperiod,PRICE_OPEN,0);
double longcci=iCCI(Symbol(),0,longcciperiod,PRICE_OPEN,0);
double shortema=iMA(Symbol(),0,shortmaperiod,0,MODE_EMA,PRICE_OPEN,0);
double longema=iMA(Symbol(),0,longmaperiod,0,MODE_EMA,PRICE_OPEN,0);
double emavalue=shortema-longema;

if (tradeconditions == 0) tradeconditions++;   


if (tradeconditions > 0) {
   if (shortcci > 0 && longcci > 0 && emavalue > 0) {
      OrderSend(Symbol(),OP_BUY,vol,Ask,1,Ask-stoploss*Point,Ask+takeprofit*Point,NULL,magicnumber,0,Blue);
      tradeconditions=-1;
      trend=1;
      Alert(trend);
      }
   if (shortcci < 0 && longcci < 0 && emavalue < 0) {
      OrderSend(Symbol(),OP_SELL,vol,Bid,1,Bid+stoploss*Point,Bid-takeprofit*Point,NULL,magicnumber,0,Red);
      tradeconditions=-1;
      trend=-1;
      Alert(trend);
      }
   }
if (tradeconditions < 0) {
   if (trend > 0) {
      if (shortcci < 0 && longcci < 0) {
         for (int alltheorders2=OrdersTotal(); alltheorders2 >= 0; alltheorders2--) {
            OrderSelect(alltheorders2,SELECT_BY_POS,MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber) OrderClose(OrderTicket(),OrderLots(),Bid,1,Blue);
            tradeconditions=1;
            }
         }
      }
   if (trend < 0) {
      if (shortcci > 0 && longcci > 0) {
         for (int alltheorders3=OrdersTotal(); alltheorders3 >= 0; alltheorders3--) {
            OrderSelect(alltheorders3,SELECT_BY_POS,MODE_TRADES);
            if (OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber) OrderClose(OrderTicket(),OrderLots(),Ask,1,Red);
            tradeconditions=1;
            }
         }
      }
   
   }




}



}
int deinit() {
return(0);
}








Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Commodity channel index
Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


It issuies visual alerts to the screen