Welles Wilder's Directional Movement System uses three indicators to determine whether the market is trending, and in which direction, and sends trading signals accordingly. A buy signal occurs when +DI line crosses above -DI line. A sell signal occurs when -DI line crosses below +DI line.
usingcAlgo.API;usingcAlgo.API.Indicators;namespacecAlgo.Robots{// This sample cBot shows how to use the Directional Movement System indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassDirectionalMovementSystemSample:Robot{privatedouble_volumeInUnits;privateDirectionalMovementSystem_directionalMovementSystem;[Parameter("Volume (Lots)", DefaultValue = 0.01)]publicdoubleVolumeInLots{get;set;}[Parameter("Stop Loss (Pips)", DefaultValue = 10)]publicdoubleStopLossInPips{get;set;}[Parameter("Take Profit (Pips)", DefaultValue = 10)]publicdoubleTakeProfitInPips{get;set;}[Parameter("Label", DefaultValue = "Sample")]publicstringLabel{get;set;}publicPosition[]BotPositions{get{returnPositions.FindAll(Label);}}protectedoverridevoidOnStart(){_volumeInUnits=Symbol.QuantityToVolumeInUnits(VolumeInLots);_directionalMovementSystem=Indicators.DirectionalMovementSystem(20);}protectedoverridevoidOnBar(){if(_directionalMovementSystem.ADX.Last(1)<25)return;if(_directionalMovementSystem.DIPlus.Last(1)>_directionalMovementSystem.DIMinus.Last(1)&&_directionalMovementSystem.DIPlus.Last(2)<=_directionalMovementSystem.DIMinus.Last(2)){ClosePositions(TradeType.Sell);ExecuteMarketOrder(TradeType.Buy,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}elseif(_directionalMovementSystem.DIPlus.Last(1)<_directionalMovementSystem.DIMinus.Last(1)&&_directionalMovementSystem.DIPlus.Last(2)>=_directionalMovementSystem.DIMinus.Last(2)){ClosePositions(TradeType.Buy);ExecuteMarketOrder(TradeType.Sell,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}privatevoidClosePositions(TradeTypetradeType){foreach(varpositioninBotPositions){if(position.TradeType!=tradeType)continue;ClosePosition(position);}}}}
The Average Directional Movement Index (ADX) indicates whether the market is trending or ranging.
Signature
1
publicabstractIndicatorDataSeriesADX{get;}
Return Value
IndicatorDataSeries
Examples
1 2 3 4 5 6 7 8 9101112131415
//...[Robot]publicclassSampleRobot:Robot//...privateDirectionalMovementSystem_dms;protectedoverridevoidInitialize(){_dms=Indicators.DirectionalMovementSystem(Period);}//...protectedoverridevoidOnBar(){Print("The Current Average Directional Movement Index is: {0}",_dms.ADX.LastValue);}//...
The Positive Direction Indicator (+DI) indicates upward trend movement.
Signature
1
publicabstractIndicatorDataSeriesDIPlus{get;}
Return Value
IndicatorDataSeries
Examples
1 2 3 4 5 6 7 8 9101112131415
//...[Robot]publicclassSampleRobot:Robot//...privateDirectionalMovementSystem_dms;protectedoverridevoidInitialize(){_dms=Indicators.DirectionalMovementSystem(Period);}//...protectedoverridevoidOnBar(){Print("The Current Positive Direction Indicator (+DI) is: {0}",_dms.DIPlus.LastValue);}//...
The Negative Direction Indicator (-DI) indicates downward trend movement.
Signature
1
publicabstractIndicatorDataSeriesDIMinus{get;}
Return Value
IndicatorDataSeries
Examples
1 2 3 4 5 6 7 8 9101112131415
//...[Robot]publicclassSampleRobot:Robot//...privateDirectionalMovementSystem_dms;protectedoverridevoidInitialize(){_dms=Indicators.DirectionalMovementSystem(Period);}//...protectedoverridevoidOnBar(){Print("The Current Negative Direction Indicator (-DI) is: {0}",_dms.DIMinus.LastValue);}//...