you can also 'just' use
iMA(Symbol(),PERIOD_CURRENT,4,bar,MODE_SMMA,PRICE_MEDIAN,0)
Instead of
int MaMetod=2; int MaPeriod = 24; int MaMetod2 = 3; int MaPeriod2= 2; double maOpen1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,1); double maClose1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,1); double maLow1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,1); double maHigh1=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,1); double maOpen2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,2); double maClose2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,2); double maLow2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,2); double maHigh2=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,2); double maOpen3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,3); double maClose3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,3); double maLow3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_LOW,3); double maHigh3=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_HIGH,3); double maOpen4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_OPEN,4); double maClose4=iMA(NULL,0,MaPeriod,0,MaMetod,PRICE_CLOSE,4); haOpen1 =(haOpen2+ haClose2)/2; haClose1=(maOpen1+maHigh1+maLow1+maClose1)/4; double haHigh1=MathMax(maHigh1,MathMax(haOpen1,haClose1)); double haLow1=MathMin(maLow1,MathMin(haOpen1,haClose1)); haOpen2 =(haOpen3+ haClose3)/2; haClose2=(maOpen2+maHigh2+maLow2+maClose2)/4; double haHigh2=MathMax(maHigh2,MathMax(haOpen2,haClose2)); double haLow2=MathMin(maLow2,MathMin(haOpen2,haClose2)); haOpen3 =(haOpen4 + haClose4)/2; haClose3=(maOpen3+maHigh3+maLow3+maClose3)/4; double haHigh3=MathMax(maHigh3,MathMax(haOpen3,haClose3)); double haLow3=MathMin(maLow3,MathMin(haOpen3,haClose3)); if((haOpen1>haClose1) && (haOpen2<haClose2)); // buy if((haOpen1>haClose1) && (haOpen2<haClose2)); //sell
Try like this :
The call :
double haHigh,haLow,haOpen,haClose;
calculateHA(MaPeriod,MaMethod,haOpen,haClose,haHigh,haLow,i);
hahu[i] = haHigh;
hahd[i] = haLow;
hahbu[i] = haOpen;
hahbd[i] = haClose;
The function :
#define _haInstances 1 #define _haInstancesSize 4 double workHa[][_haInstances*_haInstancesSize]; #define _haH 0 #define _haL 1 #define _haO 2 #define _haC 3 void calculateHA(int maPeriod, int maMethod, double& tOpen, double& tClose, double& tHigh, double& tLow, int i, int instanceNo=0) { if (ArrayRange(workHa,0)!= Bars) ArrayResize(workHa,Bars); int r=Bars-i-1; instanceNo*=_haInstancesSize; // // // // // double maOpen = iMA(NULL,0,maPeriod,0,maMethod,PRICE_OPEN ,i); double maClose = iMA(NULL,0,maPeriod,0,maMethod,PRICE_CLOSE,i); double maLow = iMA(NULL,0,maPeriod,0,maMethod,PRICE_LOW ,i); double maHigh = iMA(NULL,0,maPeriod,0,maMethod,PRICE_HIGH ,i); double haOpen = (r>0) ? (workHa[r-1][instanceNo+_haO] + workHa[r-1][instanceNo+_haC])/2.0 : maOpen; double haClose = (maOpen+maHigh+maLow+maClose)/4; double haHigh = MathMax(maHigh, MathMax(haOpen, haClose)); double haLow = MathMin(maLow, MathMin(haOpen, haClose)); if(haOpen<haClose) { workHa[r][instanceNo+_haH] = haLow; workHa[r][instanceNo+_haL] = haHigh; } else { workHa[r][instanceNo+_haH] = haHigh; workHa[r][instanceNo+_haL] = haLow; } workHa[r][instanceNo+_haO] = haOpen; workHa[r][instanceNo+_haC] = haClose; // // // // // tHigh = workHa[r][instanceNo+_haH]; tLow = workHa[r][instanceNo+_haL]; tOpen = workHa[r][instanceNo+_haO]; tClose = workHa[r][instanceNo+_haC]; }
you can also 'just' use
Instead of
Grand, that'd save my scrolling finger from fatigue.. Could you explain how that code would provide the result? I rather enjoy understanding how all these things work but that code doesn't translate into Heiken ashi smoothed to me..
Grand, that'd save my scrolling finger from fatigue.. Could you explain how that code would provide the result? I rather enjoy understanding how all these things work but that code doesn't translate into Heiken ashi smoothed to me..
Really?
Well maybe this does:
Hi,
I'm trying to use the heiken ashi without using the iCustom call, am I on the right lines with this:
it doesn't seem to work, yet I can't figure out from the Hieken Ashi Smoothed source code how haHigh and haLow are factored into the iCustom call... can anyone provide further guidance?
Hi,
were you able to solve this?
Jan
Hi,
were you able to solve this?
Jan
Two solutions already posted as response to his question
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.
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
Something like
//+------------------------------------------------------------------+ //| Heiken Ashi iCustom function | //+------------------------------------------------------------------+ enum HAbuffer{ HA_LOW_HIGH, HA_HIGH_LOW, HA_OPEN, HA_CLOSE, HA_BOTTOM, HA_TOP }; PRICE Heiken_Ashi(HAbuffer buf, INDEX iBar){ return Heiken_Ashi(_Symbol, ENUM_TIMEFRAMES(_Period), buf, iBar); } PRICE Heiken_Ashi(ENUM_TIMEFRAMES tf, HAbuffer buf, INDEX iBar){ return Heiken_Ashi(_Symbol, tf, buf, iBar); } PRICE Heiken_Ashi(SYMBOL sym, ENUM_TIMEFRAMES tf, HAbuffer buf, INDEX iBar){ #define HA "Heiken Ashi" if(buf < HA_BOTTOM) return iCustom(sym, tf, HA, // All four parameters are just colors buf, iBar); PRICE lh = iCustom(sym, tf, HA, HA_LOW_HIGH, iBar); PRICE hl = iCustom(sym, tf, HA, HA_HIGH_LOW, iBar); return HA_BOTTOM == buf ? MathMin(lh, hl) : MathMax(lh, hl); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm trying to use the heiken ashi without using the iCustom call, am I on the right lines with this:
it doesn't seem to work, yet I can't figure out from the Hieken Ashi Smoothed source code how haHigh and haLow are factored into the iCustom call... can anyone provide further guidance?