Ayuda con EaHola a todos, os adjunto un EA que hace lo siguiente :
si el precio está por encima la EMA 50 y aparece una engulfing bar bullish pone una orden limite en el high de la engulfing. Para ventas lo contrario. Alguien podria modificar el experto para que en vez de poner una limit order abriera directamente la orden al cierre de la engulfing ? Gracias.
Re: Ayuda con EaHas probado a cambiar OP_BUYLIMIT por OP_BUY y OP_SELLLIMIT por OP_SELL? Echa un vistazo aquí si tienes dudas: http://docs.mql4.com/trading/OrderType
Ah y no olvides de borrar los precios de las limits Saludos, FXWizard
Re: Ayuda con EaHolaFx, muchas gracias por la respuesta. He cambiado lo que comentas y ahora solo abre un trade.
Lo de borrar los precios de las limits, no tengo ni idea que es. Como verás estoy perdidisimo en programacion..... Te adjunto el codigo como ha quedado : //+------------------------------------------------------------------+ //| H4 Engulf Strategy.mq4 | //| Copyright 2012,Martin Riley. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2012,Will Thomas." #property link "http://www.metaquotes.net" extern double LotSize=0.0; extern double MaxLots = 50.0; extern int RiskPercent = 5; extern int CheckForCross = 6; extern int TrailingStop=200; extern bool DisableLiveTrading=false; extern double CandlePercentageCheck=12; extern int _MagicNumber = 347520934; extern string EAName="Engulf"; static int PrevTime; static double sellBreakEven=0, buyBreakEven=0; static double SL=0; static double sell_current_ts, buy_current_ts, Poin; static int sellTimeOpen, buyTimeOpen; static double StopLevel; static double pip; static int expires=0; int init() { if (Point == 0.00001) { Poin = 0.0001; //5 digits } else if (Point == 0.001) { Poin = 0.01; //3 digits } else { Poin = Point; } if (MarketInfo(Symbol(), MODE_DIGITS) == 2) { pip = 0.01; } else if (MarketInfo(Symbol(), MODE_DIGITS) == 3) { pip = 0.01; } else if (MarketInfo(Symbol(), MODE_DIGITS) == 4) { pip = 0.0001; } else if (MarketInfo(Symbol(), MODE_DIGITS) == 5) { pip = 0.0001; } else { pip = 0.0001; } switch ( Period() ) { case PERIOD_MN1: expires = 2419200; break; case PERIOD_W1: expires = 604800; break; case PERIOD_D1: expires = 86400; break; case PERIOD_H4: expires = 14400; break; case PERIOD_H1: expires = 3600; break; case PERIOD_M30: expires = 1800; break; case PERIOD_M15: expires = 900; break; case PERIOD_M5: expires = 300; break; case PERIOD_M1: expires = 60; break; } StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL) + MarketInfo(Symbol(), MODE_SPREAD); Print("Expiry set to ",expires); return(0); } double CalcLotsVolume() { double SendLots;//The actual Lotsize that will be sent with the order double MaxLot;//Broker's Maximum permitted amount of a lot. double MinLot;//Broker's Step for changing lots, e.g 0.01. double LotStep;//Broker's Minimum permitted amount of a lot. if (LotSize > 0.0) SendLots = NormalizeLot(LotSize);//The manual LotSize, bounded by broker's specs else {//Calculate AutoLot: MaxLot = MarketInfo(Symbol(), MODE_MAXLOT); MinLot = MarketInfo(Symbol(), MODE_MINLOT); LotStep = MarketInfo(Symbol(), MODE_LOTSTEP); SendLots = NormalizeDouble(MathFloor(AccountFreeMargin() * RiskPercent / 100.0 / (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * LotStep)) * LotStep, 2); if (SendLots < MinLot) SendLots = MinLot;//Broker's absolute minimum Lot if (SendLots > MaxLot) SendLots = MaxLot;//Broker's absolute maximum Lot } if (SendLots > MaxLots) SendLots = MaxLots;//Never exceed our manualy set limit return (SendLots); } double NormalizeLot(double Lots) { double NormalizedLot;//The final LotSize, bounded by broker's specs double InverseLotStep; double LotStep = MarketInfo(Symbol(), MODE_LOTSTEP); double MinLot = MarketInfo(Symbol(), MODE_MINLOT); double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT); if (MinLot == 0.0) MinLot = 0.1;//In case MarketInfo returns no info if (MaxLot == 0.0) MaxLot = 5; //In case MarketInfo returns no info if (LotStep == 0.0) InverseLotStep = 1 / MinLot;//In case MarketInfo returns no info else InverseLotStep = 1 / LotStep; NormalizedLot = MathFloor(Lots * InverseLotStep) / InverseLotStep; if (NormalizedLot < MinLot) NormalizedLot = MinLot;//Broker's absolute minimum Lot if (NormalizedLot > MaxLot) NormalizedLot = MaxLot;//Broker's absolute maximum Lot return (NormalizedLot); } int start() { double spread, SMA50, LastSMA50, LastHigh, LastLow, LastOpen, LastClose, CompareHigh, CompareLow, CompareOpen, CompareClose, sellProfit, buyProfit; int cnt; string name = EAName+" ("+Symbol()+"-"+Period()+")"; bool result = true; int activeSell, activeBuy; double Lot; // Need to Check All Pending Orders - If price breaks the low or high of the previous candle in the wrong direction, remove the pending order. // Manage trade // Sell // As soon as it breaks 0 which is commission set stop loss for (cnt=0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == _MagicNumber) { if (OrderType() == OP_SELL) { if (TimeCurrent() > sellTimeOpen) { Print("Deleting SellStop at ",TimeToStr(Time[0], TIME_DATE|TIME_SECONDS)); OrderDelete(OrderTicket()); } } if (OrderType() == OP_BUY) { if (TimeCurrent() > buyTimeOpen) { Print("Deleting BuyStop at ",TimeToStr(Time[0], TIME_DATE|TIME_SECONDS)); OrderDelete(OrderTicket()); } } SMA50=iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0); if (OrderType() == OP_SELL) { activeSell = 1; /* if (Ask > SMA50) { OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Blue); } */ if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Blue); } } } } if (OrderType() == OP_BUY) { activeBuy = 1; /* if (Bid < SMA50) { OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red); } */ if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Red); } } } } } } if (PrevTime!=Time[0]) { Lot = CalcLotsVolume(); // Define the Moving Averages SMA50=iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,0); LastSMA50=iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,1); //////////////////////// // THIS IS A SELL.... //////////////////////// // Check X Candles for no recent SMA Cross if (activeSell == 0 && activeBuy == 0) { bool NoSMACross = true; for(cnt=0;cnt<CheckForCross;cnt++){ //Check the Last X Candles and Ensure the High is below the MA for a SHORT and Low is above for a LONG //If there is a cross, ditch if(iHigh(0,0,cnt) > iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,cnt)){ NoSMACross = false; } } // If NoSMACross = true Check next Check if (NoSMACross == true) { double Candle3Open = iOpen(Symbol(), 0, 2); double Candle3Close = iClose(Symbol(), 0, 2); double Candle3High = iHigh(Symbol(), 0, 2); double Candle3Low = iLow(Symbol(), 0, 2); double Candle2Open = iOpen(Symbol(), 0, 1); double Candle2Close = iClose(Symbol(), 0, 1); double Candle2Highest = iHigh(Symbol(), 0, 1); double Candle2Lowest = iLow(Symbol(), 0, 1); double Candle1Open = iOpen(Symbol(), 0 , 1); // Rule 1 - Check that the 3rd candle back is a upward bullish candle // Candle open would be lower than the close on a bullish candle if (Candle3Open < Candle3Close) { // Rule 2 - Candle 2 open is bigger or equal to candle 3 close AND candle 2 close is less than or equal to candle3 open if (Candle2Open >= Candle3Close && Candle2Close <= Candle3Open) { // We are now onto candle 1 // We put sell on 1 pip plus spread below candle2close // Stoploss is highest point of candle 2 + 1 pip // Open is lowest of candle 2 + 1 pip + spread // TP is difference between stoploss and open in pips // Pending order mofo // Rule 3 - new rule added by will and martin double v1 = MathAbs(Candle3Open-Candle3Close); double v2 = MathAbs(Candle3High-Candle3Low); double per = (100/v2)*v1; Print("Percentage of first candle is ",per,"%"); if (per > CandlePercentageCheck) { double stop = Candle2Highest + pip; double open = Candle2Lowest - (pip); double take = Candle2Highest - Candle2Lowest; take = Bid - take; Print("New SellStop at ",open," with take ",take," and stop ",stop," at time ",TimeToStr(Time[0], TIME_DATE|TIME_SECONDS)); result = OrderSend(Symbol(), OP_SELL, Lot, open, 3, stop, take, name+" Sell", _MagicNumber, 0, Blue); if(result == false) { Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(1000); } sellTimeOpen= TimeCurrent() + expires; } if (ObjectFind("ArrowDownA"+Time[0]) == -1) { ObjectCreate(StringConcatenate("ArrowDownA",Time[0]),OBJ_ARROW,0,Time[0],open); ObjectSet(StringConcatenate("ArrowDownA",Time[0]), OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN); ObjectSet(StringConcatenate("ArrowDownA",Time[0]), OBJPROP_COLOR, Blue); } } } } } //////////////////////// // THIS IS A BUY.... //////////////////////// // Check X Candles for no recent SMA Cross if (activeSell == 0 && activeBuy == 0) { bool BuyNoSMACross = true; for(cnt=0;cnt<CheckForCross;cnt++){ //Check the Last X Candles and Ensure the High is below the MA for a SHORT and Low is above for a LONG //If there is a cross, ditch if(iHigh(0,0,cnt) < iMA(NULL,0,50,0,MODE_SMA,PRICE_CLOSE,cnt)){ BuyNoSMACross = false; } } // If NoSMACross = true Check next Check if (BuyNoSMACross == true) { double BuyCandle3Open = iOpen(Symbol(), 0, 2); double BuyCandle3Close = iClose(Symbol(), 0, 2); double BuyCandle3High = iHigh(Symbol(), 0, 2); double BuyCandle3Low = iLow(Symbol(), 0, 2); double BuyCandle2Open = iOpen(Symbol(), 0, 1); double BuyCandle2Close = iClose(Symbol(), 0, 1); double BuyCandle2Highest = iHigh(Symbol(), 0, 1); double BuyCandle2Lowest = iLow(Symbol(), 0, 1); double BuyCandle1Open = iOpen(Symbol(), 0 , 1); // Whats happening explained... // Check to make sure the 3rd candle back is on a downtrend by making sure the open is bigger than the close.. // Then make sure that the 2nd candle is engulfing (outside bar) the 3rd candle. So the open of the 2nd candle must be less than or equal to close of candle 3, and the close of 2 must be // bigger than the close of 3 (showing an uptrend i.e. a buy) // Martin and will have added the percentage check, which checks the size of candle 3 to make sure its big enough (optimised) // If all checks out, then its a valid BUY, but we set a pending order, // Open the trade by the highest value of candle 2 plus a pip. // Rule 1 - Check that the 3rd candle back is a upward bullish candle // Candle open would be lower than the close on a bullish candle if (BuyCandle3Open > BuyCandle3Close) { // Rule 2 - Candle 2 open is bigger or equal to candle 3 close AND candle 2 close is less than or equal to candle3 open if (BuyCandle2Open <= BuyCandle3Close && BuyCandle2Close >= BuyCandle3Open) { // We are now onto candle 1 // We put sell on 1 pip plus spread below candle2close // Stoploss is highest point of candle 2 + 1 pip // Open is lowest of candle 2 + 1 pip + spread // TP is difference between stoploss and open in pips // Pending order mofo // Rule 3 - new rule added by will and martin double BuyV1 = MathAbs(BuyCandle3Open-BuyCandle3Close); double BuyV2 = MathAbs(BuyCandle3High-BuyCandle3Low); double BuyPer = (100/BuyV2)*BuyV1; Print("Percentage of first candle is ",BuyPer,"%"); if (BuyPer > CandlePercentageCheck) { double BuyStop = BuyCandle2Lowest - pip; double BuyOpen = BuyCandle2Highest + (pip); double BuyTake = BuyCandle2Highest - BuyCandle2Lowest; BuyTake = Ask + BuyTake; Print("New BuyStop at ",BuyOpen," with take ",BuyTake," and stop ",BuyStop," at time ",TimeToStr(Time[0], TIME_DATE|TIME_SECONDS)); result = OrderSend(Symbol(), OP_BUY, Lot, BuyOpen, 3, BuyStop, BuyTake, name+" Buy", _MagicNumber, 0, Red); if(result == false) { Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(1000); } buyTimeOpen=TimeCurrent()+expires; } if (ObjectFind("ArrowUpA"+Time[0]) == -1) { ObjectCreate(StringConcatenate("ArrowUpA",Time[0]),OBJ_ARROW,0,Time[0],BuyOpen); ObjectSet(StringConcatenate("ArrowUpA",Time[0]), OBJPROP_ARROWCODE, SYMBOL_ARROWUP); ObjectSet(StringConcatenate("ArrowUpA",Time[0]), OBJPROP_COLOR, Red); } } } // Check One, was the Comparison Candle a BULL // Check Two, Last Candle Opens Higher, and Closes Lower //if(CompareOpen < CompareClose && LastOpen => CompareClose && LastClose <= CompareOpen) { // SELL SELL SELL // Pending SellStop Order Needed to be Placed at LastLow + Spread + 1 pip // SL Needed to be Placed at LastHigh 1 pip // TP Needed to be Placed at Bid + (LastHigh - LastLow) //} } } PrevTime=Time[0]; } return(0); }
3 mensajes
• Página 1 de 1
|
|
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados