My programming knowledge is very basic and I attempted to modify the code and the mod makes sense to me but it doesn't seem to work. Here is what I attempted. The changes are in red. I added global variables, prefru, prefrd,
double prefru, prefrd, fru2, frd2; void start() { if(IsTradeAllowed()==false) return; co=CalculateCurrentOrders(); CheckForSignals(); if (co==0) //---- calculate open orders by current symbol CheckForOpen(); else { CheckForClose(); BreakEvenStop(); TrailStop(); } } double LotsRisk(int StopLoss) { double lot=Lots,risk=MaximumRisk; int SL=StopLoss; if (SL<=0) { SL=100; if (Digits==5 || Digits==3) SL=1000; } double minlot=MarketInfo(Symbol(),MODE_MINLOT); int nl=0; if (minlot<1) nl=1; if (minlot<0.1) nl=2; if (minlot<0.01) nl=3; //---- select lot size if (!FixedLot) lot=NormalizeDouble(AccountBalance()*risk*0.001/SL,nl); //---- return lot size lot=MathMax(lot,minlot); return(lot); } //+------------------------------------------------------------------+ //| Calculate open positions | //+------------------------------------------------------------------+ int CalculateCurrentOrders() { int ord; //---- for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderSymbol()==Symbol() && OrderMagicNumber()==myMagic) ord++; } //---- return orders volume return(ord); } //+------------------------------------------------------------------+ //| Check for open order conditions | //+------------------------------------------------------------------+ void CheckForSignals() { //indicators variables double fru1,frd1; for (int i=3;i<Bars;i++) { if (fru1<Point || fru1>999999) fru1 = iFractals(NULL,0,MODE_UPPER,i); if (frd1<Point || frd1>999999) frd1 = iFractals(NULL,0,MODE_LOWER,i); if (fru1>Point && fru1<999999 && frd1>Point && frd1<999999) break; } fru2=fru1; frd2=frd1; buysig=false; sellsig=false; //long entry signal condition if (fru1!=prefru) { if (fru1>Point && fru1<999999 && Bid>=fru1+BreakoutPips*Point && Low[0]<fru1+BreakoutPips*Point) { buysig=true; } } //short entry signal if (frd1!=prefrd) { if (frd1>Point && frd1<999999 && Ask<=frd1-BreakoutPips*Point && High[0]>frd1+BreakoutPips*Point) { sellsig=true; } } closebuy=false; closesell=false; } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { bool bres; for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue; if(OrderMagicNumber()!=myMagic || OrderSymbol()!=Symbol()) continue; //---- check order type if(OrderType()==OP_BUY && closebuy) { bres=CloseAtMarket(OrderTicket(),OrderLots()); prefru=fru2; continue; } if(OrderType()==OP_SELL && closesell) { bres=CloseAtMarket(OrderTicket(),OrderLots()); prefrd=frd2; continue; } } } bool CloseAtMarket(int ticket,double lot) { bool bres=false; int tr; tries=0; while (!bres && tries<OrderTriesNumber) { tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(2000); } RefreshRates(); bres=OrderClose(ticket,lot,OrderClosePrice(),slippage,White); tries++; } if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError())); return(bres); }
Any feedback will be greatly appreciated. Thank you for your time in advance.
vikneshk:
My programming knowledge is very basic and I attempted to modify the code and the mod makes sense to me but it doesn't seem to work. Here is what I attempted. The changes are in red. I added global variables, prefru, prefrd,
Comparing doubles is going to get you in trouble, read this: Can price != price ?
Why not check the datetime instead ?
If you don't mind, could you explain how I could use datetime please
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi. I need help modifying an EA that I paid to have coded. It is a basic fractal breakout EA with trailing stop and breakeven, TP and SL. I want to modify it such that, once a fractal is used as a signal to open a trade, another trade will not be opened based on the same fractal. This is to prevent the instance when, a trade is profitably closed and theprice comes back towards the fractal to head in the opposite direction. This is the original code.