//+--------------------------------------------------------------------+ //| Copyright: (C) 2014 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) 2014 Forex Software Ltd." #property link "http://forexsb.com" #property version "2.00" #property strict #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CoralTrendv1 : public Indicator { public: CoralTrendv1(SlotTypes slotType) { SlotType=slotType; IndicatorName="CoralTrend v1"; WarningMessage = ""; IsAllowLTF = true; ExecTime = ExecutionTime_AtBarOpening; IsSeparateChart = false; IsDiscreteValues = false; IsDefaultGroupAll = false; } virtual void Calculate(DataSet &dataSet); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CoralTrendv1::Calculate(DataSet &dataSet) { Data=GetPointer(dataSet); // Reading the parameters int iPeriod = (int) NumParam[0].Value; int previous = CheckParam[0].Checked ? 1 : 0; double coeff0 = 0.4; double coeff9 = coeff0 * coeff0; double coeff10 = 0; coeff10 = coeff9 * coeff0; double coeff3 = -coeff10; double coeff4 = 3.0 * (coeff9 + coeff10); double coeff5 = -3.0 * (2.0 * coeff9 + coeff0 + coeff10); double coeff6 = 3.0 * coeff0 + 1.0 + coeff10 + 3.0 * coeff9; double coeff11 = iPeriod; if (coeff11 < 1.0) coeff11 = 1.0; coeff11 = (coeff11 - 1.0) / 2.0 + 1.0; double coeff1 = 2 / (coeff11 + 1.0); double coeff2 = 1 - coeff1; double CoralBuffer[];ArrayResize(CoralBuffer,Data.Bars); ArrayInitialize(CoralBuffer,0); double buffer1[];ArrayResize(buffer1,Data.Bars); ArrayInitialize(buffer1,0); double buffer2[];ArrayResize(buffer2,Data.Bars); ArrayInitialize(buffer2,0); double buffer3[];ArrayResize(buffer3,Data.Bars); ArrayInitialize(buffer3,0); double buffer4[];ArrayResize(buffer4,Data.Bars); ArrayInitialize(buffer4,0); double buffer5[];ArrayResize(buffer5,Data.Bars); ArrayInitialize(buffer5,0); double buffer6[];ArrayResize(buffer6,Data.Bars); ArrayInitialize(buffer6,0); for(int bar = iPeriod -1; bar < Data.Bars; bar++) { buffer1[bar] = coeff1 * Data.Close[bar] + coeff2 * (buffer1[bar - 1]); buffer2[bar] = coeff1 * (buffer1[bar]) + coeff2 * (buffer2[bar - 1]); buffer3[bar] = coeff1 * (buffer2[bar]) + coeff2 * (buffer3[bar - 1]); buffer4[bar] = coeff1 * (buffer3[bar]) + coeff2 * (buffer4[bar - 1]); buffer5[bar] = coeff1 * (buffer4[bar]) + coeff2 * (buffer5[bar - 1]); buffer6[bar] = coeff1 * (buffer5[bar]) + coeff2 * (buffer6[bar - 1]); CoralBuffer[bar] = coeff3 * (buffer6[bar]) + coeff4 * (buffer5[bar]) + coeff5 * (buffer4[bar]) + coeff6 * (buffer3[bar]); } // Calculation int firstBar=iPeriod+previous+2; // Saving the components if(SlotType==SlotTypes_Open || SlotType==SlotTypes_Close) { ArrayResize(Component[1].Value, Data.Bars); ArrayInitialize(Component[1].Value,0); for(int bar=firstBar; 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); ArrayInitialize(Component[1].Value,0); Component[1].FirstBar = firstBar; ArrayResize(Component[2].Value, Data.Bars); ArrayInitialize(Component[2].Value,0); Component[2].FirstBar = firstBar; } ArrayResize(Component[0].Value,Data.Bars); Component[0].CompName = "Coral Value"; Component[0].DataType = IndComponentType_IndicatorValue; Component[0].FirstBar = firstBar; ArrayCopy(Component[0].Value,CoralBuffer); 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=="The Moving Average rises") IndicatorRisesLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The Moving Average falls") IndicatorFallsLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The bar opens above the Moving Average") BarOpensAboveIndicatorLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The bar opens below the Moving Average") BarOpensBelowIndicatorLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The bar opens above the Moving Average after opening below it") BarOpensAboveIndicatorAfterOpeningBelowLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The bar opens below the Moving Average after opening above it") BarOpensBelowIndicatorAfterOpeningAboveLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The position opens above the Moving Average") { 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 the Moving Average") { Component[0].PosPriceDependence=PositionPriceDependence_BuyLowerSellHigher; 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 the Moving Average") BarClosesBelowIndicatorLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); else if(ListParam[0].Text=="The bar closes above the Moving Average") BarClosesAboveIndicatorLogic(firstBar,previous,CoralBuffer,Component[1],Component[2]); } } //+------------------------------------------------------------------+