Jump to content

[ASK] CUSTOM DMI indi from Metastock >too>> Tradestation/Multicharts


Recommended Posts

Hi guys and gals I need to convert this ADX & DMI Metastock indicator to Tradestation.

 

I tried, but cant get the loop right that needs to take the place of the Sum function as in Metastock!!

 

Hope anyone can help me!!!! Thanx a trillioN!!

 

N:= 14;

 

TR := SUM(MAX(MAX(HIGH-LOW,ABS(HIGH-REF(CLOSE,1))),ABS(LOW-REF(CLOSE,1))),N);

HD := HIGH-REF(HIGH,1);

LD := REF(LOW,1)-LOW;

DMP:= SUM(IF(HD>0 & HD>LD,HD,0),N); //here lies the problem to get these 2 lines to tradestation

DMM:= SUM(IF(LD>0 & LD>HD,LD,0),N);

PDI:= DMP*100/TR;

MDI:= DMM*100/TR;

ADX:= MA(ABS(MDI-PDI)/(MDI+PDI)*100,N);

 

=D>=D>=D>

 

The build in DMI function in multicharts does not produce the same results as the above indicator I use in Metastock.

Link to comment
Share on other sites

Hi there,

 

investor can you give a code in metastock thanks

 

TR := SUM(MAX(MAX(HIGH-LOW,ABS(HIGH-REF(CLOSE,1))),ABS(LOW-REF(CLOSE,1))),N);

HD := HIGH-REF(HIGH,1);

LD := REF(LOW,1)-LOW;

DMP:= SUM(IF(HD>0 & HD>LD,HD,0),N); //here lies the problem to get these 2 lines to tradestation

DMM:= SUM(IF(LD>0 & LD>HD,LD,0),N);

PDI:= DMP*100/TR;

MDI:= DMM*100/TR;

ADX:= MA(ABS(MDI-PDI)/(MDI+PDI)*100,N);

Link to comment
Share on other sites

You could use DirMovement function to get the DMIs. The MDI in your code is probably the DMI-. You can also open up the built in function to see how it is programmed. As long as it arrives at the same value as the metastock adx, it should not matter if the code is not exactly the same, right?
Link to comment
Share on other sites

Nope the code they used build in in Multicharts for the DMI is totally different from mine. Here is what I came up with so far, but keep getting a floating point error!!>:)

 

BTW this is the function that I call into my system.

 

inputs:

PriceH( numericseries ),

PriceL( numericseries ),

PriceC( numericseries ),

Len( numericsimple ),

cDMIPlus( numericref ),

cDMIMinus( numericref ),

cADX(numericref);

 

variables: TR (0),HD(0), LD(0), DMP(0),DMM(0), PDI(0), MDI (0);

 

//////////////////-----1------//////////////////

TR = sum (maxlist (maxlist(PriceH-PriceL, AbsValue(PriceH-PriceC[1]) ) , AbsValue(PriceL-PriceC[1])),Len);

 

 

/////////////////------2------//////////////////

for Value1 = 0 to 13

begin

 

HD = PriceH - PriceH[1];

LD = PriceL[1] - PriceL;

 

if HD>0 and HD>LD then begin

DMP = DMP + HD;

end

else begin

DMP = 0;

end;

 

if LD>0 and LD>HD then begin

DMM = DMM + LD;

end

else begin

DMM = 0;

end;

end;

///////////////-------3-----//////////////////

cDMIPlus = DMP*100/TR;

cDMIMinus = DMM*100/TR;

 

cADX = Average(AbsValue(cDMIMinus-cDMIPlus)/(cDMIMinus+cDMIPlus)*100,Len);

 

MyADX = 1;

 

Hope you can assist me on this have really been struggeling to get this code to work and give similar result as in metastock!

Link to comment
Share on other sites

Maybe the floating point error is because of division by zero, at least it is a problem that needs to be fixed anyway.

 

Also you need to learn how mc/ts executes the program once for each bar and how that affects programming. By the looks of it Metastock executes program just once.

 

inputs:

PriceH( numericseries ),

PriceL( numericseries ),

PriceC( numericseries ),

Len( numericsimple ),

 

 

variables: TR (0),HD(0), LD(0), DMP(0),DMM(0), PDI(0), MDI (0);

var: cDMIPlus( 0 ), cDMIMinus( 0 ),cADX(0) ; //since you calculate these why were they inputs??

var: netDMI(0); // added this var to get rid of possible divzero error in cADX calculation

 

//////////////////-----1------//////////////////

TR = sum (maxlist (maxlist(PriceH-PriceL, AbsValue(PriceH-PriceC[1]) ) , AbsValue(PriceL-PriceC[1])),Len);

 

HD = PriceH - PriceH[1]; // these should be outside of loop as far as i can tell

LD = PriceL[1] - PriceL;

 

 

/////////////////------2------//////////////////

DMP = 0;

DMM = 0;

for Value1 = 0 to Len-1 // replaced your 13 with LEN-1 here

begin

 

 

if HD[value1]>0 and HD[value1]>LD[value1] then begin

DMP = DMP + HD[value1];

end

else begin

DMP = DMP + 0; // we are calculating a sum so dont reset DMP to 0

end;

 

if LD[value1]>0 and LD[value1]>HD[value1] then begin

DMM = DMM + LD[value1];

end

else begin

DMM = DMM + 0; // fixed this one also

end;

end;

///////////////-------3-----//////////////////

cDMIPlus =0;

cDMIMinus =0;

if TR<>0 then begin

cDMIPlus = DMP*100/TR;

cDMIMinus = DMM*100/TR;

end;

netDMI=0;

if cDMIMinus+cDMIPlus <> 0 then netDMI=(cDMIMinus-cDMIPlus)/(cDMIMinus+cDMIPlus);

cADX = Average(AbsValue(netDMI)*100,Len);

 

MyADX = 1;

Edited by leon1
Link to comment
Share on other sites

you could try to calculate tr in a for loop instead, maybe it makes a difference:

 

 

tr=0;

for Value1 = 0 to Len-1

begin

tr = tr +maxlist( (PriceH[value1]-PriceL[value1]) , AbsValue(PriceH[value1]-PriceC[value1+1]) , AbsValue(PriceL[value1]-PriceC[value1+1]) );

end;

 

If you are still getting problem try to set Len to 2 and calculate the values with a calculator for yourself to see which one has the correct values and then hope that it will give you some clue as to why the values differ from expected.

Edited by leon1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...