Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Multiple Ribbon Demo
Author/Uploader: Jorgen Wallgren - jorgen.wallgren [at] gmail.com
Date/Time added: 2009-03-17 22:46:37
Origin: Inspired by Dennis Brown's great looking chart!
Keywords: Ribbon
Level: medium
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

I was inspired by Dennis Brown\'s great looking chart, and here is one of the results:
This demo code comes with a ready to use Multiple Ribbon code and a FillColor Function which will return the different shades of the color according to your specifications. You plot a Ribbon by calling the function as follows: MultiRibbon(\"Color\", \"Ribbon Number\", \"Name To Display\");
The \"Ribbon Number\" is simply the order of the ribbon, starting with 1 as the bottom Ribbon. You can add as many
ribbons as you want, until you run out of chart space. Just keep track of the \'Serial Number\' (Ribbon Number). :-)

Formula:

_SECTION_BEGIN("Multiple Ribbon Demo");
// I was inspired by Dennis Brown's great looking chart, and here is one of the
results:
// This demo code comes with a ready to use Multiple Ribbon code and a
FillColor Function which will return the different 
// shades of the color according to your specifications.
// You plot a Ribbon by calling the function as follows: MultiRibbon("Color",
"Ribbon Number", "Name To Display");
// The "Ribbon Number" is simply the order of the ribbon, starting with 1 as
the bottom Ribbon. You can add as many 
// ribbons as you want, until you run out of chart space. Just keep track of
the 'Serial Number' (Ribbon Number). :-)
RibbonThickness	= Param("Ribbon Thickness", 1, 1, 5, 0.1);
Font				= ParamList("Font:","Arial|Calibri|Futura|Tahoma|Times New Roman");

function GfxConvertBarToPixelX(Bar) 
{ 
 lvb = Status("lastvisiblebar"); fvb = Status("firstvisiblebar"); 
 pxchartleft = Status("pxchartleft"); pxchartwidth = Status("pxchartwidth"); 
 return pxchartleft + Bar  * pxchartwidth / (Lvb - fvb + 1); 
} 

procedure MultiRibbon(RibbonColor, Position, Label)
{
 LineColor	= colorLightGrey;
 Position	= RibbonThickness * Position;
 x2 = Status("pxchartright");
 y2 = Status("pxchartbottom");

 RibbonColor =
IIf(GfxConvertBarToPixelX(BarIndex()-Status("firstvisiblebarindex")) > y2/1.5 *
(RibbonThickness/100) * 18 , RibbonColor, colorYellow);

 Plot(0, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", LineColor, styleOwnScale | styleNoLabel, 0, 100);
 Plot(Position, "", RibbonColor, styleArea | styleOwnScale | styleNoLabel, 0,
100);

 GfxSetTextColor(colorBlack); 
 GfxSelectFont(Font, y2/1.5 * (RibbonThickness/100), 400); 
 GfxDrawText(Label, 8, y2 * 1.001 -(y2 * Position/100) , y2/1.5 *
(RibbonThickness/100) * 17, y2, 2 + 32 + 256);
 
}

//=================================================================================================
// EXAMPLES OF DIFFERENT CALCULATIONS WITH THE RESULTING COLORS AND CALL TO
PLOT MULTI-RIBBON CODE:
// METHOD: Once you have a indicator result you want in a ribbon, just call it
by 
// MultiRibbon("Color Calculation", " Serial Number of the ribbon", "The text
label");
// You can call as many ribbons you want, until you run our of chart space.
Just keep track of the
// Serial Number. :-)
//=================================================================================================
Plot( Close, "Price", colorBlack, styleCandle );

// FUNCTION WHICH CALCULATES AND RETURN THE DIFFERENT SHADES OF GREEN AND RED
COLORS:
function FillColor(Value, MaxPosVal, MinPosVal, MaxNegVal, MinNegVal)
{
 UpRed		= 0;
 UpGreen	= 255;
 UpBlue		= 0;
 DnRed		= 255;
 DnGreen	= 0;
 DnBlue		= 0;
 DarkColor	= 0;
 LightColor	= 230;

 Upred = IIf(Value > 0, LightColor - int((LightColor
-(((MaxPosVal-Value)*(LightColor-DarkColor))/(MaxPosVal-MinPosVal)))), IIf(Value
== 0, 255, 0));
 UpBlue = UpRed;
 DnGreen = IIf(Value <= 0, LightColor - int((LightColor
-(((abs(MaxNegVal)-abs(Value))*(LightColor-DarkColor))/(abs(MaxNegVal)-abs(MinNegVal))))),
IIf(Value == 0, 255, 0));
 DnBlue = DnGreen;
 Color	= IIf(Value >= 0, ColorRGB(UpRed, UpGreen, UpBlue), ColorRGB(DnRed,
DnGreen, DnBlue));
return Color;
}

//==========================================================================================================
// ADX CALCULATIONS:
//==========================================================================================================
// Check if +DI and -DI Crosses:
Range 			= 10;
Buy 			= Cross(PDI(Range), MDI(Range));
Sell			= Cross(MDI(Range), PDI(Range));
StatusCross	= Flip(Buy, Sell); 
Buy				= IIf(Zig(ADX(Range), 1) > Ref(Zig(ADX(Range), 1), -1) AND PDI(Range) >
MDI(Range), 1, 0);
Sell			= IIf(Zig(ADX(Range), 1) > Ref(Zig(ADX(Range), 1), -1) AND PDI(Range) <
MDI(Range), 1, 0);
// Check the difference between +DI and -DI and plot the strength of the colors
accordingly:
Value 			= PDI(Range)- MDI(Range);
MaxValue 		= HHV(Value, Status("lastvisiblebar") - Status("firstvisiblebar"));
MinValue 		= LLV(Value, Status("lastvisiblebar") - Status("firstvisiblebar"));
Color 			= IIf(Value >= 0, FillColor(Value, MaxValue, 0, MinValue, 0),
FillColor(Value, MaxValue, 0, MinValue, 0));
MultiRibbon(IIf(StatusCross, Color	, Color), 1, "ADX: (+DI) - (-DI)");
// Check the ADX value and plot the color strength accordingly:
Value 			= ADX(Range);
MaxValue 		= HHV(Value, Status("lastvisiblebar") - Status("firstvisiblebar"));
MinValue 		= LLV(Value, Status("lastvisiblebar") - Status("firstvisiblebar"));
Color 			= IIf(Buy, FillColor(Value, MaxValue, MinValue, 0, 0), IIf(Sell,
FillColor(-Value, 0, 0, -MaxValue, -MinValue), colorYellow));
MultiRibbon(Color, 2, "ADX Trend");
//==========================================================================================================
// PREMIER STOCHASTIC OSCILLATOR WITH "AWESOME INDICATOR" COLORING
CALCULATIONS:
//==========================================================================================================
StochLen		= 8; //Param("Stoch Len", 8, 3, 30 ); 
Period 		= 25; //Param("Smooth Period", 25, 5, 100 ); 
SK 				= StochK( StochLen, 1 ); 
Len 			= sqrt( Period ); 
NormStochK		= 0.1 * ( SK - 50 ); 
SmoothStoch	= EMA( EMA( NormStochK, Len ), Len ); 
expSS 			= exp( SmoothStoch ); 
Premier 		= ( expSS - 1 )/( expSS + 1 ); 
// Borrowed this from the Awesome Indicator:
SlowMA			= MA( Avg ,34);
FastMA			= MA( Avg,5);
// Modify the value, so we can calculate the colors using the standard
function:
Value			= Premier + 1;
MaxValue		= 2;
MinValue		= 0;
Color			= IIf((SlowMA - FastMA) <= Ref(SlowMA - FastMA, -1), FillColor(Value,
MaxValue, MinValue, 0, 0), FillColor(-Value, 0,0, -MinValue, -MaxValue));
MultiRibbon(Color, 3, "Premier Stochastic Osc."); 
//==========================================================================================================
// JUST ADDING 2 COLRED RIBBONS AS DEMO.
//==========================================================================================================
MultiRibbon(colorRed, 4, "Red Color"); 
MultiRibbon(colorBrightGreen, 5, "Green Color"); 
//=================================================================================================
// END EXAMPLES
//=================================================================================================

_SECTION_END();

Comments:

Thomas Ludwig

2009-03-25 14:44:04
Very nice coding, indeed! Thanks a lot, Jorgen.
Jaezrod

2009-03-26 16:45:53
Nice Work, very usefull Thanks a lot.
Jorgen Wallgren
jorgen.wallgren [at] gmail.com
2009-03-27 05:54:17
Thank you Thomas and Jaezrod!!! I highly appreciate your feedback!!! :-)


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM