Skip to content

Commit 58a3548

Browse files
authored
Merge branch 'master' into x5xkuk-codex/create-gold-trading-algo-bot-for-ctrader
2 parents 51f2655 + fd920f6 commit 58a3548

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Robots/XAUUSD Trend Strategy/XAUUSD Trend Strategy/GoldTrendStrategy.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ protected override void OnStart()
9191

9292
if (!UseDynamicVolume)
9393
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
94+
9495
_fastMa = Indicators.SimpleMovingAverage(FastMaSource, FastMaPeriod);
9596
_slowMa = Indicators.SimpleMovingAverage(SlowMaSource, SlowMaPeriod);
9697
_rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, RsiPeriod);
@@ -133,12 +134,9 @@ protected override void OnTick()
133134

134135
foreach (var position in Positions.FindAll(Label))
135136
{
136-
double? newStopLoss;
137-
138-
if (position.TradeType == TradeType.Buy)
139-
newStopLoss = Symbol.Bid - TrailingStopInPips * Symbol.PipSize;
140-
else
141-
newStopLoss = Symbol.Ask + TrailingStopInPips * Symbol.PipSize;
137+
double? newStopLoss = position.TradeType == TradeType.Buy
138+
? Symbol.Bid - TrailingStopInPips * Symbol.PipSize
139+
: Symbol.Ask + TrailingStopInPips * Symbol.PipSize;
142140

143141
if (position.TradeType == TradeType.Buy && (position.StopLoss == null || newStopLoss > position.StopLoss))
144142
ModifyPosition(position, newStopLoss, position.TakeProfit);
@@ -163,10 +161,8 @@ private void ClosePositions(TradeType tradeType)
163161
{
164162
foreach (var position in Positions.FindAll(Label))
165163
{
166-
if (position.TradeType != tradeType)
167-
continue;
168-
169-
ClosePosition(position);
164+
if (position.TradeType == tradeType)
165+
ClosePosition(position);
170166
}
171167
}
172168
}

0 commit comments

Comments
 (0)