//+------------------------------------------------------------------+ //| CCI_For_Gazuz2.mq4 | //| tonyc2a@yahoo.com | //| | //+------------------------------------------------------------------+ #property copyright "tonyc2a@yahoo.com" #property link "" extern int Risk=20; extern int mm=1; extern int CCI_Period=20; extern int Slippage=4; extern int Lots=1; extern int StopLoss=60; extern int TakeProfit=999; extern int TrailingStop = 30; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double BuyCrossPoint=0; double SellCrossPoint=0; bool abv01=( iCCI(Symbol(),Period(),1,PRICE_CLOSE,1) > BuyCrossPoint ); bool abv02=( iCCI(Symbol(),Period(),1,PRICE_CLOSE,2) > SellCrossPoint ); bool blw01=( iCCI(Symbol(),Period(),1,PRICE_CLOSE,1) < SellCrossPoint ); bool blw02=( iCCI(Symbol(),Period(),1,PRICE_CLOSE,2) < BuyCrossPoint ); //---- TODO: Add your code here. //+----Main Section: Determines entries and exits-----------------+ for(int x=1;x<OrdersTotal();x++){ OrderSelect(x, SELECT_BY_POS, MODE_TRADES); if(OrderType()==OP_BUY && OrderSymbol()==Symbol()){ if(abv02 && blw01){ OrderClose(x,OrderLots(),OrderClosePrice(),Slippage,White); Alert("CCI Expert Closed Buy Trade"+"."+Symbol()); return(0); }//end if }//end if if(OrderType()==OP_SELL && OrderSymbol()==Symbol()){ if(abv01 && blw02){ OrderClose(x,OrderLots(),OrderClosePrice(),Slippage,Gold); Alert("CCI Expert Closed Sell Trade"+"."+Symbol()); return(0); }//end if }//end if }//end for if(OrdersTotal()<1){ if(abv02 && blw01){ OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,"CCI Expert Short Trade",0,0,Gold); Alert("CCI Expert Opened a Short Trade: "+Symbol()); return(0); } if(abv01 && blw02){ OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,"CCI Expert Long Trade",0,0,White); Alert("CCI Expert Opened a Long Trade: "+Symbol()); return(0); } } //+---------------------------------------------------------------+ //+----Trailing Stop Section--------------------------------------+ for (int i = 0; i < OrdersTotal(); i++){ OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY){ if (Bid - OrderOpenPrice() > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)){ if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)){ OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red); } } } else if(OrderType() == OP_SELL){ if(OrderOpenPrice() - Ask > TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)){ if((OrderStopLoss() > Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) || (OrderStopLoss() == 0)){ OrderModify(OrderTicket(), OrderOpenPrice(),Ask + TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit(), Red); } } } } //+---------------------------------------------------------------+ //---- return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Commodity channel index
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It automatically opens orders when conditions are reached
It can change open orders parameters, due to possible stepping strategy
Other Features:
It issuies visual alerts to the screen