Angle of Averages (AOA) by jetaro

57117 downloads / 8559 views / Created: 06.02.2017
 Average Rating: 0

Indicator Description

this indicator gives the angle in degrees of the moving average chosen.

Comments

fixed 2/14/2017. Exported strategy should compile now.
fixed an issue where the mqh wasn't making trades.
El indicador tiene valores en grados -90 , 0, 90, pero no permite valores negativos.
El indicador no detecta cuando los grados asciende.
The indicator has values in degrees -90, 0, 90, but does not allow negative values.
The indicator does not detect when the degrees rise
//============================================================== // Forex Strategy Builder // Copyright © Miroslav Popov. All rights reserved. //============================================================== // THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, // EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. //============================================================== using System; using System.Drawing; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Store { public class AOA : Indicator { public AOA() { IndicatorName = "Angle Of Averages AOA"; PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter; SeparatedChart = true; SeparatedChartMinValue = -90; SeparatedChartMaxValue = 90; IndicatorAuthor = "Jim Totaro, original by mladen"; IndicatorVersion = "1.01"; IndicatorDescription = "Angle of Averages."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "AOA line rises", "AOA line falls", "AOA line is higher than the Level line", "AOA line is lower than the Level line", "AOA line crosses the Level line upward", "AOA line crosses the Level line downward", "AOA line changes its direction upward", "AOA line changes its direction downward" }; IndParam.ListParam[0].Index = 0; IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index]; IndParam.ListParam[0].Enabled = true; IndParam.ListParam[0].ToolTip = "Logic of application of the indicator."; IndParam.ListParam[1].Caption = "MA Smoothing method"; IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod)); IndParam.ListParam[1].Index = (int)MAMethod.Smoothed; IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index]; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "The Moving Average method used for smoothing AOA value."; IndParam.ListParam[2].Caption = "Base price"; IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice)); IndParam.ListParam[2].Index = (int)BasePrice.Close; IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index]; IndParam.ListParam[2].Enabled = true; IndParam.ListParam[2].ToolTip = "The price AOA is based on."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "MA Smoothing period"; IndParam.NumParam[0].Value = 34; IndParam.NumParam[0].Min = 5; IndParam.NumParam[0].Max = 200; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "The period for smoothing of the moving average."; IndParam.NumParam[1].Caption = "Bars for Angle Calculation"; IndParam.NumParam[1].Value = 6; IndParam.NumParam[1].Min = 5; IndParam.NumParam[1].Max = 200; IndParam.NumParam[1].Enabled = true; IndParam.NumParam[1].ToolTip = "The number of bars to calculate AOA value."; IndParam.NumParam[2].Caption = "Level"; IndParam.NumParam[2].Value = 8; IndParam.NumParam[2].Min = 0; IndParam.NumParam[2].Max = 90; IndParam.NumParam[2].Enabled = true; IndParam.NumParam[2].ToolTip = "Angle signal level in degrees."; // The CheckBox parameters IndParam.CheckParam[0].Caption = "Use previous bar value"; IndParam.CheckParam[0].Enabled = true; IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar."; } public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var Pi = 3.14159265358979323846264338327950288; // Reading the parameters var maMethod = (MAMethod)IndParam.ListParam[1].Index; var basePrice = (BasePrice)IndParam.ListParam[2].Index; var period = (int)IndParam.NumParam[0].Value; var AngleBars = (int)IndParam.NumParam[1].Value; double AngleLevel = IndParam.NumParam[2].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + previous; double[] price = Price(basePrice); var pos = new double[Bars]; var neg = new double[Bars]; var AOA = new double[Bars]; var angleh = new double[Bars]; var anglec = new double[Bars]; var angle = new double[Bars]; double[] ma = MovingAverage(period, 0, maMethod, price); for (int i = firstBar; i < 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 += Math.Max(High[i - k], Close[i - k - 1]) - Math.Min(Low[i - k], Close[i - k - 1]); } range /= (double)AngleBars * 20.0; if (range != 0) angle[i] = Math.Atan(change / (range * AngleBars)) * 180.0 / Pi; else angle[i] = 0; angleh[i] = angle[i]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Angle of Average"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = firstBar; Component[0].Value = angleh; Component[1] = new IndicatorComp(); Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = firstBar; Component[1].Value = new double[Bars]; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = firstBar; Component[2].Value = new double[Bars]; // 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"; } // Calculation of the logic var logicRule = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "AOA line rises": logicRule = IndicatorLogic.The_indicator_rises; SpecialValues = new double[] { 0 }; break; case "AOA line falls": logicRule = IndicatorLogic.The_indicator_falls; SpecialValues = new double[] { 0 }; break; case "AOA line is higher than the Level line": logicRule = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new[] { AngleLevel, - AngleLevel }; break; case "AOA line is lower than the Level line": logicRule = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new[] { AngleLevel, - AngleLevel }; break; case "AOA line crosses the Level line upward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new[] { AngleLevel, - AngleLevel }; break; case "AOA line crosses the Level line downward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new[] { AngleLevel, - AngleLevel }; break; case "AOA line changes its direction upward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[] { 0 }; break; case "AOA line changes its direction downward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[] { 0 }; break; } OscillatorLogic(firstBar, previous, angleh, AngleLevel, - AngleLevel, ref Component[1], ref Component[2], logicRule); } public override void SetDescription() { string longLevel = IndParam.NumParam[1].ValueToString; string shortLevel = IndParam.NumParam[1].AnotherValueToString(100 - IndParam.NumParam[1].Value); EntryFilterLongDescription = ToString() + " "; EntryFilterShortDescription = ToString() + " "; ExitFilterLongDescription = ToString() + " "; ExitFilterShortDescription = ToString() + " "; switch (IndParam.ListParam[0].Text) { case "AOA rises": EntryFilterLongDescription += "rises"; EntryFilterShortDescription += "falls"; ExitFilterLongDescription += "rises"; ExitFilterShortDescription += "falls"; break; case "AOA falls": EntryFilterLongDescription += "falls"; EntryFilterShortDescription += "rises"; ExitFilterLongDescription += "falls"; ExitFilterShortDescription += "rises"; break; case "AOA is higher than the Level line": EntryFilterLongDescription += "is higher than the Level " + longLevel; EntryFilterShortDescription += "is lower than the Level " + shortLevel; ExitFilterLongDescription += "is higher than the Level " + longLevel; ExitFilterShortDescription += "is lower than the Level " + shortLevel; break; case "AOA is lower than the Level line": EntryFilterLongDescription += "is lower than the Level " + longLevel; EntryFilterShortDescription += "is higher than the Level " + shortLevel; ExitFilterLongDescription += "is lower than the Level " + longLevel; ExitFilterShortDescription += "is higher than the Level " + shortLevel; break; case "AOA crosses the Level line upward": EntryFilterLongDescription += "crosses the Level " + longLevel + " upward"; EntryFilterShortDescription += "crosses the Level " + shortLevel + " downward"; ExitFilterLongDescription += "crosses the Level " + longLevel + " upward"; ExitFilterShortDescription += "crosses the Level " + shortLevel + " downward"; break; case "AOA crosses the Level line downward": EntryFilterLongDescription += "crosses the Level " + longLevel + " downward"; EntryFilterShortDescription += "crosses the Level " + shortLevel + " upward"; ExitFilterLongDescription += "crosses the Level " + longLevel + " downward"; ExitFilterShortDescription += "crosses the Level " + shortLevel + " upward"; break; case "AOA changes its direction upward": EntryFilterLongDescription += "changes its direction upward"; EntryFilterShortDescription += "changes its direction downward"; ExitFilterLongDescription += "changes its direction upward"; ExitFilterShortDescription += "changes its direction downward"; break; case "AOA changes its direction downward": EntryFilterLongDescription += "changes its direction downward"; EntryFilterShortDescription += "changes its direction upward"; ExitFilterLongDescription += "changes its direction downward"; ExitFilterShortDescription += "changes its direction upward"; break; } } public override string ToString() { return IndicatorName + (IndParam.CheckParam[0].Checked ? "* (" : " (") + IndParam.ListParam[1].Text + ", " + // Smoothing method IndParam.ListParam[2].Text + ", " + // Base price IndParam.NumParam[0].ValueToString + ")"; // Smoothing period } } }
//+--------------------------------------------------------------------+ //| 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 <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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); } } //+------------------------------------------------------------------+
Risk warning: Forex, spread bets and CFD are leveraged products. They may not be suitable for you as they carry a high degree of risk to your capital and you can lose more than your initial investment. You should ensure you understand all of the risks.
Copyright © 2006 - 2024, Forex Software Ltd.;