Re: [amibroker] Re: FILL COLOR BETWEEN TREND CHANNEL

2010-09-08 Thread reinsley
  I split the stuff in two parts.

Please merge part 1 and part 2.


Part 1 :


// pattern detector
// patterns intraday trading system Beta version - Conceived and 
developed by Vinod K. Iyer, Kodaikanal - Trade at your own Risk - 
Property of Vinod K. Iyer - Not for Free Circulation
// AB library
_SECTION_BEGIN( Price );
SetChartOptions( 0, chartShowArrows | chartShowDates | chartLogarithmic 
| chartWrapTitle );
_N( Title = StrFormat( {{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, 
Lo %g, Close %g (%.1f%%) {{VALUES}}, O, H, L, C, SelectedValue( ROC( C, 
1 ) ) ) );
Plot( C, Close, ParamColor( Color, colorWhite ), styleNoTitle | 
ParamStyle( Style ) | GetPriceStyle() );
_SECTION_END();
riskAmount = Param( Risk Amount, 25, 10, 1, 5 );
Limit = Param(  Trade Till (Hour)(Min)(Sec), 08, 08, 22, 
100 );
since = ( TimeNum() = 08 AND TimeNum() = Limit ) AND ( DateNum() 
== LastValue( DateNum() ) );

_SECTION_BEGIN( Alerts );
SRbS = ParamToggle( S/R broken, Off,On, 1 );
SRcS = ParamToggle( S/R confirmed, Off,On, 1 );
PjabS = ParamToggle( Price just above/below, Off,On, 1 );
_SECTION_END();

_SECTION_BEGIN( Main Parameters );
PlotP1P2 = ParamToggle( Plot P1/P2 Shapes, Off,On, 1 );
P1Shape = Param( P1 Shape Typ, 35, 0, 50, 1 );//default 35
P2Shape = Param( P2 Shape Typ, 37, 0, 50, 1 );//default 37
Parallellinesswitch = ParamToggle( Plot Parallel Lines, Off,On, 1 );
DisRange = Param( Plot Parallel Lines Trigger, 300, 0, 1000, 20 );

_SECTION_BEGIN( Styles );
Style_SL = ParamStyle( Support, styleLine + styleThick, maskDefault ) 
+ styleNoRescale;
Style_RL = ParamStyle( Resistance, styleLine + styleThick, maskDefault 
) + styleNoRescale;
Style_PHL = ParamStyle( Parallel Support, styleLine + styleDashed, 
maskDefault ) + styleNoRescale;
Style_PLL = ParamStyle( Parallel Resistance, styleLine + styleDashed, 
maskDefault ) + styleNoRescale;
_SECTION_END();

_SECTION_BEGIN( Colors );
Color_SL = ParamColor( Support, colorLime );
Color_RL = ParamColor( Resistance, colorRed );
Shadowcolor = ParamColor( Shadow, ColorRGB( 56, 63, 118 ) );

if ( Version()  4.75 )
{
 Backgroundcolor = ParamColor( Your Background, colorBlack );
}

Color_PLL = Color_RL; //ParamColor(Resistance,colorRed);

Color_PHL = Color_SL; //ParamColor(Support,colorLime);
_SECTION_END();

_SECTION_BEGIN( Pattern Selection );
AscTs = ParamToggle( Ascending Triangle, Off,On, 1 );
DscTs = ParamToggle( Descending Triangle, Off,On, 1 );
STs = ParamToggle( Symmetrically Triangle, Off,On, 1 );
ETs = ParamToggle( Expanding Triangle, Off,On, 1 );
RWs = ParamToggle( Rising Wedge, Off,On, 1 );
FWs = ParamToggle( Falling Wedge, Off,On, 1 );
UTs = ParamToggle( Up Trend, Off,On, 1 );
DTs = ParamToggle( Down Trend, Off,On, 1 );
Ranges = ParamToggle( Range, Off,On, 1 );
NonDefinedPatterns = ParamToggle( Not defined Patterns, Off,On, 1 );
_SECTION_END();
//Plot( OBV(), _DEFAULT_NAME(), ParamColor(Color, colorCycle ), 
styleDashed| styleOwnScale | styleThick | styleNoLabel  );


//calcs
HH = HHV( H, 20 );
LL = LLV( L, 20 );
Mid = LL + ( ( HH - LL ) / 2 );
Div = 100 - ( HH / ( 0.01 * Mid ) );
Per = LastValue( abs( Div ) );
Hp1 = Ref( H, -1 );
Hp2 = Ref( H, -2 );
Hp3 = Ref( H, -3 );
Hp4 = Ref( H, -4 );
Hp5 = Ref( H, -5 );
Hp6 = Ref( H, -6 );
Lp1 = Ref( L, -1 );
Lp2 = Ref( L, -2 );
Lp3 = Ref( L, -3 );
Lp4 = Ref( L, -4 );
Lp5 = Ref( L, -5 );
Lp6 = Ref( L, -6 );
Hf1 = Ref( H, 1 );
Hf2 = Ref( H, 2 );
Hf3 = Ref( H, 3 );
Hf4 = Ref( H, 4 );
Hf5 = Ref( H, 5 );
Hf6 = Ref( H, 6 );
Lf1 = Ref( L, 1 );
Lf2 = Ref( L, 2 );
Lf3 = Ref( L, 3 );
Lf4 = Ref( L, 4 );
Lf5 = Ref( L, 5 );
Lf6 = Ref( L, 6 );
x = Cum( 1 );
divx = LastValue( x ) - x;

//Tops
A = H;
Top1 = A  Hf2  A  Hf1  A  Hp1  A  Hp2  divx  2;
Top2 = A  Hf3  A  Hf2  A == Hf1  A  Hp1  A  Hp2  divx  3 ;
Top3 = A  Hf4  A  Hf3  A == Hf2  A = Hf1  A  Hp1  A  Hp2  
divx  4;
Top4 = A  Hf5  A  Hf4  A == Hf3  A = Hf2  A = Hf1  A  Hp1  A 
  Hp2  divx  5;
Top5 = A  Hf6  A  Hf5  A == Hf4  A = Hf3  A == Hf2  A = Hf1  A 
  Hp1  A  Hp2  divx  6;
Top = Top1 OR Top2 OR Top3 OR Top4 OR Top5;
TopHigh = ValueWhen( Top, H );
TopX = ValueWhen( Top, X );

//Valleys
A = L;
Valley1 = A  Lf2  A = Lf1  A = Lp1  A  Lp2  divx2;
Valley2 = A  Lf3  A  Lf2  A == Lf1  A  Lp1  A  Lp2  divx3;
Valley3 = A  Lf4  A  Lf3  A == Lf2  A = Lf1  A  Lp1  A  Lp2  
divx4;
Valley4 = A  Lf5  A  Lf4  A == Lf3  A = Lf2  A = Lf1  A  Lp1  
A  Lp2  divx5;
Valley5 = A  Lf6  A  Lf5  A == Lf4  A = Lf3  A == Lf2  A = Lf1 
 A  Lp1  A  Lp2  divx6;
Valley = Valley1 OR Valley2 OR Valley3 OR Valley4 OR Valley4 OR Valley5;
ValleyLow = ValueWhen( Valley, L );
ValleyX = ValueWhen( Valley, X );
x = Cum( 1 );
xb = LastValue( ValueWhen( Valley, x, 1 ) );
xa = LastValue( ValueWhen( Valley, x, 2 ) );
yb = LastValue( ValueWhen( Valley, L, 1 ) );
Ya = LastValue( ValueWhen( Valley, L, 2 ) );
xab_log = log( yb / yA ) / ( xb - xa );
SL = exp( ( x - xb ) * xab_log ) * yb;
RocSL = ROC( SL, 1 );
xd = LastValue( ValueWhen( top, x, 1 ) );
xc = LastValue( ValueWhen( top, x, 2 ) );
yd = LastValue( 

Re: [amibroker] Re: FILL COLOR BETWEEN TREND CHANNEL

2010-09-08 Thread reinsley
  Part 2 :



DefinedPatterns = AscT | DscT | ST | ET | RW | FW | UT | DT;

Filter = BarIndex() == LastValue( BarIndex() ) AND NOT GroupID() == 253;

Filter = Filter AND
  ( AscT AND AscTs ) | ( DscT AND DscTs ) | ( ST AND STs ) |
  ( ET AND ETs ) | ( RW AND RWs ) | ( FW AND FWs ) |
  ( UT AND UTs ) | ( DT AND DTs ) | ( Range AND Ranges ) |
  ( SupSignals AND NonDefinedPatterns AND NOT DefinedPatterns ) |
  ( ResSignals AND NonDefinedPatterns AND NOT DefinedPatterns );

// | PLLSignals | PHLSignals | Trade Variables
Red = C  O;

Green = C  O;

Buy = FW | UT;

//Buy=Buy1  !Ref(Buy1,-1);
Short = RW | DT;

//Short = Short1  !Ref(Short1,-1);
Buy1 = BarsSince( Buy );

Short1 = BarsSince( Short );

BuyPrice = ( round( ValueWhen( Buy, C ) * 10 ) ) / 10;

ShortPrice = ( round( ValueWhen( Short, C ) * 10 ) ) / 10;

Buystop = ( round( ( BuyPrice - ( BuyPrice * 0.5 / 100 ) ) * 10 ) ) / 10;

Shortstop = ( round( ( ShortPrice + ( ShortPrice * 0.5 / 100 ) ) * 10 ) 
) / 10;

Buystop1 = ( ( Cross( Buystop, C ) OR Cross( Buystop, L ) ) AND since ) ;

Shortstop1 = ( ( Cross( H, Shortstop ) OR Cross( C, Shortstop ) ) AND 
since );

Sell1 = ( Buy1  0 AND ( ( CCI( 14 )  Ref( CCI( 14 ), -1 ) AND Red ) OR 
( x == xd  NOT AnZ ) ) AND since );

Sell = Sell1 AND NOT Ref( Sell1, -1 );

Cover1 = ( Short1  0 AND ( ( CCI( 14 )  Ref( CCI( 14 ), -1 ) AND Green 
) OR ( x == xb  NOT AnZ ) ) AND since );

Cover = Cover1 AND NOT Ref( Cover1, -1 );

SellPrice = ( round( ValueWhen( Sell, C ) * 10 ) ) / 10;

CoverPrice = ( round( ValueWhen( Cover, C ) * 10 ) ) / 10;

Buy11 = Cum( Buy );

Short11 = Cum( Short );

//Indicator
if ( Status( action ) == actionIndicator )
 (
 Title = EncodeColor( colorLightBlue ) + Patterns Trading 
System - Conceived, developed  and Property of  Vinod K. Iyer -  + \n 
+ EncodeColor( colorYellow ) + Name() +  -  + EncodeColor( colorYellow 
) + Interval( 2 ) + EncodeColor( colorWhite ) +
   -  + Date() +  -  + EncodeColor( colorYellow ) + 
TurnOver=Rs.   + EncodeColor( colorWhite ) + WriteVal( ( ( ( V 
* C ) / 10 ) ), 1.2 ) +Lakhs -  +
 \n +
 WriteIf( LastValue( AscT ), Ascending Triangle - 
bullish formation that usually forms during an uptrend as a continuation 
pattern + ,  ) +
 WriteIf( LastValue( DscT ), Decending Triangle - 
bearish formation that usually forms during a downtrend as a 
continuation pattern. + ,  ) +
 WriteIf( LastValue( ST ), Symmetrical Triangle - mark 
important trend reversals, they more often mark a continuation of the 
current trend - direction of the next major move can only be determined 
after a valid breakout. + ,  ) +
 WriteIf( LastValue( ET ), Expanding Triangle - The 
expanding triangle is said to be a good indicator of a reversal pattern 
+ ,  ) +
 WriteIf( LastValue( RW ), Rising Wedge - rising wedges 
definitely slope up and have a bearish bias + ,  ) +
 WriteIf( LastValue( FW ), Falling Wedge - falling 
wedges definitely slope down and have a bullish bias. +  ,  ) +
 WriteIf( LastValue( UT ), Up Channel - Bullish Trend 
+ ,  ) +
 WriteIf( LastValue( DT ), Down Channel - Bearish 
Trend + ,  ) +
 \n +
 WriteIf( Sup_pricejustabove, EncodeColor( 
colorBrightGreen ) + Price just above Support,
  WriteIf( Sup_confirmed, EncodeColor( 
colorBrightGreen ) + Support Confirmed, EncodeColor( colorWhite ) +  
) ) +
 WriteIf( Sup_break, EncodeColor( colorRed ) + Support 
Break + ,  ) + \n +
 WriteIf( Res_pricejustbelow, EncodeColor( colorRed ) + 
Price just below Resistance,
  WriteIf( Res_confirmed, EncodeColor( colorRed 
) + Resistance Confirmed, EncodeColor( colorWhite ) +  ) ) +
 WriteIf( Res_break, EncodeColor( colorBrightGreen ) + 
Resistance Break + ,  ) + \n +

 EncodeColor( colorBrightGreen ) +
 WriteIf( BuyPrice, BUY:   + ( BuyPrice ) +   ,  ) +
 WriteIf( BuyStop,  - BUY SL:   + ( BuyStop ),  ) +
 WriteIf( SellPrice ,   -  BUY TP:   + ( SellPrice ) + 
 ,  ) +
 \n +
 EncodeColor( colorRed ) +
 WriteIf( ShortPrice, SHORT:   + ( ShortPrice ) +   
,  ) +
 WriteIf( ShortStop, -  SHORT SL:   + ( ShortStop ) + 
  ,  ) +
 WriteIf( CoverPrice,-  SHORT TP:   + ( CoverPrice 
) +   ,  ) + \n +
 \n +


 WriteIf( Range, Range, Not defined ) );


//Shapes
if ( PlotP1P2 )
{
 PlotShapes( IIf( x == xa  NOT AnZ, P1Shape, shapeNone ), Color_SL, 
0, SL, -13 );
 PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), Color_SL, 0, SL, 
-25 );
 PlotShapes( IIf( x == xc  NOT AnZ, P1Shape, shapeNone ), Color_RL, 
0, H, 13 );
 PlotShapes( IIf( Short, shapeDownArrow,