//+--------------------------------------------------------------------+ //| Copyright: (C) 2014 Forex Software Ltd. | //| Website: http://forexsb.com/ | //| Support: http://forexsb.com/forum/ | //| License: Proprietary under the following circumstances: | //| | //| This code is a part of Forex Strategy Builder. It is free for | //| use as an integral part of Forex Strategy Builder. | //| One can modify it in order to improve the code or to fit it for | //| personal use. This code or any part of it cannot be used in | //| other applications without a permission. | //| The contact information cannot be changed. | //| | //| NO LIABILITY FOR CONSEQUENTIAL DAMAGES | //| | //| In no event shall the author be liable for any damages whatsoever | //| (including, without limitation, incidental, direct, indirect and | //| consequential damages, damages for loss of business profits, | //| business interruption, loss of business information, or other | //| pecuniary loss) arising out of the use or inability to use this | //| product, even if advised of the possibility of such damages. | //+--------------------------------------------------------------------+ #property copyright "Copyright (C) 2014 Forex Software Ltd." #property link "http://forexsb.com" #property version "2.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class LinearRegressionValueV2 : public Indicator { public: LinearRegressionValueV2(SlotTypes slotType) { SlotType=slotType; IndicatorName="Linear Regression Value V2"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_AtBarOpening; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void LinearRegressionValueV2::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters BasePrice basePrice = (BasePrice)ListParam[2].Index; int LRVPeriod = (int)NumParam[0].Value; double dLevel = NumParam[1].Value; MAMethod maMethod = (MAMethod)ListParam[3].Index; MAMethod maMethodf = (MAMethod)ListParam[1].Index; MAMethod maMethods = (MAMethod)ListParam[4].Index; int LRVForecast= (int)NumParam[2].Value; int iMomentum = (int)NumParam[3].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // Calculation double Zscore[];ArrayResize(Zscore,Data.Bars);ArrayInitialize(Zscore,0); double buffer[];ArrayResize(buffer,Data.Bars);ArrayInitialize(buffer,0); double Trigger[];ArrayResize(Trigger,Data.Bars);ArrayInitialize(Trigger,0); double stdevi[];ArrayResize(stdevi,Data.Bars);ArrayInitialize(stdevi,0); int iFirstBar = LRVPeriod + iMomentum + 2; double adBasePrice[];Price(basePrice,adBasePrice); double sumXSqr = LRVPeriod * (LRVPeriod-1) * (2*LRVPeriod-1) / 6.0; double sumX = LRVPeriod * (LRVPeriod-1) * 0.5; double price[];ArrayResize(price,Data.Bars);ArrayInitialize(price,0); MovingAverage(1, 0, maMethod, adBasePrice,price); for(int iBar = iFirstBar; iBar < Data.Bars; iBar++) { double sumXY = 0; double sumY = 0; // // // // // for (int k=0; k