//+------------------------------------------------------------------+ //| FarhadCrab6.mq4 | //| Copyright © 2007, Farhad Farshad | //| http://www.fxperz.com //| farhadfarshad11@yahoo.com //| ***** PLEASE NOTE ***** //| This EA best works on EURUSD 1M TimeFrame. //| If you get money from this EA please donate some to poor people of your country. //+-----------------------------------------------------------------+ #property copyright "Copyright © 2007, Farhad Farshad" #property link "http://www.fxperz.com" #include extern double maxLoss = 100; // Maximum Loss that you can bear in percent extern double maxYield = 0.1; // a number between 0 to 100 (not more than 10 is recommended) extern double lTakeProfit = 300; // recomended no more than 20 extern double sTakeProfit = 300; // recomended no more than 20 extern double takeProfit = 300; // recomended no more than 20 extern double pr = 300; //take profit in sideway markets. extern double stopLoss = 0; // extern int magicEA = 124; // Magic EA identifier. Allows for several co-existing EA with different input values extern double lTrailingStop = 15; // trail stop in points extern double sTrailingStop = 15; // trail stop in points extern color clOpenBuy = Blue; //Different colors for different positions extern color clCloseBuy = Aqua; //Different colors for different positions extern color clOpenSell = Red; //Different colors for different positions extern color clCloseSell = Violet; //Different colors for different positions extern color clModiBuy = Blue; //Different colors for different positions extern color clModiSell = Red; //Different colors for different positions extern int Slippage = 3; extern string nameEA = "FarhadCrab6.mq4";// To "easy read" which EA place an specific order and remember me forever :) double maLongCurrent, maShortCurrent, maLongPrevious, maShortPrevious, faRSICurrent, deMark; double realTP, realSL, faMiddle, faHighest, faLowest, closeCurrent,faCloseM5, closeCurrentD, closePreviousD; int cnt, ticket; bool isBuying = false, isSelling = false, isBuyClosing = false, isSellClosing = false; double initialDeposit; //First of All Specify your initial Deposit. double lLots , sLots;// you can change the lot but be aware of margin. Its better to trade with 1/4 of your capital. //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { /* */ initialDeposit=AccountBalance(); //System Stoploss based on LongTerm Moving Average (Fibo 55 day MA) //StopLoss For Buy Positions (Optional) //if ((maLongCurrent>closeCurrentD) && (maLongPrevioushighCurrentH1)) { if ((AccountEquity()>(initialDeposit+((maxYield/100)*initialDeposit))) || (AccountBalance()-AccountEquity()>((maxLoss/100)*initialDeposit)) //|| ((maLongCurrent>closeCurrentD) && (maLongPrevioushighCurrentH1)) ){ CloseBuyPositions(); //return(0); } //StopLoss For Sell Positions (Optional) //if ((maLongCurrentclosePreviousD) && (maLongCurrent(initialDeposit+((maxYield/100)*initialDeposit))) || (AccountBalance()-AccountEquity()>((maxLoss/100)*initialDeposit)) //|| ((maLongCurrentclosePreviousD) && (maLongCurrentcloseCurrentD) //downtrend { oversold = 0.15; overbought = 0.85; } if (maLongCurrent-((OrderLots())*500))) n = 0; else n = 1; if (OrdersTotal()>n) { return(0); } int bnt; for(bnt=0;bnt1)){ return(0); } } //Check Margin Requirement if(AccountFreeMargin()<0){ Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } //Buy Condition if ((!takeBuyPositions()) && (n == 0) ){ if ( (deMarkoverbought) //&& (previousdeMark > deMark) && (rsi > 70) // && ((maLongCurrent>closeCurrentD)) ) { OpenSell(); return(0); } } if ((!takeSellPositions()) && (n == 1)){ if ( (deMark>0.70) && (previousdeMark > deMark) && (OrderType()==OP_BUY) ) { hedgeOpenSell(); return(0); } } //Trailing Expressions TrailingPositionsBuy(lTrailingStop); TrailingPositionsSell(sTrailingStop); return (0); } //Number of Buy Positions bool takeBuyPositions() { for (int i=0; itrailingStop*Point) { if (OrderStopLoss()trailingStop*Point) { if (OrderStopLoss()>Ask+trailingStop*Point || OrderStopLoss()==0) ModifyStopLoss(Ask+trailingStop*Point); } } } } } } void ModifyStopLoss(double ldStopLoss) { bool fm; fm = OrderModify(OrderTicket(),OrderOpenPrice (),ldStopLoss,OrderTakeProfit(),0,CLR_NONE); } void OpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossBuy(); ldTake = GetTakeProfitBuy(); lsComm = GetCommentForOrder(); if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-((OrderLots())*500))) lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/10),1)/10; else lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1)/10; OrderSend(Symbol(),OP_BUY,lLots,Ask,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenBuy); } void OpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossSell(); ldTake = GetTakeProfitSell(); lsComm = GetCommentForOrder(); if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-((OrderLots())*500))) sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/10),1)/10; else sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1)/10; OrderSend(Symbol(),OP_SELL,sLots,Bid,Slippage,ldStop,ldTake,nameEA,magicEA,0,clOpenSell); } void hedgeOpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossBuy(); ldTake = GetTakeProfitBuy(); lsComm = GetCommentForOrder(); //if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-(MathSqrt(OrderLots())*500))) //lLots = 0.2; //MathRound(AccountBalance()/4000); //else lLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1)/10; OrderSend(Symbol(),OP_BUY,lLots,Ask,Slippage,Ask-60*Point,ldTake,nameEA,magicEA,0,clOpenBuy); } void hedgeOpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossSell(); ldTake = GetTakeProfitSell(); lsComm = GetCommentForOrder(); // if ((AccountEquity()-AccountBalance()==0) || (AccountEquity()-AccountBalance()>-(MathSqrt(OrderLots())*500))) //sLots = 0.2; //MathRound(AccountBalance()/4000); // else sLots = NormalizeDouble((MathRound((AccountBalance()-500)/1000)/5),1)/10; OrderSend(Symbol(),OP_SELL,sLots,Bid,Slippage,Bid+60*Point,ldTake,nameEA,magicEA,0,clOpenSell); } string GetCommentForOrder() { return(nameEA); } double GetSizeLot() { return(lLots); } double GetTakeProfitBuy() { if (iADX(NULL,0,14,PRICE_MEDIAN,MODE_MAIN,0)<25) return(Ask+lTakeProfit*Point); else return(Ask+pr*Point); } double GetTakeProfitSell() { if (iADX(NULL,0,14,PRICE_MEDIAN,MODE_MAIN,0)<25) return(Bid-sTakeProfit*Point); else return (Bid-pr*Point);} double GetStopLossBuy() { if (stopLoss==0) return(0); else return(Ask - stopLoss*Point);} double GetStopLossSell() { if (stopLoss==0) return(0); else return(Bid + stopLoss*Point);} void calculateIndicators() { // Calculate indicators' value closeCurrentD = iClose(NULL,PERIOD_M1,0); //Close Price Current for D1 TimeFrame closePreviousD = iClose(NULL,PERIOD_M1,1); //Close Price Previous for D1 TimeFrame maLongCurrent = iMA(NULL,PERIOD_M1,55,1,MODE_SMMA,PRICE_TYPICAL,0); //Current Long Term Moving Average maLongPrevious = iMA(NULL,PERIOD_M1,55,1,MODE_SMMA,PRICE_TYPICAL,1); //Previous Long Term Moving Average // Check for BUY, SELL, and CLOSE signal isBuying = false; isSelling = false; isBuyClosing = false; isSellClosing = false; } void CloseBuyPositions(){ for (int i=0; i