Navigation´╝ÜHome > Content >

takeprofitwaw_EA.mq4

Time: 2015-05-15 | Download file:takeprofitwaw_EA.mq4

extern int MagicNumber = 0605540;
extern double lots = 0.01; // lots size fisso

extern double Ampiezza = 8;
extern int Secondi = 5;
extern double AggiuntaPe = 5;
extern int SecondiPe = 3;
extern int Slippage = 1;
extern double maxspread = 2; // maximum spread allowed by the expert
extern double Trailing = 2.5;

double Valori[];
int LastTimeTot,LastTimePar,LastOpenOrd;
double pt,StopLevel,TP;
double TakeProf = 40;
double TrailingPt;
double AmpiezzaPt;
double AggiuntaPt;

int init(){
pt=Point;
if(Digits==3 || Digits==5) pt=Point*10;

if(Secondi<2) Secondi=2;
if(Secondi>60) Secondi=60;

AmpiezzaPt = Ampiezza * pt;
AggiuntaPt = AggiuntaPe * pt;
TrailingPt = Trailing * pt;

ArrayResize( Valori, Secondi);

TP = TakeProf * pt;
return(0);
}

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

int start()
{

int i,ActTimePar;

if (TimeCurrent()!=LastTimeTot) {
ActTimePar=TimeSeconds(TimeCurrent());
ActTimePar %= Secondi;
if ( Secondi < (TimeCurrent()-LastTimeTot)) {
ArrayInitialize(Valori,Bid);
} else {
if ( LastTimeParmaxVal) {
ActTimePar=TimeSeconds(TimeCurrent());
ActTimePar%=Secondi;
Valori[ActTimePar] = Bid;

if(BidmaxVal) maxVal = Bid;
}

double differMxMn = maxVal-minVal;
double Retrace = differMxMn/10;
int begin=GetTickCount();

if (count()==0)
{
if (differMxMn>AmpiezzaPt && (Ask-Bid)<=maxspread*pt && IsTradeAllowed())
{
if (Bid>maxVal-Retrace) {
TikerOp = OrderSend(Symbol(),OP_BUYSTOP,lots,nd(Ask+AggiuntaPt),Slippage,nd(Bid+AggiuntaPt-TrailingPt),nd(Bid+TP),"MaloNot ",MagicNumber,0,Red);
Print ("OrderSend OP_SELLSTOP ",(GetTickCount()-begin));
if(TikerOp==-1) Print("Error opening order!: ", GetLastError());
}
if (BidOrderStopLoss()+TrailingPt+pt) {
TikerMo = OrderModify(OrderTicket(),0,nd(Bid-TrailingPt),nd(Bid+TP),0,Blue);
Print ("OrderModify OP_SELL : OpenPrice ",OrderOpenPrice()," Time ", (GetTickCount()-begin));
if(TikerMo==false) Print("Error Modify order!: ", GetLastError());
}
break;

case OP_SELLSTOP:
if (differMxMnminVal+Retrace)) { OrderDelete(OrderTicket()); Print (" ********************************** "); break; }
if (Ask-Bid>maxspread*pt) { Print (" Spread alto durante ordine ",DoubleToStr(Ask-Bid,5)); }

if (OrderOpenTime()minVal+Retrace)) { OrderDelete(OrderTicket()); Print (" ********************************** "); break; }
if (Ask-Bid>maxspread*pt) { Print (" Spread alto durante ordine",DoubleToStr(Ask-Bid,5)); }

if (OrderOpenTime()0){
for(int i=OrdersTotal()-1;i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)cnt++;
}
return(cnt);
}
} 

Recommend