usingcAlgo.API;usingcAlgo.API.Indicators;usingcAlgo.API.Internals;namespacecAlgo.Robots{// This sample cBot shows how to use the Linear Regression R Squared indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassLinearRegressionRSquaredSample:Robot{privatedouble_volumeInUnits;privateLinearRegressionRSquared_linearRegressionRSquared;privateSimpleMovingAverage_simpleMovingAverage;privateExponentialMovingAverage_exponentialMovingAverage;[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);_linearRegressionRSquared=Indicators.LinearRegressionRSquared(Bars.ClosePrices,20);_simpleMovingAverage=Indicators.SimpleMovingAverage(_linearRegressionRSquared.Result,10);_exponentialMovingAverage=Indicators.ExponentialMovingAverage(Bars.ClosePrices,20);}protectedoverridevoidOnBar(){if(Bars.ClosePrices.Last(1)>_exponentialMovingAverage.Result.Last(1)&&Bars.ClosePrices.Last(2)<=_exponentialMovingAverage.Result.Last(2)){ClosePositions(TradeType.Sell);if(_linearRegressionRSquared.Result.Last(1)>_simpleMovingAverage.Result.Last(1)){ExecuteMarketOrder(TradeType.Buy,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}elseif(Bars.ClosePrices.Last(1)<_exponentialMovingAverage.Result.Last(1)&&Bars.ClosePrices.Last(2)>=_exponentialMovingAverage.Result.Last(2)){ClosePositions(TradeType.Buy);if(_linearRegressionRSquared.Result.Last(1)>_simpleMovingAverage.Result.Last(1)){ExecuteMarketOrder(TradeType.Sell,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}}}privatevoidClosePositions(TradeTypetradeType){foreach(varpositioninBotPositions){if(position.TradeType!=tradeType)continue;ClosePosition(position);}}}}
The Result Series of the Linear Regression R Squared indicator.
Signature
1
publicabstractIndicatorDataSeriesResult{get;}
Return Value
IndicatorDataSeries
Examples
1 2 3 4 5 6 7 8 91011
privateLinearRegressionRSquaredrSquared;protectedoverridevoidOnStart(){// initialize rSquared indicatorrSquared=Indicators.LinearRegressionRSquared(MarketSeries.Close,9);}protectedoverridevoidOnTick(){// Print the last value of rSquared indicator to the logPrint("The current value of R Squared is {0}",rSquared.Result.LastValue);}