Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Candlesticks, Condensed for Amibroker (AFL)
SPASHA
almost 10 years ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 3)
Tags:
amibroker, exploration

Candlesticks, Condensed

Indicator / Formula

Copy & Paste Friendly
//Candlesticks, Condensed

// original written by pasha dave re written by dave in stocks and commodities

SegmentCount = 5; 
SegmentDivisor = 100 / SegmentCount; 
CandleRange = High - Low; 
AvgRange = MA( CandleRange, 6 ); 
RangeMultiplier = CandleRange / AvgRange; 
CandleRange /= 100; 

RangeMultiplier = Min( RangeMultiplier, 1 ); 

HO = round( ( RangeMultiplier * ( High - Open ) / CandleRange ) / SegmentDivisor ); 
HC = round( ( RangeMultiplier * ( High - Close ) / CandleRange ) / SegmentDivisor ); 
OL = round( ( RangeMultiplier * ( Open - Low ) / CandleRange ) / SegmentDivisor ); 

DigitMult = SegmentCount + 1; 

// signature is encoded to fit into integer 
CandleSignature = DigitMult * DigitMult * HO + DigitMult * HC + OL; 

Title = Name() + " " + Date() + " " + StrFormat( "Signature %.0f:%.0f:%.0f", HO, HC, OL ); 
Plot( C, "Close", colorDefault, styleCandle ); 

Filter = False; 

// statistics 
Pct1P = Pct2P = Pct3P = Pct4P = 0; 
Avg1P = Avg2P = Avg3P = Avg4P = 0; 

// count of occurrence of patterns 
Cnt = 0; 

MaxSegment = SegmentCount * DigitMult * DigitMult + SegmentCount * DigitMult + SegmentCount; 

if( BarCount > MaxSegment ) 
{ 
   // changes over 1..4 periods 
   // you can change it to Close - Ref( Close, -1 ) 
   // to get dollar gains instead of percent changes 
    
   Chg1P = ROC( Close, 1 ); 
   Chg2P = ROC( Close, 2 ); 
   Chg3P = ROC( Close, 3 ); 
   Chg4P = ROC( Close, 4 ); 

   // number of times given pattern is followed by UP movement 
   Up1P = Up2P = Up3P = Up4P = 0; 
   // gain 
   Gain1P = Gain2P = Gain3P = Gain4P = 0; 

   for( i = 0; i < BarCount - 4; i++ ) 
   { 
       sig = CandleSignature[ i ]; 
       
       if( sig >= 0 && sig <= MaxSegment ) 
       { 
         Cnt[ sig ]++; // increase occurrence counter for given sig 

         // if change > 0 increase UP counter 
	   Up1P[ sig ] += Chg1P[ i + 1 ] > 0;         
	   // add change to total gain 
         Gain1P[ sig ] += Chg1P[ i + 1 ]; 
          
         Up2P[ sig ] += Chg1P[ i + 2 ] > 0;
         Gain2P[ sig ] += Chg1P[ i + 2 ]; 

         Up3P[ sig ] += Chg1P[ i + 3 ] > 0;
         Gain3P[ sig ] += Chg1P[ i + 3 ];
         Up4P[ sig ] += Chg4P[ i + 1 ] > 0;
         Gain4P[ sig ] += Chg4P[ i + 1 ]; 
      } 
    } 
    

    for( sig = 0; sig <= MaxSegment; sig++ ) 
    { 
       // if any patterns of given signature were found 
      if( Cnt[ sig ] ) 
      { 
          qty = Cnt[ sig ]; 
          Pct1P[ sig ] = Up1P[ sig ] / qty; 
          Pct2P[ sig ] = Up2P[ sig ] / qty; 
          Pct3P[ sig ] = Up3P[ sig ] / qty; 
          Pct4P[ sig ] = Up4P[ sig ] / qty; 
          
          Avg1P[ sig ] = Gain1P[ sig ] / qty; 
          Avg2P[ sig ] = Gain2P[ sig ] / qty; 
          Avg3P[ sig ] = Gain3P[ sig ] / qty; 
          Avg4P[ sig ] = Gain4P[ sig ] / qty; 
       } 
    } 
    
    Filter = Cnt; 
} 
else 
{ 
    PopupWindow("Not enough bars in " + Name() + " Please select symbols that have more than " + 
                MaxSegment + " bars", "Problem" ); 
} 

// multiply factors by 100 to get percents 
Pct1P *= 100; 
Pct2P *= 100; 
Pct3P *= 100; 
Pct4P *= 100; 
    
bi = BarIndex(); 
Sig1 = bi % DigitMult; 
Sig2 = floor( bi / DigitMult ) % DigitMult; 
Sig3 = floor( bi / ( DigitMult * DigitMult ) ); 
    
Signature = 100 * Sig3 + 10 * Sig2 + Sig1; 
    
SetOption("NoDefaultColumns", True ); 
AddTextColumn( Name(), "Symbol" ); 
AddColumn( Signature, "Signature", 3.0 ); 
AddColumn( Cnt, "Count", 1.0 ); 
AddColumn( Pct1P, "Pct1P%", 1.1 ); 
AddColumn( Pct2P, "Pct2P%", 1.1 ); 
AddColumn( Pct3P, "Pct3P%", 1.1 ); 
AddColumn( Pct4P, "Pct4P%", 1.1 ); 
AddColumn( Avg1P, "Avg1P%", 1.1 ); 
AddColumn( Avg2P, "Avg2P%", 1.1 ); 
AddColumn( Avg3P, "Avg3P%", 1.1 ); 
AddColumn( Avg4P, "Avg4P%", 1.1 ); 


3 comments

1. val2004

hi,can you describe your indicator please with a pict even better

tks

2. davidalan

needs a semicolon end line 69

3. administrator

Thanks davidalan

Leave Comment

Please login here to leave a comment.

Back