Download MetaTrader 5

Engulfing indicator

To add comments, please log in or register
creskita
59
creskita 2017.03.19 15:55 

Can anyone help with an engulfing indicator? I have one but it isn't indicating on all the candles for some reason.

Thanks.

Carl Schreiber
6670
Carl Schreiber 2017.03.19 16:29  
Sorry, but my crystal ball has a crack - can you describe (or screen shot) what have you done, what have you got and what have you expected - then may be...
whroeder1
14753
whroeder1 2017.03.19 16:38  
creskita: Can anyone help with an engulfing indicator?
You have only three choices: Search for it, learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
creskita
59
creskita 2017.03.19 21:40  

Of course I'm willing to provide more details on it and only expect help.

The initial question was just that, a question to see if there was anybody here who could do so.

This is the coding:


#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrBlue
#property indicator_color2 clrBlue 
#property indicator_width1 10
#property indicator_width2 10 

double BodyHigh[];  
double BodyLow[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


int OnInit()
  {
 
 
//--- indicator buffers mapping
  
  
SetIndexBuffer(0,BodyHigh);
SetIndexStyle(0,DRAW_HISTOGRAM);
  
SetIndexBuffer(1,BodyLow);
SetIndexStyle(1,DRAW_HISTOGRAM);
  
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
                
   for (int i=Bars-2-IndicatorCounted();i>=0;i--)

   {
  
   Print (i);
   double hi=high[i];
   double lo=low[i];
   double prevhi=high[i+1];
   double prevlo=low[i+1];
  
   double bodyhigh=MathMax (close[i],open[i]);
   double bodylow=MathMin (close[i],open[i]);
   if(hi>prevhi&&lo<prevlo)   
  
  
   {
   BodyHigh[i]=bodyhigh;
   BodyLow[i]=bodylow;
  
   }
  
  
   }
  

   return(rates_total);
  }
//+------------------------------------------------------------------+



For some reason there are many candles which do look like they would be engulfing, but aren't being indicated as such.

Thanks.

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
Carl Schreiber
6670
Carl Schreiber 2017.03.19 23:14  

Maybe this  helps you to find a solution?

I tell you there is practically nothing that does not exist for MT4/5. So searching for a couple on minutes saves you hours of coding in many times!

Price Action. Automating the Engulfing Pattern Trading Strategy
Price Action. Automating the Engulfing Pattern Trading Strategy
  • 2015.09.22
  • Dmitry Iglakov
  • www.mql5.com
This article describes a process of creating an Expert Advisor for MetaTrader 4 based on the Engulfing pattern, as well as the pattern recognition principle, rules of setting pending orders and stop orders. The results of testing and optimization are provided for your information.
Keith Watford
Moderator
9639
Keith Watford 2017.03.20 00:58  

Please use the SRC button when posting code. I have done it for you this time.


for (int i=Bars-2-IndicatorCounted();i>=0;i--)

if Bars=1000 and IndicatorCounted=999, your calculation for i will return

i=1000-2-999   

which is minus 1 which is not a valid bar index.

You print I, but as the loop is not executed, there is no print, so haven't you noticed this?

whroeder1
14753
whroeder1 2017.03.20 02:34  
creskita
59
creskita 2017.03.20 14:11  
  1. Don't "declare all variables as globals" That is bad programming.
  2. Arrays are ~10x slower than variables. Cache them in variables where possible.
       for(;;){
          T  next  = arr[--iNext];
          if(!(value < next))  break;
          arr[iEmpty] = next;
          iEmpty = iNext;
       }
  3. Don't do per tick what you can do once per bar. If you're waiting for price to reach a trigger, ignore all ticks until you reach it (or a new bar starts and you recalculate.)
creskita
59
creskita 2017.03.20 14:23  
creskita
59
creskita 2017.03.20 14:23  
To add comments, please log in or register