Please Help edit an EA

Hello Everybody,
I am using an EA that I like alot. It simply places a sell order when the RSI goes above 80, and a buy order when it goes below 20.

Here are the lines of code that are currently being used to perform those actions…

double diRSI0=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0);
double diRSI1=iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,0);

if ((diRSI0>80)){
OpenSell();
return(0);
}

if ((diRSI1<20)){
OpenBuy();
return(0);
}

I would like to to these indicators…Using the default Bollinger Bands, I would like to to work as follows…

If RSI > 80 & the last bar closed above the top BB line, Sell
If RSI < 20 & the last bar closed below the bottom BB line, Buy

Would anybody be able to assit w/ the lines of code I need to add ?

What “double” lines do I need, and how to I make it ensure both “double” lines are true for it to activate the buy/sell ??

Thank you for any feedback.

How much coding have you done before? And is that EA going to be used with MT4?

:slight_smile:

Zero Coding using this program.

I do have coding experiance with non-related scripting.

and this is being used in mt4 (already running, just want a little additional cushion…I like the idea of very few trades, but high % chance of ending in a positive result…hence trading at the high and lows of RSI)

Here is a copy of the EA that I am working with.

I downloaded it free form forex-tsp/forums.

Very effective and simple to use, I just want to add the BB…or any other suggestions an more experianced trader may have to go with the goal of fewer trades for high % profit. I dont know how to save it as attachment…so here it is.

#property copyright “newdigital”
#property link “http://www.forex-tsd.com
#define MAGIC 751518

extern double lStopLoss = 200;
extern double sStopLoss = 200;
extern double lTakeProfit = 400;
extern double sTakeProfit = 400;
extern double lTrailingStop = 10;
extern double sTrailingStop = 10;
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 = false;
extern int FromHourTrade = 9;
extern int ToHourTrade = 17;
extern bool UseSound = false;
extern string NameFileSound = “alert.wav”;
extern double Lots = 0.01;
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&gt;80)){
     OpenSell();
     return(0);
  }
     
  if ((diRSI0&gt;90)){
     OpenSell();
     return(0);
  }

  if ((diRSI1&lt;20)){
     OpenBuy();
     return(0);
  }
  
  if ((diRSI1&lt;10)){
     OpenBuy();
     return(0);
  }

}
TrailingPositionsBuy(lTrailingStop);
TrailingPositionsSell(sTrailingStop);
return (0);
}

bool ExistPositions() {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
return(True);
}
}
}
return(false);
}
void TrailingPositionsBuy(int trailingStop) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice()>trailingStopPoint) {
if (OrderStopLoss()<Bid-trailingStop
Point)
ModifyStopLoss(Bid-trailingStopPoint);
}
}
}
}
}
}
void TrailingPositionsSell(int trailingStop) {
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask>trailingStop
Point) {
if (OrderStopLoss()>Ask+trailingStopPoint || 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-lStopLossPoint);}
double GetStopLossSell() { return(Ask+sStopLoss
Point); }
double GetTakeProfitBuy() { return(Ask+lTakeProfitPoint); }
double GetTakeProfitSell() { return(Bid-sTakeProfit
Point); }

I think the code noted in red should work. I put the RSIPERIOD in with the BBands as they would probably be using the same period as the RSI I would think…and that variable is defined somewhere else in the code I presume.

Oh, and after previewing my post, it looks like this forum’s text editor put a “space” in the word Lower (LOWE R), so just in case it looks like that to you, there shouldn’t be one.

Hope that helps :slight_smile:

Oops…that RSIPERIOD should be RSIPeriod…I was just copying & pasting from one of my EA’s…:o …and somethings are very “case sensitive”. :slight_smile: