//+--------------------------------------------------------------------+ //| 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 EmaPredictive : public Indicator { public: EmaPredictive(SlotTypes slotType) { SlotType=slotType; IndicatorName="EmaPredictive"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_DuringTheBar; IsSeparateChart = false; IsDiscreteValues = false; IsDeafultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void EmaPredictive::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters double longPeriod = NumParam[0].Value; double shortPeriod = NumParam[1].Value; double extraTimeForward=NumParam[2].Value; int prvs=CheckParam[0].Checked ? 1 : 0; if (longPeriod == shortPeriod) longPeriod = longPeriod + 0.1; const int firstBar=3; double extBuffer[]; ArrayResize(extBuffer,Data.Bars); ArrayInitialize(extBuffer, 0); double ma1 = 0; double ma3 = 0; double p1 = 0; double p3 = 0; double t1 = 0; double t3 = 0; double t=0; p1=2.0/(longPeriod+1.0); p3=2.0/(shortPeriod+1.0); //---- t1=(longPeriod-1.0)/2.0; t3=(shortPeriod-1.0)/2.0; t=shortPeriod+extraTimeForward; ma1=1;//Close[iBar]; ma3=ma1; for(int iBar=firstBar; iBarData.High[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 positive gap (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=firstBar; ArrayResize(Component[2].Value,Data.Bars); Component[2].FirstBar=firstBar; } ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "MA Value"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value,extBuffer); if(SlotType==SlotTypes_Open) { Component[1].CompName = "Position opening price"; Component[1].DataType = IndComponentType_OpenPrice; } else 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_Close) { Component[1].CompName = "Position closing price"; Component[1].DataType = IndComponentType_ClosePrice; } 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(SlotType==SlotTypes_OpenFilter || SlotType==SlotTypes_CloseFilter) { if(ListParam[0].Text=="The Moving Average rises") { IndicatorRisesLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } else if(ListParam[0].Text=="The Moving Average falls") { IndicatorFallsLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above the Moving Average") { BarOpensAboveIndicatorLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens below the Moving Average") { BarOpensBelowIndicatorLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar opens above the Moving Average after opening below it") { BarOpensAboveIndicatorAfterOpeningBelowLogic(firstBar,prvs,extBuffer,Component[1], Component[2]); } else if(ListParam[0].Text=="The bar opens below the Moving Average after opening above it") { BarOpensBelowIndicatorAfterOpeningAboveLogic(firstBar,prvs,extBuffer,Component[1], Component[2]); } else if(ListParam[0].Text=="The position opens above the Moving Average") { Component[0].PosPriceDependence=PositionPriceDependence_BuyHigherSellLower; Component[0].UsePreviousBar=prvs; 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 the Moving Average") { Component[0].PosPriceDependence=PositionPriceDependence_BuyLowerSelHigher; Component[0].UsePreviousBar=prvs; 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 the Moving Average") { BarClosesBelowIndicatorLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } else if(ListParam[0].Text=="The bar closes above the Moving Average") { BarClosesAboveIndicatorLogic(firstBar,prvs,extBuffer,Component[1],Component[2]); } } } //+------------------------------------------------------------------+