6
6
// profit of any kind. Use it at your own risk.
7
7
//
8
8
// -------------------------------------------------------------------------------------------------
9
-
10
9
using System ;
11
10
using cAlgo . API ;
12
11
using cAlgo . API . Indicators ;
13
12
using cAlgo . API . Internals ;
13
+ using cAlgo . API ;
14
+ using cAlgo . API . Indicators ;
14
15
15
16
namespace cAlgo . Robots
16
17
{
@@ -23,7 +24,7 @@ public class GoldTrendStrategy : Robot
23
24
private RelativeStrengthIndex _rsi ;
24
25
private Supertrend _supertrend ;
25
26
private MacdCrossOver _macd ;
26
-
27
+
27
28
[ Parameter ( "Fast MA Source" , Group = "Fast MA" ) ]
28
29
public DataSeries FastMaSource { get ; set ; }
29
30
@@ -75,6 +76,9 @@ public class GoldTrendStrategy : Robot
75
76
[ Parameter ( "Trailing Stop (Pips)" , DefaultValue = 50 , Group = "Trade" , MinValue = 0 ) ]
76
77
public double TrailingStopInPips { get ; set ; }
77
78
79
+ [ Parameter ( "Volume (Lots)" , DefaultValue = 0.01 , Group = "Trade" ) ]
80
+ public double VolumeInLots { get ; set ; }
81
+
78
82
[ Parameter ( "Stop Loss (Pips)" , DefaultValue = 100 , Group = "Trade" , MinValue = 1 ) ]
79
83
public double StopLossInPips { get ; set ; }
80
84
@@ -96,6 +100,10 @@ protected override void OnStart()
96
100
_rsi = Indicators . RelativeStrengthIndex ( Bars . ClosePrices , RsiPeriod ) ;
97
101
_supertrend = Indicators . Supertrend ( SupertrendPeriods , SupertrendMultiplier ) ;
98
102
_macd = Indicators . MacdCrossOver ( Bars . ClosePrices , MacdLongCycle , MacdShortCycle , MacdSignalPeriods ) ;
103
+ _volumeInUnits = Symbol . QuantityToVolumeInUnits ( VolumeInLots ) ;
104
+ _fastMa = Indicators . SimpleMovingAverage ( FastMaSource , FastMaPeriod ) ;
105
+ _slowMa = Indicators . SimpleMovingAverage ( SlowMaSource , SlowMaPeriod ) ;
106
+ _rsi = Indicators . RelativeStrengthIndex ( MarketSeries . Close , RsiPeriod ) ;
99
107
100
108
_fastMa . Result . Line . Color = Color . Gold ;
101
109
_slowMa . Result . Line . Color = Color . DarkOrange ;
@@ -156,6 +164,21 @@ private double GetTradeVolume()
156
164
return Symbol . NormalizeVolumeInUnits ( units , RoundingMode . ToNearest ) ;
157
165
}
158
166
167
+ var inUptrend = _fastMa . Result . LastValue > _slowMa . Result . LastValue ;
168
+ var inDowntrend = _fastMa . Result . LastValue < _slowMa . Result . LastValue ;
169
+
170
+ if ( inUptrend && _rsi . Result . LastValue < Oversold )
171
+ {
172
+ ClosePositions( TradeType . Sell ) ;
173
+ ExecuteMarketOrder( TradeType . Buy , SymbolName , _volumeInUnits , Label , StopLossInPips , TakeProfitInPips ) ;
174
+ }
175
+ else if ( inDowntrend && _rsi . Result . LastValue > Overbought )
176
+ {
177
+ ClosePositions ( TradeType . Buy ) ;
178
+ ExecuteMarketOrder ( TradeType . Sell , SymbolName , _volumeInUnits , Label , StopLossInPips , TakeProfitInPips ) ;
179
+ }
180
+ }
181
+
159
182
private void ClosePositions ( TradeType tradeType )
160
183
{
161
184
foreach ( var position in Positions . FindAll ( Label ) )
0 commit comments