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

TDL & HA & TGL for Amibroker (AFL)
morgen
about 4 years ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 6)
Tags:
amibroker, support, resistance, heikin ashi

Trendlines both Support and Resistance with Buy and Sell signals.
It is a compilation based on initial authors work.

Screenshots

Indicator / Formula

Copy & Paste Friendly
//TRENDLINES

//SUPPORT

x = Cum(1);

//perchg = 0.03*LastValue( Highest( ROC( Low, 50 ) ));

k= Param("k",0.03,0,1,0.001,0) ;
ROCper= Param("ROCper",34,3,100,1,0) ;

perchg = k*LastValue( Highest( ROC( Low, ROCper ) ));

startvalue = LastValue( Trough( Low, perchg, 1 ) );
endvalue1 = LastValue( Trough( Low, perchg, 2 ) );

startbar = LastValue( ValueWhen( Low == startvalue, x, 1 ) );
endbar = LastValue( ValueWhen( Low == endvalue1, x, 1 ) );

Aa = (endvalue1-startvalue)/(endbar-startbar);
b = startvalue;

trendline = Aa * ( x  - startbar ) + b; 

Plot( IIf( x >= endbar, trendline, Null ), "\nSupport", colorBlue,styleLine+styleThick );
//---------------------------------------------------------------------------------------------------

//RESISTANCE

x = Cum(1);

//perchgH = 0.03*LastValue( Highest ( ROC( High , 50 ) ));
perchgH = k*LastValue( Highest ( ROC( High , ROCper ) ));

startvalueH = LastValue( Peak ( High , perchgH, 1 ) );
endvalue1H = LastValue( Peak ( High , perchgH, 2 ) );

startbarH = LastValue( ValueWhen( High == startvalueH, x, 1 ) );
endbarH = LastValue( ValueWhen( High == endvalue1H, x, 1 ) );

AaH = (endvalue1H-startvalueH)/(endbarH-startbarH);
bH = startvalueH;

trendlineH = AaH * ( x  - startbarH ) + bH; 

Plot( IIf( x >= endbarH, trendlineH, Null ), "\nResistance", colorRed,styleLine+styleThick );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//Plot( Close, "Price", colorBlue, styleCandle );





//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HEIKIN ASHI EXACT FORMULA BEGIN DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

_SECTION_BEGIN("HA Looping ( no AMA() )");
//SetChartOptions(0,chartShowArrows|chartShowDates);
///////////////////////////////////////////////////////////
//
// Heikin Ashi - Calculated Properly with no use of AMA
//
// JF Derzi, December 2012
//
//

HaClose[0] = (Open[0]+High[0]+Low[0]+Close[0]) / 4;
HaOpen[0]  = (HaClose[0] + Open[0]) / 2;
HaHigh[0]  = Max( High[0], Max( HaClose[0], HaOpen[0] ) );
HaLow[0]   = Min( Low[0], Min( HaClose[0], HaOpen[0] ) );

for (i=1; i<BarCount; i++)
	{
	HaClose[i] = (Open[i]+High[i]+Low[i]+Close[i]) / 4;
	Haopen[i]  = (HaClose[i-1] + HaOpen[i-1]) / 2; // Here is the problem when using Arrays: Haopen always uses its own previous value
	HaHigh[i]  = Max( High[i], Max( HaClose[i], HaOpen[i] ) );
	Halow[i]   = Min( Low[i], Min( HaClose[i], HaOpen[i] ) );
}

//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "HA", colorBlack, styleCandle );

barcolorha = IIf(HaClose>=HaOpen,colorGreen,colorRed);
SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange));
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikinAshiDerzi", barcolorha, styleCandle );

//Title = Name()+" "+Date()+" Heikin Ashi -- HaOpen:"+NumToStr(HaOpen,1.2,True)+" / HaHigh:"+NumToStr(HaHigh,1.2,True)+
//        " / HaLow:"+NumToStr(Halow,1.2,True)+" HaClose:"+NumToStr(Haclose,1.2, True);

