Unidirectional Three Bars Swing by Popov
46662 downloads / 4556 views / Created: 24.05.2013 Average Rating: 5
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 UnidirectionalThreeBarsSwing : Indicator
{
public UnidirectionalThreeBarsSwing()
{
IndicatorName = "Unidirectional Three Bars Swing";
PossibleSlots = SlotTypes.OpenFilter;
IndicatorAuthor = "Miroslav Popov";
IndicatorVersion = "2.0";
IndicatorDescription = "A custom indicator for FSB and FST.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new string[] { "Three bars swing pattern" };
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.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
int iFirstBar = 4;
double[] adUp = new double[Bars];
double[] adDn = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
// Long trade
if (Close[iBar - 3] < Open[iBar - 3] && // Candle 1 is black
Low[iBar - 2] < Low[iBar - 3] && // Candle 2 has lower low than candle 1
Close[iBar - 1] > Open[iBar - 1] && // Candle 3 is white
Low[iBar - 1] > Low[iBar - 2] && // Candle 3 has higher low than candle 2
Close[iBar - 1] > Open[iBar - 3]) // Candle 3 closes above candle 1 open
adUp[iBar] = 1;
// Short trade
if (Close[iBar - 3] > Open[iBar - 3] && // Candle 1 is white
High[iBar - 2] > High[iBar - 3] && // Candle 2 has higher high than candle 1
Close[iBar - 1] < Open[iBar - 1] && // Candle 3 is black
High[iBar - 1] < High[iBar - 2] && // Candle 3 has lower high than candle 2
Close[iBar - 1] < Open[iBar - 3]) // Candle 3 closes below candle 1 open
adUp[iBar] = 1;
}
// Saving the components
Component = new IndicatorComp[2];
Component[0] = new IndicatorComp();
Component[0].CompName = "Allow long entry";
Component[0].DataType = IndComponentType.AllowOpenLong;
Component[0].ChartType = IndChartType.NoChart;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adUp;
Component[1] = new IndicatorComp();
Component[1].CompName = "Allow short entry";
Component[1].DataType = IndComponentType.AllowOpenShort;
Component[1].ChartType = IndChartType.NoChart;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adUp;
}
public override void SetDescription()
{
EntryFilterLongDescription = "there is a Three Bars Swing pattern";
EntryFilterShortDescription = "there is a Three Bars Swing pattern";
}
public override string ToString()
{
return IndicatorName;
}
}
}
//+--------------------------------------------------------------------+ //| 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 UnidirectionalThreeBarsSwing : public Indicator { public: UnidirectionalThreeBarsSwing(SlotTypes slotType) { SlotType=slotType; IndicatorName="Unidirectional Three Bars Swing"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void UnidirectionalThreeBarsSwing::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int iFirstBar=4; double adUp[]; ArrayResize(adUp,Data.Bars); ArrayInitialize(adUp,0); for(int iBar=iFirstBar; iBar<Data.Bars; iBar++) { // Long trade if(Data.Close[iBar-3]<Data.Open[iBar-3] && // Candle 1 is black Data.Low[iBar - 2] < Data.Low[iBar - 3] && // Candle 2 has lower low than candle 1 Data.Close[iBar - 1] > Data.Open[iBar - 1] && // Candle 3 is white Data.Low[iBar - 1] > Data.Low[iBar - 2] && // Candle 3 has higher low than candle 2 Data.Close[iBar - 1] > Data.Open[iBar - 3]) // Candle 3 closes above candle 1 open adUp[iBar]=1; // Short trade if(Data.Close[iBar-3]>Data.Open[iBar-3] && // Candle 1 is white Data.High[iBar - 2] > Data.High[iBar - 3] && // Candle 2 has higher high than candle 1 Data.Close[iBar - 1] < Data.Open[iBar - 1] && // Candle 3 is black Data.High[iBar - 1] < Data.High[iBar - 2] && // Candle 3 has lower high than candle 2 Data.Close[iBar - 1] < Data.Open[iBar - 3]) // Candle 3 closes below candle 1 open adUp[iBar]=1; } // Saving the components ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType_AllowOpenLong; Component[0].FirstBar = iFirstBar; ArrayCopy(Component[0].Value,adUp); ArrayResize(Component[1].Value,Data.Bars); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType_AllowOpenShort; Component[1].FirstBar = iFirstBar; ArrayCopy(Component[1].Value,adUp); } //+------------------------------------------------------------------+
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.;