Download MetaTrader 5

Is there an EA based on a buffer value(s) of an indicator?

To add comments, please log in or register
Have you found a good programmer? Make a targeted order!
Neal_Van
327
Neal_Van 2016.05.10 03:37 

that I could see as an example?

So far all I've seen is EA's that have conditions written into the EA but not actually done by calling the buffer of an indicator... 

Neal_Van
327
Neal_Van 2016.05.10 23:39  

Are experienced programmers getting what I'm saying?  I've noticed that the code in an EA seems to be a recreation of an indicator --- for example a call to iMA with the parameters of the indicator but not a direct call from say iCustom..  Can I create an EA with reference to iCustom to reference a specific buffer rather than recreating the indicator within the EA? and if this is possible is there an existing EA I can look at... 

 Thank you kindly, Sincerely Neal 

Marco vd Heijden
Moderator
4685
Marco vd Heijden 2016.05.10 23:40  
Yes by using iCustom() you can call the indicator to read it's buffers.
Neal_Van
327
Neal_Van 2016.05.10 23:46  
Marco vd Heijden:
Yes by using iCustom() you can call the indicator to read it's buffers.

Hi, Thank you for response...

Is there an example in code of an EA that you know of?  I've looked through the codebase and can't find any...  

Marco vd Heijden
Moderator
4685
Marco vd Heijden 2016.05.11 00:02  
Neal_Van:

Hi, Thank you for response...

Is there an example in code of an EA that you know of?  I've looked through the codebase and can't find any...  

yes here

https://www.mql5.com/en/forum/80885/page2#comment_2436424

notification from (mt4 Pc) to (android mt4 )
notification from (mt4 Pc) to (android mt4 )
  • reviews: 1
  • www.mql5.com
i configure mt4 PC to send notification to my (mt4 android), but does not work.
Neal_Van
327
Neal_Van 2016.05.11 00:04  
Specifically the aim is to make the stop loss to equal a buffer value of a specific indicator by using iCustom in an EA which if it works will also have to be converted to pips...   
Neal_Van
327
Neal_Van 2016.05.11 00:05  

Thank you Marco! I'll have a look... 

Marco vd Heijden
Moderator
4685
Marco vd Heijden 2016.05.11 00:09  

It depends on the output of the indicator so you have to analyze that first.

Usually it is a price level.

Neal_Van
327
Neal_Van 2016.05.11 01:11  
Marco vd Heijden:

It depends on the output of the indicator so you have to analyze that first.

Usually it is a price level.

I looked this code over and it appears to be an indicator? I want to use iCustom as an expert / automated trade to modify the order / stop loss.....  I appreciate your help but I don't think this will work with as an expert?
Doerk Hilger
1154
Doerk Hilger 2016.05.11 01:25  
I guess you are looking for an EA which translates indicator values to tradeable signals, right? Which indicators to you want to use, maybe I can help.
Neal_Van
327
Neal_Van 2016.05.11 02:20  
Doerk Hilger:
I guess you are looking for an EA which translates indicator values to tradeable signals, right? Which indicators to you want to use, maybe I can help.

For the sake of example a stop loss based on a manually entered trade of a moving average would suffice.  For example,  if I'm long I want the stop loss to move with the MA as long as price stayed above it and the opposite for a short--- stay short until the price goes above the moving average..  basically a stop loss based upon the moving average of each new buffer value of the moving average.  

This indicator could be used as the example.  

//+------------------------------------------------------------------+
//|                                                         TEMA.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2010, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Triple Exponential Moving Average"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  DarkBlue
#property indicator_width1  1
#property indicator_label1  "TEMA"
#property indicator_applied_price PRICE_CLOSE
//--- input parameters
input int                InpPeriodEMA=14;               // EMA period
input int                InpShift=0;                    // Indicator's shift
//--- indicator buffers
double                  TemaBuffer[];
double                  Ema[];
double                  EmaOfEma[];
double                  EmaOfEmaOfEma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,TemaBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,Ema,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,EmaOfEma,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,EmaOfEmaOfEma,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,3*InpPeriodEMA-3);
//--- sets indicator shift
   PlotIndexSetInteger(0,PLOT_SHIFT,InpShift);
//--- name for indicator label
   IndicatorSetString(INDICATOR_SHORTNAME,"TEMA("+string(InpPeriodEMA)+")");
//--- name for index label
   PlotIndexSetString(0,PLOT_LABEL,"TEMA("+string(InpPeriodEMA)+")");
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Triple Exponential Moving Average                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//--- check for data
   if(rates_total<3*InpPeriodEMA-3)
      return(0);
//---
   int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
//--- calculate EMA
   ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpPeriodEMA,price,Ema);
//--- calculate EMA on EMA array
   ExponentialMAOnBuffer(rates_total,prev_calculated,InpPeriodEMA-1,InpPeriodEMA,Ema,EmaOfEma);
//--- calculate EMA on EMA array on EMA array
   ExponentialMAOnBuffer(rates_total,prev_calculated,2*InpPeriodEMA-2,InpPeriodEMA,EmaOfEma,EmaOfEmaOfEma);
//--- calculate TEMA
   for(int i=limit;i<rates_total && !IsStopped();i++)
      TemaBuffer[i]=3*Ema[i]-3*EmaOfEma[i]+EmaOfEmaOfEma[i];
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
12
To add comments, please log in or register