//+------------------------------------------------------------------+ //| RSI.mq4 | //| code by Newdigital | //| http://www.forex-tsd.com | //| using Gordago software | //| http://www.gordago.com | //| | //+------------------------------------------------------------------+ #property copyright "newdigital" #property link "http://www.forex-tsd.com" #define MAGIC 751518 extern double lStopLoss = 60; extern double sStopLoss = 60; extern double lTakeProfit = 120; extern double sTakeProfit = 120; extern double lTrailingStop = 25; extern double sTrailingStop = 25; extern color clOpenBuy = Blue; extern color clCloseBuy = Aqua; extern color clOpenSell = Red; extern color clCloseSell = Violet; extern color clModiBuy = Blue; extern color clModiSell = Red; extern string Name_Expert = "RSI"; extern int Slippage = 4; extern bool UseHourTrade = True; extern int FromHourTrade = 9; extern int ToHourTrade = 17; extern bool UseSound = True; extern string NameFileSound = "alert.wav"; extern double Lots = 0.10; extern int RSIPeriod=14; void deinit() { Comment(""); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start(){ if (UseHourTrade){ if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) { Comment("Time for trade has not come else!"); return(0); } else Comment(""); }else Comment(""); if(Bars<100){ Print("bars less than 100"); return(0); } if(lStopLoss<10){ Print("StopLoss less than 10"); return(0); } if(lTakeProfit<10){ Print("TakeProfit less than 10"); return(0); } if(sStopLoss<10){ Print("StopLoss less than 10"); return(0); } if(sTakeProfit<10){ Print("TakeProfit less than 10"); return(0); } double diRSI0=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0); double diRSI1=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0); if(AccountFreeMargin()<(1000*Lots)){ Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } if (!ExistPositions()){ if ((diRSI0>70)){ OpenBuy(); return(0); } if ((diRSI1<30)){ OpenSell(); return(0); } } TrailingPositionsBuy(lTrailingStop); TrailingPositionsSell(sTrailingStop); return (0); } bool ExistPositions() { 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); if (fm && UseSound) PlaySound(NameFileSound); } void OpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossBuy(); ldTake = GetTakeProfitBuy(); lsComm = GetCommentForOrder(); OrderSend(Symbol(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenBuy); if (UseSound) PlaySound(NameFileSound); } void OpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = GetStopLossSell(); ldTake = GetTakeProfitSell(); lsComm = GetCommentForOrder(); OrderSend(Symbol(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,MAGIC,0,clOpenSell); if (UseSound) PlaySound(NameFileSound); } string GetCommentForOrder() { return(Name_Expert); } double GetSizeLot() { return(Lots); } double GetStopLossBuy() { return (Bid-lStopLoss*Point);} double GetStopLossSell() { return(Ask+sStopLoss*Point); } double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); } double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }