Correlation EA assistance needed

 

Im still learning alot regarding mt4 programming

Basically saw the idea regarding correlation and bolligner bands 

Buy on the EUR/USD if price is below the middle line (20SMA) of the bands on the EUR/USD pair and price as crossed and closed below the lower band on the USDCHF pair

Sell on the EUR/USD if price is above the middle line (20SMA) of the bands on the EUR/USD pair and price as crossed and closed above the higher band on the USDCHF pair


Questions:

Just need to know if my logic is correct regarding my code below  ?

If I state "USDCHF" and "EURUSD" inside the ibands will it check the logic on the "USDCHF"pair and place a trade on "EURUSD" if I place the EA on the EURUSD chair ?

Or this there a different approach of looking at it ?

Code:

BUY

 //Open Buy Order

   if(Cross(0, Close[1] < iBands("USDCHF", PERIOD_CURRENT, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 0)) //Candlestick Close crosses above Bollinger Bands
   && Close[1] < iMA("EURUSD", PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 0) && Close[1] <  iBands("EURUSD", PERIOD_CURRENT, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 0)
   )
     {
      RefreshRates();
      price = Ask;
      SL = 30 * myPoint; 
      TP = 30 * myPoint;   
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_BUY, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else 
         myAlert("order", "");
      myOrderModifyRel(ticket, 0, TP);
      myOrderModifyRel(ticket, SL, 0);
     }

   SELL

if(Cross(1, Close[1] > iBands("USDCHF", PERIOD_CURRENT, 20, 2, 0, PRICE_CLOSE, MODE_HIGH, 0)) //Candlestick Close crosses below Bollinger Bands
   && Close[1] > iMA("EURUSD", PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 0) && Close[1] < iBands("EURUSD", PERIOD_CURRENT, 20, 2, 0, PRICE_CLOSE, MODE_HIGH, 0) 
   )
     {
      RefreshRates();
      price = Bid;
      SL = 30 * myPoint; 
      TP = 30 * myPoint;  
      if(IsTradeAllowed())
        {
         ticket = myOrderSend(OP_SELL, price, TradeSize, "");
         if(ticket <= 0) return;
        }
      else 
         myAlert("order", "");
      myOrderModifyRel(ticket, 0, TP);
      myOrderModifyRel(ticket, SL, 0);
     }
  }
 

1°)specify which Close[1] :  close of EU or UC ?


2°)maybe it's better to place trade order on the openning of new canlde (candle 0) if previous one (candle 1) fulfill all conditions 

 

//buy conditions :

bool buy_condition=(iClose("USDCHF",PERIOD_CURRENT,1) < iBands("USDCHF", PERIOD_CURRENT, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, 1) 
                 && iClose("EURUSD",PERIOD_CURRENT,1) < iMA("EURUSD", PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 1));

 

//sell conditions

bool sell_condition=(iClose("USDCHF",PERIOD_CURRENT,1) > iBands("USDCHF",PERIOD_CURRENT,20,2,0,PRICE_CLOSE,MODE_UPPER,1) 
                  && iClose("EURUSD",PERIOD_CURRENT,1) > iMA("EURUSD", PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, 1));
 
paul selvan:

1°)specify which Close[1] :  close of EU or UC ?


2°)maybe it's better to place trade order on the openning of new canlde (candle 0) if previous one (candle 1) fulfill all conditions 

1. Well Ill check if the candle close above/below the bands on the UC then confirm on the EU if the price is above the middle band and take the trade on the EU

 
paul selvan:

//buy conditions :

Thanks will try it out

 
all the best