[Parameter("Period", DefaultValue = 14)]publicintPeriod{get;set;}protectedoverridevoidOnStart(){// initialize a new instance of LinearRegressionIntercept indicator class_linearRegressionIntercept=Indicators.LinearRegressionIntercept(MarketSeries.Close,Period);}
usingcAlgo.API;usingcAlgo.API.Indicators;usingcAlgo.API.Internals;namespacecAlgo.Robots{// This sample cBot shows how to use the Linear Regression Intercept indicator[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]publicclassLinearRegressionInterceptSample:Robot{privatedouble_volumeInUnits;privateLinearRegressionIntercept_linearRegressionIntercept;[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);_linearRegressionIntercept=Indicators.LinearRegressionIntercept(Bars.ClosePrices,20);}protectedoverridevoidOnBar(){if(Bars.ClosePrices.Last(1)>_linearRegressionIntercept.Result.Last(1)&&Bars.ClosePrices.Last(2)<=_linearRegressionIntercept.Result.Last(2)){ClosePositions(TradeType.Sell);ExecuteMarketOrder(TradeType.Buy,SymbolName,_volumeInUnits,Label,StopLossInPips,TakeProfitInPips);}elseif(Bars.ClosePrices.Last(1)<_linearRegressionIntercept.Result.Last(1)&&Bars.ClosePrices.Last(2)>=_linearRegressionIntercept.Result.Last(2)){ClosePositions(TradeType.Buy);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 Intercept Indicator
Signature
1
publicabstractIndicatorDataSeriesResult{get;}
Return Value
IndicatorDataSeries
Examples
1234567
publicoverridevoidCalculate(intindex){// Result of _linearRegressionIntercept at the current indexdoubleresult=_linearRegressionIntercept.Result[index];// Print the current result to the logPrint("Linear Regression Intercept at the current index is = {0}",result);}