How are EA's applied to charts?

Back to topics list To post a new topic, please log in or register
avatar
4
Pipthagoras 2016.02.29 22:21
 

So I've written my first EA, which is designed to alert me whenever a Hanging Man candlestick appears. What I am now struggling to understand is, how to apply it to multiple charts. Do I manually have to drag it onto every chart (currency pair AND time frame) individually, or can I make it apply itself to specific currency pairs and time frames when it is launched?

 Also, is there a way of adding something to the Alert() that will tell me which of the charts the candlestick has occurred on?

 Thanks. 

avatar
Moderator
3404
GumRai 2016.02.29 22:35 #
 
You're probably using High[], Low[] etc in your code. To check other symbols use iHigh(), iLow() etc instead. You will need to use the symbol string in the calculations, so include the string in your alert to tell you the symbol that the pattern occured on.
avatar
4
Pipthagoras 2016.03.01 00:47 #
 
GumRai:
You're probably using High[], Low[] etc in your code. To check other symbols use iHigh(), iLow() etc instead. You will need to use the symbol string in the calculations, so include the string in your alert to tell you the symbol that the pattern occured on.
Thanks for the help, that is correct. Does that mean to say that if I wanted to refer to the last candlesticks high on the daily EURUSD chart, I should use the code iHigh[1]("EURUSD", PERIOD_D1, 0)?
avatar
Moderator
3404
GumRai 2016.03.01 01:27 #
 

Not quite, there are no square brackets

 iHigh[1]("EURUSD", PERIOD_D1, 0)   //remove [1]
 iHigh("EURUSD", PERIOD_D1, 0)      //this gives the high of the current daily bar
 iHigh("EURUSD", PERIOD_D1, 1)      //this gives the high of the previous(closed) daily bar

You can store the symbol names in a string array and loop through them

avatar
12985
WHRoeder 2016.03.01 02:41 #
 
Pipthagoras: how to apply it to multiple charts.
Do not trade multiple currencies
  • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
  • Code it to trade the chart pair only. Look at the others if you must.
  • Then put it on other charts to trade the other pairs. Done.
avatar
4
Pipthagoras 2016.03.01 12:05 #
 
WHRoeder:
Do not trade multiple currencies
  • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
  • Code it to trade the chart pair only. Look at the others if you must.
  • Then put it on other charts to trade the other pairs. Done.
The EA is only supposed to be an alert. It's simply designed to find potential trading opportunities for me, based on PA signals. The only issue with multiple timeframes if that, for example, the body of a doji candlestick on a low timeframe should be much smaller than the body of a doji on a higher timeframe. I could fix this using dynamic (percentage) values for the size of the body, rather than fixed values.
avatar
4
Pipthagoras 2016.03.01 12:10 #
 
GumRai:

Not quite, there are no square brackets

You can store the symbol names in a string array and loop through them

Thanks for all the help. One final question though: can you apply multiple symbols and periods to this? For example, could I write 

 iHigh("USDCHF, EURUSD, USDCAD", PERIOD_D1, PERIOD_H4, 1)

 Im guessing that this would be the wrong way of writing this, but if you understand what I mean, is there a way of doing this, or do you have to write iHigh() for each symbol and period individually? 

avatar
Moderator
3404
GumRai 2016.03.01 12:36 #
 

No, you can't do that

As I said, you can do it with an array and loop. This is an example that may give you some ideas

  string symbol_array[]={"EURUSD","EURJPY","GBPUSD","USDJPY"}; //4 symbols used, indexed 0 to 3
  string com="";
  for (int x=0;x<4;x++)
     {
     double symbol_high=iHigh(symbol_array[x],0,0);
     int dig=(int)MarketInfo(symbol_array[x],MODE_DIGITS);
     com+=symbol_array[x]+" High="+DoubleToStr(symbol_high,dig)+"\n";
     }
  Comment(com);
avatar
12985
WHRoeder 2016.03.01 16:18 #
 
Do not trade multiple currencies
  • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
  • Code it to trade the chart pair only. Look at the others if you must.
  • Then put it on other charts to trade the other pairs. Done.
  1. Pipthagoras iHigh("USDCHF, EURUSD, USDCAD", PERIOD_D1, PERIOD_H4, 1)
    No need for that if you
    • Code it to trade the chart pair only.
    • Then put it on other charts to trade the other pairs.
  2. GumRai's code is an example of "other problems." The code only runs on a tick of the current symbol and it does not take into account that the other symbol may not have started a new bar when the current symbol has and visa versa.
Back to topics list  

To add comments, please log in or register