//+--------------------------------------------------------------------+ //| Copyright: (C) 2014, Miroslav Popov - All rights reserved! | //| 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 | //| another applications without a permission. 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 2014, Miroslav Popov" #property link "http://forexsb.com" #property version "1.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class RSquared : public Indicator { public: RSquared(SlotTypes slotType) { SlotType=slotType; IndicatorName="R-Squared"; WarningMessage = ""; IsAllowLTF = false; ExecTime = ExecutionTime_AtBarOpening; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void RSquared::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters MAMethod maMethod=(MAMethod)ListParam[1].Index; BasePrice basePrice=(BasePrice)ListParam[2].Index; int iRSPeriod = (int)NumParam[0].Value; int iMAPeriod= (int)NumParam[1].Value; double dLevel = NumParam[2].Value; int iPrvs=CheckParam[0].Checked ? 1 : 0; int iFirstBar=iRSPeriod+iMAPeriod+1; double adPrice[];Price(basePrice,adPrice); double adR[]; ArrayResize(adR,Data.Bars); ArrayInitialize(adR, 0); double adRR[]; ArrayResize(adRR,Data.Bars); ArrayInitialize(adRR, 0); double adAvgRR[]; ArrayResize(adAvgRR,Data.Bars); ArrayInitialize(adAvgRR, 0); double RCoeff[]; ArrayResize(RCoeff,Data.Bars); ArrayInitialize(RCoeff, 0); double X[];ArrayResize(X,Data.Bars); ArrayInitialize(X, 0); double Y[];ArrayResize(Y,Data.Bars); ArrayInitialize(Y, 0); double AvgX; double AvgP; double SumXP; double SumXX; double SumPP; double LowerEQ1; double LowerEQ2; double UpperEQ; double LowerEQ; for(int iBar=iFirstBar; iBar