Open Close Gap by Popov

48435 downloads / 4492 views / Created: 11.08.2015
 Average Rating: 5

Indicator Description

The "Open Close Gap" indicator measures the gap between current bar Open and previous bar Close. We can set the reference gap height in points. The indicator can be used as an Opening Logic Condition to filter out or allow long and short entries.

Two kind of gaps:

  • Positive Gap - when the current Open is higher than the previous Close.

  • Negative Gap - when the current Open is lower than the previous Close.



Logical Conditions:

  • Do not trade on gap - when the current gap is higher than the predefined value, the program doesn't allow long and short entries.

  • Trade on gap - the program allows long and short entries only when the current gap is higher than the predefined value.

  • Trade long on positive gap - the program allows long entry on a positive gap and a short entry on a negative gap.

  • Trade long on negative gap - the program allows long entry on a negative gap and a short entry on a positive gap.



Chart
The indicator represent the gap as a histogram chart.

Open Close Gap


Comments

//============================================================== // Forex Strategy Builder // Copyright © Forex Software Ltd. 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.Globalization; using ForexStrategyBuilder.Infrastructure.Entities; using ForexStrategyBuilder.Infrastructure.Enums; using ForexStrategyBuilder.Infrastructure.Interfaces; namespace ForexStrategyBuilder.Indicators.Custom { public class OpenCloseGap : Indicator { public OpenCloseGap() { IndicatorName = "Open Close Gap"; PossibleSlots = SlotTypes.OpenFilter; SeparatedChart = true; IsDeafultGroupAll = true; IsGeneratable = false; IndicatorAuthor = "Miroslav Popov"; IndicatorVersion = "1.0"; IndicatorDescription = "The indicator measures the bar Close-Open gap."; } public override void Initialize(SlotTypes slotType) { SlotType = slotType; // The ComboBox parameters IndParam.ListParam[0].Caption = "Logic"; IndParam.ListParam[0].ItemList = new[] { "Do not trade on gap", "Trade on gap", "Trade long on positive gap", "Trade long on negative gap" }; 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 = "Determines the entry conditions"; IndParam.ListParam[1].Caption = "Base price"; IndParam.ListParam[1].ItemList = new[] {"Open"}; IndParam.ListParam[1].Index = 0; IndParam.ListParam[1].Text = "Open"; IndParam.ListParam[1].Enabled = true; IndParam.ListParam[1].ToolTip = "Current bar Open minus previous bar Close."; // The NumericUpDown parameters IndParam.NumParam[0].Caption = "Gap height [points]"; IndParam.NumParam[0].Value = 100; IndParam.NumParam[0].Min = 1; IndParam.NumParam[0].Max = 2000; IndParam.NumParam[0].Enabled = true; IndParam.NumParam[0].ToolTip = "Gap height in points"; // 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; // Reading the parameters double gapLimit = IndParam.NumParam[0].Value*Point; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] histogram = new double[Bars]; double[] longSignal = new double[Bars]; double[] shortSignal = new double[Bars]; int firstBar = 2; for (int bar = 1; bar < Bars; bar++) histogram[bar] = Open[bar] - Close[bar - 1]; double sigma = Sigma(); if (IndParam.ListParam[0].Text == "Do not trade on gap") { for (int bar = 1 + previous; bar < Bars; bar++) { double trade = Math.Abs(histogram[bar - previous]) < gapLimit - sigma ? 1 : 0; longSignal[bar] = trade; shortSignal[bar] = trade; } } else if (IndParam.ListParam[0].Text == "Trade on gap") { for (int bar = 1 + previous; bar < Bars; bar++) { double trade = Math.Abs(histogram[bar - previous]) >= gapLimit ? 1 : 0; longSignal[bar] = trade; shortSignal[bar] = trade; } } else if (IndParam.ListParam[0].Text == "Trade long on positive gap") { for (int bar = 1 + previous; bar < Bars; bar++) { longSignal[bar] = histogram[bar - previous] >= gapLimit ? 1 : 0; shortSignal[bar] = histogram[bar - previous] <= -gapLimit ? 1 : 0; } } else if (IndParam.ListParam[0].Text == "Trade long on negative gap") { for (int bar = 1 + previous; bar < Bars; bar++) { longSignal[bar] = histogram[bar - previous] <= -gapLimit ? 1 : 0; shortSignal[bar] = histogram[bar - previous] >= gapLimit ? 1 : 0; } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Gap Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = histogram }; Component[1] = new IndicatorComp { CompName = "Is long entry allowed", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = longSignal }; Component[2] = new IndicatorComp { CompName = "Is short entry allowed", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = shortSignal }; } public override void SetDescription() { double gapLimit = IndParam.NumParam[0].Value; string posGapText = gapLimit.ToString(CultureInfo.InvariantCulture); string negGapText = (-gapLimit).ToString(CultureInfo.InvariantCulture); EntryFilterLongDescription = "Open Close Gap "; EntryFilterShortDescription = "Open Close Gap "; if (IndParam.ListParam[0].Text == "Do not trade on gap") { EntryFilterLongDescription += "is less than " + posGapText; EntryFilterShortDescription += "is less than " + posGapText; } else if (IndParam.ListParam[0].Text == "Trade on gap") { EntryFilterLongDescription += "is more than " + posGapText; EntryFilterShortDescription += "is more than " + posGapText; } else if (IndParam.ListParam[0].Text == "Trade long on positive gap") { EntryFilterLongDescription += "is more than " + posGapText; EntryFilterShortDescription += "is less than " + negGapText; } else if (IndParam.ListParam[0].Text == "Trade long on negative gap") { EntryFilterLongDescription += "is less than " + negGapText; EntryFilterShortDescription += "is more than " + posGapText; } } } }
//+--------------------------------------------------------------------+ //| Copyright: (C) 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) 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 OpenCloseGap : public Indicator { public: OpenCloseGap(SlotTypes slotType) { SlotType=slotType; IndicatorName="Open Close Gap"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = true; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OpenCloseGap::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters double gapLimit=NumParam[0].Value*Data.Point; int previous=CheckParam[0].Checked ? 1 : 0; // Calculation double histogram[]; ArrayResize(histogram,Data.Bars); ArrayInitialize(histogram,0); double longSignal[]; ArrayResize(longSignal,Data.Bars); ArrayInitialize(longSignal,0); double shortSignal[]; ArrayResize(shortSignal,Data.Bars); ArrayInitialize(shortSignal,0); int firstBar= 2; for(int bar = 1; bar<Data.Bars; bar++) histogram[bar]=Data.Open[bar]-Data.Close[bar-1]; double sigma=Sigma(); if(ListParam[0].Text=="Do not trade on gap") { for(int bar=1+previous; bar<Data.Bars; bar++) { double trade=MathAbs(histogram[bar])<gapLimit-sigma ? 1 : 0; longSignal[bar]=trade; shortSignal[bar]=trade; } } else if(ListParam[0].Text=="Trade on gap") { for(int bar=1+previous; bar<Data.Bars; bar++) { double trade=MathAbs(histogram[bar])>=gapLimit ? 1 : 0; longSignal[bar]=trade; shortSignal[bar]=trade; } } else if(ListParam[0].Text=="Trade long on positive gap") { for(int bar=1+previous; bar<Data.Bars; bar++) { longSignal[bar]=histogram[bar-previous]>=gapLimit ? 1 : 0; shortSignal[bar]=histogram[bar-previous]<=-gapLimit ? 1 : 0; } } else if(ListParam[0].Text=="Trade long on negative gap") { for(int bar=1+previous; bar<Data.Bars; bar++) { longSignal[bar]=histogram[bar-previous]<=-gapLimit ? 1 : 0; shortSignal[bar]=histogram[bar-previous]>=gapLimit ? 1 : 0; } } // Saving the components Component[0].CompName="Gap Histogram"; Component[0].DataType=IndComponentType_IndicatorValue; Component[0].FirstBar=firstBar; ArrayResize(Component[0].Value,Data.Bars); ArrayCopy(Component[0].Value,histogram); Component[1].CompName="Is long entry allowed"; Component[1].DataType=IndComponentType_AllowOpenLong; Component[1].FirstBar=firstBar; ArrayResize(Component[1].Value,Data.Bars); ArrayCopy(Component[1].Value,longSignal); Component[2].CompName="Is short entry allowed"; Component[2].DataType=IndComponentType_AllowOpenShort; Component[2].FirstBar=firstBar; ArrayResize(Component[2].Value,Data.Bars); ArrayCopy(Component[2].Value,shortSignal); } //+------------------------------------------------------------------+
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.;