_SECTION_END();

HAup= HaClose>=HaOpen ;
haDelta= HaClose-HaOpen ;
MAhaDelta= MA(haDelta,3) ;
haDeltaUpMA= haDelta>MA(haDelta,3) ;

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXHEIKIN ASHI EXACT FORMULA END DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD

//PRICE

_SECTION_BEGIN("Price");
//SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%)Vol " +
            WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
//Plot( C, "", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

//barcolorc= IIf(C>O AND C>Ref(C,-1), colorBlue,
//           IIf(C<O AND C<Ref(C,-1), colorRed, colorTan)); //MODEL MODEL MODEL 3 CULORI
//SetBarFillColor( IIf(C>O AND C>Ref(C,-1), colorBrightGreen,
//                 IIf(C<O AND C<Ref(C,-1), colorOrange, colorTan))); //MODEL MODEL MODEL 3 CULORI
//Plot( C, "", barcolorc, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
//Plot( C, "", barcolorc, styleBar+styleThick );
_SECTION_END(); 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// TREND ADVISER AND TRENDING RIBBON

//TREND ADVISER

pointer[0] = 0;

/* Phase filter */

/*
Cond1 = Close > MA(Close, 50)AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
Cond2 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND NOT(MA(Close, 50) > MA(Close, 200)) ;
Cond3 = Close > MA(Close, 50)AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200) ;
Cond4 = NOT(Close > MA(Close, 50))AND Close > MA(Close, 200)AND MA(Close, 50) > MA(Close, 200);
Cond5 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND MA(Close, 50) > MA(Close, 200);
Cond6 = NOT(Close > MA(Close, 50))AND NOT(Close > MA(Close, 200))AND NOT(MA(Close, 50) > MA(Close, 200));
*/

Cond1 = C>=MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);
Cond2 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)<MA(C,200) ;
Cond3 = C>=MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200) ;
Cond4 = C<MA(C,50) AND C>=MA(C,200) AND MA(C,50)>=MA(C,200);
Cond5 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)>=MA(C,200);
Cond6 = C<MA(C,50) AND C<MA(C,200) AND MA(C,50)<MA(C,200);


for (i = 1; i < BarCount; i++)
{

  if (Cond1[i])
    pointer[i] = 1;
  if (Cond2[i])
    pointer[i] = 2;
  if (Cond3[i])
    pointer[i] = 3;
  if (Cond4[i])
    pointer[i] = 4;
  if (Cond5[i])
    pointer[i] = 5;
  if (Cond6[i])
    pointer[i] = 6;

}

/* Plot Graphic */
GraphXSpace= 15 ;
dynamic_color = IIf(pointer < 4, colorGreen, colorRed);
//Plot(pointer, "TrendAdvisor", dynamic_color, styleHistogram | styleThick, Null, Null, 0);
//SetChartBkGradientFill(ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorLightYellow));

Cond = pointer<4 ;
//===============================================================================================================

//TRENDING RIBBON

//R1========================================== 1 TREND ===========================
/*
r1 = IIf(macdup AND cond AND ADX()>18 AND ADX()<49 AND PDI()>18 OR 
         uptrend AND ADX()>18 AND ADX()<49 AND PDI()>18 ,colorBrightGreen,
     IIf(!macdup AND !cond OR
         downtrend OR
         ADX()<18 ,colorRed,colorTan)) ;   
         */     

//--------------------------------------------------------------------------------

// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX 
// are both trending down.
_SECTION_BEGIN("trending ribbon");
MACDup= MACD()>Signal() ;
uptrend= (MACD()>Signal() AND PDI()>MDI()) ;
downtrend= (MACD()<Signal() AND PDI()<MDI()) ;

Plot( 3, /* defines the height of the ribbon in percent of pane width */"",
      IIf(macdup AND cond AND ADX()>18 AND ADX()<49 AND PDI()>18 OR 
          uptrend AND ADX()>18 AND ADX()<49 AND PDI()>18 ,colorBrightGreen,
      IIf(!macdup AND !cond OR
          downtrend OR
          ADX()<18 ,colorRed,colorTan)),styleOwnScale|styleArea|styleNoLabel,-0.5,100 );
    
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//FORMULE

