Coding help - page 758

 
anees:

but I have seen many people have posted codes here which I'm sure not all of them were written by them.

In fact, the the code I attached above is also available on your thread https://www.mql5.com/en/forum/180648/page623, Comment # 9337

can you please help me? thank you.

And you fail to see this post too : https://www.mql5.com/en/forum/180648/page623 ? Please, get serious ...


I am not telling that the code posted by other users is coded by them (in fact, most of it is not)

What I am telling is that I (as in me, "mladen") am  not going to touch stolen (decompiled) code - and you shall see many, many posts (like the one you "did not see") where I told that. So, unless you can post the original code, I am not going to do anything with such a code. Like it or not, that is what is ... all the best

 
Dear Mladen, how to use iMA or iCustomMa functions with an extended price,
as e.g. pr_haclose?  The simplest solutions
iMA(NULL,0,avgPeriod,0,avgType,pr_haclose,i);

iCustomMa(avgType,iMA(NULL,0,1,0,MODE_SMA,pr_haclose,i),avgPeriod,i,0);
return warnings.
 
wojtekpaul:
Dear Mladen, how to use iMA or iCustomMa functions with an extended price,
as e.g. pr_haclose?  The simplest solutions
iMA(NULL,0,avgPeriod,0,avgType,pr_haclose,i);

iCustomMa(avgType,iMA(NULL,0,1,0,MODE_SMA,pr_haclose,i),avgPeriod,i,0);
return warnings.
You need to use custom get price (instead of using the iMA() to retrieve the price). In some of the latest versions you can get the getPrice() function, but in any case it looks like this :
enum enPrices
{
   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low
   pr_median,     // Median
   pr_typical,    // Typical
   pr_weighted,   // Weighted
   pr_average,    // Average (high+low+open+close)/4
   pr_medianb,    // Average median body (open+close)/2
   pr_tbiased,    // Trend biased price
   pr_tbiased2,   // Trend biased (extreme) price
   pr_haclose,    // Heiken ashi close
   pr_haopen ,    // Heiken ashi open
   pr_hahigh,     // Heiken ashi high
   pr_halow,      // Heiken ashi low
   pr_hamedian,   // Heiken ashi median
   pr_hatypical,  // Heiken ashi typical
   pr_haweighted, // Heiken ashi weighted
   pr_haaverage,  // Heiken ashi average
   pr_hamedianb,  // Heiken ashi median body
   pr_hatbiased,  // Heiken ashi trend biased price
   pr_hatbiased2  // Heiken ashi trend biased (extreme) price
};

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
//

#define priceInstances 1
double workHa[][priceInstances*4];
double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int instanceNo=0)
{
  if (tprice>=pr_haclose)
   {
      if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); instanceNo*=4;
         int r = Bars-i-1;
        
         //
         //
         //
         //
         //
        
         double haOpen;
         if (r>0)
                haOpen  = (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0;
         else   haOpen  = (open[i]+close[i])/2;
         double haClose = (open[i] + high[i] + low[i] + close[i]) / 4.0;
         double haHigh  = MathMax(high[i], MathMax(haOpen,haClose));
         double haLow   = MathMin(low[i] , MathMin(haOpen,haClose));

         if(haOpen  <haClose) { workHa[r][instanceNo+0] = haLow;  workHa[r][instanceNo+1] = haHigh; }
         else                 { workHa[r][instanceNo+0] = haHigh; workHa[r][instanceNo+1] = haLow;  }
                                workHa[r][instanceNo+2] = haOpen;
                                workHa[r][instanceNo+3] = haClose;
         //
         //
         //
         //
         //
        
         switch (tprice)
         {
            case pr_haclose:     return(haClose);
            case pr_haopen:      return(haOpen);
            case pr_hahigh:      return(haHigh);
            case pr_halow:       return(haLow);
            case pr_hamedian:    return((haHigh+haLow)/2.0);
            case pr_hamedianb:   return((haOpen+haClose)/2.0);
            case pr_hatypical:   return((haHigh+haLow+haClose)/3.0);
            case pr_haweighted:  return((haHigh+haLow+haClose+haClose)/4.0);
            case pr_haaverage:   return((haHigh+haLow+haClose+haOpen)/4.0);
            case pr_hatbiased:
               if (haClose>haOpen)
                     return((haHigh+haClose)/2.0);
               else  return((haLow+haClose)/2.0);        
            case pr_hatbiased2:
               if (haClose>haOpen)  return(haHigh);
               if (haClose<haOpen)  return(haLow);
                                    return(haClose);        
         }
   }
  
   //
   //
   //
   //
   //
  
   switch (tprice)
   {
      case pr_close:     return(close[i]);
      case pr_open:      return(open[i]);
      case pr_high:      return(high[i]);
      case pr_low:       return(low[i]);
      case pr_median:    return((high[i]+low[i])/2.0);
      case pr_medianb:   return((open[i]+close[i])/2.0);
      case pr_typical:   return((high[i]+low[i]+close[i])/3.0);
      case pr_weighted:  return((high[i]+low[i]+close[i]+close[i])/4.0);
      case pr_average:   return((high[i]+low[i]+close[i]+open[i])/4.0);
      case pr_tbiased:  
               if (close[i]>open[i])
                     return((high[i]+close[i])/2.0);
               else  return((low[i]+close[i])/2.0);        
      case pr_tbiased2:  
               if (close[i]>open[i]) return(high[i]);
               if (close[i]<open[i]) return(low[i]);
                                     return(close[i]);        
   }
   return(0);
}  
 

Hi there Mladen,

Could you add buffers for every different color?

Thanks! 

 
mladen:

You need to use custom get price (instead of using the iMA() to retrieve the price). In some of the latest versions you can get the getPrice() function

so, tha formula
iCustomMa(avgType,getPrice(pr_haclose,pr_open,pr_close,pr_high,pr_low,i),avgPeriod,i,0);
would be correct?
 
wojtekpaul:
so, tha formula
iCustomMa(avgType,getPrice(pr_haclose,pr_open,pr_close,pr_high,pr_low,i),avgPeriod,i,0);
would be correct?
No

Like this :

iCustomMa(avgType,getPrice(pr_haclose,Open,Close,High,Low,i),avgPeriod,i,0);
 
mladen:
Like this :

...Open,Close,High,Low,...

Those four quantities refer to 

   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low

?
 
wojtekpaul:

Those four quantities refer to 

   pr_close,      // Close
   pr_open,       // Open
   pr_high,       // High
   pr_low,        // Low

?
No. If you take a look at the function , the 4 parameters are referring to 4 arrays containing open, close, high and low values. You are trying to use constant integer values instead of arrays that are expected in the function. Please use it as posted and then it will work
 

OK, thank you so much for your help!  :)

(what we will do after 31st January?) :(

 
Dear Mladen,

Can you plz code this for mt4 indicator .... its in Amibroker AFL coding ... Thanks  alot



_SECTION_BEGIN("Market Trend");
SetChartOptions(0,chartShowArrows|chartShowDates);

function predictCycle( arg1, arg2 )
{
  local var1, var2;

  result = arg1 + arg2;

  return result;
}

Predict=0;
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Predict = PredictCycle(C,Periods);

Buy = Predict>Ref(Predict,-1);
Sell = Predict<Ref(Predict,-1);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Plot(Predict,"Predict",colorWhite,styleLine | styleThick);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-5);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-5);

 _SECTION_END(); 
Reason: