Download MetaTrader 5

EA Initialization parameters

To add comments, please log in or register
Deposit to your account via PayPal
Keagan Roos
27
Keagan Roos 2016.11.24 13:33 


Hello fellow traders,

I am new to programming and Automated trading, though – I’m keen to keep on learning! I'd love to see your feedback/recommendations on the following code.

I am trying to limit my robot to:

*Only EURUSD & GDPUSD securities;

*Only work on 1 hour period;

*Only work on chart using Japanese candle stick mode

Please see my code below and advise.

int init ();

// Define internal variable names here.
int;
double;
bool
Chart_Period = false,                                                
Chart_Symbol = false,
Chart_Mode = false;

/////////////////////////////////////////////////////////////////////////////////////
// Ensure Correct Parametres for EA are met (1 hour period, EURUSD &//
// GBPUSD securities, and Candlestick mode)                                     //
////////////////////////////////////////////////////////////////////////////////////

if (PERIOD_CURRENT=PERIOD_H1)
   Chart_Period = true;
  {if Chart_Period = true continue;
   if Chart_Period = false
      {Alert("Trade using 1hr period only. EA Doesn't work.");
   return;}}

if (ChartSymbol(long chart_id="EURUSD","GBPUSD"))
   Chart_Symbol = true;
  {if Chart_Symbol = true continue;
   if Chart_Symbol = false
     {Alert("Trade using EURUSD & GBPUSD symbols only. EA Doesn't work.");
   return;}}
  
if (CHART_MODE=CHART_CANDLES)
   Chart_Mode = true;
  {if Chart_Mode = true continue;
   if Chart_Mode = false
     {Alert("Trade using Japanese Candle Stick Chart only. EA Doesn't work.");
   return;}}

Thanks guys!

Keagan.


 


honest_knave
Moderator
2159
honest_knave 2016.11.24 13:54  
int OnInit()
  {
   if(_Symbol != "EURUSD" && _Symbol != "GBPUSD")
     {
      Print("This EA only works on EURUSD and GBPUSD");
      return(INIT_FAILED);
     }
   if(_Period != PERIOD_H1)
     {
      Print("This EA only works on H1 chart");
      return(INIT_FAILED);
     }
   if(ChartGetInteger(0,CHART_MODE) != CHART_CANDLES)
     {
      Print("This EA only works on a candlestick chart");
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }
Keagan Roos
27
Keagan Roos 2016.11.24 14:51  
honest_knave:
int OnInit()
  {
   if(_Symbol != "EURUSD" && _Symbol != "GBPUSD")
     {
      Print("This EA only works on EURUSD and GBPUSD");
      return(INIT_FAILED);
     }
   if(_Period != PERIOD_H1)
     {
      Print("This EA only works on H1 chart");
      return(INIT_FAILED);
     }
   if(ChartGetInteger(0,CHART_MODE) != CHART_CANDLES)
     {
      Print("This EA only works on a candlestick chart");
      return(INIT_FAILED);
     }
   return(INIT_SUCCEEDED);
  }

Thanks honest_knave! You are a legend mate - it took me literally hours to come up with my long section of code (haha). 

Have a great weekend and best of luck with your trading.

 Keagan.  

whroeder1
14470
whroeder1 2016.11.24 15:12  
Keagan Roos: I am trying to limit my robot to:

*Only EURUSD & GDPUSD securities;

*Only work on 1 hour period;

*Only work on chart using Japanese candle stick mode

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Just only put it on those two pairs
  3. Just only use that TF
  4. EA's have no eyes. They can't see any mode.
To add comments, please log in or register