Engulfing indicator

 

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

Thanks.

 
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...
 
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.
 

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
 

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.
 

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?

 
  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.)
 
Thanks
 
Reason: