e-Invester Posted June 25, 2012 Report Share Posted June 25, 2012 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. Quote Link to comment Share on other sites More sharing options...
metal1713006284 Posted June 25, 2012 Report Share Posted June 25, 2012 (edited) investor can you give a right code in metastock thanks. this produce errors thanks pdi-An '(' must immediately follow a function name.) Edited June 25, 2012 by metal Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 25, 2012 Author Report Share Posted June 25, 2012 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); Quote Link to comment Share on other sites More sharing options...
leon1 Posted June 25, 2012 Report Share Posted June 25, 2012 why wouldnt you use the built in adx/dmi? Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 25, 2012 Author Report Share Posted June 25, 2012 why wouldnt you use the built in adx/dmi? My system is allready based on that calculation for the DMI and it works the best out of the 2 in backtests run over multiple intervals of 1 to 10yrs. That's the problem, so have to duplicate this one. Quote Link to comment Share on other sites More sharing options...
leon1 Posted June 26, 2012 Report Share Posted June 26, 2012 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? Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 27, 2012 Author Report Share Posted June 27, 2012 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! Quote Link to comment Share on other sites More sharing options...
leon1 Posted June 27, 2012 Report Share Posted June 27, 2012 (edited) 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 June 27, 2012 by leon1 e-Invester 1 Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 28, 2012 Author Report Share Posted June 28, 2012 Thanx a million Leon1, you really helped me alot on this one!!! hope I can someday repay the favor to you!! Best regards and happy trading wishes!=D> Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 28, 2012 Author Report Share Posted June 28, 2012 Problem is the TR = sum (maxlist (maxlist(PriceH-PriceL, AbsValue(PriceH-PriceC[1]) ) , AbsValue(PriceL-PriceC[1])),Len); still doesn't give the same result as the TR statement in Metastock..How that possible?? Quote Link to comment Share on other sites More sharing options...
leon1 Posted June 28, 2012 Report Share Posted June 28, 2012 (edited) 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 June 28, 2012 by leon1 e-Invester 1 Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 28, 2012 Author Report Share Posted June 28, 2012 will give it a try Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.