heiken ashi ea problem

 
hi, i'm making an expert advisor based on heiken ashi candle signals.
As an indicator I am using "Heiken_Ashi.mq5", found here in the code base section, you will find it attached.
While I am writing the ea.
The ea, for now, should go to buy or close sell positions when the last finished candle is green (open heiken ashi <close heiken ashi) and the reverse on a red candle (open heiken ashi> close heiken ashi).
The problem is that it doesn't do that. It happens that the ea goes to buy even with red candles and vice versa.
I have evaluated hypotheses:
1) the code, either of the ea or of the indicator are wrong;
2) the EA and the indicator use different data (I don't know how);
therefore it may happen that a red candle of the indicator corresponds to a green candle for the EA.

Could you help me understand the problem? Thank you
Files:
 

possibly, the inputs for the indicator mentioned in the EA  and the inputs of the indicator which you are using on the chart are different. 

Try to make same inputs in the EA and indicator to get consistant results.

 
Satyam Shivam #:

possibly, the inputs for the indicator mentioned in the EA  and the inputs of the indicator which you are using on the chart are different. 

Try to make same inputs in the EA and indicator to get consistant results.

how do i use the same input? Should I integrate the indicator into the expert advisor?
 

In the EA, you create exactly same inputs as you have un the indicator. 

This way the user will be able to change the inputs of the indicator from the EA itself. 

then, in your code for the eA, pass all the inputs of the EA, to the indicator through the iCustom function. 


And lastly, while testing when you attach the EA and the indicator on the chart, you must ensure that the inputs you have entered in the EA must be exactly same as the inputs you have entered in the indicator. 

 
Satyam Shivam #:

In the EA, you create exactly same inputs as you have un the indicator. 

This way the user will be able to change the inputs of the indicator from the EA itself. 

then, in your code for the eA, pass all the inputs of the EA, to the indicator through the iCustom function. 


And lastly, while testing when you attach the EA and the indicator on the chart, you must ensure that the inputs you have entered in the EA must be exactly same as the inputs you have entered in the indicator. 

thanks for reply!

forgive me but what exactly do you mean by "input"?

 

One option is to use the colour buffer of the indicator.

#resource "\\Indicators\\Examples\\Heiken_Ashi.ex5"
int handle=INVALID_HANDLE;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if((handle=iCustom(_Symbol,_Period,"::Indicators\\Examples\\Heiken_Ashi.ex5"))==INVALID_HANDLE)
      return(INIT_FAILED);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
enum ENUM_SIGNAL_TYPE
  {
   SIGNAL_NONE=0,
   SIGNAL_BUY=1,
   SIGNAL_SELL=-1
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
ENUM_SIGNAL_TYPE Signal()
  {
   double Buffer[];
   if(CopyBuffer(handle,4,0,2,Buffer)<=0)
      return(SIGNAL_NONE);
//---
   #define Green 0.0
   #define Red 1.0
//---
   if(Buffer[0]==Red && Buffer[1]==Green)
      return(SIGNAL_BUY);
//---
   if(Buffer[0]==Green && Buffer[1]==Red)
      return(SIGNAL_SELL);
//---
   #undef Green
   #undef Red
//---
   return(SIGNAL_NONE);    
  }     
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(handle);
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   datetime curTime=iTime(_Symbol,_Period,0);
   static datetime preTime=curTime;
   if(preTime==curTime)
      return;
//---
   if(Signal()==SIGNAL_BUY)
     {
      Print("Buy");
      preTime=curTime;
     }   
//---
  }
//+------------------------------------------------------------------+
Files:
 
Ernst Van Der Merwe #:

One option is to use the colour buffer of the indicator.

thanks for your interest.
this solution is fine for the current problem but solved this problem if there is another one:
I will need to know if the candles have a shadow, if it depends on the opening of a new order or the closing of an existing one.

I can still take your code as an example, thanks

 

ERR_INDICATOR_WRONG_HANDLE

4807

Wrong indicator handle

 
Vladimir Karputov #:

ERR_INDICATOR_WRONG_HANDLE

4807

Wrong indicator handle


what does it mean? can't I open a new thread?

 
Andrea Di #:

thanks for your interest.
this solution is fine for the current problem but solved this problem if there is another one:
I will need to know if the candles have a shadow, if it depends on the opening of a new order or the closing of an existing one.

I can still take your code as an example, thanks

Simply copy the other buffers' data as well.

ENUM_SIGNAL_TYPE Signal()
  {
   double Open[],High[],Low[],Close[],Color[];
//---
   if(CopyBuffer(handle,0,0,1,Open )<=0 ||
      CopyBuffer(handle,1,0,1,High )<=0 ||
      CopyBuffer(handle,2,0,1,Low  )<=0 ||
      CopyBuffer(handle,3,0,1,Close)<=0 ||
      CopyBuffer(handle,4,0,2,Color)<=0)
      return(SIGNAL_NONE);
//---
   #define Green 0.0
   #define Red 1.0
//---
   if(Color[0]==Red && Color[1]==Green && Low[0]<Open[0])
 
Ernst Van Der Merwe #:

Simply copy the other buffers' data as well.

I did, it worked fine before this morning, next I added sma indicators and now i get error 4807, "Wrong indicator handle" on all CopyBuffer() functions.

I attach the new versions of files.

Reason: