|
|
-DI & +DI Tip
Last post 06-15-2007, 18:34 by Jose. 14 replies.
-
09-11-2006, 14:31 |
-
Bulli
-
-

-
Joined on 09-27-2005
-
Brazil
-
Posts 139
-
-
|
Hi Friends,
It seems that everybody looks for -DI & +Di
You should look for the following in the help file:
Plus Directional Movement = +DI
Minus Directional Movement = -DI
Bulli
|
|
-
09-12-2006, 19:13 |
-
henry1224
-
-

-
Joined on 10-29-2004
-
Glastonbury, CT
-
Posts 901
-
-
|
if you create an Oscillator from the directional movement, then you can smooth it out with a small MA,.
Per1:=14; A:=Mov(Mov(PDI(Per1),3,E),3,E)-Mov(Mov(MDI(Per1),3,E),3,E); Sig:=Mov(A,5,E); B:= (A-Sig)*2; Buy:=Cross(B,0); Sell:=Cross(0,B); D:=If(BarsSince(Buy)<BarsSince(Sell),1,0); D>Ref(D,-1)
|
|
-
06-11-2007, 18:13 |
-
amory
-
-

-
Joined on 04-19-2007
-
sydney australia
-
Posts 99
-
-
|
hello Henry.
I have only just come across this oscillator of yours & thumped it straight on to my DI+/- template.
now I don't know whether I am using it correctly, it came up as a series of witches- hats which on second glance, proved to be extremely effective bull-signals, some of the best I've seen.
question: is there another formula that would give the equivalent signals for a downturn?
thank you
amory
|
|
-
06-12-2007, 2:36 |
-
amory
-
-

-
Joined on 04-19-2007
-
sydney australia
-
Posts 99
-
-
|
"question: is there another formula that would give the equivalent signals for a downturn?"
I have tried to answer my own question by turning a few of the items in Henry's formula back-to-front, as follows:-
Per1:=14; A:=Mov(Mov(PDI(Per1),3,E),3,E)-Mov(Mov(MDI(Per1),3,E),3,E); Sig:=Mov(A,5,E); B:= (A-Sig)*2; Buy:=Cross(0,B); Sell:=Cross(B,0); D:=If(BarsSince(buy)>BarsSince(sell),1,0); D<Ref(D,-1)
considering that the original formula is really over my head, the result on chart turned out not too bad. but not as precise as it ought to be, by comparison with the "positive" formula.
amory
|
|
-
06-12-2007, 3:07 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 1,608
-
-
|
Amory, If you mean to have a long/short swing system this might help: |
Per1:=14; A:=Mov(Mov(PDI(Per1),3,E),3,E)-Mov(Mov(MDI(Per1),3,E),3,E); Sig:=Mov(A,5,E);
tr:=A>Sig;
long:=tr and alert(tr=0,2); short:=tr=0 and alert(tr=1,2);
long-short;
|
untested I have taken the liberty of editing h's original code. The results will be 1 as a long entry signal, or a -1 as a short entry signal. You could adapt this to be a short-term trend indicator. Give it a try and let us know how it turns out. Hope this helps. wabbit
MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
06-12-2007, 3:22 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 1,608
-
-
|
... thinking about this a little more, you could do something like this, maybe? |
prd1:=14; prd2:=5; A:=dema(PDI(prd1)-MDI(prd1),prd2); Sig:=Mov(A,prd2,E);
tr:=A>Sig;
long:=tr and alert(tr=0,2); short:=tr=0 and alert(tr=1,2);
long-short;
|
untested Hope this helps. wabbit
MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
06-12-2007, 7:23 |
-
amory
-
-

-
Joined on 04-19-2007
-
sydney australia
-
Posts 99
-
-
|
they all work, Wabbit, not a crook one among them. probably some variation different stocks & reliability might depend on direction of major trend. anyway, a nice addition to the DI template.
thanks very much for help
amory
|
|
-
06-13-2007, 20:30 |
-
hayseed
-
-
-
Joined on 03-07-2005
-
-
Posts 1,352
-
-
|
hey amory.... twice now you've mentioned witches hats when describing a plotted line..... which is a good description.... those 'witches hats' can become somewhat cluttering so my preference is to change the style to histogram.... the slender lines seem less obtrusive while giving the same information.... better still is just to create a trend ribbon....
with that in mind we can change wabbits/henry's code a bit to enable us to color the up bar green and down bar red individually.....h
---------------------------------
prd1:=14; prd2:=5; A:=Dema(PDI(prd1)-MDI(prd1),prd2); Sig:=Mov(A,prd2,E);
tr:=A>Sig;
long:=tr AND Alert(tr=0,2); short:=tr=0 AND Alert(tr=1,2);
If(long,1,0); If(short,-1,0);
---------------------------------
|
|
-
06-13-2007, 20:42 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 1,608
-
-
|
hayseed: If(long,1,0); If(short,-1,0);
hayseed and all, This can be abbreviated / shortened as: long; -short; which is slightly faster than having MS compute an If-Then-Else function with no difference in the results. hayseed's function then is: |
prd1:=14; prd2:=5; A:=Dema(PDI(prd1)-MDI(prd1),prd2); Sig:=Mov(A,prd2,E);
tr:=A>Sig;
long:=tr AND Alert(tr=0,2); short:=tr=0 AND Alert(tr=1,2);
long; -short;
|
Hope this helps. wabbit
MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
06-13-2007, 20:54 |
-
hayseed
-
-
-
Joined on 03-07-2005
-
-
Posts 1,352
-
-
|
Re: General programming tip
hey wabbit.... thanks.... ' -short '..... can't recall ever seeing it put like that before but clearly see the savings now..... thanks again....h
|
|
-
06-14-2007, 3:34 |
-
amory
-
-

-
Joined on 04-19-2007
-
sydney australia
-
Posts 99
-
-
|
Re: General programming tip
I am most impressed, Wabbit! those little histogram-lines sure look better than the "hats". and they do seem to know what the DI+/- is trying to convey.
thanks Hayseed and Wabbit.
amory
|
|
-
06-14-2007, 3:38 |
-
amory
-
-

-
Joined on 04-19-2007
-
sydney australia
-
Posts 99
-
-
|
Re: General programming tip
and thanks Henry1224 for starting the ball rolling!
amory
|
|
-
06-15-2007, 14:00 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: General programming tip
wabbit:|
prd1:=14; prd2:=5; A:=Dema(PDI(prd1)-MDI(prd1),prd2); Sig:=Mov(A,prd2,E);
tr:=A>Sig;
long:=tr AND Alert(tr=0,2); short:=tr=0 AND Alert(tr=1,2);
long; -short;
|
I would improve the above formula code in a number of ways:
1) Add user input variables to allow for experimentation of parameters;
2) Rename all variables with meaningful names;
3) Add comments for clarity wherever possible;
4) Add a properly constructed trade signals "latch", so that Long & Short signals may be combined;
5) As a result of #4, the formula could now be properly referenced for complete Long/Short signals, rather than just short signals.
jose '-)
MetaStockTools.com
|
|
-
06-15-2007, 17:26 |
-
hayseed
-
-
-
Joined on 03-07-2005
-
-
Posts 1,352
-
-
|
Re: General programming tip
hey jose..... in reguards to your prior post here, i printed/studied everything you had written back when i first purchased meta, even though most of it was beyond my abilities at the time..... must of missed the " - "..... i see it now....
anyone considering learning to code could get a head start by doing the same printing/studying of jose's codes...... primarily for 3 reasons....
first, is his consistent use of comments .... it helps....
second, is you can be assured the code works..... many sites have twice the formulas but most are just collections/submissions without reguard to errors....
third, is his readable method ...... readable code is easier to grasp..... we can't learn what we can't grasp....
and enough of that.....
hey jose.... true, often times that last line reference can be a pain..... sometimes we can get around it by using "FmlVar" .... that way we can to reference addtional " variable" lines in the orignal formula......such as, .....h
------------------------------------------------------
long:= FmlVar("wabbitts di","LONG") ;
short:= FmlVar("wabbitts di","SHORT") ;
long; -short;
---------------------------------------------------
|
|
-
06-15-2007, 18:34 |
-
Jose
-
-

-
Joined on 01-20-2005
-
Koh Pha-Ngan, Earth
-
Posts 1,087
-
-
|
Re: General programming tip
Thanks Hayseed.
I prefer to avoid the use of FmlVar() calls wherever possible, as not only do they slow processing considerably, but also take a lot more formula space.
If the original formula example had a long-short single output, it would then be neater to reference it (once) this way:
-------------------------------
x:= Fml("wabbitts di");
long:= x=1;
short:= x=-1;
long;-short
-------------------------------
jose '-)
MetaStockTools.com
|
|
|
|