Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// Create subscription and bind indicator
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(_bollingerBands, ProcessCandle)
.BindEx(_bollingerBands, ProcessCandle)
.Start();

// Setup chart visualization if available
Expand All @@ -83,7 +83,7 @@
}
}

private void ProcessCandle(ICandleMessage candle, decimal middleBand, decimal upperBand, decimal lowerBand)
private void ProcessCandle(ICandleMessage candle, IIndicatorValue bollingerValue)
{
// Skip unfinished candles
if (candle.State != CandleStates.Finished)
Expand All @@ -93,14 +93,16 @@
if (!IsFormedAndOnlineAndAllowTrading())
return;

var typed = (BollingerBandsValue)bollingerValue;

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyClassicStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyClassicStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyClassicStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyClassicStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

// Trading logic:
// Sell when price is at or above the upper band
if (candle.ClosePrice >= upperBand && Position >= 0)
if (candle.ClosePrice >= typed.UpBand && Position >= 0)
{
SellMarket(Volume + Math.Abs(Position));
}
// Buy when price is at or below the lower band
else if (candle.ClosePrice <= lowerBand && Position <= 0)
else if (candle.ClosePrice <= typed.LowBand && Position <= 0)
{
BuyMarket(Volume + Math.Abs(Position));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// Create subscription and bind indicator
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(_bollingerBands, ProcessCandle)
.BindEx(_bollingerBands, ProcessCandle)
.Start();

// Setup chart visualization if available
Expand All @@ -83,7 +83,7 @@
}
}

private void ProcessCandle(ICandleMessage candle, decimal middleBand, decimal upperBand, decimal lowerBand)
private void ProcessCandle(ICandleMessage candle, IIndicatorValue bollingerValue)
{
// Skip unfinished candles
if (candle.State != CandleStates.Finished)
Expand All @@ -93,14 +93,16 @@
if (!IsFormedAndOnlineAndAllowTrading())
return;

var typed = (BollingerBandsValue)bollingerValue;

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyLowBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyLowBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyLowBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyLowBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

// Trading logic:
// Sell when price touches the lower band (only when no position)
if (candle.ClosePrice <= lowerBand && Position == 0)
if (candle.ClosePrice <= typed.LowBand && Position == 0)
{
SellMarket(Volume);
}
// Buy to close position when price reaches the middle band (only when short)
else if (candle.ClosePrice >= middleBand && Position < 0)
else if (candle.ClosePrice >= typed.MovingAverage && Position < 0)
{
BuyMarket(Math.Abs(Position));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// Create subscription and bind indicator
var subscription = SubscribeCandles(CandleType);
subscription
.Bind(_bollingerBands, ProcessCandle)
.BindEx(_bollingerBands, ProcessCandle)
.Start();

// Setup chart visualization if available
Expand All @@ -83,7 +83,7 @@
}
}

private void ProcessCandle(ICandleMessage candle, decimal middleBand, decimal upperBand, decimal lowerBand)
private void ProcessCandle(ICandleMessage candle, IIndicatorValue bollingerValue)
{
// Skip unfinished candles
if (candle.State != CandleStates.Finished)
Expand All @@ -93,14 +93,16 @@
if (!IsFormedAndOnlineAndAllowTrading())
return;

var typed = (BollingerBandsValue)bollingerValue;

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyUpBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyUpBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyUpBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 96 in Samples/06_Strategies/02_HistoryBollingerBands/BollingerStrategyUpBandStrategy.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'BollingerBandsValue' could not be found (are you missing a using directive or an assembly reference?)

// Trading logic:
// Buy when price touches the upper band (only when no position)
if (candle.ClosePrice >= upperBand && Position == 0)
if (candle.ClosePrice >= typed.UpBand && Position == 0)
{
BuyMarket(Volume);
}
// Sell to close position when price reaches the middle band (only when long)
else if (candle.ClosePrice <= middleBand && Position > 0)
else if (candle.ClosePrice <= typed.MovingAverage && Position > 0)
{
SellMarket(Math.Abs(Position));
}
Expand Down
Loading