Skip to content

Commit

Permalink
63267897: correction in code
Browse files Browse the repository at this point in the history
  • Loading branch information
LucyFreelanceDeveloper committed Jun 9, 2024
1 parent eda8c82 commit f3b7488
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class BollingerBandTrendFollow_cBot : Robot
public int Length { get; set; }

[Parameter("Upper", Group ="Basic settings", DefaultValue = 1)]
public int Upper { get; set; }
public int MultiplierUpper { get; set; }

[Parameter("Lower", Group ="Basic settings", DefaultValue = 0.5)]
public double Lower { get; set; }
public double MultiplierLower { get; set; }

[Parameter("Risk percentage", Group ="Basic settings", DefaultValue = 2.5)]
public double RiskPercentage { get; set; }
Expand All @@ -48,24 +48,23 @@ protected override void OnStart()

}

protected override void OnBar()
protected override void OnBarClosed()
{
// **********************************
// Perform calculations and analysis
// **********************************

DataSeries symbolClosePrices = MarketData.GetBars(TimeFrame.Daily, BenchmarkSymbol).ClosePrices;
StandardDeviation std = Indicators.StandardDeviation(symbolClosePrices, Length, MovingAverageType.Simple);
BollingerBands bollingerBands = Indicators.BollingerBands(symbolClosePrices, Length, std.Result[0], MovingAverageType.Simple);
double stdLastValue = Indicators.StandardDeviation(Bars.ClosePrices, Length, MovingAverageType.Simple).Result.LastValue;
double smaLastValue = Indicators.SimpleMovingAverage(Bars.ClosePrices, Length).Result.LastValue;

IndicatorDataSeries topBand = bollingerBands.Top;
IndicatorDataSeries bottomBand = bollingerBands.Bottom;
double upperBand = smaLastValue + MultiplierUpper * stdLastValue;
double lowerBand = smaLastValue + MultiplierLower * stdLastValue;

string label = $"BollingerBandTrendFollow_cBot-{Symbol.Name}";

// Filter
DataSeries benchmarkSymbolClosePrices = MarketData.GetBars(TimeFrame.Daily, BenchmarkSymbol).ClosePrices;
double benchmarkSymbolClose = MarketData.GetBars(TimeFrame.Daily, BenchmarkSymbol).ClosePrices.LastValue;
double benchmarkSymbolClose =benchmarkSymbolClosePrices.LastValue;
bool filter = EnableFilter ? benchmarkSymbolClose >= Indicators.SimpleMovingAverage(benchmarkSymbolClosePrices, 200).Result.LastValue: true;

// Check position
Expand All @@ -76,12 +75,10 @@ protected override void OnBar()
double qty = ((RiskPercentage/100) * Account.Balance) / (AtrMultiplier * Indicators.AverageTrueRange(AtrLength, MovingAverageType.Simple).Result.LastValue);
double qtyInLots = ((int)(qty /Symbol.VolumeInUnitsStep)) * Symbol.VolumeInUnitsStep;

DataSeries close = Bars.ClosePrices;
double lastClose = Bars.ClosePrices.LastValue;

bool crossOverUpperBand = close.Last(1) < topBand.Last(1) && close.Last(0) > topBand.Last(0);
bool crossOverLowerBand = close.Last(1) > bottomBand.Last(1) && close.Last(0) < bottomBand.Last(0);
bool buyCondition = crossOverUpperBand && !isOpenPosition && filter;
bool sellCondition = crossOverLowerBand && isOpenPosition;
bool buyCondition = lastClose > upperBand && !isOpenPosition && filter;
bool sellCondition = lastClose < lowerBand && isOpenPosition;


// ********************************
Expand Down

0 comments on commit f3b7488

Please sign in to comment.