Custom Donchian Channel by footon
44982 downloads / 3839 views / Created: 24.05.2013 Average Rating: 0
Comments
//==============================================================
// Forex Strategy Builder
// Copyright (c) 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 Donchian_Channel : Indicator
{
public Donchian_Channel()
{
IndicatorName = "Custom Donchian Channel";
PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;
IndicatorAuthor = "Footon";
IndicatorVersion = "2.0";
IndicatorDescription = "Footon's indi corner: custom indicators for FSB and FST.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
if (SlotType == SlotTypes.Open)
IndParam.ListParam[0].ItemList = new string[]
{
"Enter long at the Upper Band",
"Enter long at the Lower Band"
};
else if (SlotType == SlotTypes.OpenFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar opens below the Upper Band",
"The bar opens above the Upper Band",
"The bar opens below the Lower Band",
"The bar opens above the Lower Band",
"The position opens below the Upper Band",
"The position opens above the Upper Band",
"The position opens below the Lower Band",
"The position opens above the Lower Band",
"The bar opens below the Upper Band after opening above it",
"The bar opens above the Upper Band after opening below it",
"The bar opens below the Lower Band after opening above it",
"The bar opens above the Lower Band after opening below it",
"The bar touches the Upper Band",
"The bar touches the Lower Band"
};
else if (SlotType == SlotTypes.Close)
IndParam.ListParam[0].ItemList = new string[]
{
"Exit long at the Upper Band",
"Exit long at the Lower Band"
};
else if (SlotType == SlotTypes.CloseFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar closes below the Upper Band",
"The bar closes above the Upper Band",
"The bar closes below the Lower Band",
"The bar closes above the Lower Band"
};
else
IndParam.ListParam[0].ItemList = new string[]
{
"Not Defined"
};
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 Donchian Channel.";
IndParam.ListParam[1].Caption = "Base price";
IndParam.ListParam[1].ItemList = new string[] { "High & Low" };
IndParam.ListParam[1].Index = 0;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "Base price";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "Period";
IndParam.NumParam[0].Value = 10;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 200;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The width of the range we are looking for an extreme in.";
IndParam.NumParam[1].Caption = "Shift";
IndParam.NumParam[1].Value = 0;
IndParam.NumParam[1].Min = 0;
IndParam.NumParam[1].Max = 200;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "The number of bars to shift with.";
// 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.";
return;
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
int iPeriod = (int)IndParam.NumParam[0].Value;
int iShift = (int)IndParam.NumParam[1].Value;
int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
// Calculation
double[] adUpBand = new double[Bars];
double[] adDnBand = new double[Bars];
int iFirstBar = iPeriod + iShift + iPrvs + 2;
for (int iBar = iFirstBar; iBar < Bars - iShift; iBar++)
{
double dMax = double.MinValue;
double dMin = double.MaxValue;
for (int i = 0; i < iPeriod; i++)
{
if (High[iBar - i] > dMax) dMax = High[iBar - i];
if (Low[iBar - i] < dMin) dMin = Low[iBar - i];
}
adUpBand[iBar + iShift] = dMax;
adDnBand[iBar + iShift] = dMin;
}
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp();
Component[0].CompName = "Upper Band";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.Blue;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adUpBand;
Component[1] = new IndicatorComp();
Component[1].CompName = "Lower Band";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.Blue;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adDnBand;
Component[2] = new IndicatorComp();
Component[2].ChartType = IndChartType.NoChart;
Component[2].FirstBar = iFirstBar;
Component[2].Value = new double[Bars];
Component[3] = new IndicatorComp();
Component[3].ChartType = IndChartType.NoChart;
Component[3].FirstBar = iFirstBar;
Component[3].Value = new double[Bars];
// Sets the Component's type.
if (SlotType == SlotTypes.Open)
{
Component[2].DataType = IndComponentType.OpenLongPrice;
Component[2].CompName = "Long position entry price";
Component[3].DataType = IndComponentType.OpenShortPrice;
Component[3].CompName = "Short position entry price";
}
else if (SlotType == SlotTypes.OpenFilter)
{
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[2].CompName = "Is long entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
Component[3].CompName = "Is short entry allowed";
}
else if (SlotType == SlotTypes.Close)
{
Component[2].DataType = IndComponentType.CloseLongPrice;
Component[2].CompName = "Long position closing price";
Component[3].DataType = IndComponentType.CloseShortPrice;
Component[3].CompName = "Short position closing price";
}
else if (SlotType == SlotTypes.CloseFilter)
{
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[2].CompName = "Close out long position";
Component[3].DataType = IndComponentType.ForceCloseShort;
Component[3].CompName = "Close out short position";
}
if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close)
{
if (iPeriod > 1)
{
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{ // Covers the cases when the price can pass through the band without a signal.
double dOpen = Open[iBar]; // Current open price
// Upper band
double dValueUp = adUpBand[iBar - iPrvs]; // Current value
double dValueUp1 = adUpBand[iBar - iPrvs - 1]; // Previous value
double dTempValUp = dValueUp;
if ((dValueUp1 > High[iBar - 1] && dValueUp < dOpen) || // The Open price jumps above the indicator
(dValueUp1 < Low[iBar - 1] && dValueUp > dOpen) || // The Open price jumps below the indicator
(Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Open price is in a positive gap
(Close[iBar - 1] > dValueUp && dValueUp > dOpen)) // The Open price is in a negative gap
dTempValUp = dOpen; // The entry/exit level is moved to Open price
// Lower band
double dValueDown = adDnBand[iBar - iPrvs]; // Current value
double dValueDown1 = adDnBand[iBar - iPrvs - 1]; // Previous value
double dTempValDown = dValueDown;
if ((dValueDown1 > High[iBar - 1] && dValueDown < dOpen) || // The Open price jumps above the indicator
(dValueDown1 < Low[iBar - 1] && dValueDown > dOpen) || // The Open price jumps below the indicator
(Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Open price is in a positive gap
(Close[iBar - 1] > dValueDown && dValueDown > dOpen)) // The Open price is in a negative gap
dTempValDown = dOpen; // The entry/exit level is moved to Open price
if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
IndParam.ListParam[0].Text == "Exit long at the Upper Band")
{
Component[2].Value[iBar] = dTempValUp;
Component[3].Value[iBar] = dTempValDown;
}
else
{
Component[2].Value[iBar] = dTempValDown;
Component[3].Value[iBar] = dTempValUp;
}
}
}
else
{
for (int iBar = 2; iBar < Bars; iBar++)
{
if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
IndParam.ListParam[0].Text == "Exit long at the Upper Band")
{
Component[2].Value[iBar] = adUpBand[iBar - iPrvs];
Component[3].Value[iBar] = adDnBand[iBar - iPrvs];
}
else
{
Component[2].Value[iBar] = adDnBand[iBar - iPrvs];
Component[3].Value[iBar] = adUpBand[iBar - iPrvs];
}
}
}
}
else
{
switch (IndParam.ListParam[0].Text)
{
case "The bar opens below the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band);
break;
case "The bar opens above the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band);
break;
case "The bar opens below the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band);
break;
case "The bar opens above the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band);
break;
case "The bar opens below the Upper Band after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
break;
case "The bar opens above the Upper Band after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
break;
case "The bar opens below the Lower Band after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
break;
case "The bar opens above the Lower Band after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
break;
case "The position opens above the Upper Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[1].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[0].UsePreviousBar = iPrvs;
Component[1].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens below the Upper Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[1].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[0].UsePreviousBar = iPrvs;
Component[1].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens above the Lower Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[1].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[0].UsePreviousBar = iPrvs;
Component[1].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The position opens below the Lower Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[1].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[0].UsePreviousBar = iPrvs;
Component[1].UsePreviousBar = iPrvs;
Component[2].DataType = IndComponentType.Other;
Component[3].DataType = IndComponentType.Other;
Component[2].ShowInDynInfo = false;
Component[3].ShowInDynInfo = false;
break;
case "The bar closes below the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band);
break;
case "The bar closes above the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band);
break;
case "The bar closes below the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band);
break;
case "The bar closes above the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band);
break;
case "The bar touches the Upper Band":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[2].Value[iBar] = High[iBar - 1] >= adUpBand[iBar - iPrvs] ? 1 : 0;
Component[3].Value[iBar] = Low[iBar - 1] <= adDnBand[iBar - iPrvs] ? 1 : 0;
}
break;
case "The bar touches the Lower Band":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[2].Value[iBar] = Low[iBar - 1] <= adDnBand[iBar - iPrvs] ? 1 : 0;
Component[3].Value[iBar] = High[iBar - 1] >= adUpBand[iBar - iPrvs] ? 1 : 0;
}
break;
default:
break;
}
}
return;
}
///
/// Sets the indicator logic description
///
public override void SetDescription()
{
switch (IndParam.ListParam[0].Text)
{
case "Enter long at the Upper Band":
EntryPointLongDescription = "at the Upper Band of " + ToString();
EntryPointShortDescription = "at the Lower Band of " + ToString();
break;
case "Enter long at the Lower Band":
EntryPointLongDescription = "at the Lower Band of " + ToString();
EntryPointShortDescription = "at the Upper Band of " + ToString();
break;
case "Exit long at the Upper Band":
ExitPointLongDescription = "at the Upper Band of " + ToString();
ExitPointShortDescription = "at the Lower Band of " + ToString();
break;
case "Exit long at the Lower Band":
ExitPointLongDescription = "at the Lower Band of " + ToString();
ExitPointShortDescription = "at the Upper Band of " + ToString();
break;
case "The bar opens below the Upper Band":
EntryFilterLongDescription = "the bar opens below the Upper Band of " + ToString();
EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString();
break;
case "The bar opens above the Upper Band":
EntryFilterLongDescription = "the bar opens above the Upper Band of " + ToString();
EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString();
break;
case "The bar opens below the Lower Band":
EntryFilterLongDescription = "the bar opens below the Lower Band of " + ToString();
EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString();
break;
case "The bar opens above the Lower Band":
EntryFilterLongDescription = "the bar opens above the Lower Band of " + ToString();
EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString();
break;
case "The position opens above the Upper Band":
EntryFilterLongDescription = "the position opening price is higher than the Upper Band of " + ToString();
EntryFilterShortDescription = "the position opening price is lower than the Lower Band of " + ToString();
break;
case "The position opens below the Upper Band":
EntryFilterLongDescription = "the position opening price is lower than the Upper Band of " + ToString();
EntryFilterShortDescription = "the position opening price is higher than the Lower Band of " + ToString();
break;
case "The position opens above the Lower Band":
EntryFilterLongDescription = "the position opening price is higher than the Lower Band of " + ToString();
EntryFilterShortDescription = "the position opening price is lower than the Upper Band of " + ToString();
break;
case "The position opens below the Lower Band":
EntryFilterLongDescription = "the position opening price is lower than the Lower Band of " + ToString();
EntryFilterShortDescription = "the position opening price is higher than the Upper Band of " + ToString();
break;
case "The bar opens below the Upper Band after opening above it":
EntryFilterLongDescription = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Upper Band after opening below it":
EntryFilterLongDescription = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar opens below the Lower Band after opening above it":
EntryFilterLongDescription = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Lower Band after opening below it":
EntryFilterLongDescription = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar closes below the Upper Band":
ExitFilterLongDescription = "the bar closes below the Upper Band of " + ToString();
ExitFilterShortDescription = "the bar closes above the Lower Band of " + ToString();
break;
case "The bar closes above the Upper Band":
ExitFilterLongDescription = "the bar closes above the Upper Band of " + ToString();
ExitFilterShortDescription = "the bar closes below the Lower Band of " + ToString();
break;
case "The bar closes below the Lower Band":
ExitFilterLongDescription = "the bar closes below the Lower Band of " + ToString();
ExitFilterShortDescription = "the bar closes above the Upper Band of " + ToString();
break;
case "The bar closes above the Lower Band":
ExitFilterLongDescription = "the bar closes above the Lower Band of " + ToString();
ExitFilterShortDescription = "the bar closes below the Upper Band of " + ToString();
break;
default:
break;
}
return;
}
///
/// Indicator to string
///
public override string ToString()
{
string sString = IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.NumParam[0].ValueToString + ", " + // Period
IndParam.NumParam[1].ValueToString + ")"; // Shift
return sString;
}
}
}
//+--------------------------------------------------------------------+ //| 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 <Forexsb.com/Indicator.mqh> #include <Forexsb.com/Enumerations.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CustomDonchianChannel : public Indicator { public: CustomDonchianChannel(SlotTypes slotType) { SlotType=slotType; IndicatorName="Custom Donchian Channel"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CustomDonchianChannel::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int iPeriod = (int)NumParam[0].Value; int iShift = (int)NumParam[1].Value; int iPrvs = CheckParam[0].Checked ? 1 : 0; // Calculation double adUpBand[]; ArrayResize(adUpBand, Data.Bars);ArrayInitialize(adUpBand,0); double adDnBand[]; ArrayResize(adDnBand, Data.Bars);ArrayInitialize(adDnBand,0); int iFirstBar=iPeriod+iShift+iPrvs+2; for(int iBar=iPeriod+iPrvs+2; iBar<Data.Bars-iShift; iBar++) { double dMax = DBL_MIN; double dMin = DBL_MAX; for(int i=0; i<iPeriod; i++) { if(Data.High[iBar - i] > dMax) dMax = Data.High[iBar - i]; if(Data.Low[iBar - i] < dMin) dMin = Data.Low[iBar - i]; } adUpBand[iBar + iShift] = dMax; adDnBand[iBar + iShift] = dMin; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Upper Band"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adUpBand); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Lower Band"; Component[1].DataType = IndComponentType_IndicatorValue; Component[1].FirstBar = iFirstBar; ArrayCopy(Component[1].Value,adDnBand); ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=iFirstBar; ArrayResize(Component[3].Value,Data.Bars); Component[3].FirstBar=iFirstBar; // Sets the Component's type. if(SlotType==SlotTypes_Open) { Component[2].DataType = IndComponentType_OpenLongPrice; Component[2].CompName = "Long position entry price"; Component[3].DataType = IndComponentType_OpenShortPrice; Component[3].CompName = "Short position entry price"; } else if(SlotType==SlotTypes_OpenFilter) { Component[2].DataType = IndComponentType_AllowOpenLong; Component[2].CompName = "Is long entry allowed"; Component[3].DataType = IndComponentType_AllowOpenShort; Component[3].CompName = "Is short entry allowed"; } else if(SlotType==SlotTypes_Close) { Component[2].DataType = IndComponentType_CloseLongPrice; Component[2].CompName = "Long position closing price"; Component[3].DataType = IndComponentType_CloseShortPrice; Component[3].CompName = "Short position closing price"; } else if(SlotType==SlotTypes_CloseFilter) { Component[2].DataType = IndComponentType_ForceCloseLong; Component[2].CompName = "Close out long position"; Component[3].DataType = IndComponentType_ForceCloseShort; Component[3].CompName = "Close out short position"; } if(SlotType==SlotTypes_Open || SlotType==SlotTypes_Close) { if(iPeriod>1) { for(int iBar=iFirstBar; iBar<Data.Bars; iBar++) { // Covers the cases when the price can pass through the band without a signal. double dOpen=Data.Open[iBar]; // Current open price // Upper band double dValueUp = adUpBand[iBar - iPrvs]; // Current value double dValueUp1 = adUpBand[iBar - iPrvs - 1]; // Previous value double dTempValUp = dValueUp; if((dValueUp1>Data.High[iBar-1] && dValueUp<dOpen) || // The Data.Open price jumps above the indicator (dValueUp1 < Data.Low[iBar - 1] && dValueUp > dOpen) || // The Data.Open price jumps below the indicator (Data.Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Data.Open price is in a positive gap (Data.Close[iBar - 1] > dValueUp && dValueUp > dOpen)) // The Data.Open price is in a negative gap dTempValUp=dOpen; // The entry/exit level is moved to Data.Open price // Lower band double dValueDown = adDnBand[iBar - iPrvs]; // Current value double dValueDown1 = adDnBand[iBar - iPrvs - 1]; // Previous value double dTempValDown = dValueDown; if((dValueDown1>Data.High[iBar-1] && dValueDown<dOpen) || // The Data.Open price jumps above the indicator (dValueDown1 < Data.Low[iBar - 1] && dValueDown > dOpen) || // The Data.Open price jumps below the indicator (Data.Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Data.Open price is in a positive gap (Data.Close[iBar - 1] > dValueDown && dValueDown > dOpen)) // The Data.Open price is in a negative gap dTempValDown=dOpen; // The entry/exit level is moved to Data.Open price if(ListParam[0].Text=="Enter long at the Upper Band" || ListParam[0].Text=="Exit long at the Upper Band") { Component[2].Value[iBar] = dTempValUp; Component[3].Value[iBar] = dTempValDown; } else { Component[2].Value[iBar] = dTempValDown; Component[3].Value[iBar] = dTempValUp; } } } else { for(int iBar=2; iBar<Data.Bars; iBar++) { if(ListParam[0].Text=="Enter long at the Upper Band" || ListParam[0].Text=="Exit long at the Upper Band") { Component[2].Value[iBar] = adUpBand[iBar - iPrvs]; Component[3].Value[iBar] = adDnBand[iBar - iPrvs]; } else { Component[2].Value[iBar] = adDnBand[iBar - iPrvs]; Component[3].Value[iBar] = adUpBand[iBar - iPrvs]; } } } } else { if(ListParam[0].Text=="The bar opens below the Upper Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_below_the_Upper_Band); } else if(ListParam[0].Text=="The bar opens above the Upper Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_above_the_Upper_Band); } else if(ListParam[0].Text=="The bar opens below the Lower Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_below_the_Lower_Band); } else if(ListParam[0].Text=="The bar opens above the Lower Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_above_the_Lower_Band); } else if(ListParam[0].Text=="The bar opens below the Upper Band after opening above it") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_below_Upper_Band_after_above); } else if(ListParam[0].Text=="The bar opens above the Upper Band after opening below it") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_above_Upper_Band_after_below); } else if(ListParam[0].Text=="The bar opens below the Lower Band after opening above it") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_below_Lower_Band_after_above); } else if(ListParam[0].Text=="The bar opens above the Lower Band after opening below it") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_opens_above_Lower_Band_after_below); } else if(ListParam[0].Text=="The position opens above the Upper Band") { Component[0].PosPriceDependence = PositionPriceDependence_PriceBuyHigher; Component[1].PosPriceDependence = PositionPriceDependence_PriceSellLower; Component[0].UsePreviousBar = iPrvs; Component[1].UsePreviousBar = iPrvs; Component[2].DataType = IndComponentType_Other; Component[3].DataType = IndComponentType_Other; Component[2].ShowInDynInfo = false; Component[3].ShowInDynInfo = false; } else if(ListParam[0].Text=="The position opens below the Upper Band") { Component[0].PosPriceDependence = PositionPriceDependence_PriceBuyLower; Component[1].PosPriceDependence = PositionPriceDependence_PriceSellHigher; Component[0].UsePreviousBar = iPrvs; Component[1].UsePreviousBar = iPrvs; Component[2].DataType = IndComponentType_Other; Component[3].DataType = IndComponentType_Other; Component[2].ShowInDynInfo = false; Component[3].ShowInDynInfo = false; } else if(ListParam[0].Text=="The position opens above the Lower Band") { Component[0].PosPriceDependence = PositionPriceDependence_PriceSellLower; Component[1].PosPriceDependence = PositionPriceDependence_PriceBuyHigher; Component[0].UsePreviousBar = iPrvs; Component[1].UsePreviousBar = iPrvs; Component[2].DataType = IndComponentType_Other; Component[3].DataType = IndComponentType_Other; Component[2].ShowInDynInfo = false; Component[3].ShowInDynInfo = false; } else if(ListParam[0].Text=="The position opens below the Lower Band") { Component[0].PosPriceDependence = PositionPriceDependence_PriceSellHigher; Component[1].PosPriceDependence = PositionPriceDependence_PriceBuyLower; Component[0].UsePreviousBar = iPrvs; Component[1].UsePreviousBar = iPrvs; Component[2].DataType = IndComponentType_Other; Component[3].DataType = IndComponentType_Other; Component[2].ShowInDynInfo = false; Component[3].ShowInDynInfo = false; } else if(ListParam[0].Text=="The bar closes below the Upper Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_closes_below_the_Upper_Band); } else if(ListParam[0].Text=="The bar closes above the Upper Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_closes_above_the_Upper_Band); } else if(ListParam[0].Text=="The bar closes below the Lower Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_closes_below_the_Lower_Band); } else if(ListParam[0].Text=="The bar closes above the Lower Band") { BandIndicatorLogic(iFirstBar,iPrvs,adUpBand,adDnBand,Component[2],Component[3], BandIndLogic_The_bar_closes_above_the_Lower_Band); } else if(ListParam[0].Text=="The bar touches the Upper Band") { for(int iBar=iFirstBar+iPrvs; iBar<Data.Bars; iBar++) { Component[2].Value[iBar] = Data.High[iBar - 1] >= adUpBand[iBar - iPrvs] ? 1 : 0; Component[3].Value[iBar] = Data.Low[iBar - 1] <= adDnBand[iBar - iPrvs] ? 1 : 0; } } else if(ListParam[0].Text=="The bar touches the Lower Band") { for(int iBar=iFirstBar+iPrvs; iBar<Data.Bars; iBar++) { Component[2].Value[iBar] = Data.Low[iBar - 1] <= adDnBand[iBar - iPrvs] ? 1 : 0; Component[3].Value[iBar] = Data.High[iBar - 1] >= adUpBand[iBar - iPrvs] ? 1 : 0; } } } } //+------------------------------------------------------------------+
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.;
Copyright © 2006 - 2024, Forex Software Ltd.;