Advertisement
Maurizio-Ciullo

Heiken Ashi

Apr 2nd, 2022
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {*****************************************************************************
  2. Description : HeikinAshiSyn - This Paintbar is a Variation of the Heikin Ashi Candlestick to assist in reading the trend.
  3. ******************************************************************************}
  4.  
  5. inputs: UpColor(RGB(0,192,255)),  
  6.         DnColor(RGB(255,128,64)),  
  7.         HiLoColor(DarkGray),
  8.         CompBars(0),
  9.         SmoothHA(False),
  10.         SmoothAvgType(1 {1 JTHull, 2 SMA, 3 EMA, 4 wAverage} ),
  11.         SmoothLength(6),
  12.         ReverseColor(false);  
  13.  
  14. vars: haClose(0),haOpen(0),haHigh(0),haLow(0),
  15.         color(0), newHi(0), newLo(0),
  16.         iOpen(0), iClose(0), iHi(0), iLo(0)  
  17. ;
  18.  if SmoothHA = False then begin;
  19.     iOpen = Open;
  20.     iClose = Close;
  21.     iHi = High;
  22.     iLo = Low;
  23.  end else begin;
  24.     if SmoothAvgType = 1 then begin;
  25.         iOpen = jthma(Open, SmoothLength);
  26.         iClose = jthma(Close, SmoothLength);
  27.         iHi = jthma(High, SmoothLength);
  28.         iLo = jthma(Low, SmoothLength);
  29.     end;   
  30.     if SmoothAvgType = 2 then begin;
  31.         iOpen = average(Open, SmoothLength);
  32.         iClose = average(Close, SmoothLength);
  33.         iHi = average(High, SmoothLength);
  34.         iLo = average(Low, SmoothLength);
  35.     end;   
  36.     if SmoothAvgType = 3 then begin;
  37.         iOpen = xAverage(Open, SmoothLength);
  38.         iClose = xAverage(Close, SmoothLength);
  39.         iHi = xAverage(High, SmoothLength);
  40.         iLo = xAverage(Low, SmoothLength);
  41.     end;   
  42.     if SmoothAvgType = 4 then begin;
  43.         iOpen = wAverage(Open, SmoothLength);
  44.         iClose = wAverage(Close, SmoothLength);
  45.         iHi = wAverage(High, SmoothLength);
  46.         iLo = wAverage(Low, SmoothLength);
  47.     end;   
  48.  end;  
  49.  
  50.  if BarNumber > 1 then begin
  51.     haClose = (iOpen+iHi+iLo+iClose)/4;
  52.     haOpen = (haOpen [1] + haClose [1])/2 ;
  53.     haHigh = MaxList(iHi, haOpen, haClose) ;
  54.     haLow = MinList(iLo, haOpen, haClose) ;
  55.      
  56.     if haClose > haOpen then
  57.         color = UpColor
  58.     else
  59.         color = DnColor;
  60.    
  61.     if CompBars > 0 then begin;
  62.         for value1 = 1 to CompBars begin
  63.             if haOpen <= MaxList(haOpen[value1],haClose[value1]) and
  64.                 haOpen >= MinList(haOpen[value1],haClose[value1]) and
  65.             haClose <= MaxList(haOpen[value1],haClose[value1]) and
  66.             haClose >= MinList(haOpen[value1],haClose[value1]) then
  67.                 color = color[value1];
  68.         end;
  69.     end;
  70.      
  71.     if ReverseColor then begin;
  72.         if color = UpColor then
  73.             color = DnColor
  74.         else
  75.             color = UpColor;
  76.     end;
  77.    
  78.     Plot1( haOpen,  "Open",  color ) ;    
  79.     Plot2( haClose, "Close", color ) ;    
  80.     Plot3( haHigh,  "High",  HiLoColor ) ;    
  81.     Plot4( haLow,   "Low",   HiLoColor ) ;
  82.      
  83. end else begin;
  84.  
  85.     haOpen = iOpen;
  86.     haClose = (iOpen+iHi+iLo+iClose)/4;
  87.     haHigh = MaxList( iHi, haOpen, haClose);
  88.     haLow = MinList( iLo, haOpen,haClose);
  89.  
  90. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement