//+--------------------------------------------------------------------+ //| 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 #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class ParabolicSARCombo : public Indicator { public: ParabolicSARCombo(SlotTypes slotType) { SlotType=slotType; IndicatorName="Parabolic SAR Combo"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ParabolicSARCombo::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); double dAfMin = NumParam[0].Value; double dAfInc = NumParam[1].Value; double dAfMax = NumParam[2].Value; int previous=CheckParam[0].Checked ? 1 : 0; // Reading the parameters double dPExtr; double dadPsarNew=0; int aiDir[]; ArrayResize(aiDir,Data.Bars); ArrayInitialize(aiDir, 0); double adPsar[]; ArrayResize(adPsar,Data.Bars);ArrayInitialize(adPsar, 0); //---- Calculating the initial values adPsar[0]=0; double dAf=dAfMin; int intDirNew=0; if(Data.Close[1]>Data.Open[0]) { aiDir[0] = 1; aiDir[1] = 1; dPExtr=MathMax(Data.High[0],Data.High[1]); adPsar[1]=MathMin(Data.Low[0],Data.Low[1]); } else { aiDir[0] = -1; aiDir[1] = -1; dPExtr=MathMin(Data.Low[0],Data.Low[1]); adPsar[1]=MathMax(Data.High[0],Data.High[1]); } for(int bar=2; bar0 && adPsar[bar]>MathMin(Data.Low[bar-1],Data.Low[bar-2])) adPsar[bar]=MathMin(Data.Low[bar-1],Data.Low[bar-2]); else if(aiDir[bar]<0 && adPsar[bar]0 && Data.High[bar]>dPExtr) { dPExtr=Data.High[bar]; dAf=MathMin(dAf+dAfInc,dAfMax); } if(aiDir[bar]<0 && Data.Low[bar]0 ? Data.High[bar]: Data.Low[bar]; } } // Saving the components if(SlotType==SlotTypes_Open || SlotType==SlotTypes_Close) { ArrayResize(Component[1].Value,Data.Bars); for(int bar=8; bar Data.High[bar - 1] && value < Data.Open[bar]) || // The Data.Open price jumps above the indicator (value1 < Data.Low[bar - 1] && value > Data.Open[bar]) || // The Data.Open price jumps below the indicator (Data.Close[bar-1]value && value>Data.Open[bar])) // The Data.Open price is in a negative gap tempVal=Data.Open[bar]; Component[1].Value[bar]=tempVal; // Entry or exit value } } else { ArrayResize(Component[1].Value,Data.Bars); Component[1].FirstBar=8; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=8; } ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Psar Value"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = 8; ArrayCopy(Component[0].Value,adPsar); if(SlotType==SlotTypes_Open) { Component[1].CompName = "Position opening price"; Component[1].DataType = IndComponentType_OpenPrice; } 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"; } if(SlotType==SlotTypes_Close) { Component[1].CompName = "Position closing price"; Component[1].DataType = IndComponentType_ClosePrice; } 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(SlotType==SlotTypes_OpenFilter || SlotType==SlotTypes_CloseFilter) { if(ListParam[0].Text=="PSAR rises") { IndicatorRisesLogic(8,0,adPsar,Component[1],Component[2]); } else if(ListParam[0].Text=="PSAR falls") { IndicatorFallsLogic(8,0,adPsar,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above PSAR") { BarOpensAboveIndicatorLogic(8,0,adPsar,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens below PSAR") { BarOpensBelowIndicatorLogic(8,0,adPsar,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above PSAR after opening below it") { BarOpensAboveIndicatorAfterOpeningBelowLogic(8,0,adPsar,Component[1], Component[2]); } else if(ListParam[0].Text=="The bar opens below PSAR after opening above it") { BarOpensBelowIndicatorAfterOpeningAboveLogic(8,0,adPsar,Component[1], Component[2]); } else if(ListParam[0].Text=="The position opens above PSAR") { Component[0].PosPriceDependence=PositionPriceDependence_BuyHigherSellLower; Component[0].UsePreviousBar=previous; Component[1].DataType=IndComponentType_Other; Component[1].ShowInDynInfo=false; Component[2].DataType=IndComponentType_Other; Component[2].ShowInDynInfo=false; } else if(ListParam[0].Text=="The position opens below PSAR") { Component[0].PosPriceDependence=PositionPriceDependence_BuyLowerSelHigher; Component[0].UsePreviousBar=previous; Component[1].DataType=IndComponentType_Other; Component[1].ShowInDynInfo=false; Component[2].DataType=IndComponentType_Other; Component[2].ShowInDynInfo=false; } else if(ListParam[0].Text=="The bar closes below PSAR") { BarClosesBelowIndicatorLogic(8,0,adPsar,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar closes above PSAR") { BarClosesAboveIndicatorLogic(8,0,adPsar,Component[1],Component[2]); } } } //+------------------------------------------------------------------+