PureBytes Links
Trading Reference Links
|
See if this does what you want. I have not looked at it for quite sometime but as I recall it duplicated Metastock's formula.
Bill
dunnType1 = IIf(BarsSince(H > Ref(H, -1) AND L > Ref(L, -1)) < BarsSince(L < Ref(L, -1) AND H < Ref(H, -1)), 1, -1);
dunnType2 = IIf(BarsSince((H > Ref(H, -1) AND L > Ref(L, -1)) AND (Ref(H, -1) > Ref(H, -2) AND Ref(L, -1) > Ref(L, -2)))
< BarsSince((L < Ref(L, -1) AND H < Ref(H, -1)) AND (Ref(L, -1) < Ref(L, -2) AND Ref(H, -1) < Ref(H, -2))), 1, -1);
swing = ParamToggle("Type Swing", "Dunn-1|Dunn-2", 1);
typeSwing = IIf(swing == 0, dunnType1, dunnType2);
dunnUpInterval = BarsSince(typeSwing == -1);
dunnDownInterval = BarsSince(typeSwing == 1);
upSwingHighValue = IIf((dunnUpInterval > dunnDownInterval) AND H > Ref(H, -1), HighestSince(dunnUpInterval == 1, H, 1), 0);
downSwingLowValue = IIf((dunnUpInterval < dunnDownInterval) AND L < Ref(L, -1), LowestSince(dunnDownInterval == 1, L, 1), 0);
upSwingHighValueLow = ValueWhen(H == upSwingHighValue, L, 1);
downSwingLowValueHigh = ValueWhen(L == downSwingLowValue, H, 1);
trend = IIf(typeSwing == 1 AND H > downSwingLowValueHigh, 1, IIf(typeSwing = -1
AND L < upSwingHighValueLow, -1, 0));//1 = uptrend, -1 = downtrend
colorDunniganTrend = IIf(trend == 1, ParamColor("color Up Dunnigan Trend", colorYellow),
ParamColor("color Down Dunnigan Trend", colorRed));
trendBinary = ValueWhen(trend != 0, trend, 1);
Plot(trendBinary, "", colorDunniganTrend, styleThick);
--- In amibroker@xxxxxxxxxxxxxxx, "Tim" <timkthung@xxx> wrote:
>
> Dear All,
>
> I am new to AB. Would someone please show me how to add the code for a Buy or Sell signal based on the value of 1 or -1 in following formula.
>
> Thanks in advance.
>
> Tim
>
>
> //Dunn-Type1
> //==========
>
> TD1 = IIf( BarsSince( H > Ref( H, -1 ) AND L > Ref( L, -1 ) ) <
> BarsSince( L < Ref( L, -1 ) AND H < Ref( H, -1 ) ), 1, -1 );
>
> //Dunn-Type2
> //==========
>
> TD2 = IIf( BarsSince( ( H > Ref( H, -1 ) AND L > Ref( L, -1 ) ) AND
> ( Ref( H, -1 ) > Ref( H, -2 ) AND Ref( L, -1 ) > Ref( L, -2 ) ) ) <
> BarsSince( ( L < Ref( L, -1 ) AND H < Ref( H, -1 ) ) AND
> ( Ref( L, -1 ) < Ref( L, -2 ) AND Ref( H, -1 ) < Ref( H, -2 ) ) ), 1, -1 );
>
> // Ask to use 1 Day OR 2 Day Swing type}
> St = Param( "Short Term Swing Type, 1 or 2 ?", 2, 1, 2, 1 );
>
> //{Call Swing Type Formula}
> Sd = IIf( St == 1, TD1, TD2 );
>
> //{Number Of Periods Since Swing Started Up}
> Hc = BarsSince( SD = -1 );
>
> //{Number Of Periods Since Swing Started Down}
> Lc = BarsSince( SD = 1 );
>
> //{Find Highest Value Of Up Swing}
> Hv = IIf( Hc > Lc AND H > Ref( H, -1 ), HighestSince( Hc = 1, H, 1 ) , 0 );
>
> //{Find Lowest Value Of Down Swing}
> Lv = IIf( Hc < Lc AND L < Ref( L, -1 ), LowestSince( Lc = 1, L, 1 ) , 0 );
>
> //{Find The Low Of The Highest High}
> Hlv = ValueWhen( H = Hv, L, 1 ) ;
>
> //{Find The High Of The Lowest Low}
> Lhv = ValueWhen( L = Lv, H, 1 ) ;
>
> //{Calculate AND Plot Trend Direction,
> //Note: 1= Uptrend,
> //-1= Downtrend}
>
> TD3 = IIf( Sd = 1 AND H > Lhv, 1, IIf( Sd = -1 AND L < Hlv, -1, 0 ) );
> TD4 = ValueWhen( TD2 != 0, TD2, 1 );
>
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
amibroker-digest@xxxxxxxxxxxxxxx
amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|