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&PREVfunction&TGL for Amibroker (AFL)
morgen
over 11 years ago
Amibroker (AFL)

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

It is critical important in trading, I am convinced, to have a good Trailing Stop Loss (TSL).
Because that, I come with another TSL that converts Metastock PREV function in Amibroker language.
Thanks to Amibroker Creator!

Screenshots

Similar Indicators / Formulas

NRTR WATR
Submitted by allexiss over 13 years ago
DODA BAND BUY SELL
Submitted by saas over 11 years ago
JMA Stoploss
Submitted by kuzukapama over 13 years ago
TSL & HL & New
Submitted by morgen over 12 years ago
Stop Loss Indicator
Submitted by nabcha over 14 years ago
ABKP Benchmark Bar
Submitted by amitabh over 14 years ago

Indicator / Formula

Copy & Paste Friendly


///////////////////////////////////////////////////////////////////////////
//Amibroker .afl equivalent for Metastock PREV function.
///////////////////////////////////////////////////////////////////////////

SetBarsRequired( 100000, 0 );

ATRMulti = Param("ATRmulti",1.7,1,20,0.1,0) ;
ATRPeriod = Param("ATRper",10,1,50,1,0) ;

//AvPrc = (High + Low + Close) / 3;
AvPrc = (High + Low + 2*Close) / 4;
calc = AvPrc - ATR(ATRPeriod ) * ATRMulti;

result = calc;

previous = Null;

for( i = 1; i < BarCount; i++ )
{
  if( Close[ i - 1 ] >= previous AND calc[ i ] <= previous )
    result[ i ] = previous;

  previous = result[ i ];
}

Plot( result, "\nresult", colorRed,styleLine+styleThick );

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//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();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//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
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//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();
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//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) ;
haup= HaClose>=HaOpen ;
Lim= (ADX()<50 AND MFI()>30) ;
mybuy= C>result ;
//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>result AND MACD()>Signal() AND Hist>Ref(Hist,-1) AND C>O AND HaClose>=HaOpen     ,1,0);
myShort = IIf( C<result      ,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);






























0 comments

Leave Comment

Please login here to leave a comment.

Back