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

TSL&ATR&EMA&TGL for Amibroker (AFL)

Rating:
5 / 5 (Votes 1)
Tags:
amibroker, stop loss

Another Trailing Stop Loss (TSL) from Web.

Screenshots

Similar Indicators / Formulas

NRTR WATR
Submitted by allexiss over 8 years ago
DODA BAND BUY SELL
Submitted by saas over 6 years ago
JMA Stoploss
Submitted by kuzukapama over 8 years ago
TSL & HL & New
Submitted by morgen over 7 years ago
Stop Loss Indicator
Submitted by nabcha over 9 years ago
ABKP Benchmark Bar
Submitted by amitabh over 9 years ago

Indicator / Formula

Copy & Paste Friendly









//HEIKIN-ASHI ORIGINAL

//SetChartOptions(0,chartShowArrows | chartShowDates);
HaClose = (O + H + L + C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
xDiff = (HaHigh - Halow) * 10000;
//barcolor = IIf(HaClose >= HaOpen,colorGreen,colorRed);
//barcolor= IIf(HaClose>=HaOpen AND C>Ref(C,-1) AND C>=O,colorGreen,
//          IIf(HaClose<HaOpen AND C<Ref(C,-1) AND C<O, colorRed, colorBrown)) ;
//SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange));
//SetBarFillColor(IIf(HaClose>=HaOpen AND C>Ref(C,-1) AND C>=O,colorBrightGreen,
//                IIf(HaClose<HaOpen AND C<Ref(C,-1) AND C<O, colorOrange, colorTan)) );
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikin-ashi", barcolor, styleCandle );
//PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "\nHeikin-ashi", colorBlack, styleCandle );

//HaDelta & MA

HaDelta= HaClose-HaOpen ;
MAhadelta= MA(Hadelta,3) ;
Hadeltaup3= Hadelta>MA(Hadelta,3) ;
Hadeltaup33 = Hadelta>MA(MA(Hadelta,3),3) ;
//Plot(Hadelta,"haDelta",colorBlack) ;
//Plot(0,"",colorBrown) ;
//Plot( MA1, "MA1", colorRed );
//Plot( MA2, "MA2", colorBlue );

Haup= HaClose>=HaOpen ;
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//TRENDING RIBBON

// 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");
uptrend= (PDI()>MDI() AND MACD()>Signal()) ;
downtrend=MDI()>PDI() AND Signal()>MACD();
Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
    IIf(uptrend,colorLime,IIf(downtrend,colorRed,colorTan)),styleOwnScale|styleArea|styleNoLabel,-0.5,100 );
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//MODEL PENTRU 3 CULORI , ADICA 3 CONDITII

//bar3culori= IIf(C> NLBL, colorBlue, IIf(C<NLSL, colorRed, colorTan));//MODEL MODEL MODEL 3 CULORI
//SetBarFillColor(IIf(HaClose>=HaOpen,colorBrightGreen,colorOrange));

//bar3culori= IIf(C> NLBL, colorBlue, IIf(C<NLSL, colorRed, colorTan));//MODEL MODEL MODEL 3 CULORI
//SetBarFillColor(IIf(HaClose>=HaOpen AND C>Ref(C,-1),colorBrightGreen,
//                  IIf(HaClose<HaOpen AND C<Ref(C,-1), colorRed, colorTan)) );
//SetBarFillColor= IIf(C> NLBL, colorBlue, IIf(C<NLSL, colorRed, colorTan));//MODEL MODEL MODEL 3 CULORI
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//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 )) ));
barcolor= IIf(C>O AND C>Ref(C,-1) AND HaClose>=HaOpen,colorBlue,
          IIf(C<O AND C<Ref(C,-1) AND HaClose<HaOpen,colorRed,colorTan)) ;
//Plot( C, "", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
Plot( C, "", barcolor,styleBar+styleThick ); 
_SECTION_END();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// TRAILING STOP LOSS & ATR & EMA

/*
This formula plots two exponential moving averages along with
an auto-switching exponential ATR trailing stop.
*/


per = Param("per",10,2,50,1,0);
mult = Param("mult",2,1,10,0.1,0);
tr = Ref(EMA(ATR(1),per),0)*mult;
mov = Param("FastEMA",5,1,100,1,0);
mov2 = Param("SlowEMA",34,10,200,1,0);

trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
trailArray = Ref(trailArray,-1);

//GraphXSpace = 5;
//SetChartOptions(0, chartShowDates);
//Plot(EMA(Close,mov),"\nFastEMA",colorRed,styleLine);
MAupcol=IIf(EMA(Close,mov)>Ref(EMA(Close,mov),-1),colorRed,colorPink) ;
Plot(EMA(Close,mov),"\nFastEMA",MAupcol,styleDots);
//Plot(EMA(Close,mov2),"\nSlowEMA",colorBlue,styleLine);
MA2upcol=IIf(EMA(Close,mov2)>Ref(EMA(Close,mov2),-1),colorBlue,colorAqua) ;
Plot(EMA(Close,mov2),"\nSlowEMA",MA2upcol,styleDots);
Plot(trailArray,"\ntrailArray",colorRed,styleStaircase+styleThick);
//Plot( C, "\nCandle",colorBlack, styleCandle );
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//FORMULE

stochup= StochK()>StochD() ;
stoch80= StochK()<80 ;
MACDup= MACD()>Signal() ;
Hist= MACD()-Signal() ;
Histup= Hist>Ref(Hist,-1) ;
MFIupema5= MFI()>EMA(MFI(),5) ;
MFI30= MFI()>30 ;
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() ;
CCIup0= CCI()>0 ;
top2up= BBandTop(C,20,2)>=Ref(BBandTop(C,20,2),-1) ;
top1up= BBandTop(C,20,1)>=Ref(BBandTop(C,20,1),-1) ;
Cuptop1= C>BBandTop(C,20,1) ;
mybuy= C>trailArray ;
PlotShapes(IIf(Cross(EMA(Close,mov),EMA(Close,mov2)),shapeUpTriangle,shapeNone),colorAqua,0,Low,Offset=-25) ;
PlotShapes(IIf(Cross(EMA(Close,mov2),EMA(Close,mov)),shapeDownTriangle,shapeNone),colorCustom12,0,High,Offset=-25) ;
//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 = mybuy AND macdup AND histup AND cupo AND haup ;
myShort = !mybuy ; 
}
else
{
myBuy   = IIf( C>trailArray AND MACD()>Signal() AND Hist>Ref(Hist,-1) AND C>O AND HaClose>=HaOpen     ,1,0);
myShort = IIf( C<trailArray     ,1,0);
}

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


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






















1 comments

1. amon

Foarte bun. Bravo!

Leave Comment

Please login here to leave a comment.

Back