请问TB的DMI算法与其他软件DMI算法区别在哪里? [开拓者 TB]
- 咨询内容:
http://bbs.tb18.net/forum.php?mo ... 7&highlight=dmi
这个页面下版主写了个DMI代码。应该是移植于TS的?- Params
- Numeric Length(14);
- NumericRef oDMIPlus;
- NumericRef oDMIMinus;
- NumericRef oDMI;
- NumericRef oADX;
- NumericRef oADXR;
- NumericRef oVolty;
- Vars
- NumericSeries sDMI;
- NumericSeries sADX;
- Numeric sADX0;
- NumericSeries sVolty;
- Numeric PlusDM;
- Numeric MinusDM;
- Numeric UpperMove;
- Numeric LowerMove;
- Numeric SumPlusDM(0);
- Numeric SumMinusDM(0);
- Numeric SumTR(0);
- NumericSeries AvgPlusDM;
- NumericSeries AvgMinusDM;
- Numeric SF; // smoothing factor
- Numeric Divisor;
- Numeric i;
- NumericSeries TRValue;
- Begin
- SF = 1/length;
- TRValue = TrueRange;
- If(CurrentBar == Length)
- {
- for i = 0 To Length - 1
- {
- PlusDM = 0 ;
- MinusDM = 0 ;
- UpperMove = High[i] - High[ i + 1 ] ;
- LowerMove = Low[ i + 1 ] - Low[i] ;
- if (UpperMove > LowerMove and UpperMove > 0 )
- {
- PlusDM = UpperMove;
- }else if (LowerMove > UpperMove and LowerMove > 0)
- {
- MinusDM = LowerMove ;
- }
- SumPlusDM = SumPlusDM + PlusDM ;
- SumMinusDM = SumMinusDM + MinusDM ;
- SumTR = SumTR + TRValue[i] ;
- }
- AvgPlusDM = SumPlusDM / Length ;
- AvgMinusDM = SumMinusDM / Length ;
- sVolty = SumTR / Length ;
- }Else if(CurrentBar > Length)
- {
- PlusDM = 0 ;
- MinusDM = 0 ;
- UpperMove = High - High[1] ;
- LowerMove = Low[1] - Low ;
- if (UpperMove > LowerMove and UpperMove > 0 )
- {
- PlusDM = UpperMove;
- }else if (LowerMove > UpperMove and LowerMove > 0 )
- {
- MinusDM = LowerMove ;
- }
- AvgPlusDM = AvgPlusDM[1] + SF * ( PlusDM - AvgPlusDM[1] ) ;
- AvgMinusDM = AvgMinusDM[1] + SF * ( MinusDM - AvgMinusDM[1] ) ;
- sVolty = sVolty[1] + SF * ( TRValue - sVolty[1] ) ;
- }Else
- {
- oDMIPlus = InvalidNumeric;
- oDMIMinus = InvalidNumeric;
- oDMI = InvalidNumeric;
- oADX = InvalidNumeric;
- oADXR = InvalidNumeric;
- oVolty = InvalidNumeric;
- Return True;
- }
-
- if (sVolty > 0)
- {
- oDMIPlus = 100 * AvgPlusDM / sVolty ;
- oDMIMinus = 100 * AvgMinusDM / sVolty ;
- }else
- {
- oDMIPlus = 0 ;
- oDMIMinus = 0 ;
- }
- Divisor = oDMIPlus + oDMIMinus ;
- if (Divisor > 0)
- {
- sDMI = 100 * Abs( oDMIPlus - oDMIMinus ) / Divisor;
- }else
- {
- sDMI = 0 ;
- }
- sADX0 = Cum( sDMI ) / CurrentBar ;
- if(CurrentBar > 0)
- {
- if (CurrentBar <= Length)
- {
- sADX = sADX0 ;
- oADXR = ( sADX + sADX[ CurrentBar - 1 ] ) * 0.5 ;
- }else
- {
- sADX = sADX[1] + SF * ( sDMI - sADX[1] ) ;
- oADXR = ( sADX + sADX[ Length - 1 ] ) * 0.5 ;
- }
- }
- oVolty = sVolty;
- oDMI = sDMI;
- oADX = sADX;
- Return True;
- Params
- TB技术人员:
顶起,请管理员回答!
- TB客服:
我们提供的代码移植于TS,至于文华移植的代码就不知道算法是什么样的了
- 网友回复:
nopain 发表于 2013-7-25 14:36
我们提供的代码移植于TS,至于文华移植的代码就不知道算法是什么样的了
Params
Numeric N(22);
Numeric M(6);
Numeric k_ADXRUp(70);
Numeric k_ADXRDown(30);
Vars
numericseries TR;
numericseries HD;
numericseries LD;
numericseries DMP;
numericseries DMM;
numericseries PDI;
numericseries MDI;
NumericSeries ADX;
NumericSeries ADXR;
Begin
//计算ADX公式
TR = AvgTrueRange(N);
HD = HIGH-HIGH[1];
LD = LOW[1]-LOW;
DMP = XAverage(IIF(HD>0&&HD>LD,HD,0),N);
DMM = XAverage(IIF(LD>0&&LD>HD,LD,0),N);
PDI = DMP*100/TR;
MDI = DMM*100/TR;
ADX = ABS(MDI-PDI)/(MDI+PDI)*100;
ADXR = Average(ADX,M);
PlotNumeric("PDI",PDI);
PlotNumeric("MDI",MDI);
PlotNumeric("ADX", adx);
PlotNumeric("ADXR",ADXR);
End
文华的代码就是这么短一段
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 1145508240 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容