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 ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
st for Amibroker (AFL)
Copy & Paste Friendly
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | // Supertrend - Translated from Kolier MQ4 // see: http://kolier.li/indicator/kolier-supertrend-indi // translation in Amibroker AFL code by E.M.Pottasch, 2011 sdfact= Param ( "Standard Deviation Factor" ,2,0.5,5,0.1); offset= Param ( "Offset" ,2,2,50,1); ATR_Multiplier= Param ( "ATR_Multiplier" ,2,0.5,10,0.1); ATR_Period= Param ( "ATR_Period" ,5,2,20,1); TrendMode= ParamToggle ( "TrendMode" , "Off|On" ,1); procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice) { global buffer_line_down; global buffer_line_up; buffer_line_down = Null ; buffer_line_up = Null ; PHASE_NONE = 0; PHASE_BUY = 1; PHASE_SELL = -1; phase=PHASE_NONE; band_upper = 0;band_lower = 0; for (i = ATR_Period + 1; i < BarCount ; i++) { band_upper = CalcPrice[i] + ATR_Multiplier * tr[i]; band_lower = CalcPrice[i] - ATR_Multiplier * tr[i]; if (phase==PHASE_NONE) { buffer_line_up[i] = CalcPrice[i]; buffer_line_down[i] = CalcPrice[i]; } if (phase!=PHASE_BUY && Close [i]>buffer_line_down[i-1] && ! IsEmpty (buffer_line_down[i-1])) { phase = PHASE_BUY; buffer_line_up[i] = band_lower; buffer_line_up[i-1] = buffer_line_down[i-1]; } if (phase!=PHASE_SELL && Close [i]<buffer_line_up[i-1] && ! IsEmpty (buffer_line_up[i-1])) { phase = PHASE_SELL; buffer_line_down[i] = band_upper; buffer_line_down[i-1] = buffer_line_up[i-1]; } if (phase==PHASE_BUY && ((TrendMode==0 && ! IsEmpty (buffer_line_up[i-2])) || TrendMode==1) ) { if (band_lower>buffer_line_up[i-1]) { buffer_line_up[i] = band_lower; } else { buffer_line_up[i] = buffer_line_up[i-1]; } } if (phase==PHASE_SELL && ((TrendMode==0 && ! IsEmpty (buffer_line_down[i-2])) || TrendMode==1) ) { if (band_upper<buffer_line_down[i-1]) { buffer_line_down[i] = band_upper; } else { buffer_line_down[i] = buffer_line_down[i-1]; } } } } tr = ATR (ATR_Period); CalcPrice=( H + L )/2; calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice); TrendUp=buffer_line_up;TrendDown=buffer_line_down; totalTrend= IIf (TrendUp,TrendUp,TrendDown); dtotalTrend=totalTrend- Ref (totalTrend,-1); vtotalTrend= ValueWhen (dtotalTrend,dtotalTrend); cross_bull=vtotalTrend>0 AND Ref (vtotalTrend,-1)<0; cross_bull= Ref (cross_bull,1); cross_bull[ BarCount -1]=1; cross_bear=vtotalTrend<0 AND Ref (vtotalTrend,-1)>0; cross_bear= Ref (cross_bear,1); cross_bear[ BarCount -1]=1; nw_bull = Ref ( Flip (cross_bull,cross_bear),-1); nw_bear = Ref ( Flip (cross_bear,cross_bull),-1); SetChartOptions (0, chartShowDates ); Title = "Symbol: " + Name (); Plot ( C , "Close" , colorLightGrey , styleCandle ); Plot ( IIf (nw_bull,1, Null ), "" , ColorRGB (0, Min ( BarsSince (cross_bull),255),0), styleArea | styleOwnScale ,0,1,0,-1); Plot ( IIf (nw_bear,1, Null ), "" , ColorRGB (2* Min ( BarsSince (cross_bear),255),0,0), styleArea | styleOwnScale ,0,1,0,-1); Plot (buffer_line_up, "\ntu" , colorBlue , styleThick ); Plot (buffer_line_down, "\ntd" , colorRed , styleThick ); |