//+--------------------------------------------------------------------+ //| Copyright: (C) 2014 Forex Software Ltd. | //| Author: Jim Totaro original by mladen | //| 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 "1.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class AngleOfAveragesAOA : public Indicator { public: AngleOfAveragesAOA(SlotTypes slotType) { SlotType=slotType; IndicatorName="Angle Of Averages AOA"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_AtBarOpening; IsSeparateChart = true; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ void AngleOfAveragesAOA::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); double Pi = 3.14159265358979323846264338327950288; // Reading the parameters MAMethod maMethod=(MAMethod)ListParam[1].Index; BasePrice basePrice=(BasePrice)ListParam[2].Index; int period = (int)NumParam[0].Value; int AngleBars = (int)NumParam[1].Value; double AngleLevel = (double)NumParam[2].Value; int iPrvs=CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = period + iPrvs; double basePrc[];Price(basePrice,basePrc); double angleh[];ArrayResize(angleh,Data.Bars);ArrayInitialize(angleh,0); double angle[];ArrayResize(angle,Data.Bars);ArrayInitialize(angle,0); double ma[];ArrayResize(ma,Data.Bars);ArrayInitialize(ma,0); //--- calculate the indicator MovingAverage(period, 0, maMethod, basePrc, ma); for (int i = iFirstBar; i < Data.Bars; i++) { if (i <= AngleBars) continue; double change = ma[i]-ma[i-AngleBars]; double range = 0; for (int k = 0; k < 20 * AngleBars && (i - k - 1) >= 0; k++) { range+=MathMax(Data.High[i-k],Data.Close[i-k-1])-MathMin(Data.Low[i-k],Data.Close[i-k-1]); } range/=(double)AngleBars*20.0; if (range!=0) angle[i]=MathArctan(change/(range*AngleBars))*180.0/Pi; else angle[i]=0; angleh[i]=angle[i]; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Angle of Average"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,angleh); ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=iFirstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; // Sets the Component's type if(SlotType==SlotTypes_OpenFilter) { Component[1].DataType=IndComponentType_AllowOpenLong; Component[1].CompName="Is long entry allowed"; Component[2].DataType=IndComponentType_AllowOpenShort; Component[2].CompName="Is short entry allowed"; } else if(SlotType==SlotTypes_CloseFilter) { Component[1].DataType=IndComponentType_ForceCloseLong; Component[1].CompName="Close out long position"; Component[2].DataType=IndComponentType_ForceCloseShort; Component[2].CompName="Close out short position"; } if(ListParam[0].Text=="AOA line rises") { OscillatorLogic(iFirstBar,iPrvs,angleh,0,0,Component[1],Component[2],IndicatorLogic_The_indicator_rises); } else if(ListParam[0].Text=="AOA line falls") { OscillatorLogic(iFirstBar,iPrvs,angleh,0,0,Component[1],Component[2],IndicatorLogic_The_indicator_falls); } else if(ListParam[0].Text=="AOA line is higher than the Level line") { OscillatorLogic(iFirstBar,iPrvs,angleh,AngleLevel,-AngleLevel,Component[1],Component[2],IndicatorLogic_The_indicator_is_higher_than_the_level_line); } else if(ListParam[0].Text=="AOA line is lower than the Level line") { OscillatorLogic(iFirstBar,iPrvs,angleh,AngleLevel,-AngleLevel,Component[1],Component[2],IndicatorLogic_The_indicator_is_lower_than_the_level_line); } else if(ListParam[0].Text=="AOA line crosses the Level line upward") { OscillatorLogic(iFirstBar,iPrvs,angleh,AngleLevel,-AngleLevel,Component[1],Component[2],IndicatorLogic_The_indicator_crosses_the_level_line_upward); } else if(ListParam[0].Text=="AOA line crosses the Level line downward") { OscillatorLogic(iFirstBar,iPrvs,angleh,AngleLevel,-AngleLevel,Component[1],Component[2],IndicatorLogic_The_indicator_crosses_the_level_line_downward); } else if(ListParam[0].Text=="AOA line changes its direction upward") { OscillatorLogic(iFirstBar,iPrvs,angleh,0,0,Component[1],Component[2],IndicatorLogic_The_indicator_changes_its_direction_upward); } else if(ListParam[0].Text=="AOA line changes its direction downward") { OscillatorLogic(iFirstBar,iPrvs,angleh,0,0,Component[1],Component[2],IndicatorLogic_The_indicator_changes_its_direction_downward); } } //+------------------------------------------------------------------+