Heiken Ashi Smoothed without using iCustom - page 2

 
whroeder1:
Why? Just get the value of the indicator 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
Something likeBecause the D1 has lots of ticks. Don't do per tick what you can do per bar or per order.

The reason I would like to avoid using the indicator is that I am a seller here on MQL5 and you are not allowed to add additional files to your products. That is why I would like to build in the logic into the EA. I am on a good way (using SetArraysAsSeries etc.) but for some reasons the signal is sometimes not in sync with the indicator (Heiken_Ashi_Smoothed.ex4). On a new bar I am doing this (arraysize it set to 500):

int smoothed(int shift)
  {
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haHigh, haLow, haClose;
   int pos2=arraysize-2;
   for(int pos=arraysize-2; pos>=0; pos--)
     {
      maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,pos);
      maClose=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,pos);
      maLow=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,pos);
      maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,pos);

      //Print(ArraySize(ExtMapBuffer5));
      //Print(Bars);
      haOpen=(ExtMapBuffer5[pos+1]+ExtMapBuffer6[pos+1])/2;
      haClose=(maOpen+maHigh+maLow+maClose)/4;
      haHigh=MathMax(maHigh, MathMax(haOpen, haClose));
      haLow=MathMin(maLow, MathMin(haOpen, haClose));

      if (haOpen<haClose) 
        {
         ExtMapBuffer7[pos]=haLow;
         ExtMapBuffer8[pos]=haHigh;
        } 
      else
        {
         ExtMapBuffer7[pos]=haHigh;
         ExtMapBuffer8[pos]=haLow;
        } 
      ExtMapBuffer5[pos]=haOpen;
      ExtMapBuffer6[pos]=haClose;
     }

   int i;
   for(i=0; i<pos2; i++) ExtMapBuffer1[i]=iMAOnArray(ExtMapBuffer7,0,MaPeriod2,0,MaMetod2,i);
   for(i=0; i<pos2; i++) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer8,0,MaPeriod2,0,MaMetod2,i);

   return(Crossed(ExtMapBuffer1[shift],ExtMapBuffer2[shift]));
  }
  
int Crossed(double haOpen, double haClose)
{

static int last_direction = -1;
int current_direction = -1;

if(haOpen<=haClose) current_direction=OP_BUY;
if(haOpen>haClose) current_direction=OP_SELL;

if(current_direction != last_direction) 
{
   last_direction = current_direction;
   return(current_direction);
}
  
return(-1);
}
 
Jan Flodin: The reason I would like to avoid using the indicator is that I am a seller here on MQL5 and you are not allowed to add additional files to your products.
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. You can't have additional files, just embed the other indicator(s) inside your compiled indicator. Add the CI(s) to your code as a resource.
              Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum
 
whroeder1:
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. You can't have additional files, just embed the other indicator(s) inside your compiled indicator. Add the CI(s) to your code as a resource.
              Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum

Thanks a lot. Everything is clear now. I have also edited my previous post.

 
Jan Flodin:

Sorry, I was only asking because there was no real confirmation that any or both of the solutions were working. I am also not sure if Marco's suggestion using the PRICE_MEDIAN option was an answer to that the backtesting was slow or if it was posted as a total solution. 

Confirmation? :)

Who exactly should confirm? A teacher?


Without joking : when it comes to coding there is one and only one "expert" that confirms all the code - the computer. Either the code works as it is supposed to work or it does not work. No talking or fancy blabbing or getting angry type of "persuading" works for code. The ultimate "judge" does not know how to lie, does not know how to make false statements - so simply take the code, paste it in your code editor compile, and if it works you have the confirmation. That is all