Download MetaTrader 5

EA

To add comments, please log in or register
billc
393
billc  
Is it possible to write an EA that recognises a buy or sell arrow created by a  2 moving averages indictor, and buys or sells on that? When an EA creates the moving averages within itself it is never anywhere near the result of the indicator.
whroeder1
17092
whroeder1  
A moving average is an indicator. You just said EA trades with moving averages. Therefor "it is possible to write an EA that recognizes ... of an indicator." Your words.
Just get the value(s) of the indicator(s) into the EA and do what you want with it.
You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
Sergey Golubev
Moderator
101608
Sergey Golubev  

Ea is not trading "the chart". Ea is trading the data/quotes.
besides, what you see on the chart (arrow on open bar which may be disappeared) and what EA is trading (arrow on previous bar which can not be disappeared) - are two different "stories" in some cases.

So, it is better to understand some programming logic (to understand how EA shoud work).

or to improve your EA

Charles Stangor
251
Charles Stangor  

Something like this might get you started (mql5):


 void OnTick()
  {
  
  static datetime LastBar = 0;
  datetime ThisBar = (datetime)SeriesInfoInteger(_Symbol,PERIOD_CURRENT,SERIES_LASTBAR_DATE);
  int NumBars = SeriesInfoInteger(_Symbol,PERIOD_CURRENT,SERIES_BARS_COUNT);
 
     //if(LastBar != ThisBar)
     //   {
         LastBar = ThisBar;
         //Print("NB " + NumBars);
        
         double  indicator_1[], indicator_2[]; 
         int buy_ = CopyBuffer(indicator_handle,0,0,NumBars,indicator_1);
         ArraySetAsSeries(indicator_1,true);
         //Print(TimeToString(ThisBar + " " + buy_ + " " + indicator_1[NumBars-1]));
         //Print (ThisBar + " " + "buy_ " + buy_ + " " + NumBars + " " + indicator_1[0]);
         //Print (ThisBar + " -1 " + "buy_ " + buy_ + " " + NumBars + " " + indicator_1[1]);
         
         int sell_ = CopyBuffer(indicator_handle,1,0,NumBars,indicator_2);
         ArraySetAsSeries(indicator_2,true);
         //Print (ThisBar + " " + "sell_ " + sell_ + " " + NumBars + " " + indicator_2[0]);
         //Print (ThisBar+ " -1 " + "sell_ " + sell_ + " " + NumBars + " " + indicator_2[1]);
         
      if((double)indicator_1[0] >1 ) 
         {
         Print (ThisBar + " " + "buy: " + indicator_1[0]);
         //place_order("BUY 1 - MKT 10000 10000", "", true);
         }

      if((double)indicator_2[0] >1 ) 
         {
         Print (ThisBar + " " + "sell: " + indicator_2[0]);
         //place_order("SELL 1 - MKT 10000 10000", "", true);
         }
      //}
   } 
 
To add comments, please log in or register