stochup= StochK()>StochD() ;
stochdn80= StochK()<80 ;
MACDup= MACD()>Signal() ;
MACDup0= MACD()>0 ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupMA7= MFI()>MA(MFI(),7) ;
MFI30= MFI()>30 ;
MFIup50= MFI()>50 ;
MFIdn80= MFI()<80 ;
RSIupMA7= RSI()>MA(RSI(),7) ;
RSIup50= RSI()>50 ;
Cupo= C>O ;
MA10up= MA(C,10)>=Ref(MA(C,10),-1) ;
MA20up= MA(C,20)>=Ref(MA(C,20),-1) ;
EMA50up= EMA(C,50)>=Ref(EMA(C,50),-1) ;
CupEMA50= C>EMA(C,50) ;
Cupma20= C>MA(C,20) ;
PDIupmdi= PDI()>MDI() ;
PDIup20= PDI()>20 ;
UpTrend= (MACD()>Signal() AND PDI()>MDI()) ;
DownTrend= (MACD()<Signal() AND PDI()<MDI()) ;
CCIup0= CCI()>0 ;
CCIupMA7= CCI()>MA(CCI(),7) ;
CCIdn200= CCI()<200 ;
top2up= BBandTop(C,15,2)>=Ref(BBandTop(C,15,2),-1) ;
Cuptop1= C>BBandTop(C,20,1) ;
HAup= HaClose>=HaOpen ;
upbar = H>=Ref(H,-1) AND L>Ref(L,-1);
downbar = L<=Ref(L,-1) AND H<Ref(H,-1);
ADXup18= ADX()>18 ;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//PARAMTOGGLE

// This combines indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
//    { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
// switch test calculation and compare the results
if(tgl)
{
myBuy = macdup ;
myShort = !macdup ;
}
else
{
myBuy   = IIf( MACD()>Signal()    ,1,0);
myShort = IIf( MACD()<Signal()    ,1,0);
} 


//myBuy   = Cross(C,trailArray) AND macdup OR 
//          Cross(MACD(),Signal()) AND Buystopnew ;
//myShort = Cross(trailArray,C) ; 

Buy = ExRem(myBuy, myShort);
Sell = ExRem(myShort, myBuy);

//PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);
//PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);

//PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,trailArray);
//PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,trailArray);

//PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-10);
//PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-10);

StrongBuy = Buy AND Cross(MACD(),Signal()) AND histup AND stochup AND haup AND adxup18 AND cond ;
MediumBuy = Buy AND histup AND stochup AND haup AND adxup18 ;
WeakBuy = Buy ;

StrongSell = Sell AND !stochup AND !mfiupma7 AND !haup ;
MediumSell = Sell AND !stochup AND stochdn80 AND !haup ;
WeakSell = Sell ; 

PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,haLow,Offset=-10);
PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);
PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,haLow,Offset=-10);

PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,haHigh,Offset=-10);
PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);
PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,haHigh,Offset=-10);

/*
PlotShapes(IIf(StrongBuy,shapeUpTriangle,shapeNone),colorBlue,0,Low,Offset=-10);
PlotShapes(IIf(MediumBuy,shapeUpArrow,shapeNone),colorBlue,0,Low,Offset=-10);
PlotShapes(IIf(WeakBuy,shapeHollowUpArrow,shapeNone),colorBlue,0,Low,Offset=-10);

PlotShapes(IIf(StrongSell,shapeDownTriangle,shapeNone),colorRed,0,High,Offset=-10);
PlotShapes(IIf(MediumSell,shapeDownArrow,shapeNone),colorRed,0,High,Offset=-10);
PlotShapes(IIf(WeakSell,shapeHollowDownArrow,shapeNone),colorRed,0,High,Offset=-10); 


















































































































0 comments

Leave Comment

Please login here to leave a comment.

Back