HI,
Can any one help me please…
In this EA i have set cci >200 to buy and -200 to sell for scalping but,
its countunisly opening oders how to set is to sleep for at least 60 second.
thanks you…
//±-----------------------------------------------------------------+
//| CCI EA.mq4 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| |
//±-----------------------------------------------------------------+
#property copyright “Copyright 2018”
#property link “”
#property version “1.00”
#property strict
input double StopLoss=100;
input double TakeProfit=40;
input double TrailingStop=15;
input double Moving_Avarage=5;
input int RSIperiod=14;
input double BuyLevel=30;
input double SellLevel=70;
input bool AutoLot=False;
input double Risk=10;
input double ManualLots=0.01;
input int MagicNumber=1&2;
input string Comment=“Candle_Pro_EA”;
input int Slippage=10;
int OrderBuy,OrderSell;
int LotDigits;
double MacdCurrent,MacdPrevious;
double SignalCurrent,SignalPrevious;
double MaCurrent,MaPrevious;
int ticket;
int total;
//±-----------------------------------------------------------------+
//| Expert initialization function |
//±-----------------------------------------------------------------+
int init()
{
return(0);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
int deinit()
{
return(0);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
int start()
{
OrderBuy=0;
OrderSell=0;
for(int cnt=0; cnt<OrdersTotal(); cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderComment()==Comment)
{
if(OrderType()==OP_BUY) OrderBuy++;
if(OrderType()==OP_SELL) OrderSell++;
}
}
// double rsi=iRSI(Symbol(),0,RSIperiod,PRICE_CLOSE,0);
double x1 = iCCI(Symbol(),_Period,20,PRICE_TYPICAL,0);
//open position
if(OrderBuy < 1 && x1< 200 && x1>= 200 ) OPBUY();
if(OrderSell < 1 && x1> -200 && x1>= -200 ) OPSELL();
//close position by signal
if(OrderBuy > 0 && x1> 200 ) CloseBuy();
if(OrderSell > 0 && x1< 200 ) CloseSell();
//— it is important to enter the market correctly, but it is more important to exit it correctly…
for(int cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//— long position is opened
if(OrderType()==OP_BUY)
{
}
//— check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>PointTrailingStop)
{
if(OrderStopLoss()<Bid-PointTrailingStop)
{
//— modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return(0);
}
}
}
}
else // go to short position
{
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return(0);
}
}
}
}
}
return(0);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
void OPBUY()
{
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Bid-StopLossPoint; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfitPoint; else TakeProfitLevel=0.0;
ticket=OrderSend(Symbol(),OP_BUY,LOT(),Ask,Slippage,StopLossLevel,TakeProfitLevel,Comment,MagicNumber,0,DodgerBlue);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
void OPSELL()
{
double StopLossLevel;
double TakeProfitLevel;
if(StopLoss>0) StopLossLevel=Ask+StopLossPoint; else StopLossLevel=0.0;
if(TakeProfit>0) TakeProfitLevel=Bid-TakeProfitPoint; else TakeProfitLevel=0.0;
ticket=OrderSend(Symbol(),OP_SELL,LOT(),Bid,Slippage,StopLossLevel,TakeProfitLevel,Comment,MagicNumber,0,DeepPink);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
void CloseSell()
{
total=OrdersTotal();
for(int y=OrdersTotal()-1; y>=0; y–)
{
if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber)
{
ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);
}
}
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
void CloseBuy()
{
total=OrdersTotal();
for(int y=OrdersTotal()-1; y>=0; y–)
{
if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber)
{
ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);
}
}
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
double LOT()
{
double lotsi;
double ilot_max =MarketInfo(Symbol(),MODE_MAXLOT);
double ilot_min =MarketInfo(Symbol(),MODE_MINLOT);
double tick=MarketInfo(Symbol(),MODE_TICKVALUE);
double myAccount=AccountBalance();
if(ilot_min==0.01) LotDigits=2;
if(ilot_min==0.1) LotDigits=1;
if(ilot_min==1) LotDigits=0;
if(AutoLot)
{
lotsi=NormalizeDouble((myAccount*Risk)/10000,LotDigits);
} else { lotsi=ManualLots;
}
if(lotsi>=ilot_max) { lotsi=ilot_max; }
return(lotsi);
}
//±-----------------------------------------------------------------+