Trabalho concluído
Termos de Referência
the current code is a break out ea .
Stop opening Trades after the first trade. only the first trade after the breakout should be trade.
After that, the ea must wait untill the price breaks out and trade again. every entry must be recognized.
Input Variables ( tradehours) where I can put time in, like 08:00 untill 22:00 o'clock. (8 am to 10 pm)
integrate an ATR trailing stop with enable - disable choice ( period of ATR must be able to put in.
give your price / days
//////////////////////////////////////////////////code/////////////////////////////////////////////////////////
void OnTick(){
double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
double Poin=SymbolInfoDouble(_Symbol, SYMBOL_POINT);
int Dig=(int)SymbolInfoInteger(_Symbol, SYMBOL_DIGITS);
int stopLevel=(int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
MqlRates mrate[];
CopyRates(_Symbol,_Period,0,4,mrate);
double close3=mrate[0].close; // bar 3
double close2=mrate[1].close; // bar 2
double close1=mrate[2].close; // bar 1
double close0=mrate[3].close; // bar 0
double open3=mrate[0].open; // bar 3
double open2=mrate[1].open; // bar 2
double open1=mrate[2].open; // bar 1
double open0=mrate[3].open; // bar 0
double low3=mrate[0].low; // bar 3
double low2=mrate[1].low; // bar 2
double low1=mrate[2].low; // bar 1
double low0=mrate[3].low; // bar 0
double high3=mrate[0].high; // bar 3
double high2=mrate[1].high; // bar 2
double high1=mrate[2].high; // bar 1
double high0=mrate[3].high; // bar 0
datetime time3=mrate[0].time;
datetime time2=mrate[1].time;
datetime time1=mrate[2].time;
datetime time0=mrate[3].time;
double upLine0=0,upLine1=0,upLine2=0, upLine3=0, dnLine0=0,dnLine1=0, dnLine2=0, dnLine3=0 ;
if(ObjectFind(0,levels_sirname+"_UpName")>-1){
upLine0=ObjectGetValueByTime(0,levels_sirname+"_UpName",time0);
upLine1=ObjectGetValueByTime(0,levels_sirname+"_UpName",time1);
upLine2=ObjectGetValueByTime(0,levels_sirname+"_UpName",time2);
upLine3=ObjectGetValueByTime(0,levels_sirname+"_UpName",time3);
}
if(ObjectFind(0,levels_sirname+"_DnName")>-1){
dnLine0=ObjectGetValueByTime(0,levels_sirname+"_DnName",time0);
dnLine1=ObjectGetValueByTime(0,levels_sirname+"_DnName",time1);
dnLine2=ObjectGetValueByTime(0,levels_sirname+"_DnName",time2);
dnLine3=ObjectGetValueByTime(0,levels_sirname+"_DnName",time3);
}
if (trail_==TRFIX_){
if (trailStop>0)
fSimpleTrailing(trailStop);
}
if (trail_==TRSTOP_)
fSimpleTrailing(slPp);
if(PositionSelect(_Symbol)==false)
{
double sl=0,tp=0;
if (time0!=lastOrder){
// dont change this settings below, they finde every entry
if (upLine0>0 && close1>open1 && close0>open0 && low1>upLine1 && low1<low0 && Ask>high1 ){
sl=low1;
if ((Ask-sl)/Poin<stopLevel)
sl=NormalizeDouble(Ask-stopLevel*Poin,Dig);
slPp=(int)((Ask-sl)/Poin);
if (tp_==EXITNO_) tp=0;
if (tp_==EXIT11_) tp=NormalizeDouble(Ask+slPp*Poin,Dig);
if (tp_==EXIT12_) tp=NormalizeDouble(Ask+slPp*2*Poin,Dig);
if (tp_==EXIT13_) tp=NormalizeDouble(Ask+slPp*3*Poin,Dig);
if (tp_==EXIT14_) tp=NormalizeDouble(Ask+slPp*4*Poin,Dig);
if (tp_==FIX_)
if(takeProfit>0) tp=NormalizeDouble(Ask+takeProfit*Poin,Dig); else sl=0;
Trade.Buy(NormLot(_Symbol,lots),_Symbol,Ask,sl,tp,"");
lastOrder=time0;
return;
}
// dont change this settings below, they finde every entry
if (dnLine0>0 && close1<open1 && close0<open0 && high1<dnLine1 && high1>high0 && Bid<low1 ){
sl=high1;
if ((sl-Bid)/Poin<stopLevel)
sl=NormalizeDouble(Bid+stopLevel*Poin,Dig);
slPp=(int)((sl-Bid)/Poin);
if (tp_==EXITNO_) tp=0;
if (tp_==EXIT11_) tp=NormalizeDouble(Bid-slPp*Poin,Dig);
if (tp_==EXIT12_) tp=NormalizeDouble(Bid-slPp*2*Poin,Dig);
if (tp_==EXIT13_) tp=NormalizeDouble(Bid-slPp*3*Poin,Dig);
if (tp_==EXIT14_) tp=NormalizeDouble(Bid-slPp*4*Poin,Dig);
if (tp_==FIX_)
if (takeProfit>0) tp=NormalizeDouble(Bid-takeProfit*Poin,Dig); else sl=0;
Trade.Sell(NormLot(_Symbol,lots),_Symbol,Bid,sl,tp,"");
lastOrder=time0;
return;
}
}
}
}
//+------------------------------------------------------------------+
double NormLot( string symbol, double lot_)
{
double LOTSTEP=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
double MaxLot=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
double MinLot=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
if(!LOTSTEP || !MaxLot || !MinLot) return(0);
double lot=LOTSTEP*MathFloor(lot_/LOTSTEP);
if(lot<MinLot) lot=MinLot;
if(lot>MaxLot) lot=MaxLot;
return(lot);
}
//+------------------------------------------------------------------+
void fSimpleTrailing(int Trail){
if(Trail<=0) return;
if(!PositionSelect(_Symbol)) return;
double Ask=SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double Bid=SymbolInfoDouble(_Symbol, SYMBOL_BID);
int stopLevel=(int)SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
double nsl,tmsl,psl;
switch(Pos.PositionType()){
case POSITION_TYPE_BUY:
nsl=NormalizeDouble(Bid-_Point*Trail,_Digits);
if(nsl>=NormalizeDouble(Pos.PriceOpen(),_Digits)){
if(nsl>NormalizeDouble(Pos.StopLoss(),_Digits)){
tmsl=NormalizeDouble(Bid-_Point*stopLevel,_Digits);
if(nsl<tmsl){
Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
}
}
}
break;
case POSITION_TYPE_SELL:
nsl=NormalizeDouble(Ask+_Point*Trail,_Digits);
if(nsl<=NormalizeDouble(Pos.PriceOpen(),_Digits)){
psl=NormalizeDouble(Pos.StopLoss(),_Digits);
if(nsl<psl || psl==0){
tmsl=NormalizeDouble(Ask+_Point*stopLevel,_Digits);
if(nsl>tmsl){
Trade.PositionModify(_Symbol,nsl,Pos.TakeProfit());
}
}
}
break;
}
}