From 86ef1cad32c94e98889154408017f5a284180fe6 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 25 Jan 2025 03:58:37 +0330 Subject: [PATCH] Cleanup Backups ... --- Documents/BKP/1/1.mq5 | 580 -- Documents/BKP/1/2.mq5 | 195 - Documents/BKP/1/3.mq5 | 319 - Documents/BKP/1/4.mq5 | 530 -- Documents/BKP/1/tmp.codes.mq5 | 729 --- ...-121.smc.market.cycle.helper.class.old.mq5 | 4143 ------------- .../BKP/1/x-121.smc.twpv.conditions2.mq5 | 137 - .../BKP/1/x-121.smc.x.signal.lib copy.mq5 | 1983 ------- Documents/BKP/1/x-121.smc.x.signal.lib.mq5 | 1943 ------- .../BKP/1/x-121.smc.xobgpv.signal.lib.mq5 | 1020 ---- .../BKP/1/x-121.smc.xobspv.signal.lib.mq5 | 1138 ---- .../1/x-121.smc.xtwpv.old.1.signal.lib.mq5 | 1420 ----- .../1/x-121.smc.xtwpv.old.12signal.lib.mq5 | 1367 ----- .../BKP/1/x-121.smc.xtwpv.old.3signal.lib.mq5 | 957 --- .../1/x-121.smc.xtwpv.old.4.signal.lib.mq5 | 1083 ---- .../BKP/1/x-121.smc.xtwpv.old.signal.lib.mq5 | 2060 ------- Documents/BKP/1/x-saherelm.x121.helper.mq5 | 4636 --------------- Documents/BKP/1/x-saherelm.x121.mq5 | 2407 -------- .../BKP/1/x-saherelm.x121.old.helper.mq5 | 5171 ----------------- Documents/BKP/1/x-saherelm.x121.old.mq5 | 2321 -------- Documents/BKP/1/x-saherelm.x121.xempty.mq5 | 325 -- Documents/BKP/2/tmp.signalling.mq5 | 1302 ----- Documents/BKP/2/x-121.smc.xpvt.signal.lib.mq5 | 2484 -------- Documents/BKP/2/x-121.smc.xpz.signal.lib.mq5 | 1700 ------ .../BKP/2/x-121.smc.xrspvi.signal.lib.mq5 | 2483 -------- .../BKP/2/x-121.smc.xstrpv.signal.lib.mq5 | 2097 ------- 26 files changed, 44530 deletions(-) delete mode 100644 Documents/BKP/1/1.mq5 delete mode 100644 Documents/BKP/1/2.mq5 delete mode 100644 Documents/BKP/1/3.mq5 delete mode 100644 Documents/BKP/1/4.mq5 delete mode 100644 Documents/BKP/1/tmp.codes.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.market.cycle.helper.class.old.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.twpv.conditions2.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.x.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xobgpv.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xobspv.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.1.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.12signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.3signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.signal.lib.mq5 delete mode 100644 Documents/BKP/1/x-saherelm.x121.helper.mq5 delete mode 100644 Documents/BKP/1/x-saherelm.x121.mq5 delete mode 100644 Documents/BKP/1/x-saherelm.x121.old.helper.mq5 delete mode 100644 Documents/BKP/1/x-saherelm.x121.old.mq5 delete mode 100644 Documents/BKP/1/x-saherelm.x121.xempty.mq5 delete mode 100644 Documents/BKP/2/tmp.signalling.mq5 delete mode 100644 Documents/BKP/2/x-121.smc.xpvt.signal.lib.mq5 delete mode 100644 Documents/BKP/2/x-121.smc.xpz.signal.lib.mq5 delete mode 100644 Documents/BKP/2/x-121.smc.xrspvi.signal.lib.mq5 delete mode 100644 Documents/BKP/2/x-121.smc.xstrpv.signal.lib.mq5 diff --git a/Documents/BKP/1/1.mq5 b/Documents/BKP/1/1.mq5 deleted file mode 100644 index 90e6eeb9..00000000 --- a/Documents/BKP/1/1.mq5 +++ /dev/null @@ -1,580 +0,0 @@ -////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// --------------------------------------------- -// Name: XSTR -// Description: Super Trend Indicator ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121_XAMA Indicator" -#property strict - -// -// START Constants ... -// - -#define ShortName "XSTR" - -// -// END Constants ... -// - -// -// START Inputs ... -// - -// -// Market ... -input group "ATR"; -input int atrLength = 14; // Length -input double atrMultiplier = 3.0; // Multiplier -input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To - -// -// Presentation ... -input group "Presentation"; -input bool showTrends = true; // Show Trends -input bool fillTrends = true; // Fill Trends - -// -// END Inputs ... -// - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// START Buffers ... -// - -// -#property indicator_chart_window - -// -#property indicator_buffers 9 -#property indicator_plots 2 - -// -#define fillUpBufferIndex 0 -double fillUpBuffer[]; - -#define fillDownBufferIndex 1 -double fillDownBuffer[]; - -// -#define fillingPlotBufferIndex 0 - -// -#property indicator_label1 "XSTR Filling" -#property indicator_type1 DRAW_FILLING -#property indicator_color1 clrBisque, clrPaleGreen - -// -#define mainBufferIndex 2 -#define mainPlotBufferIndex 1 -double mainBuffer[]; - -// -#define mainColorBufferIndex 3 -double mainColorBuffer[]; - -// -#property indicator_label2 "XSTR" -#property indicator_type2 DRAW_COLOR_LINE -#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed -#property indicator_style2 STYLE_DOT - -// -// DATA Buffers ... - -// -#define atrBufferIndex 4 -double atrBuffer[]; - -// -#define trendBufferIndex 5 -double trendBuffer[]; - -// -#define upBufferIndex 6 -double upBuffer[]; - -// -#define downBufferIndex 7 -double downBuffer[]; - -// -#define priceBufferIndex 8 -double priceBuffer[]; - -// -// END Buffers ... -// - -// -// START Global Definitions: Variables, Properties and etc ... -// - -// -int maxLength; - -// -int atrHandler = INVALID_HANDLE; - -// -int changeOfTrend; -int startBearishTrend; -int startBullishTrend; - -// -// END Global Definitions: Variables, Properties and etc ... -// - -// -// START Event Handlers ... -// - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - atrHandler = iATR( - _Symbol, - _Period, - atrLength); - if (atrHandler == INVALID_HANDLE) - { - return INIT_FAILED; - } - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -// -// DeInitialization ... -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed - - // - // Here we can handle De Initialization Reasons ... - IndicatorRelease(atrHandler); -} - -// -// Calculating what we want ... -int OnCalculate( - // - // total Candles on chart ... - const int rates_total, - // - // total calculated Candles on charts ... - const int prev_calculated, - // - // history of Candles Open Time ... - const datetime &time[], - // - // history of Candles Open Price ... - const double &open[], - // - // history of Candles High Price ... - const double &high[], - // - // history of Candles Low Price ... - const double &low[], - // - // history of Candles Close Price ... - const double &close[], - // - // history of Tick Volumes on Candle ... - const long &tick_volume[], - // - // history of Trade Volumes ... - const long &volume[], - // - // history of Candles Spread Price ... - const int &spread[]) -{ - // - int numOfRequiredAtrs; - if (prev_calculated > rates_total || prev_calculated < 0) - { - numOfRequiredAtrs = rates_total; - } - else - { - // - numOfRequiredAtrs = rates_total - prev_calculated; - if (prev_calculated > 0) - { - numOfRequiredAtrs++; - } - } - - // - // Checking for stop ... - if (IsStopped()) - { - return 0; - } - - // - // Check Number of items Copy or not ... - int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer); - if (copiedATRs <= 0) - { - return 0; - } - - // - int limit; - - // - // checking for the limit start of calculation of an indicator ... - if (prev_calculated > rates_total || prev_calculated <= 0) - { - // - // starting index for calculation of all bars ... - limit = maxLength; - } - else - { - // - // starting number for calculation of new bars - limit = prev_calculated - 1; - } - - // - // Main Loop ... - for (int i = limit; i < rates_total && !IsStopped(); i++) - { - // - // Calculated Price ... - double price = getPrice( - atrAppliedTo, - open, - high, - low, - close, - i); - // price = (high[i] + low[i]) / 2; - priceBuffer[i] = price; - - // - double atr = atrBuffer[i]; - - // - // Up ... - upBuffer[i] = price + (atrMultiplier * atr); - - // - // Down ... - downBuffer[i] = price - (atrMultiplier * atr); - - // - if (close[i] > upBuffer[i - 1]) - { - // - trendBuffer[i] = 1; - if (trendBuffer[i - 1] == -1) - { - changeOfTrend = 1; - } - } - else if (close[i] < downBuffer[i - 1]) - { - // - trendBuffer[i] = -1; - if (trendBuffer[i - 1] == 1) - { - changeOfTrend = 1; - } - } - else if (trendBuffer[i - 1] == 1) - { - // - trendBuffer[i] = 1; - changeOfTrend = 0; - } - else if (trendBuffer[i - 1] == -1) - { - // - trendBuffer[i] = -1; - changeOfTrend = 0; - } - - // - // Down Trend Starting ... - if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0) - { - startBearishTrend = 1; - } - else - { - startBearishTrend = 0; - } - - // - // Up Trend Starting ... - if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0) - { - startBullishTrend = 1; - } - else - { - startBullishTrend = 0; - } - - // - if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1]) - { - downBuffer[i] = downBuffer[i - 1]; - } - - // - if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1]) - { - upBuffer[i] = upBuffer[i - 1]; - } - - // - if (startBearishTrend == 1) - { - upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr); - } - - // - if (startBullishTrend == 1) - { - downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr); - } - - // - // Draw the indicator ... - - // - double colorIDX = 0; - mainColorBuffer[i] = colorIDX; - - // - if (trendBuffer[i] == 1) - { - // - mainBuffer[i] = downBuffer[i]; - if (changeOfTrend == 1) - { - mainBuffer[i - 1] = mainBuffer[i - 2]; - changeOfTrend = 0; - } - - // - colorIDX = 1; - } - else if (trendBuffer[i] == -1) - { - // - mainBuffer[i] = upBuffer[i]; - if (changeOfTrend == 1) - { - // - mainBuffer[i - 1] = mainBuffer[i - 2]; - changeOfTrend = 0; - } - - // - colorIDX = 2; - } - - // - if (showTrends) - { - mainColorBuffer[i] = colorIDX; - } - - // - // Filling ... - if (fillTrends) - { - // - fillUpBuffer[i] = mainBuffer[i]; - fillDownBuffer[i] = close[i]; - } - else - { - // - fillUpBuffer[i] = EMPTY_VALUE; - fillDownBuffer[i] = EMPTY_VALUE; - } - } - - // - return rates_total; -} - -// -// END Event Handlers ... -// - -// -// START Functions ... -// - -// -// Validate Input Args for Initialization ... -bool ValidateInputs() -{ - // - bool result = false; - - // - // Validate Args ... - result = - // - atrLength >= 2 - // - ; - - // - return result; -} - -// -// Retrieve all Exists Input Max Length ... -// use for Start Of Drawing ... -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = atrLength; - - // - return result; -} - -// -// Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -// -// Define Indexes and Styles ... -void DefineBuffers() -{ - // - // PLOT Buffers ... - - // - // FILLINGS ... - SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA); - SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA); - PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false); - - // - // MAIN ... - SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA); - PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends); - SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX); - - // - // DATA Buffers ... - - // - // ATR ... - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); - - // - // TREND ... - SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS); - - // - // UP ... - SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS); - - // - // DOWN ... - SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS); - - // - // PRICE ... - SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS); -} - -// -// END Functions ... -// - -// -// TEMPLATE Function ... - -template -double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i) -{ - switch (tprice) - { - case PRICE_CLOSE: - return (close[i]); - case PRICE_OPEN: - return (open[i]); - case PRICE_HIGH: - return (high[i]); - case PRICE_LOW: - return (low[i]); - case PRICE_MEDIAN: - return ((high[i] + low[i]) / 2.0); - case PRICE_TYPICAL: - return ((high[i] + low[i] + close[i]) / 3.0); - case PRICE_WEIGHTED: - return ((high[i] + low[i] + close[i] + close[i]) / 4.0); - } - return (0); -} diff --git a/Documents/BKP/1/2.mq5 b/Documents/BKP/1/2.mq5 deleted file mode 100644 index 3081db24..00000000 --- a/Documents/BKP/1/2.mq5 +++ /dev/null @@ -1,195 +0,0 @@ - -//+------------------------------------------------------------------+ -//| SuperTrend.mq5 | -//| Copyright 2011, FxGeek | -//| http://www.mql5.com | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2011, FxGeek" -#property link " http://www.mql5.com" -#property version "1.00" -#property indicator_chart_window -#property indicator_buffers 9 -#property indicator_plots 2 - -#property indicator_label1 "Filling" -#property indicator_type1 DRAW_FILLING -#property indicator_color1 clrBisque, clrPaleGreen - -#property indicator_label2 "SuperTrend" -#property indicator_type2 DRAW_COLOR_LINE -#property indicator_color2 clrGreen, clrRed - -input int Periode=10; -input double Multiplier=3; -input bool Show_Filling=true; // Show as DRAW_FILLING - -double Filled_a[]; -double Filled_b[]; -double SuperTrend[]; -double ColorBuffer[]; -double Atr[]; -double Up[]; -double Down[]; -double Middle[]; -double trend[]; - -int atrHandle; -int changeOfTrend; -int flag; -int flagh; -//+------------------------------------------------------------------+ -//| Custom indicator initialization function | -//+------------------------------------------------------------------+ -int OnInit() - { -//--- indicator buffers mapping - SetIndexBuffer(0,Filled_a,INDICATOR_DATA); - SetIndexBuffer(1,Filled_b,INDICATOR_DATA); - SetIndexBuffer(2,SuperTrend,INDICATOR_DATA); - SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX); - SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS); - SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS); - SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS); - SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS); - SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS); - - atrHandle=iATR(_Symbol,_Period,Periode); -//--- - return(0); - } -//+------------------------------------------------------------------+ -//| Custom indicator iteration function | -//+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[]) - { -//--- - int to_copy; - if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total; - else - { - to_copy=rates_total-prev_calculated; - if(prev_calculated>0) to_copy++; - } - - if(IsStopped()) return(0); //Checking for stop flag - if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0) - { - Print("Getting Atr is failed! Error",GetLastError()); - return(0); - } - - int first; - if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator - { - first=Periode; // starting index for calculation of all bars - } - else - { - first=prev_calculated-1; // starting number for calculation of new bars - } - for(int i=first; iUp[i-1]) - { - trend[i]=1; - if(trend[i-1]==-1) changeOfTrend=1; - - } - else if(close[i]0) - { - flag=1; - } - else - { - flag=0; - } - - if(trend[i]>0 && trend[i-1]<0) - { - flagh=1; - } - else - { - flagh=0; - } - - if(trend[i]>0 && Down[i]Up[i-1]) - Up[i]=Up[i-1]; - - if(flag==1) - Up[i]=Middle[i]+(Multiplier*Atr[i]); - - if(flagh==1) - Down[i]=Middle[i]-(Multiplier*Atr[i]); - - //-- Draw the indicator - if(trend[i]==1) - { - SuperTrend[i]=Down[i]; - if(changeOfTrend==1) - { - SuperTrend[i-1]=SuperTrend[i-2]; - changeOfTrend=0; - } - ColorBuffer[i]=0.0; - } - else if(trend[i]==-1) - { - SuperTrend[i]=Up[i]; - if(changeOfTrend==1) - { - SuperTrend[i-1]= SuperTrend[i-2]; - changeOfTrend = 0; - } - ColorBuffer[i]=1.0; - } - - if(Show_Filling) - { - Filled_a[i]= SuperTrend[i]; - Filled_b[i]= close[i]; - }else{ - Filled_a[i]= EMPTY_VALUE; - Filled_b[i]= EMPTY_VALUE; - } - - } - -//--- return value of prev_calculated for next call - return(rates_total); - } -//+------------------------------------------------------------------+ - - \ No newline at end of file diff --git a/Documents/BKP/1/3.mq5 b/Documents/BKP/1/3.mq5 deleted file mode 100644 index 136b238d..00000000 --- a/Documents/BKP/1/3.mq5 +++ /dev/null @@ -1,319 +0,0 @@ - - // - // Reading Previous Conditions ... - ENUM_XPOI_EVENTS consolidationPoiEventsPrev[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEventsPrev[]; - X121SMCCycleConditions consolidationConditionsPrev; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEventsPrev, - consolidationPoiEventsPrev, - consolidationConditionsPrev, - cIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - X121SMCCycleConditions conditionState = consolidationConditions; - X121SMCCycleConditions conditionStatePrev = consolidationConditionsPrev; - - // - XOHCL cCBar; - result = cCBar.Init( - conditionState.symbol, - conditionState.period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cPBar; - result = cCBar.GetPreviousBar(cPBar); - if (!result) - { - return result; - } - - // - // Engulf ... - ENUM_X_DIRECTION cCBarEngulfDir; - bool isCCBarEngulfed = consolidationCycleHelper - .mBarAnalyser - .IsEngulfBar( - cCBar, - cCBarEngulfDir, - 0 // Extended ... - ); - bool isCCBarBullishEngulfed = - isCCBarEngulfed && - IsBullish(cCBarEngulfDir); - bool isCCBarBearishEngulfed = - isCCBarEngulfed && - IsBearish(cCBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cCBarMomentumDir; - bool isCCBarMomentum = consolidationCycleHelper - .mBarAnalyser - .IsMomentumBar( - cCBar, - cCBarMomentumDir, - 1 // Extended ... - ); - bool isCCBarBullishMomentum = - isCCBarMomentum && - IsBullish(cCBarMomentumDir); - bool isCCBarBearishMomentum = - isCCBarMomentum && - IsBearish(cCBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cCBarRejectDir; - bool isCCBarRejected = consolidationCycleHelper - .mBarAnalyser - .IsRejectionBar( - cCBar, - cCBarRejectDir, - 1 // Extended ... - ); - bool isCCBarBullishRejected = - isCCBarRejected && - IsBullish(cCBarRejectDir); - bool isCCBarBearishRejected = - isCCBarRejected && - IsBearish(cCBarRejectDir); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCCBarPassedBullish = - // - isCCBarBullishEngulfed || - isCCBarBullishMomentum || - isCCBarBullishRejected - // - ; - - // - // Bearish ... - bool isCCBarPassedBearish = - // - isCCBarBearishEngulfed || - isCCBarBearishMomentum || - isCCBarBearishRejected - // - ; - - // - double cPeakPrev = conditionStatePrev.x121Conditions.peaksBuffer[0]; - double cValePrev = conditionStatePrev.x121Conditions.valesBuffer[0]; - - // - double cPeak = conditionState.x121Conditions.peaksBuffer[1]; - double cVale = conditionState.x121Conditions.valesBuffer[1]; - - // - bool isCPeakSame = cPeak == cPeakPrev; - bool isCValeSame = cVale == cValePrev; - - // - bool isCNewPeakPrev = conditionStatePrev.x121Conditions.isNewPeak; - bool isCNewPeakOverLastPrev = conditionStatePrev.x121Conditions.isNewPeakOverLast; - bool isCNewPeakUnderLastPrev = conditionStatePrev.x121Conditions.isNewPeakUnderLast; - - // - bool isCNewValePrev = conditionStatePrev.x121Conditions.isNewVale; - bool isCNewValeOverLastPrev = conditionStatePrev.x121Conditions.isNewValeOverLast; - bool isCNewValeUnderLastPrev = conditionStatePrev.x121Conditions.isNewValeUnderLast; - - // - bool isCRSIOverSold = conditionState.x121Conditions.isRSIOverSold; - bool isCRSICrossedOverOverSold = conditionState.x121Conditions.isRSICrossedOverOverSold; - bool isCRSICrossedUnderOverSold = conditionState.x121Conditions.isRSICrossedUnderOverSold; - - // - bool isCRSIOverBought = conditionState.x121Conditions.isRSIOverBought; - bool isCRSICrossedOverOverBought = conditionState.x121Conditions.isRSICrossedOverOverBought; - bool isCRSICrossedUnderOverBought = conditionState.x121Conditions.isRSICrossedUnderOverBought; - - // - bool isCRSIOverSoldPrev = conditionStatePrev.x121Conditions.isRSIOverSold; - bool isCRSICrossedOverOverSoldPrev = conditionStatePrev.x121Conditions.isRSICrossedOverOverSold; - bool isCRSICrossedUnderOverSoldPrev = conditionStatePrev.x121Conditions.isRSICrossedUnderOverSold; - - // - bool isCRSIOverBoughtPrev = conditionStatePrev.x121Conditions.isRSIOverBought; - bool isCRSICrossedOverOverBoughtPrev = conditionStatePrev.x121Conditions.isRSICrossedOverOverBought; - bool isCRSICrossedUnderOverBoughtPrev = conditionStatePrev.x121Conditions.isRSICrossedUnderOverBought; - - // - isBullish = - // - isCNewValePrev && - isCCBarPassedBullish - // - ; - - // - isBearish = - // - isCNewPeakPrev && - isCCBarPassedBearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.pivot = - isBullish - ? conditionState.x121Conditions.valesBuffer[1] - : conditionState.x121Conditions.peaksBuffer[1]; - - // - double peak = analyseConditions.x121Conditions.peaksBuffer[1]; - double vale = analyseConditions.x121Conditions.valesBuffer[1]; - - // - double strUpper = analyseConditions.x121Conditions.strUpBuffer[1]; - double strLower = analyseConditions.x121Conditions.strDownBuffer[1]; - - // - bool isStrSwitchedToBullish = analyseConditions.x121Conditions.isStrSwitchedToBullish; - bool isStrSwitchedToBearish = analyseConditions.x121Conditions.isStrSwitchedToBearish; - - // - isBullish = isStrSwitchedToBullish; - isBearish = isStrSwitchedToBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.pivot = - isBullish - ? peak - : vale; - - - - // - // Looking For Sar Change ... - - // - double sar = analyseConditions.x121Conditions.sarBuffer[1]; - - // - double peak = analyseConditions.x121Conditions.peaksBuffer[1]; - double vale = analyseConditions.x121Conditions.valesBuffer[1]; - - // - bool isSarEqualsToPeak = analyseConditions.x121Conditions.isSarEqualsToPeak; - bool isSarEqualsToVale = analyseConditions.x121Conditions.isSarEqualsToVale; - - // - bool isSarSwitchedToBullish = analyseConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = analyseConditions.x121Conditions.isSarSwitchedToBearish; - - // - isBullish = - isBullish && - isSarEqualsToPeak && - isSarSwitchedToBullish; - - // - isBearish = - isBearish && - isSarEqualsToVale && - isSarSwitchedToBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - Print("Sar Switched ..."); - - - - // - // Detect a Zone Arround Price Zone ... - int supplyZonesCount = consolidationState.CountSupplyZones(); - if (IsValidSize(supplyZonesCount)) { - // - for (int i = 0; i < supplyZonesCount; i++) { - // - XCSupplyZone *iZone = consolidationState.supplyZones[i]; - - // - bool isOver = iZone.Lower() > pzUpper; - bool isUnder = iZone.Upper() < pzLower; - - // - bool isValid = - isOver || - isUnder; - if (isValid) { - - } - } - } - - // - // Method 1 ... - // VWap Switch Start ... - - // - bool bullishMethod1 = - // - isSarBullish && - isStrBullish && - isSlopesBullish && - hasBullishTrend && - cBar.IsBullish() && - isAtrBullishSlope && - isPVBullishFormed && - isRsiBullishFormed && - isVWapBullishFormed - // - ; - - // - bool bearishMethod1 = - // - isSarBearish && - isStrBearish && - isSlopesBearish && - hasBearishTrend && - cBar.IsBearish() && - isAtrBearishSlope && - isPVBearishFormed && - isRsiBearishFormed && - isVWapBearishFormed - // - ; diff --git a/Documents/BKP/1/4.mq5 b/Documents/BKP/1/4.mq5 deleted file mode 100644 index 15975f62..00000000 --- a/Documents/BKP/1/4.mq5 +++ /dev/null @@ -1,530 +0,0 @@ -////////////////////////////////////////////////////////////////////////////////// -////// Detect Price Zones : -///////////////////////////////////////////////////////////////////////////////// - - // - XPriceZones priceZone; - bool isPriceZoneValidForPeak; - bool isPriceZoneValidForVale; - - // - priceZone.Clean(); - isPriceZoneValidForPeak = false; - isPriceZoneValidForVale = false; - - // - // Detect Price Zone ... - - // - double pzPeak = decisionXConditions.peaksBuffer[1]; - double pzVale = decisionXConditions.valesBuffer[1]; - - // - // Detecting Decision Price ones ... - XPriceZones decisionPriceZone; - bool hasDecisionPriceZone = CalculatePriceInsideZones( - decisionPriceZone, - decisionState, - cBar // - ); - double decisionPriceZoneUpper = 0; - double decisionPriceZoneLower = 0; - bool isDecisionPriceZoneValidForPeak = false; - bool isDecisionPriceZoneValidForVale = false; - if (hasDecisionPriceZone) - { - // - bool hasBoundary = decisionPriceZone.GetBoundary( - X_DIRECTION_ALL, - decisionPriceZoneUpper, - decisionPriceZoneLower // - ); - - // - isDecisionPriceZoneValidForPeak = - hasBoundary && - pzPeak <= decisionPriceZoneUpper && - pzPeak >= decisionPriceZoneLower; - - // - isDecisionPriceZoneValidForVale = - hasBoundary && - pzVale <= decisionPriceZoneUpper && - pzVale >= decisionPriceZoneLower; - } - - // - // Detecting Analyse Price ones ... - XPriceZones analysePriceZone; - bool hasAnalysePriceZone = CalculatePriceInsideZones( - analysePriceZone, - analyseState, - cBar // - ); - double analysePriceZoneUpper = 0; - double analysePriceZoneLower = 0; - bool isAnalysePriceZoneValidForPeak = false; - bool isAnalysePriceZoneValidForVale = false; - if (hasAnalysePriceZone) - { - // - bool hasBoundary = analysePriceZone.GetBoundary( - X_DIRECTION_ALL, - analysePriceZoneUpper, - analysePriceZoneLower // - ); - - // - isAnalysePriceZoneValidForPeak = - hasBoundary && - pzPeak <= analysePriceZoneUpper && - pzPeak >= analysePriceZoneLower; - - // - isAnalysePriceZoneValidForVale = - hasBoundary && - pzVale <= analysePriceZoneUpper && - pzVale >= analysePriceZoneLower; - } - - // - // Detecting Verification Price ones ... - XPriceZones verificationPriceZone; - bool hasVerificationPriceZone = CalculatePriceInsideZones( - verificationPriceZone, - verificationState, - cBar // - ); - double verificationPriceZoneUpper = 0; - double verificationPriceZoneLower = 0; - bool isVerificationPriceZoneValidForPeak = false; - bool isVerificationPriceZoneValidForVale = false; - if (hasVerificationPriceZone) - { - // - bool hasBoundary = verificationPriceZone.GetBoundary( - X_DIRECTION_ALL, - verificationPriceZoneUpper, - verificationPriceZoneLower // - ); - - // - isVerificationPriceZoneValidForPeak = - hasBoundary && - pzPeak <= verificationPriceZoneUpper && - pzPeak >= verificationPriceZoneLower; - - // - isVerificationPriceZoneValidForVale = - hasBoundary && - pzVale <= verificationPriceZoneUpper && - pzVale >= verificationPriceZoneLower; - } - - -////////////////////////////////////////////////////////////////////////////////// -////// Detect Pivot Zones : -///////////////////////////////////////////////////////////////////////////////// - - // - double X121SMCXPivotPeak; - double X121SMCXPivotVale; - datetime X121SMCXPivotEnd; - datetime X121SMCXPivotStart; - ENUM_XPV_PIVOTS X121SMCXPivotType = XPV_NONE; - - // - // Detect PV Pivot ... - - // - bool isPivotPeakZoneRejected = false; - bool isPivotPeakZoneBreakedUp = false; - bool isPivotPeakZoneBreakedDown = false; - bool isPivotValeZoneRejected = false; - bool isPivotValeZoneBreakedUp = false; - bool isPivotValeZoneBreakedDown = false; - bool hasPivot = conditions.pivotZone.IsValid(); - if (!hasPivot) - { - // - hasPivot = IsValid(X121SMCXPivotStart); - if (!hasPivot) - { - // - bool isNewVale = decisionXConditions.isNewVale; - bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; - bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - - // - bool isNewPeak = decisionXConditions.isNewPeak; - bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; - bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - - // - bool isValeStart = - isSameVales && - isSameCycleVales; - bool isPeakStart = - isSamePeaks && - isSameCyclePeaks; - - // - bool isStart = isPeakStart || - isValeStart; - if (isStart) - { - // - X121SMCXPivotStart = cTime; - X121SMCXPivotType = - isPeakStart - ? XPV_PEAK - : XPV_VALE; - - // - X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXPivotVale = decisionXConditions.valesBuffer[1]; - } - - // - hasPivot = IsValid(X121SMCXPivotStart); - - // - // Create XPVPivot instance ... - if (hasPivot) - { - // - conditions.pivotZone.symbol = symbol; - conditions.pivotZone.period = period; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition = 3; - - // - conditions.pivotZone.upper = X121SMCXPivotPeak; - conditions.pivotZone.lower = X121SMCXPivotVale; - - // - conditions.pivotZone.type = X121SMCXPivotType; - conditions.pivotZone.from = X121SMCXPivotStart; - } - } - } - - // - if (hasPivot) - { - // - bool isBreaked = X121SMCXPivotType == XPV_PEAK - ? decisionXConditions.isBreakedUpPrevPeak - : decisionXConditions.isBreakedDownPrevVale; - - // - if (!isBreaked) - { - // - X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXPivotVale = decisionXConditions.valesBuffer[1]; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition++; - conditions.pivotZone.upper = X121SMCXPivotPeak; - conditions.pivotZone.lower = X121SMCXPivotVale; - } - else - { - // - X121SMCXPivotEnd = cTime; - conditions.pivotZone.to = cTime; - } - - // - // Fill Pivot State ... - - // - XPOIState analysePivotState; - DetectPivotPOIs( - conditions.pivotZone, - analyseState, - analysePivotState // - ); - - // - XPOIState decisionPivotState; - DetectPivotPOIs( - conditions.pivotZone, - decisionState, - decisionPivotState // - ); - - // - // Combine two State ... - XPOIState combinedPivotState; - XPOIState iStates[]; - AddRef( - analysePivotState, - iStates // - ); - AddRef( - decisionPivotState, - iStates // - ); - CombineStates( - combinedPivotState, - iStates // - ); - combinedPivotState = decisionPivotState; - - // - ArrayFree(iStates); - - // - combinedPivotState.time = decisionPivotState.time; - combinedPivotState.symbol = decisionPivotState.symbol; - combinedPivotState.period = decisionPivotState.period; - - // - // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... - FilterPivotState( - conditions.pivotZone, - combinedPivotState // - ); - - // - conditions.pivotZone.state = combinedPivotState; - - // - double peakUpper = 0; - double peakLower = 0; - double valeUpper = 0; - double valeLower = 0; - - // - datetime peakTo = NULL; - datetime valeTo = NULL; - datetime peakFrom = NULL; - datetime valeFrom = NULL; - - // - bool hasBoxData = DetectPivotStateBoxData( - conditions.pivotZone, - peakUpper, - peakLower, - peakFrom, - peakTo, - valeUpper, - valeLower, - valeFrom, - valeTo // - ); - - // - // Calculate Pivot Tick Zones ... - - // - int ticksLevels = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneLevel(); - int ticksRange = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneRange(); - - // - CalculatePivotTickZone( - conditions.pivotZone, - ticksLevels, - ticksRange // - ); - - // - isPivotPeakZoneRejected = - hasBoxData && - ( - // - IsBarReject( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - peakUpper, - X_DIRECTION_BEARISH, - cBar // - ) - // - ); - isPivotPeakZoneBreakedUp = - hasBoxData && - IsBarBreak( - peakUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotPeakZoneBreakedDown = - hasBoxData && - IsBarBreak( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotValeZoneRejected = - hasBoxData && - ( - // - IsBarReject( - valeLower, - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ) - // - ); - isPivotValeZoneBreakedUp = - hasBoxData && - IsBarBreak( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotValeZoneBreakedDown = - hasBoxData && - IsBarBreak( - valeLower, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - bool isPivotEnded = IsValid(X121SMCXPivotEnd); - if (isPivotEnded) - { - // - X121SMCXPivotPeak = 0; - X121SMCXPivotVale = 0; - X121SMCXPivotEnd = NULL; - X121SMCXPivotStart = NULL; - X121SMCXPivotType = XPV_NONE; - - // - conditions.pivotZone.Clean(); - } - - -////////////////////////////////////////////////////////////////////////////////// -////// Detect Pivot Zones : -///////////////////////////////////////////////////////////////////////////////// - - // - bool isCondition1Bullish = - // - hasPivot && - // - isCBarBullishFormed && - isCBarBullishPullbacked && - // - hasAnalyseBullishTrend && - hasDecisionBullishTrend && - hasVerificationBullishTrend && - // - decisionXConditions.isSarBullish && - analyseXConditions.isSarBullish && - verificationXConditions.isSarBullish && - // - false - // - ; - - // - bool isCondition1Bearish = - // - hasPivot && - // - isCBarBearishFormed && - isCBarBearishPullbacked && - // - hasAnalyseBearishTrend && - hasDecisionBearishTrend && - hasVerificationBearishTrend && - // - decisionXConditions.isSarBearish && - analyseXConditions.isSarBearish && - verificationXConditions.isSarBearish && - // - false - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - conditions.priceZone = analysePriceZone; - conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale; - - // - pzPeak = analysePriceZoneUpper; - pzVale = analysePriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - // point = - // isCondition1Bullish ? pzPeak - // : pzVale; - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCondition1Bullish - ? pzVale - : pzPeak; - } diff --git a/Documents/BKP/1/tmp.codes.mq5 b/Documents/BKP/1/tmp.codes.mq5 deleted file mode 100644 index 07fd1fbe..00000000 --- a/Documents/BKP/1/tmp.codes.mq5 +++ /dev/null @@ -1,729 +0,0 @@ - // - double cPZoneUpper = 0; - double cPZoneLower = 0; - datetime cPZoneFrom = NULL; - datetime cPZoneTo = NULL; - result = consolidationPriceZone.GetBoxData( - X_DIRECTION_ALL, - cPZoneUpper, - cPZoneLower, - cPZoneFrom, - cPZoneTo // - ); - if (!result) - { - return result; - } - - // - double aPZoneUpper = 0; - double aPZoneLower = 0; - datetime aPZoneFrom = NULL; - datetime aPZoneTo = NULL; - result = analysePriceZone.GetBoxData( - X_DIRECTION_ALL, - aPZoneUpper, - aPZoneLower, - aPZoneFrom, - aPZoneTo // - ); - if (!result) - { - return result; - } - - - // - // RSI ... - double rsi = decisionConditions.x121Conditions.rsiBuffer[1]; - - // - bool isRSIOverBought = decisionConditions.x121Conditions.isRSIOverBought; - bool isRSICrossedOverOverBought = decisionConditions.x121Conditions.isRSICrossedOverOverBought; - bool isRSICrossedUnderOverBought = decisionConditions.x121Conditions.isRSICrossedUnderOverBought; - - // - bool isRSIOverSold = decisionConditions.x121Conditions.isRSIOverSold; - bool isRSICrossedOverOverSold = decisionConditions.x121Conditions.isRSICrossedOverOverSold; - bool isRSICrossedUnderOverSold = decisionConditions.x121Conditions.isRSICrossedUnderOverSold; - - // - // PV ... - double peak = decisionConditions.x121Conditions.peaksBuffer[1]; - double vale = decisionConditions.x121Conditions.valesBuffer[1]; - - // - bool isNewPeak = decisionConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = decisionConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = decisionConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = decisionConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = decisionConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = decisionConditions.x121Conditions.isNewValeUnderLast; - - // - // STR ... - double str = decisionConditions.x121Conditions.strBuffer[1]; - - // - bool isStrBullish = decisionConditions.x121Conditions.isStrBullish; - bool isStrBearish = decisionConditions.x121Conditions.isStrBearish; - - // - bool isStrSwitchedToBullish = decisionConditions.x121Conditions.isStrSwitchedToBullish; - bool isStrSwitchedToBearish = decisionConditions.x121Conditions.isStrSwitchedToBearish; - - // - // ATR ... - double atr = decisionConditions.x121Conditions.atrBuffer[1]; - double atrUpper = decisionConditions.x121Conditions.atrUpperBuffer[1]; - double atrLower = decisionConditions.x121Conditions.atrLowerBuffer[1]; - - // - bool isCloseOverATRUpper = decisionConditions.x121Conditions.isCloseOverATRUpper; - bool isCloseOverATRLower = decisionConditions.x121Conditions.isCloseOverATRLower; - - // - bool isCloseUnderATRUpper = decisionConditions.x121Conditions.isCloseUnderATRUpper; - bool isCloseUnderATRLower = decisionConditions.x121Conditions.isCloseUnderATRLower; - - // - bool isRejectUpATRUpper = decisionConditions.x121Conditions.isRejectUpATRUpper; - bool isRejectDownATRUpper = decisionConditions.x121Conditions.isRejectDownATRUpper; - - // - bool isRejectUpATRLower = decisionConditions.x121Conditions.isRejectUpATRLower; - bool isRejectDownATRLower = decisionConditions.x121Conditions.isRejectDownATRLower; - - // - bool isBreakUpATRUpper = decisionConditions.x121Conditions.isBreakUpATRUpper; - bool isBreakDownATRUpper = decisionConditions.x121Conditions.isBreakDownATRUpper; - - // - bool isBreakUpATRLower = decisionConditions.x121Conditions.isBreakUpATRLower; - bool isBreakDownATRLower = decisionConditions.x121Conditions.isBreakDownATRLower; - - // - // SAR ... - double sar = decisionConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarBullish = decisionConditions.x121Conditions.isSarBullish; - bool isSarBearish = decisionConditions.x121Conditions.isSarBearish; - - // - bool isSarSwitchedToBullish = decisionConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = decisionConditions.x121Conditions.isSarSwitchedToBearish; - - // - // DON ... - - // - double donOpenUpper = decisionConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOpenLower = decisionConditions.x121Conditions.donOpenLowerBuffer[1]; - double donHighUpper = decisionConditions.x121Conditions.donHighUpperBuffer[1]; - double donHighLower = decisionConditions.x121Conditions.donHighLowerBuffer[1]; - double donLowUpper = decisionConditions.x121Conditions.donLowUpperBuffer[1]; - double donLowLower = decisionConditions.x121Conditions.donLowLowerBuffer[1]; - double donCloseUpper = decisionConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCloseLower = decisionConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - bool isRejectDonOpenUpper = decisionConditions.x121Conditions.isRejectDonOpenUpper; - bool isRejectDonHighUpper = decisionConditions.x121Conditions.isRejectDonHighUpper; - bool isRejectDonLowUpper = decisionConditions.x121Conditions.isRejectDonLowUpper; - bool isRejectDonCloseUpper = decisionConditions.x121Conditions.isRejectDonCloseUpper; - - // - bool isRejectDonOpenLower = decisionConditions.x121Conditions.isRejectDonOpenLower; - bool isRejectDonHighLower = decisionConditions.x121Conditions.isRejectDonHighLower; - bool isRejectDonLowLower = decisionConditions.x121Conditions.isRejectDonLowLower; - bool isRejectDonCloseLower = decisionConditions.x121Conditions.isRejectDonCloseLower; - - // - bool isBreakDonOpenUpper = decisionConditions.x121Conditions.isBreakDonOpenUpper; - bool isBreakDonHighUpper = decisionConditions.x121Conditions.isBreakDonHighUpper; - bool isBreakDonLowUpper = decisionConditions.x121Conditions.isBreakDonLowUpper; - bool isBreakDonCloseUpper = decisionConditions.x121Conditions.isBreakDonCloseUpper; - - // - bool isBreakDonOpenLower = decisionConditions.x121Conditions.isBreakDonOpenLower; - bool isBreakDonHighLower = decisionConditions.x121Conditions.isBreakDonHighLower; - bool isBreakDonLowLower = decisionConditions.x121Conditions.isBreakDonLowLower; - bool isBreakDonCloseLower = decisionConditions.x121Conditions.isBreakDonCloseLower; - - // - // VWAP ... - - // - // COMPLEX ... - // Complex Conditions ... - - // - bool isNewPeakOverATRUpper = - isNewPeak && - peak > atrUpper; - - // - bool isNewValeUnderATRLower = - isNewVale && - vale < atrLower; - - // - bool isDonHighUpperEqualsToPeak = - donHighUpper == peak; - - // - bool isDonLowLowerEqualsToVale = - donLowLower == vale; - - // - bool isBullishSign = ( - // - triggerConditions.x121Conditions.isBreakUpATRLower || - triggerConditions.x121Conditions.isRejectUpATRLower || - triggerConditions.x121Conditions.isBreakDonHighLower || - triggerConditions.x121Conditions.isRejectDonHighLower || - triggerConditions.x121Conditions.isBreakDonCloseLower || - triggerConditions.x121Conditions.isRejectDonCloseLower - // - ); - bool isBearishSign = ( - // - triggerConditions.x121Conditions.isBreakDownATRUpper || - triggerConditions.x121Conditions.isRejectDownATRUpper || - triggerConditions.x121Conditions.isBreakDonLowUpper || - triggerConditions.x121Conditions.isRejectDonLowUpper || - triggerConditions.x121Conditions.isBreakDonCloseUpper || - triggerConditions.x121Conditions.isRejectDonCloseUpper - // - ); - - - - // - // Check RSI in Over Bought or Over Sold ... - - // - bool isRSICrossedOverOverSold = consolidationConditions.x121Conditions.isRSICrossedOverOverSold; - bool isRSICrossedUnderOverBought = consolidationConditions.x121Conditions.isRSICrossedUnderOverBought; - - // - result = isRSICrossedOverOverSold || - isRSICrossedUnderOverBought; - if (!result) - { - return result; - } - - -/////////////////////////////////////////////// - - - -/** - * Draw X121 SMC Conditions ... - * - * @param conditions: X121SMCStrategyConditions instance Reference ... - * @param drawMarketStructure: Boolean ... - * @param drawPriceZones: Boolean ... - * @param drawDecisionZones: Boolean ... - * - * @return ( int ) - */ -int DrawX121SMCStrategyConditions( - X121SMCStrategyConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer, - bool drawMarketStructure = true, - bool drawPriceZones = true, - bool drawDecisionZones = true, - bool drawOnlyPriceZonesBoundary = true // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL || - !conditions.IsValid() || - !HasDirection(conditions.signalDir)) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.signalDir); - - // // - // bool hasPriceZones = conditions.priceZones.IsValid(); - // if (hasPriceZones && - // drawPriceZones) - // { - // // - // XCBaseObject *objects[]; - // int objectsCount = drawer.DrawPriceZone( - // conditions.priceZones, - // objects, - // conditions.signalDir, - // drawOnlyPriceZonesBoundary // - // ); - // if (IsValidSize(objectsCount)) - // { - // // - // Copy( - // objects, - // drawnObjects, - // false // - // ); - // } - // } - - // // - // bool hasDecisionZones = conditions.decisionZones.IsValid(); - // if (hasDecisionZones && - // drawDecisionZones) - // { - // // - // XCBaseObject *objects[]; - // int objectsCount = drawer.DrawPriceZone( - // conditions.decisionZones, - // objects, - // conditions.signalDir, - // drawOnlyPriceZonesBoundary // - // ); - // if (IsValidSize(objectsCount)) - // { - // // - // Copy( - // objects, - // drawnObjects, - // false // - // ); - // } - // } - - // // - // bool hasMarketStructure = conditions.marketStructure.IsValid(); - // if (hasMarketStructure && - // drawMarketStructure) - // { - // // - // XCBaseObject *objects[]; - // int objectsCount = drawer.DrawMarketStructure( - // conditions.marketStructure, - // objects // - // ); - // if (IsValidSize(objectsCount)) - // { - // // - // Copy( - // objects, - // drawnObjects, - // false // - // ); - // } - // } - - // - result = ArraySize(drawnObjects); - - // - return result; -} - - -//////////////////////////////////////////////// - - // // - // isCBarBearishFormed && - // (isPivotToDownRejected || - // isPivotToDownBreaked) && - // conditions.pivotZone.IsVale() && - // // - // // SAR ... - // isSarBearishFormed && - // // // - // // // STR ... - // // !(decisionXConditions.isStrBullish) && - // // // - // // // VWAP ... - // // !(decisionXConditions.isVWapBullishState || - // // decisionXConditions.isVWapBullishOrdered) && - // // - - - // // - // isCBarBullishFormed && - // (isPivotToUpRejected || - // isPivotToUpBreaked) && - // conditions.pivotZone.IsPeak() && - // // - // // SAR ... - // isSarBullishFormed && - // // // - // // // STR ... - // // !(decisionXConditions.isStrBearish) && - // // // - // // // VWAP ... - // // !(decisionXConditions.isVWapBearishState || - // // decisionXConditions.isVWapBearishOrdered) && - // // - -///////////////////////////////////////////////////////////////////// - - visionXConditions.isBreakedUpPrevCheMax && - visionXConditions.isCheSwitchedToBullish - - visionXConditions.isCheSwitchedToBearish && - visionXConditions.isBreakedDownPrevCheMin - -////////////////////////////////////////////////////////////////////// - - // - bool hasOrderBlock = hasBullishOrderBlocks || - hasBearishOrderBlocks; - if (hasOrderBlock) - { - // - Print("Detect Order Block ..."); - - // - XCBaseObject *drawnObjects[]; - - // - if (hasBullishOrderBlocks) - { - // - for (int i = 0; i < bullishOrderBlocksCount; i++) - { - // - XCOrderBlock *iOb = bullishOBs[i]; - - // - XCBullishOrderBlockObject *iObObj; - bool isCreated = triggerCycleHelper - .mPOIDetector - .mDrawer - .CreateBullishOrderBlock( - iOb, - iObObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObObj, - drawnObjects // - ); - } - } - } - - // - if (hasBearishOrderBlocks) - { - // - for (int i = 0; i < bearishOrderBlocksCount; i++) - { - // - XCOrderBlock *iOb = bearishOBs[i]; - - // - XCBearishOrderBlockObject *iObObj; - bool isCreated = triggerCycleHelper - .mPOIDetector - .mDrawer - .CreateBearishOrderBlock( - iOb, - iObObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObObj, - drawnObjects // - ); - } - } - } - - // - int drawnCount = ArraySize(drawnObjects); - if (IsValidSize(drawnCount)) - { - Print(""); - } - } - -////////////////////////////////////////////////////////////////////// - - - // - // Summarize Conditions ... - - // - bool isCondition1Bullish = - // - // Vision ... - ( - // - false - // - ) - // - && - // - // Consolidation ... - ( - // - true - // - ) - // - && - // - // Verification ... - ( - // - true - // - ) - // - && - // - // Analyse ... - ( - // - true - // - ) - // - && - // - // Decision ... - ( - // - true - // - ) - // - ; - - // - bool isCondition1Bearish = - // - // Vision ... - ( - // - false - // - ) - // - && - // - // Consolidation ... - ( - // - true - // - ) - // - && - // - // Verification ... - ( - // - true - // - ) - // - && - // - // Analyse ... - ( - // - true - // - ) - // - && - // - // Decision ... - ( - // - true - // - ) - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - // conditions.pivot = - // isCondition1Bullish - // ? conditions.pivotZone.upper - // : conditions.pivotZone.lower; - } - - -///////////////////////////////////////////////////////////////////////// - - // - // DRAW ... - // - - // - XCBaseObject *drawnObjects[]; - - // - if (hasBullishOrderBlocks) - { - // - for (int i = 0; i < bullishOrderBlocksCount; i++) - { - // - XCOrderBlock *iOb = conditions.bullishOBs[i]; - - // - XCBullishOrderBlockObject *iObObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateBullishOrderBlock( - iOb, - iObObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObObj, - drawnObjects // - ); - } - } - } - - // - if (hasBearishOrderBlocks) - { - // - for (int i = 0; i < bearishOrderBlocksCount; i++) - { - // - XCOrderBlock *iOb = conditions.bearishOBs[i]; - - // - XCBearishOrderBlockObject *iObObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateBearishOrderBlock( - iOb, - iObObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObObj, - drawnObjects // - ); - } - } - } - - // - // if (hasOldestBullishOB) - // { - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // oldestBullishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - - // // - // if (hasYoungestBullishOB) - // { - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // youngestBullishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - - // // - // if (hasOldestBearishOB) - // { - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // oldestBearishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - - // // - // if (hasYoungestBearishOB) - // { - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // youngestBearishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - -///////////////////////////////////////////////////////////////////////// diff --git a/Documents/BKP/1/x-121.smc.market.cycle.helper.class.old.mq5 b/Documents/BKP/1/x-121.smc.market.cycle.helper.class.old.mq5 deleted file mode 100644 index 492a1aad..00000000 --- a/Documents/BKP/1/x-121.smc.market.cycle.helper.class.old.mq5 +++ /dev/null @@ -1,4143 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XC121SMCCycleHelper -// Description: provides all based classes for use ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../../Classes/x-saherelm.x-poi.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... - -// -// Implementations ... - -enum ENUM_X_CYCLES -{ - X_CYCLE_NONE, - X_CYCLE_TRIGGER, - X_CYCLE_DECISION, - X_CYCLE_ANALYSE, - X_CYCLE_VERIFICATION, - X_CYCLE_CONSOLIDATION, - X_CYCLE_VISION, -}; - -string ToString(ENUM_X_CYCLES value) -{ - // - string result = EnumToString(value); - - // - StringReplace(result, "X_CYCLE_", ""); - - // - return result; -} - -enum ENUM_X_CYCLE_EVENTS -{ - SAR_CHANGE_DETECTED, - NEW_PEAK_DETECTED, - NEW_VALE_DETECTED, - PIVOT_POINT_DETECTED, - VWAP_ORDER_CHANGE_ETECTED, - VWAP_STATE_CHANGE_DETCTED, - CONSOLIDATION_BREAKED_DETECTED, - PEAK_PIVOT_STARTED, - PEAK_PIVOT_ENDED, - VALE_PIVOT_STARTED, - VALE_PIVOT_ENDED, -}; - -class XC121SMCCycleHelper : public XCBase -{ - // - public: - // - // Props ... - - // - // X121 ... - XCX121Helper *mX121Helper; - - // - // POI Detector ... - XCPOIDetector *mPOIDetector; - - // - // Bar Analyser - XCBarAnalyser *mBarAnalyser; - - // - // Constructor(s) ... - XC121SMCCycleHelper() - { - Default(); - } - - // - // Deconstructor ... - ~XC121SMCCycleHelper() - { - DeInit(); - } - - // - // Getter/Setter(s) ... - - /** - * Get Max llowed Changes to Save ... - * - * @return ( int ) - */ - int MaxAllowedSavedChanges() - { - return mMaxAllowedSavedChanges; - } - - /** - * Set Max llowed Changes to Save ... - * - * @param value: Integer ... - */ - void MaxAllowedSavedChanges(int value) - { - // - if (value < 10) - { - value = 10; - } - - // - mMaxAllowedSavedChanges = value; - } - - /** - * Get Consolidation Loopback Length ... - * - * @return ( int ) - */ - int ConsolidationLoopback() - { - return mConsolidationLoopback; - } - - /** - * Set Consolidation Loopback Length ... - * - * @param value: Integer ... - */ - void ConsolidationLoopback(int value) - { - // - if (value < 7) - { - value = 7; - } - - // - mConsolidationLoopback = value; - } - - /** - * Get Valid Pivot Points Repetition Length ... - * min => 7 - * - * @return ( int ) - */ - int ValidPivotRepetition() - { - return mValidPivotRepetition; - } - - /** - * Set Valid Pivot Points Repetition Length ... - * - * @param value: Integer ... - * min => 7 - */ - void ValidPivotRepetition(int value) - { - // - if (value < 7) - { - value = 7; - } - - // - mValidPivotRepetition = value; - } - - // - // Actions ... - - /** - * Initialize ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - * @param x121Inputs: X121Inputs instance ... - * - * @return ( bool ) - */ - bool Init( - string symbol, - ENUM_TIMEFRAMES period, - X121Inputs &x121Inputs // - ) - { - // - bool result = false; - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - return result; - } - - // - // X121 ... - mX121Helper = new XCX121Helper(); - result = mX121Helper.Init( - symbol, - period, - x121Inputs // - ); - if (!result) - { - return result; - } - - // - mPOIDetector = new XCPOIDetector( - symbol, - period // - ); - mPOIDetector.MaxNumberOfRequiredPOIs(10); - mPOIDetector.Init(); - - // - // Initialize Bar Analyser Class Instance ... - mBarAnalyser = new XCBarAnalyser(); - - // - // Set Chart Style ... - ApplyChartStyle(); - - // - return result; - } - - /** - * Retrieve Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - // - string result = NULL; - - // - result = mX121Helper.GetSymbol(); - - // - return result; - } - - /** - * Retrieve TimeFrame (Period) ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - // - ENUM_TIMEFRAMES result = NULL; - - // - result = mX121Helper.GetPeriod(); - - // - return result; - } - - /** - * Get Specified Bar ... - * - * @param source: XOHCL instance, Source Bar ... - * @param bar: XOHCL instance, Dest Bar ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &source, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = - IsValid(symbol) && - IsValid(period) && - source.IsValid(); - if (!result) - { - return result; - } - - // - int index = iBarShift( - symbol, - period, - source.time // - ); - result = bar.Init( - symbol, - period, - index // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param index: Integer ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - int index = 0 // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (index < 0) - { - index = 0; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param time: Datetime ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - datetime time = NULL // - ) - { - // - bool result = false; - - // - int index = GetBarIndex(time); - result = GetBar(bar, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Time Bar Index ... - * - * @param time: DateTime ... - * - * @return ( int ) - */ - int GetBarIndex(datetime time = NULL) - { - // - int result = -1; - - // - time = NormalizeTime(time); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = iBarShift( - symbol, - period, - time // - ); - - // - return result; - } - - /** - * Retrieve Cycle Conditions ... - * - * @param events: ENUM_X_CYCLE_EVENTS member, Array ... - * @param conditions: X121SMCCycleConditions instance ... - * @param barIndex: Integer ... - * @param loopback: Integer ... - * - * @return ( bool ) - */ - bool GetConditions( - ENUM_X_CYCLE_EVENTS &events[], - ENUM_XPOI_EVENTS &poiEvents[], - X121SMCCycleConditions &conditions, - int barIndex = 0, - int loopback = 7 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 5) - { - loopback = 5; - } - - // - Clean(events); - Clean(poiEvents); - conditions.Clean(); - - // - result = mX121Helper.GetConditions( - conditions.x121Conditions, - barIndex, - loopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - mPOIDetector.Update(poiEvents); - mPOIDetector.GetState(conditions.state); - - // - conditions.symbol = conditions.x121Conditions.symbol; - conditions.period = conditions.x121Conditions.period; - conditions.time = TimeCurrent(); - - // - result = conditions.IsValid(); - - // - if (result) - { - // - if (!IsValidSize(ArraySize(mPivots))) - { - Detect(barIndex); - } - - // - Calculate( - barIndex, - events, - conditions // - ); - } - - // - return result; - } - - /** - * Detect Market Structure ... - * - * @param model: XMarketStructure instance Reference ... - * - * @return ( bool ) - */ - bool DetectMarketStructure( - XMarketStructure &model // - ) - { - // - bool result = false; - - // - model.Clean(); - - // - int barIndex = 0; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - model.symbol = symbol; - model.period = period; - - // - int highestPeakIndex = -1; - double highestPeakVale = 0; - double highestPeak = mX121Helper - .GetHighestPeak( - barIndex, - highestPeakIndex, - highestPeakVale // - ); - - // - int lowestValeIndex = -1; - double lowestValePeak = 0; - double lowestVale = mX121Helper - .GetLowestVale( - barIndex, - lowestValeIndex, - lowestValePeak // - ); - - // - result = IsValidIndex(highestPeakIndex) && - IsValidIndex(lowestValeIndex); - if (!result) - { - return result; - } - - // - model.bias = - highestPeakIndex < lowestValeIndex - ? X_DIRECTION_BEARISH - : highestPeakIndex > lowestValeIndex - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE; - - // - result = HasDirection(model.bias); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(model.bias); - - // - // Looking for Change Of Character Proved ... - - // - // Bullish Bias: - // - Price Must Break Up Lowst Vale's Peak; - // - Create a Vale Above Lowest Vale's Peak; - - // - // Bearish Bias: - // - Price Must Breake Down HighestPeak's Vale; - // - Create a Peak Under Highest Peak's Vale; - - // - // Checking Peak Breake Up ... - int lowestValePeakBreakeUpIndex = -1; - for (int i = lowestValeIndex; i >= barIndex; i--) - { - // - XOHCL iBar; - result = GetBar(iBar, i); - if (!result) - { - continue; - } - - // - bool isBreake = iBar.IsBreakeUp(lowestValePeak); - if (isBreake) - { - // - lowestValePeakBreakeUpIndex = i; - break; - } - } - bool isValidBreakeUpLowestValePeak = IsValidIndex(lowestValePeakBreakeUpIndex) && - lowestValePeakBreakeUpIndex <= lowestValeIndex; - - // - // Checking Vale Breake Down ... - int highestPeakValeBreakeDownIndex = -1; - for (int i = highestPeakIndex; i >= barIndex; i--) - { - // - XOHCL iBar; - result = GetBar(iBar, i); - if (!result) - { - continue; - } - - // - bool isBreake = iBar.IsBreakeDown(highestPeakVale); - if (isBreake) - { - // - highestPeakValeBreakeDownIndex = i; - break; - } - } - bool isValidBreakeDownHighestPeakVale = IsValidIndex(highestPeakValeBreakeDownIndex) && - highestPeakValeBreakeDownIndex <= highestPeakIndex; - // - result = isBullish - ? isValidBreakeUpLowestValePeak - : isValidBreakeDownHighestPeakVale; - if (!result) - { - return result; - } - - // - // Checking Create a Vale above Peak ... - int valeAboveLowestValePeakIndex = -1; - double valeAboveLowestValePeakPeak = 0; - for (int i = lowestValePeakBreakeUpIndex; i >= barIndex; i--) - { - // - double iVale = mX121Helper.GetVale(i); - - // - bool isValid = - iVale > 0 && - iVale > lowestValePeak; - if (isValid) - { - // - valeAboveLowestValePeakIndex = i; - valeAboveLowestValePeakPeak = mX121Helper.GetPeak(i); - break; - } - } - bool isValidValeAboveLowestValePeak = IsValidIndex(valeAboveLowestValePeakIndex) && - valeAboveLowestValePeakIndex < lowestValePeakBreakeUpIndex; - - // - // Checking Create a Peak below Vale ... - int peakBelowHighestPeakValeIndex = -1; - double peakBelowHighestPeakValeVale = 0; - for (int i = highestPeakValeBreakeDownIndex; i >= barIndex; i--) - { - // - double iPeak = mX121Helper.GetPeak(i); - - // - bool isValid = - iPeak > 0 && - iPeak < highestPeakVale; - if (isValid) - { - // - peakBelowHighestPeakValeIndex = i; - peakBelowHighestPeakValeVale = mX121Helper.GetVale(i); - break; - } - } - bool isValidPeakBelowHighestPeakVale = IsValidIndex(peakBelowHighestPeakValeIndex) && - peakBelowHighestPeakValeIndex < highestPeakValeBreakeDownIndex; - - // - result = isBullish ? isValidValeAboveLowestValePeak - : isValidPeakBelowHighestPeakVale; - if (!result) - { - return result; - } - - // - // Now we Have to Detect Valid Peaks and Valid Vales Here ... - // based on Detected Range ... - - // - XPVPivotPoint iPeakPoint; - XPVPivotPoint iValePoint; - XPriceZones peakPriceZone; - XPriceZones valePriceZone; - - // - XPOIState state; - mPOIDetector.GetState( - state // - ); - - // - int minRepetition = 5; - - // - int from = - isBullish - ? valeAboveLowestValePeakIndex - : peakBelowHighestPeakValeIndex; - for (int i = from; i >= barIndex; i--) - { - // - XOHCL iBar; - bool isInited = GetBar(iBar, i); - - // - double iPeak = mX121Helper.GetPeak(i); - double iVale = mX121Helper.GetVale(i); - - // - bool hasPeakPriceInsideZone = CalculatePriceInsideZones( - peakPriceZone, - state, - iPeak // - ); - bool hasValePriceInsideZone = CalculatePriceInsideZones( - valePriceZone, - state, - iVale // - ); - - // - if (hasPeakPriceInsideZone) - { - // - // Peak ... - if (!iPeakPoint.IsValid()) - { - // - // Initialization ... - iPeakPoint.value = iPeak; - iPeakPoint.repetition = 1; - iPeakPoint.type = XPV_PEAK; - iPeakPoint.time = iBar.time; - } - else - { - // - if (iPeakPoint.value == iPeak) - { - iPeakPoint.repetition++; - } - else - { - // - if (iPeakPoint.repetition > minRepetition) - { - // - AddRef( - iPeakPoint, - model.peaks // - ); - - // - AddRef( - peakPriceZone, - model.peakPriceZones // - ); - } - - // - iPeakPoint.Clean(); - peakPriceZone.Clean(); - iPeakPoint.value = iPeak; - iPeakPoint.repetition = 1; - iPeakPoint.type = XPV_PEAK; - iPeakPoint.time = iBar.time; - } - } - } - - // - if (hasValePriceInsideZone) - { - // - // Vale ... - if (!iValePoint.IsValid()) - { - // - // Initialization ... - iValePoint.value = iVale; - iValePoint.repetition = 1; - iValePoint.type = XPV_VALE; - iValePoint.time = iBar.time; - } - else - { - // - if (iValePoint.value == iVale) - { - iValePoint.repetition++; - } - else - { - // - if (iValePoint.repetition > minRepetition) - { - // - AddRef( - iValePoint, - model.vales // - ); - - // - AddRef( - valePriceZone, - model.valePriceZones // - ); - } - - // - iValePoint.Clean(); - valePriceZone.Clean(); - iValePoint.value = iVale; - iValePoint.repetition = 1; - iValePoint.type = XPV_VALE; - iValePoint.time = iBar.time; - } - } - } - } - - // - // in Bullish Bias we Looking for Vales Oder ... - // in Bearish Bias we Looking for Peaks Oder ... - - // - // Bullish Bias Drawn ... - if (isBullish) - { - // - result = GetBar( - model.lowestValeBar, - lowestValeIndex // - ); - if (!result) - { - return result; - } - - // - if (isValidBreakeUpLowestValePeak) - { - // - result = GetBar( - model.lowestValePeakBreakeUpBar, - lowestValePeakBreakeUpIndex // - ); - if (!result) - { - return result; - } - } - - // - if (isValidValeAboveLowestValePeak) - { - // - result = GetBar( - model.valeAboveLowestValePeakBar, - valeAboveLowestValePeakIndex // - ); - if (!result) - { - return result; - } - } - } - - // - // Bearish Bias Drawn ... - if (!isBullish) - { - // - result = GetBar( - model.highestPeakBar, - highestPeakIndex // - ); - if (!result) - { - return result; - } - - // - if (isValidBreakeDownHighestPeakVale) - { - // - result = GetBar( - model.highestPeakValeBreakeDownBar, - highestPeakValeBreakeDownIndex // - ); - if (!result) - { - return result; - } - } - - // - if (isValidPeakBelowHighestPeakVale) - { - // - result = GetBar( - model.peakBelowHighestPeakValeBar, - peakBelowHighestPeakValeIndex // - ); - if (!result) - { - return result; - } - } - } - - // - result = model.IsValid(); - - // - return result; - } - - // - // Tools ... - - /** - * Get POI State of Specified Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * @param lookupSwingHighs: Boolean ... - * @param lookupSwingLows: Boolean ... - * @param lookupSupportZones: Boolean ... - * @param lookupResistanceZones: Boolean ... - * @param lookupSupplyZones: Boolean ... - * @param lookupDemandZones: Boolean ... - * @param lookupBullishOrderBlocks: Boolean ... - * @param lookupBearishOrderBlocks: Boolean ... - * @param lookupBullishFairValueGaps: Boolean ... - * @param lookupBearishFairValueGaps: Boolean ... - * @param lookupBullishRejectionBars: Boolean ... - * @param lookupBearishRejectionBars: Boolean ... - * @param lookupBullishMomentumBars: Boolean ... - * @param lookupBearishMomentumBars: Boolean ... - * - * @return ( bool ) - */ - bool FillPivotState( - XPVPivot &pivot, - bool lookupSwingHighs = true, - bool lookupSwingLows = true, - bool lookupSupportZones = true, - bool lookupResistanceZones = true, - bool lookupSupplyZones = true, - bool lookupDemandZones = true, - bool lookupBullishOrderBlocks = true, - bool lookupBearishOrderBlocks = true, - bool lookupBullishFairValueGaps = true, - bool lookupBearishFairValueGaps = true, - bool lookupBullishRejectionBars = true, - bool lookupBearishRejectionBars = true, - bool lookupBullishMomentumBars = true, - bool lookupBearishMomentumBars = true // - ) - { - // - bool result = false; - - // - XPOIState state; - state.Clean(); - - // - result = pivot.IsValid(); - if (!result) - { - return result; - } - - // - XPOIState _state; - mPOIDetector.GetState(_state); - result = _state.IsValid() && - _state.HasChild(); - if (!result) - { - return result; - } - - // - DetectPivotPOIs( - pivot, - _state, - state, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - result = state.IsValid() && - state.HasChild(); - if (result) - { - // - pivot.state = state; - - // - CalculatePivotTickZone(pivot); - } - - // - return result; - } - - /** - * Validate Specified Pivot's State ... - * - * @param pivot: XPVPivot instance Reference ... - * @param barIndex: Integer ... - */ - void ValidatePivotState( - XPVPivot &pivot, - int barIndex = 0 // - ) - { - // - if (!pivot.IsValid() || - !pivot.state.IsValid() || - !pivot.state.HasChild()) - { - return; - } - - // - double upperr = pivot.upper; - double lower = pivot.lower; - - // - XOHCL cBar; - bool isInited = cBar.Init( - pivot.symbol, - pivot.period, - barIndex // - ); - if (!isInited) - { - return; - } - - // - int count = 0; - - // - double ask = GetAsk(pivot.symbol); - double bid = GetBid(pivot.symbol); - - // - double pivotMid = pivot.CalculateMid(); - - // - // Try to Validate States ... - - // - bool isPriceInPremium = - // - ask > pivotMid && - bid > pivotMid && - cBar.low > pivotMid - // - ; - - // - bool isPriceInDiscount = - // - ask < pivotMid && - bid < pivotMid && - cBar.high < pivotMid - // - ; - - // - // Swings ... - XCSwing *tmpSwings[]; - - // - // Swing Highs ... - Clean(tmpSwings); - count = pivot.state.CountSwingHighs(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = pivot.state.swingHighs[i]; - - // - bool isValid = - // - iSwing.GetTime() >= pivot.from && - iSwing.GetTime() <= pivot.to && - iSwing.GetValue() > pivotMid - // - ; - if (isValid) - { - // - Add( - iSwing, - tmpSwings // - ); - } - } - - // - Copy( - tmpSwings, - pivot.state.swingHighs // - ); - } - } - - // - // Swing Lows ... - Clean(tmpSwings); - count = pivot.state.CountSwingLows(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = pivot.state.swingLows[i]; - - // - bool isValid = - // - iSwing.GetTime() >= pivot.from && - iSwing.GetTime() <= pivot.to && - iSwing.GetValue() < pivotMid - // - ; - if (isValid) - { - // - Add( - iSwing, - tmpSwings // - ); - } - } - - // - Copy( - tmpSwings, - pivot.state.swingLows // - ); - } - } - - // - Clean(tmpSwings); - - // - // Rejection Bars ... - XCRejectionBar *tmpRejections[]; - - // - // Bullish ... - Clean(tmpRejections); - count = pivot.state.CountBullishRejectionBars(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iRejection = pivot.state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iRejection.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValid = - // - iRejection.BarTime() >= pivot.from && - iBar.high < pivotMid - // - ; - if (isValid) - { - // - Add( - iRejection, - tmpRejections // - ); - } - } - - // - Copy( - tmpRejections, - pivot.state.bullishRejectionBars // - ); - } - } - - // - // Bearish ... - Clean(tmpRejections); - count = pivot.state.CountBearishRejectionBars(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iRejection = pivot.state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iRejection.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValid = - // - iRejection.BarTime() >= pivot.from && - iBar.low > pivotMid - // - ; - if (isValid) - { - // - Add( - iRejection, - tmpRejections // - ); - } - } - - // - Copy( - tmpRejections, - pivot.state.bearishRejectionBars // - ); - } - } - - // - Clean(tmpRejections); - - // - // Support Zone ... - XCSupportZone *tmpSupports[]; - count = pivot.state.CountSupportZones(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = pivot.state.supportZones[i]; - - // - bool isValid = - // - iZone.Upper() < pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpSupports // - ); - } - } - - // - Copy( - tmpSupports, - pivot.state.supportZones // - ); - } - } - - // - Clean(tmpSupports); - - // - // Resistance Zone ... - XCResistanceZone *tmpResistances[]; - count = pivot.state.CountResistanceZones(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = pivot.state.resistanceZones[i]; - - // - bool isValid = - // - iZone.Lower() > pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpResistances // - ); - } - } - - // - Copy( - tmpResistances, - pivot.state.resistanceZones // - ); - } - } - - // - Clean(tmpResistances); - - // - // Supply Zones ... - XCSupplyZone *tmpSupplies[]; - count = pivot.state.CountSupplyZones(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = pivot.state.supplyZones[i]; - - // - bool isValid = - // - iZone.Lower() > pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpSupplies // - ); - } - } - - // - Copy( - tmpSupplies, - pivot.state.supplyZones // - ); - } - } - - // - Clean(tmpSupplies); - - // - // Demand Zones ... - XCDemandZone *tmpDemands[]; - count = pivot.state.CountDemandZones(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = pivot.state.demandZones[i]; - - // - bool isValid = - // - iZone.Upper() < pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpDemands // - ); - } - } - - // - Copy( - tmpDemands, - pivot.state.demandZones // - ); - } - } - - // - Clean(tmpDemands); - - // - // Order Blocks ... - XCOrderBlock *tmpOrderBlocks[]; - - // - // Bullish ... - Clean(tmpOrderBlocks); - count = pivot.state.CountBullishOrderBlocks(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = pivot.state.bullishOrderBlocks[i]; - - // - bool isValid = - // - iZone.Upper() < pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpOrderBlocks // - ); - } - } - - // - Copy( - tmpOrderBlocks, - pivot.state.bullishOrderBlocks // - ); - } - } - - // - // Bearish ... - Clean(tmpOrderBlocks); - count = pivot.state.CountBearishOrderBlocks(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = pivot.state.bearishOrderBlocks[i]; - - // - bool isValid = - // - iZone.Lower() > pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpOrderBlocks // - ); - } - } - - // - Copy( - tmpOrderBlocks, - pivot.state.bearishOrderBlocks // - ); - } - } - - // - Clean(tmpOrderBlocks); - - // - // Fair Value Gaps ... - XCFVG *tmpFVGs[]; - - // - // Bullish ... - Clean(tmpFVGs); - count = pivot.state.CountBullishFairValueGaps(); - if (IsValidSize(count)) - { - // - if (isPriceInDiscount) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = pivot.state.bullishFairValueGaps[i]; - - // - bool isValid = - // - iZone.Upper() < pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpFVGs // - ); - } - } - - // - Copy( - tmpFVGs, - pivot.state.bullishFairValueGaps // - ); - } - } - - // - // Bearish ... - Clean(tmpFVGs); - count = pivot.state.CountBearishFairValueGaps(); - if (IsValidSize(count)) - { - // - if (isPriceInPremium) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = pivot.state.bearishFairValueGaps[i]; - - // - bool isValid = - // - iZone.Lower() > pivotMid - // - ; - if (isValid) - { - // - Add( - iZone, - tmpFVGs // - ); - } - } - - // - Copy( - tmpFVGs, - pivot.state.bearishFairValueGaps // - ); - } - } - - // - Clean(tmpFVGs); - - // - } - - /** - * Detect Cycle Trend Based On Pivots ... - * - * @param dir: ENUM_X_DIRECTION member Reference ... - * @param numberOfPivots: Integer ... - * @param maxAllowedLoopback: Integer ... - * @param minRequiredPivotVerification: Integer ... - * - * @return ( bool ) - */ - bool DetectTrend( - ENUM_X_DIRECTION &dir, - int numberOfPivots = 3, - int maxAllowedLoopback = 576, - int minRequiredPivotVerification = 5 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - if (numberOfPivots < 3) - { - numberOfPivots = 3; - } - - // - int index = 0; - double peaks[]; - double vales[]; - double peak = 0; - double vale = 0; - int peaksVerified = 0; - int valesVerified = 0; - bool canContinue = true; - while (canContinue) - { - // - // Peak ... - bool lookupPeak = ArraySize(peaks) < numberOfPivots; - if (lookupPeak) - { - // - double iPeak = mX121Helper.GetPeak(index); - if (iPeak == peak) - { - peaksVerified++; - } - else - { - // - if (peaksVerified >= minRequiredPivotVerification) - { - // - Add( - iPeak, - peaks // - ); - - // - peaksVerified = 0; - lookupPeak = ArraySize(peaks) < numberOfPivots; - } - else - { - peak = iPeak; - } - } - } - - // - // Vale ... - bool lookupVale = ArraySize(vales) < numberOfPivots; - if (lookupVale) - { - // - double iVale = mX121Helper.GetVale(index); - if (iVale == vale) - { - valesVerified++; - } - else - { - // - if (valesVerified >= minRequiredPivotVerification) - { - // - Add( - iVale, - vales // - ); - - // - valesVerified = 0; - lookupVale = ArraySize(vales) < numberOfPivots; - } - else - { - vale = iVale; - } - } - } - - // - canContinue = index < maxAllowedLoopback && - (lookupPeak || - lookupVale); - if (canContinue) - { - index++; - } - } - - // - int verifications = 0; - - // - // Peaks ... - int peaksCount = ArraySize(peaks); - if (!result && - peaksCount == numberOfPivots) - { - // - verifications = 0; - for (int i = 0; i < peaksCount - 1; i++) - { - // - double iValue = peaks[i]; - double nValue = peaks[i + 1]; - if (iValue < nValue) - { - verifications++; - } - } - - // - result = verifications == numberOfPivots - 1; - if (result) - { - dir = X_DIRECTION_BEARISH; - } - } - - // - // Vales ... - int valesCount = ArraySize(vales); - if (!result && - valesCount == numberOfPivots) - { - // - verifications = 0; - for (int i = 0; i < valesCount - 1; i++) - { - // - double iValue = vales[i]; - double nValue = vales[i + 1]; - if (iValue > nValue) - { - verifications++; - } - } - - // - result = verifications == numberOfPivots - 1; - if (result) - { - dir = X_DIRECTION_BULLISH; - } - } - - // - return result; - } - - /** - * Detect Market Structure based on Peaks and Vales ... - * - * @param dir: ENUM_X_DIRECTION member Reference ... - * @param minVerification: Integer ... - * - * @return ( bool ) - */ - bool HasPVDirection( - ENUM_X_DIRECTION &dir, - int minVerification = 12 // - ) - { - // - bool result = false; - - // - if (minVerification < 7) - { - minVerification = 7; - } - - // - dir = X_DIRECTION_NONE; - - // - int bullishSum = mBullishPeaks + mBullishVales; - int bearishSum = mBearishPeaks + mBearishVales; - - // - int diff = MathAbs(bullishSum - bearishSum); - bool isDiffPassed = diff >= minVerification; - result = isDiffPassed; - if (!result) - { - return result; - } - - // - dir = bullishSum > bearishSum - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - // Change Values Actions ... - - /** - * Count Saved Parabolic Sar Changes ... - * - * @return ( int ) - */ - int CountSarChanges() - { - return ArraySize(mSarChanges); - } - - /** - * Fill Saved Sar Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillSarChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mSarChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Sar Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastSarChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mSarChanges // - ); - - // - return result; - } - - /** - * Count Saved Peaks Changes ... - * - * @return ( int ) - */ - int CountPeaksChanges() - { - return ArraySize(mPeaksChanges); - } - - /** - * Fill Saved Peaks Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillPeaksChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mPeaksChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Peak Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastPeakChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mPeaksChanges // - ); - - // - return result; - } - - /** - * Count Saved Vales Changes ... - * - * @return ( int ) - */ - int CountValesChanges() - { - return ArraySize(mValesChanges); - } - - /** - * Fill Saved Vales Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillValesChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mValesChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Vale Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastValeChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mValesChanges // - ); - - // - return result; - } - - /** - * Count Saved VWap Order Changes ... - * - * @return ( int ) - */ - int CountVWapOrderChanges() - { - return ArraySize(mVWapOrderChanges); - } - - /** - * Fill Saved VWap Order Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillVWapOrderChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mVWapOrderChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last VWap Order Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastVWapOrderChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mVWapOrderChanges // - ); - - // - return result; - } - - /** - * Count Saved VWap State Changes ... - * - * @return ( int ) - */ - int CountVWapStateChanges() - { - return ArraySize(mVWapStateChanges); - } - - /** - * Fill Saved VWap State Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillVWapStateChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mVWapStateChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last VWap State Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastVWapStateChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mVWapStateChanges // - ); - - // - return result; - } - - /** - * Count Founded Consolidation Zones ... - * - * @return ( int ) - */ - int CountConsolidationZones() - { - return ArraySize(mConsolidationZones); - } - - /** - * Fill Broken Consolidations ... - * - * @param consolidations: XConsolidationZone instance Array Reference ... - * - * @return ( int ) - */ - int FillConsolidationZones( - XConsolidationZone &consolidations[] // - ) - { - // - Clean(consolidations); - - // - Copy( - mConsolidationZones, - consolidations // - ); - - // - int result = ArraySize(consolidations); - - // - return result; - } - - /** - * Retrieve Last Consolidation Breaks ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastConsolidationZone(XConsolidationZone &zone) - { - // - bool result = false; - - // - result = GetLastItem( - zone, - mConsolidationZones // - ); - - // - return result; - } - - /** - * Count Pivot Points Change ... - * - * @return ( int ) - */ - int CountPivotPoints() - { - return ArraySize(mPivotPoints); - } - - /** - * Retrieve All Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillPivotPoints(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(pivots)) - { - return result; - } - - // - Copy( - mPivotPoints, - pivots // - ); - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Retrieve All Peak Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillPeakPivotPoints(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XPVPivotPoint iPivot = mPivotPoints[i]; - - // - bool isValid = iPivot.IsPeak(); - if (isValid) - { - // - AddRef( - iPivot, - pivots // - ); - } - } - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Get Last Peaks Pivot Point ... - * - * @param pivot: XPVPivotPoint instance Reference ... - * - * @return ( bool ) - */ - bool GetLastPeakPivotPoint(XPVPivotPoint &pivot) - { - // - bool result = false; - - // - pivot.Clean(); - - // - XPVPivotPoint pivots[]; - int count = FillPeakPivotPoints(pivots); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - pivot = pivots[count - 1]; - - // - return result; - } - - /** - * Retrieve All Vale Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillValePivotPoints(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XPVPivotPoint iPivot = mPivotPoints[i]; - - // - bool isValid = iPivot.IsVale(); - if (isValid) - { - // - AddRef( - iPivot, - pivots // - ); - } - } - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Get Last Vale Pivot Point ... - * - * @param pivot: XPVPivotPoint instance Reference ... - * - * @return ( bool ) - */ - bool GetLastValePivotPoint(XPVPivotPoint &pivot) - { - // - bool result = false; - - // - pivot.Clean(); - - // - XPVPivotPoint pivots[]; - int count = FillValePivotPoints(pivots); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - pivot = pivots[count - 1]; - - // - return result; - } - - /** - * Count Calculated Pivots ... - * - * @return ( int ) - */ - int CountPivots() - { - return ArraySize(mPivots); - } - - /** - * Fill Pivots ... - * - * @param pivots: XPVPivot instance Reference Array ... - * - * @return ( int ) - */ - int FillPivots(XPVPivot &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - Copy( - mPivots, - pivots // - ); - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Retrieve Last Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * - * @return ( bool ) - */ - bool GetLastPivot(XPVPivot &pivot) - { - // - bool result = false; - - // - pivot.Clean(); - - // - XPVPivot pivots[]; - int count = FillPivots(pivots); - if (IsValidSize(count)) - { - pivot = pivots[count - 1]; - } - - // - result = pivot.IsValid(); - - // - return result; - } - - /** - * Retrieve Active Peak Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * - * @return ( bool ) - */ - bool GetActivePeakPivot(XPVPivot &pivot) - { - // - bool result = false; - - // - pivot.Clean(); - - // - pivot = mActivePeakPivot; - - // - result = pivot.IsValid(); - - // - return result; - } - - /** - * Retrieve Active Vale Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * - * @return ( bool ) - */ - bool GetActiveValePivot(XPVPivot &pivot) - { - // - bool result = false; - - // - pivot.Clean(); - - // - pivot = mActiveValePivot; - - // - result = pivot.IsValid(); - - // - return result; - } - - // - // Virtuals ... - - /** - * Set Default Properties Values ... - */ - virtual void Default() - { - // - ValidPivotRepetition(21); - ConsolidationLoopback(10); - MaxAllowedSavedChanges(50); - } - - // - protected: - // - - /** - * Calculate Requirements ... - * - * @param barIndex: Integer, Bar Index ... - * @param events: ENUM_X_CYCLE_EVENTS member, Array ... - * @param conditions: X121SMCCycleConditions instance ... - */ - void Calculate( - int barIndex, - ENUM_X_CYCLE_EVENTS &events[], - X121SMCCycleConditions &conditions // - ) - { - // - Clean(events); - - // - string symbol = GetSymbol(); - datetime cTime = TimeCurrent(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL changeBar; - int index = - barIndex <= 0 - ? 1 - : barIndex; - bool isInited = GetBar( - changeBar, - index // - ); - if (!isInited) - { - return; - } - - // - // Detect Sar Change ... - bool isSarSwitchedToBullish = conditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = conditions.x121Conditions.isSarSwitchedToBearish; - bool isSarChanged = isSarSwitchedToBullish || - isSarSwitchedToBearish; - - // - if (isSarChanged) - { - // - XValueChange sarChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.sarBuffer[1]; - double before = conditions.x121Conditions.sarBuffer[2]; - ENUM_X_DIRECTION dir = - isSarSwitchedToBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = sarChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddSarChange(sarChanged); - - // - if (isInited) - { - // - Add( - SAR_CHANGE_DETECTED, - events // - ); - } - } - } - - // - // Detect Peaks Changes ... - - // - bool isNewPeak = conditions.x121Conditions.isNewPeak; - double peak = conditions.x121Conditions.peaksBuffer[1]; - double peakPrev = conditions.x121Conditions.peaksBuffer[2]; - bool isPeakSameAsPrev = peak == peakPrev; - bool isNewPeakOverLast = conditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = conditions.x121Conditions.isNewPeakUnderLast; - - // - if (isNewPeak) - { - // - XValueChange peaksChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.peaksBuffer[1]; - double before = conditions.x121Conditions.peaksBuffer[2]; - ENUM_X_DIRECTION dir = - isNewPeakOverLast - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = peaksChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddPeaksChange(peaksChanged); - - // - if (isInited) - { - // - Add( - NEW_PEAK_DETECTED, - events // - ); - } - } - } - - // - // Detect Vales Changes ... - - // - bool isNewVale = conditions.x121Conditions.isNewVale; - double vale = conditions.x121Conditions.valesBuffer[1]; - double valePrev = conditions.x121Conditions.valesBuffer[2]; - bool isValeSameAsPrev = vale == valePrev; - bool isNewValeOverLast = conditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = conditions.x121Conditions.isNewValeUnderLast; - - // - if (isNewVale) - { - // - XValueChange valesChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.valesBuffer[1]; - double before = conditions.x121Conditions.valesBuffer[2]; - ENUM_X_DIRECTION dir = - isNewValeUnderLast - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = valesChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddValesChange(valesChanged); - - // - if (isInited) - { - // - Add( - NEW_VALE_DETECTED, - events // - ); - } - } - } - - // - // Count Bullish / Bearish Peaks and Vales ... - - // - // Peaks ... - - // - if (isNewPeakOverLast) - { - // - mBullishPeaks++; - mIsLastPeakBullish = true; - } - - // - if (isNewPeakUnderLast) - { - // - mBearishPeaks++; - mIsLastPeakBullish = false; - } - - // - if (isPeakSameAsPrev) - { - // - if (mIsLastPeakBullish) - { - // - mBullishPeaks++; - mBearishPeaks--; - if (mBearishPeaks < 0) - { - mBearishPeaks = 0; - } - } - else - { - // - mBullishPeaks--; - mBearishPeaks++; - if (mBullishPeaks < 0) - { - mBullishPeaks = 0; - } - } - } - - // - // Vales ... - - // - if (isNewValeOverLast) - { - // - mBullishVales++; - mIsLastValeBullish = true; - } - - // - if (isNewValeUnderLast) - { - // - mBearishVales++; - mIsLastValeBullish = false; - } - - // - if (isValeSameAsPrev) - { - // - if (mIsLastValeBullish) - { - // - mBullishVales++; - mBearishVales--; - if (mBearishVales < 0) - { - mBearishVales = 0; - } - } - else - { - // - mBullishVales--; - mBearishVales++; - if (mBullishVales < 0) - { - mBullishVales = 0; - } - } - } - - // - // VWap Direction Change ... - - // - // Ordered Change ... - bool isVWapSwitchedToBullishOrdered = - conditions.x121Conditions.isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered = - conditions.x121Conditions.isVWapSwitchedToBearishOrdered; - bool isVWAPOrderedChanged = isVWapSwitchedToBullishOrdered || - isVWapSwitchedToBearishOrdered; - // - if (isVWAPOrderedChanged) - { - // - XValueChange vwapOrderChanged; - - // - datetime time = changeBar.time; - ENUM_X_DIRECTION dir = - isVWapSwitchedToBullishOrdered - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double after = 0; - double before = 0; - if (isVWapSwitchedToBullishOrdered) - { - // - // After Max ... - after = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMax( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Min ... - before = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMin( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - else - { - // - // After Min ... - after = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMin( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Max ... - before = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMax( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - - // - // Initialize Model ... - isInited = vwapOrderChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddVWapOrderChange(vwapOrderChanged); - - // - if (isInited) - { - // - Add( - VWAP_ORDER_CHANGE_ETECTED, - events // - ); - } - } - } - - // - // States Changed ... - bool isVWapSwitchedToBullishState = - conditions.x121Conditions.isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState = - conditions.x121Conditions.isVWapSwitchedToBearishState; - bool isVWapStatesChanged = isVWapSwitchedToBullishState || - isVWapSwitchedToBearishState; - - // - if (isVWapStatesChanged) - { - // - XValueChange vwapStateChanged; - - // - datetime time = changeBar.time; - ENUM_X_DIRECTION dir = - isVWapSwitchedToBullishState - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double after = 0; - double before = 0; - if (isVWapSwitchedToBullishState) - { - // - // After Max ... - after = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMax( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Min ... - before = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMin( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - else - { - // - // After Min ... - after = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMin( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Max ... - before = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMax( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - - // - // Initialize Model ... - isInited = vwapStateChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddVWapStateChange(vwapStateChanged); - - // - if (isInited) - { - // - Add( - VWAP_STATE_CHANGE_DETCTED, - events // - ); - } - } - } - - // - // Detect Consolidations ... - - // - int consolidationLoopback = ConsolidationLoopback(); - if (IsValidSize(consolidationLoopback)) - { - // - double upper = 0; - double lower = 0; - bool hasConsolidation = - mBarAnalyser.IsConsolidate( - changeBar, - upper, - lower, - consolidationLoopback // - ); - - // - if (hasConsolidation && - !mActiveConsolidationZone.IsValid()) - { - // - // Initialize Consolidation Zone ... - bool isInited = mActiveConsolidationZone.Init( - changeBar.symbol, - changeBar.period, - upper, - lower, - consolidationLoopback // - ); - } - - // - if (!hasConsolidation && - mActiveConsolidationZone.IsValid()) - { - // - mActiveConsolidationZone.Update(); - bool isBreaked = mActiveConsolidationZone.IsBreaked(); - - // - if (isBreaked) - { - // - // Add Active to List ... - bool isInited = AddConsolidationZone(mActiveConsolidationZone); - if (isInited) - { - // - // Clean Active Zone ... - mActiveConsolidationZone.Clean(); - - // - Add( - CONSOLIDATION_BREAKED_DETECTED, - events // - ); - } - } - } - - // - // Draw ... - // if (mActiveConsolidationZone.IsValid()) - // { - // // - // if (mActiveConsolidationZoneObj != NULL) - // { - // mActiveConsolidationZoneObj.Delete(); - // } - - // // - // bool isCreated = mPOIDetector.mDrawer.CreateConsolidationZone( - // mActiveConsolidationZone, - // mActiveConsolidationZoneObj // - // ); - // } - } - - // - // Check Valid Peaks and Vales ... - if (isNewPeak || isNewVale) - { - // - int count = 0; - double value = 0; - int repetition = 0; - ENUM_TIMEFRAMES period = GetPeriod(); - int periodSeconds = PeriodSeconds(period); - int minRepetition = ValidPivotRepetition(); - ENUM_XPV_PIVOTS type = isNewPeak - ? XPV_PEAK - : XPV_VALE; - - // - XValueChange lastChange; - XValueChange prevChange; - - // - count = CountPeaksChanges(); - if (isNewPeak && count >= 2) - { - // - lastChange = mPeaksChanges[count - 1]; - prevChange = mPeaksChanges[count - 2]; - } - - // - count = CountValesChanges(); - if (isNewVale && count >= 2) - { - // - lastChange = mValesChanges[count - 1]; - prevChange = mValesChanges[count - 2]; - } - - // - if (lastChange.IsValid() && - prevChange.IsValid()) - { - // - value = prevChange.after; - int delayTime = ((int)lastChange.time - (int)prevChange.time); - repetition = delayTime / periodSeconds; - - // - bool isValidPivot = repetition >= minRepetition; - if (isValidPivot) - { - // - XPVPivotPoint pivotPoint; - pivotPoint.type = type; - pivotPoint.value = value; - pivotPoint.time = prevChange.time; - pivotPoint.repetition = repetition; - - // - bool isInited = AddPivotPoint(pivotPoint); - if (isInited) - { - // - Add( - PIVOT_POINT_DETECTED, - events // - ); - } - } - } - } - - // - // Calculate XPVPivot ... - int pvValidation = ValidPivotRepetition(); - if (IsValidSize(pvValidation)) - { - // - // Peak ... - mActivePeakPivot.symbol = symbol; - mActivePeakPivot.period = period; - mActivePeakPivot.type = XPV_PEAK; - - // - if (mActivePeakPivot.upper == 0 && peak > 0) - { - // - mActivePeakPivot.upper = peak; - mActivePeakPivot.lower = vale; - mActivePeakPivot.from = changeBar.time; - - // - Add( - PEAK_PIVOT_STARTED, - events // - ); - } - else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper == peak) - { - // - mActivePeakPivot.repetition++; - mActivePeakPivot.to = changeBar.time; - - // - if (mActivePeakPivot.IsValid()) - { - // - FillPivotState(mActivePeakPivot); - ValidatePivotState(mActivePeakPivot, barIndex); - } - } - else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper != peak) - { - // - if (mActivePeakPivot.repetition >= pvValidation) - { - // - bool isInited = AddPivot(mActivePeakPivot); - if (isInited) - { - // - Add( - PEAK_PIVOT_ENDED, - events // - ); - - // - mActivePeakPivot.Clean(); - } - } - else - { - // - mActivePeakPivot.upper = peak; - mActivePeakPivot.lower = vale; - mActivePeakPivot.repetition = 0; - mActivePeakPivot.from = changeBar.time; - - // - Add( - PEAK_PIVOT_STARTED, - events // - ); - } - } - - // - // Vale ... - mActiveValePivot.symbol = symbol; - mActiveValePivot.period = period; - mActiveValePivot.type = XPV_VALE; - - // - // Peak ... - if (mActiveValePivot.lower == 0 && vale > 0) - { - // - mActiveValePivot.lower = vale; - mActiveValePivot.upper = peak; - mActiveValePivot.from = changeBar.time; - - // - Add( - VALE_PIVOT_STARTED, - events // - ); - } - else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower == vale) - { - // - mActiveValePivot.repetition++; - mActiveValePivot.to = changeBar.time; - - // - if (mActiveValePivot.IsValid()) - { - // - FillPivotState(mActiveValePivot); - ValidatePivotState(mActiveValePivot, barIndex); - } - } - else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower != vale) - { - // - if (mActiveValePivot.repetition >= pvValidation) - { - // - bool isInited = AddPivot(mActiveValePivot); - if (isInited) - { - // - Add( - VALE_PIVOT_ENDED, - events // - ); - - // - mActiveValePivot.Clean(); - } - } - else - { - // - mActiveValePivot.lower = vale; - mActiveValePivot.upper = peak; - mActiveValePivot.repetition = 0; - mActiveValePivot.from = changeBar.time; - - // - Add( - VALE_PIVOT_STARTED, - events // - ); - } - } - } - } - - /** - * Detect Requirements ... - */ - void Detect(int barIndex) - { - // - if (isDetecting) - { - return; - } - - // - int start = barIndex; - int max = 576; - int validPivotRepetition = ValidPivotRepetition(); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - // Try To Detect Valid Peaks or Vales ... - double peak = 0; - double vale = 0; - int peakRepetition = 0; - int valeRepetition = 0; - - // - int from = start; - int index = from; - int count = start + max; - - // - bool canContinue = true; - - // - // Loop Throug Peaks and Vales ... - while (canContinue) - { - // - datetime toTime = iTime( - symbol, - period, - index // - ); - - // - double iPeak = mX121Helper.GetPeak(index); - double iVale = mX121Helper.GetVale(index); - - // - // Peak ... - if (peak == 0 && iPeak > 0) - { - // - peak = iPeak; - peakRepetition = 0; - } - else if (peak > 0 && iPeak > 0 && peak == iPeak) - { - peakRepetition++; - } - else if (peak > 0 && iPeak > 0 && peak != iPeak) - { - // - if (peakRepetition >= validPivotRepetition) - { - // - datetime fromTime = iTime( - symbol, - period, - index - peakRepetition // - ); - - // - // Create XPVPivotPoint ... - XPVPivotPoint pivotPoint; - pivotPoint.value = iPeak; - pivotPoint.time = toTime; - pivotPoint.type = XPV_PEAK; - pivotPoint.repetition = peakRepetition; - if (pivotPoint.IsValid()) - { - // - AddRef( - pivotPoint, - mPivotPoints // - ); - } - - // - // Create XPVPivot ... - XPVPivot pivot; - pivot.symbol = symbol; - pivot.period = period; - pivot.from = fromTime; - pivot.to = toTime; - pivot.repetition = peakRepetition; - pivot.type = XPV_PEAK; - pivot.upper = peak; - pivot.lower = iVale; - FillPivotState(pivot); - - // - if (pivot.IsValid()) - { - // - AddRef( - pivot, - mPivots // - ); - } - } - - // - peak = iPeak; - peakRepetition = 0; - } - - // - // Vale ... - if (vale == 0 && iVale > 0) - { - // - vale = iVale; - valeRepetition = 0; - } - else if (vale > 0 && iVale > 0 && vale == iVale) - { - valeRepetition++; - } - else if (vale > 0 && iVale > 0 && vale != iVale) - { - // - if (valeRepetition >= validPivotRepetition) - { - // - datetime fromTime = iTime( - symbol, - period, - index - valeRepetition // - ); - - // - // Create XPVPivotPoint ... - XPVPivotPoint pivotPoint; - pivotPoint.value = iVale; - pivotPoint.time = toTime; - pivotPoint.type = XPV_VALE; - pivotPoint.repetition = valeRepetition; - if (pivotPoint.IsValid()) - { - // - AddRef( - pivotPoint, - mPivotPoints // - ); - } - - // - // Create XPVPivot ... - XPVPivot pivot; - pivot.symbol = symbol; - pivot.period = period; - pivot.from = fromTime; - pivot.to = toTime; - pivot.repetition = valeRepetition; - pivot.type = XPV_VALE; - pivot.upper = iPeak; - pivot.lower = vale; - FillPivotState(pivot); - - // - if (pivot.IsValid()) - { - // - AddRef( - pivot, - mPivots // - ); - } - } - - // - vale = iVale; - valeRepetition = 0; - } - - // - index++; - canContinue = index < count; - } - - // - int pivotsCount = ArraySize(mPivots); - if (IsValidSize(mPivots)) - { - ArrayReverse(mPivots); - } - - // - isDetecting = false; - } - - // - private: - // - // Props ... - - // - bool mIsLastPeakBullish; - int mBullishPeaks; // Count Bullish Peaks ... - int mBearishPeaks; // Count Bearish Peaks ... - - // - bool mIsLastValeBullish; - int mBullishVales; // Count Bullish Vales ... - int mBearishVales; // Count Bearish Vales ... - - // - // Change Holders ... - int mMaxAllowedSavedChanges; // Max llowed Changes to Save ... - XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ... - XValueChange mPeaksChanges[]; // Holds Peaks Changes ... - XValueChange mValesChanges[]; // Holds Vales Changes ... - XValueChange mVWapOrderChanges[]; // Holds Vales Changes ... - XValueChange mVWapStateChanges[]; // Holds Vales Changes ... - - // - int mConsolidationLoopback; // Consolidation Loopback Length ... - XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ... - XConsolidationZone mActiveConsolidationZone; // Holds Actiove Consolidation Zone ... - // XCConsolidationZoneObject *mActiveConsolidationZoneObj; - - // - int mValidPivotRepetition; // Valid Pivot Point's Repetition ... - XPVPivotPoint mPivotPoints[]; // Holds Pivots ... - - // - bool isDetecting; - XPVPivot mActivePeakPivot; // Active Pivots ... - XPVPivot mActiveValePivot; // Active Pivots ... - XPVPivot mPivots[]; // Holds Active Pivot ... - - // - // Actions ... - - /** - * Release All Resources ... - */ - void DeInit() - { - // - delete mX121Helper; - - // - delete mBarAnalyser; - } - - /** - * Apply Chart Style ... - */ - void ApplyChartStyle() - { - // - // Retrieve Current Chart ID ... - long chartId = ChartID(); - - // - ENUM_CHART_MODE mMode = CHART_CANDLES; // chart's mMode - bool mShowBidLine = true; // show bid line - bool mShowAskLine = true; // show ask line - bool mShowGrid = false; // show grids on chart - bool mShowVolumes = false; // show volumes - bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) - bool mAutoScroll = true; // chart autoscroll - bool mQuickNavigation = true; // chart quick navigation state - color mForeGroundColor = clrWhite; // chart's foreground color - color mBackGroundColor = clrBlack; // chart's background color - color mUpColor = clrGreen; // Up Color - color mDownColor = clrRed; // Down Color - color mBullishColor = clrGreen; // Bullish color - color mBearishColor = clrRed; // Bearish color - color mGridColor = clrGray; // grid color - color mBidLineColor = clrGray; // bid line color - color mAskLineColor = clrRed; // ask line color - color mLineColor = clrLime; // line mMode and doji candlestick color - color mStopColor = clrGold; // Color of stop order levels (Stop Loss and Take Profit) - color mVolumesColor = clrGreen; // volumes color - - // - ChartSetInteger(chartId, CHART_MODE, mMode); - ChartSetInteger(chartId, CHART_SHOW_BID_LINE, mShowBidLine); - ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, mShowAskLine); - ChartSetInteger(chartId, CHART_SHOW_GRID, mShowGrid); - ChartSetInteger(chartId, CHART_SHOW_VOLUMES, mShowVolumes); - ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); - ChartSetInteger(chartId, CHART_AUTOSCROLL, mAutoScroll); - ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, mQuickNavigation); - ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, mForeGroundColor); - ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, mBackGroundColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_UP, mUpColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, mDownColor); - ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, mBullishColor); - ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); - ChartSetInteger(chartId, CHART_COLOR_GRID, mGridColor); - ChartSetInteger(chartId, CHART_COLOR_BID, mBidLineColor); - ChartSetInteger(chartId, CHART_COLOR_ASK, mAskLineColor); - ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, mStopColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, mLineColor); - ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor); - } - - /** - * Fill Pivot Tick Zone ... - * - * @param pivot: XPVPivot instance Reference ... - */ - void CalculatePivotTickZone( - XPVPivot &pivot // - ) - { - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - bool isInited = false; - - // - datetime from = pivot.from; - XOHCL iFromBar; - int iFromBarIndex = iBarShift( - symbol, - period, - from // - ); - isInited = iFromBar.Init( - symbol, - period, - iFromBarIndex // - ); - if (!isInited) - { - return; - } - - // - datetime to = pivot.to; - XOHCL iToBar; - int iToBarIndex = iBarShift( - symbol, - period, - to // - ); - isInited = iToBar.Init( - symbol, - period, - iToBarIndex // - ); - if (!isInited) - { - return; - } - - // - if (iFromBarIndex <= iToBarIndex) - { - return; - } - - // - XCTicksZone *iZone; - iZone = new XCTicksZone(); - - // - int ticksLevels = mPOIDetector.TicksRangeZoneLevel(); - int ticksRange = mPOIDetector.TicksRangeZoneRange(); - isInited = ticksLevels > 0 && - ticksRange > 0; - if (!isInited) - { - return; - } - - // - isInited = iZone.Init( - iFromBar, - iToBar // - ); - if (!isInited) - { - return; - } - - // - pivot.state.ticksZone = iZone; - } - - // - // Change Values Actions ... - - /** - * Add Specified Parabolic Sar Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddSarChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mSarChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mSarChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Peaks Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddPeaksChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mPeaksChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mPeaksChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Vales Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddValesChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mValesChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mValesChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified VWap Order Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddVWapOrderChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mVWapOrderChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mVWapOrderChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified VWap State Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddVWapStateChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mVWapStateChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mVWapStateChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Consolidation Zone to List ... - * - * @param zone: XConsolidationZone instance Reference ... - * - * @return ( bool ) - */ - bool AddConsolidationZone(XConsolidationZone &zone) - { - // - bool result = false; - - // - result = zone.IsValid(); - - // - int beforeCount = CountConsolidationZones(); - - // - AddRef( - zone, - mConsolidationZones // - ); - - // - int afterCount = CountConsolidationZones(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mConsolidationZones, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Pivot Point to List ... - * - * @param pivotPoint: XPVPivotPoint instance Reference ... - * - * @return ( bool ) - */ - bool AddPivotPoint(XPVPivotPoint &pivotPoint) - { - // - bool result = false; - - // - if (!pivotPoint.IsValid()) - { - return result; - } - - // - int beforeCount = CountPivotPoints(); - - // - AddRef( - pivotPoint, - mPivotPoints // - ); - - // - int afterCount = CountPivotPoints(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mPivotPoints, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Pivot to List ... - * - * @param pivot: XPVPivot instance Reference ... - * - * @return ( bool ) - */ - bool AddPivot(XPVPivot &pivot) - { - // - bool result = false; - - // - if (!pivot.IsValid()) - { - return result; - } - - // - int beforeCount = CountPivots(); - - // - AddRef( - pivot, - mPivots // - ); - - // - int afterCount = CountPivots(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mPivots, - maxAllowed // - ); - } - - // - return result; - } - - // -}; diff --git a/Documents/BKP/1/x-121.smc.twpv.conditions2.mq5 b/Documents/BKP/1/x-121.smc.twpv.conditions2.mq5 deleted file mode 100644 index ff6c2b3d..00000000 --- a/Documents/BKP/1/x-121.smc.twpv.conditions2.mq5 +++ /dev/null @@ -1,137 +0,0 @@ - - // - // OPEN ... - double triggerDonOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double triggerDonOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - double triggerDonOpenUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2]; - double triggerDonOpenLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2]; - - // - // HIGH ... - double triggerDonHighUpper = triggerConditions.x121Conditions.donHighUpperBuffer[1]; - double triggerDonHighLower = triggerConditions.x121Conditions.donHighLowerBuffer[1]; - double triggerDonHighUpperPrev = triggerConditions.x121Conditions.donHighUpperBuffer[2]; - double triggerDonHighLowerPrev = triggerConditions.x121Conditions.donHighLowerBuffer[2]; - - // - // CLOSE ... - double triggerDonCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double triggerDonCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - double triggerDonCloseUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2]; - double triggerDonCloseLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2]; - - // - // LOW ... - double triggerDonLowUpper = triggerConditions.x121Conditions.donLowUpperBuffer[1]; - double triggerDonLowLower = triggerConditions.x121Conditions.donLowLowerBuffer[1]; - double triggerDonLowUpperPrev = triggerConditions.x121Conditions.donLowUpperBuffer[2]; - double triggerDonLowLowerPrev = triggerConditions.x121Conditions.donLowLowerBuffer[2]; - - // - // Calculate PBar Rejected Don Upper and Lower ... - - // - bool isPBarRejectDonLowUpper = pBar.high > triggerDonLowUpperPrev; - bool isPBarRejectDonOpenUpper = pBar.high > triggerDonOpenUpperPrev; - bool isPBarRejectDonCloseUpper = pBar.high > triggerDonCloseUpperPrev; - bool isPBarRejectedDonUpper = isPBarRejectDonLowUpper || - isPBarRejectDonOpenUpper || - isPBarRejectDonCloseUpper; - - // - bool isPBarRejectDonHighLower = pBar.low < triggerDonHighLowerPrev; - bool isPBarRejectDonOpenLower = pBar.low < triggerDonOpenLowerPrev; - bool isPBarRejectDonCloseLower = pBar.low < triggerDonCloseLowerPrev; - bool isPBarRejectedDonLower = isPBarRejectDonHighLower || - isPBarRejectDonOpenLower || - isPBarRejectDonCloseLower; - - // - // Calculate PBar Breaked Don Upper and Lower ... - - // - bool isPBarBreakdDonLowUpper = pBar.GetUp() > triggerDonLowUpperPrev && - pBar.GetDown() < triggerDonLowUpperPrev; - bool isPBarBreakdDonOpenUpper = pBar.GetUp() > triggerDonOpenUpperPrev && - pBar.GetDown() < triggerDonOpenUpperPrev; - bool isPBarBreakdDonCloseUpper = pBar.GetUp() > triggerDonCloseUpperPrev && - pBar.GetDown() < triggerDonCloseUpperPrev; - bool isPBarBreakedDonUpper = isPBarBreakdDonLowUpper || - isPBarBreakdDonOpenUpper || - isPBarBreakdDonCloseUpper; - - // - bool isPBarBreakdDonHighLower = pBar.GetUp() > triggerDonHighLowerPrev && - pBar.GetDown() < triggerDonHighLowerPrev; - bool isPBarBreakdDonOpenLower = pBar.GetUp() > triggerDonOpenLowerPrev && - pBar.GetDown() < triggerDonOpenLowerPrev; - bool isPBarBreakdDonCloseLower = pBar.GetUp() > triggerDonCloseLowerPrev && - pBar.GetDown() < triggerDonCloseLowerPrev; - bool isPBarBreakedDonLower = isPBarBreakdDonHighLower || - isPBarBreakdDonOpenLower || - isPBarBreakdDonCloseLower; - - // - bool isRejectTriggerDonUpper = - // - // PBar ... - isPBarBearishRejected && - isPBarRejectedDonUpper && - // - // CBar ... - isCBarBearishMomentumBar && - cBar.close < triggerDonLowUpper && - // - triggerPeak == triggerDonHighUpper - // - ; - - // - bool isRejectTriggerDonLower = - // - // PBar ... - isPBarBullishRejected && - isPBarRejectedDonLower && - // - // CBar ... - isCBarBullishMomentumBar && - cBar.close > triggerDonHighLower && - // - triggerVale == triggerDonLowLower - // - ; - - // - if (isRejectTriggerDonUpper || - isRejectTriggerDonLower) - { - Print("Don Rejected ..."); - } - - // - bool isBreakedDonUpper = - // - false - // - ; - - // - bool isBreakedDonLower = - // - false - // - ; - - // - bool isEngulfedDonUpper = - // - false - // - ; - - // - bool isEngulfedDonLower = - // - false - // - ; diff --git a/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 b/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 deleted file mode 100644 index 64d1fc7c..00000000 --- a/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 +++ /dev/null @@ -1,1983 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: X -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - double higherPeak; - datetime higherPeakTime; - - // - double lowerVale; - datetime lowerValeTime; - - // - XPVPivot pivotZone; - - // - // Constructor ... - X121SMCStrategyXSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - pivotZone.Clean(); - - // - higherPeak = 0; - higherPeakTime = NULL; - - // - lowerVale = 0; - lowerValeTime = NULL; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXSignalConditions mXConditions; -X121SMCStrategyXSignalConditions mXConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - // zBar.Init( - // symbol, - // period, - // zIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - // cBar.Init( - // symbol, - // period, - // cIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - // pBar.Init( - // symbol, - // period, - // pIndex // - // ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - ENUM_X_DIRECTION consolidationTrendDir; - bool hasConsolidationTrend = - consolidationCycleHelper - .DetectMarketStructure( - consolidationTrendDir // - ); - bool hasConsolidationBullishTrend = - hasConsolidationTrend && - IsBullish(consolidationTrendDir); - bool hasConsolidationBearishTrend = - hasConsolidationTrend && - IsBearish(consolidationTrendDir); - - // - // Verification ... - ENUM_X_DIRECTION verificationTrendDir; - bool hasVerificationTrend = - verificationCycleHelper - .DetectMarketStructure( - verificationTrendDir // - ); - bool hasVerificationBullishTrend = - hasVerificationTrend && - IsBullish(verificationTrendDir); - bool hasVerificationBearishTrend = - hasVerificationTrend && - IsBearish(verificationTrendDir); - - // - // Analyse ... - ENUM_X_DIRECTION analyseTrendDir; - bool hasAnalyseTrend = - analyseCycleHelper - .DetectMarketStructure( - analyseTrendDir // - ); - bool hasAnalyseBullishTrend = - hasAnalyseTrend && - IsBullish(analyseTrendDir); - bool hasAnalyseBearishTrend = - hasAnalyseTrend && - IsBearish(analyseTrendDir); - - // - // Decision ... - ENUM_X_DIRECTION decisionTrendDir; - bool hasDecisionTrend = - decisionCycleHelper - .DetectMarketStructure( - decisionTrendDir // - ); - bool hasDecisionBullishTrend = - hasDecisionTrend && - IsBullish(decisionTrendDir); - bool hasDecisionBearishTrend = - hasDecisionTrend && - IsBearish(decisionTrendDir); - - // - // Detect Bar State ... - - // - // PinBar ... - ENUM_X_DIRECTION cBarPinDir; - bool isCBarPin = decisionCycleHelper - .mBarAnalyser - .IsPinBar( - cBar, - cBarPinDir, - 1 // - ); - bool isCBarBullishPin = - isCBarPin && - IsBullish(cBarPinDir); - bool isCBarBearishPin = - isCBarPin && - IsBearish(cBarPinDir); - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // Pull Back ... - ENUM_X_DIRECTION cBarPullbackDir; - bool isCBarPullbacked = - decisionCycleHelper - .mBarAnalyser - .HasPullBack( - cBarPullbackDir, - cBar // - ); - bool isCBarBullishPullbacked = - isCBarPullbacked && - IsBullish(cBarPullbackDir); - bool isCBarBearishPullbacked = - isCBarPullbacked && - IsBearish(cBarPullbackDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bars Pattern and Power and Pressures ... - - // - bool hasCBarBullishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBullishPattern( - cBar, - 2 // - ); - - // - bool hasCBarBearishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBearishPattern( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPower = - decisionCycleHelper - .mBarAnalyser - .HasBullishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPower = - decisionCycleHelper - .mBarAnalyser - .HasBearishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBullishPressure( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBearishPressure( - cBar, - 2 // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - ( - // - hasCBarBullishPattern && - isCBarHasBullishPower && - isCBarHasBullishPressure - // - ) - // - || - // - ( - // - isCBarBullishPin || - isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ) - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - ( - // - hasCBarBearishPattern && - isCBarHasBearishPower && - isCBarHasBearishPressure - // - ) - // - || - // - ( - // - isCBarBearishPin || - isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ) - // - ; - - // - // Set Higher Peak and Lowe Vale ... - - // - XOHCL higherPeakBar; - bool hasHigherPeak = - conditions.higherPeak > 0 && - IsValid(conditions.higherPeakTime); - bool isHigherPeakBreaked = false; - bool isHigherPeakRejected = false; - - // - if (!hasHigherPeak) - { - // - int higherPeakIDX = -1; - double higherPeak = - decisionCycleHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - decisionXConditions.peaksBuffer[1], - cIndex // - ); - - // - if (higherPeak > 0 && - IsValidIndex(higherPeakIDX)) - { - // - bool hasHigherPeak = higherPeakBar.Init( - symbol, - period, - higherPeakIDX // - ); - - // - if (hasHigherPeak) - { - // - conditions.higherPeakTime = cTime; - conditions.higherPeak = higherPeak; - } - } - } - - // - if (hasHigherPeak) - { - // - isHigherPeakBreaked = IsBarBreak( - conditions.higherPeak, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isHigherPeakRejected = IsBarReject( - conditions.higherPeak, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - XOHCL lowerValeBar; - bool hasLowerVale = - conditions.lowerVale > 0 && - IsValid(conditions.lowerValeTime); - bool isLowerValeBreaked = false; - bool isLowerValeRejected = false; - - // - if (!hasLowerVale) - { - // - int lowerValeIDX = -1; - double lowerVale = - decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - decisionXConditions.valesBuffer[1], - cIndex // - ); - - // - if (lowerVale > 0 && - IsValidIndex(lowerValeIDX)) - { - // - hasLowerVale = lowerValeBar.Init( - symbol, - period, - lowerValeIDX // - ); - - // - if (hasLowerVale) - { - // - conditions.lowerVale = lowerVale; - conditions.lowerValeTime = cTime; - } - } - } - - // - if (hasLowerVale) - { - // - isLowerValeBreaked = IsBarBreak( - conditions.lowerVale, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isLowerValeRejected = IsBarReject( - conditions.lowerVale, - X_DIRECTION_BULLISH, - cBar // - ); - } - - // - double pivotMid = 0; - bool isPivotToUpRejected = false; - bool isPivotToDownRejected = false; - bool isPivotToUpBreaked = false; - bool isPivotToDownBreaked = false; - bool hasPivot = conditions.pivotZone.IsValid(); - - // - if (!hasPivot) - { - // - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - bool hasPeakPivot = - // isSamePeaks && - hasHigherPeak && - isSameCyclePeaks && - (isHigherPeakBreaked || - isHigherPeakRejected); - - // - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - bool hasValePivot = - // isSameVales && - hasLowerVale && - isSameCycleVales && - (isLowerValeBreaked || - isLowerValeRejected); - - // - bool hasPivot = hasPeakPivot || - hasValePivot; - if (hasPivot) - { - // - XPVPivot pivot; - - // - pivot.symbol = symbol; - pivot.period = period; - - // - pivot.upper = decisionXConditions.peaksBuffer[1]; - pivot.lower = decisionXConditions.valesBuffer[1]; - - // - pivot.to = cTime; - pivot.from = cTime; - pivot.repetition = 3; - - // - pivot.type = - hasPeakPivot - ? XPV_PEAK - : XPV_VALE; - - // - hasPivot = pivot.IsValid(); - if (hasPivot) - { - conditions.pivotZone = pivot; - } - } - } - - // - if (hasPivot) - { - // - pivotMid = conditions - .pivotZone - .CalculateMid(); - - // - isPivotToUpRejected = IsBarReject( - pivotMid, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isPivotToDownRejected = IsBarReject( - pivotMid, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotToUpBreaked = IsBarBreak( - pivotMid, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isPivotToDownBreaked = IsBarBreak( - pivotMid, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - // Sar Conditions ... - - // - bool isSarBullishFormed = - ( - // - ( - // - decisionXConditions.isBreakedUpPrevSar && - (decisionXConditions.isSarBullish || - decisionXConditions.isSarSwitchedToBullish) - // - ) - // - ); - - // - bool isSarBearishFormed = - ( - // - ( - // - decisionXConditions.isBreakedDownPrevSar && - (decisionXConditions.isSarBearish || - decisionXConditions.isSarSwitchedToBearish) - // - ) - // - ); - - // - // - // - - // - // Summarize Conditions ... - - // - bool isCondition1Bullish = - // - hasPivot && - // - isCBarBullishFormed && - (isPivotToUpRejected || - isPivotToUpBreaked) && - conditions.pivotZone.IsPeak() && - // - // SAR ... - isSarBullishFormed && - // // - // // STR ... - // !(decisionXConditions.isStrBearish) && - // // - // // VWAP ... - // !(decisionXConditions.isVWapBearishState || - // decisionXConditions.isVWapBearishOrdered) && - // - true - // - ; - - // - bool isCondition1Bearish = - // - hasPivot && - // - isCBarBearishFormed && - (isPivotToDownRejected || - isPivotToDownBreaked) && - conditions.pivotZone.IsVale() && - // - // SAR ... - isSarBearishFormed && - // // - // // STR ... - // !(decisionXConditions.isStrBullish) && - // // - // // VWAP ... - // !(decisionXConditions.isVWapBullishState || - // decisionXConditions.isVWapBullishOrdered) && - // - true - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = pivotMid; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCondition1Bullish - ? conditions.pivotZone.upper - : conditions.pivotZone.lower; - - // - } - - // - // - // - - // - isBullish = - // - // false - isCondition1Bullish - // - ; - - // - isBearish = - // - // false - isCondition1Bearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXSiganlTrigger( - // - X121SMCStrategyXSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - bool isPointBreaked = - isBullish - ? ask > point && bid > point - : ask < point && bid < point; - // bool isPointBreaked = IsBarBreak( - // point, - // setupDir, - // cBar // - // ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - // isPointBreaked && - // isSlopesBullish && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - // isPointBreaked && - // isSlopesBearish && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - iAtr *= 2.5; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_X); - - // - // result = DetectX121SMCGuards( - // provider, - // guards, - // positions, - // triggerCycleHelper, - // decisionCycleHelper, - // analyseCycleHelper, - // verificationCycleHelper, - // consolidationCycleHelper, - // visionCycleHelper // - // ); - - // - return result; -} - -// -int AddX121SMCXConditionsIfNotExists( - X121SMCStrategyXSignalConditions &item, - X121SMCStrategyXSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXConditions( - X121SMCStrategyXSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 deleted file mode 100644 index 0e58dc61..00000000 --- a/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 +++ /dev/null @@ -1,1943 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: X -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - double higherPeak; - datetime higherPeakTime; - - // - double lowerVale; - datetime lowerValeTime; - - // - XPVPivot pivotZone; - - // - // Constructor ... - X121SMCStrategyXSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - pivotZone.Clean(); - - // - higherPeak = 0; - higherPeakTime = NULL; - - // - lowerVale = 0; - lowerValeTime = NULL; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXSignalConditions mXConditions; -X121SMCStrategyXSignalConditions mXConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - // zBar.Init( - // symbol, - // period, - // zIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - // cBar.Init( - // symbol, - // period, - // cIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - // pBar.Init( - // symbol, - // period, - // pIndex // - // ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; - bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; - - // - // Verification ... - bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; - bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; - - // - // Analyse ... - bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; - bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; - - // - // Decision ... - bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; - bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; - - // - // Detect Bar State ... - - // - // PinBar ... - ENUM_X_DIRECTION cBarPinDir; - bool isCBarPin = decisionCycleHelper - .mBarAnalyser - .IsPinBar( - cBar, - cBarPinDir, - 1 // - ); - bool isCBarBullishPin = - isCBarPin && - IsBullish(cBarPinDir); - bool isCBarBearishPin = - isCBarPin && - IsBearish(cBarPinDir); - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // Pull Back ... - ENUM_X_DIRECTION cBarPullbackDir; - bool isCBarPullbacked = - decisionCycleHelper - .mBarAnalyser - .HasPullBack( - cBarPullbackDir, - cBar // - ); - bool isCBarBullishPullbacked = - isCBarPullbacked && - IsBullish(cBarPullbackDir); - bool isCBarBearishPullbacked = - isCBarPullbacked && - IsBearish(cBarPullbackDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bars Pattern and Power and Pressures ... - - // - bool hasCBarBullishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBullishPattern( - cBar, - 2 // - ); - - // - bool hasCBarBearishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBearishPattern( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPower = - decisionCycleHelper - .mBarAnalyser - .HasBullishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPower = - decisionCycleHelper - .mBarAnalyser - .HasBearishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBullishPressure( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBearishPressure( - cBar, - 2 // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - ( - // - hasCBarBullishPattern && - isCBarHasBullishPower && - isCBarHasBullishPressure - // - ) - // - || - // - ( - // - isCBarBullishPin || - // isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ) - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - ( - // - hasCBarBearishPattern && - isCBarHasBearishPower && - isCBarHasBearishPressure - // - ) - // - || - // - ( - // - isCBarBearishPin || - // isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ) - // - ; - - // - // Set Higher Peak and Lowe Vale ... - - // - XOHCL higherPeakBar; - bool hasHigherPeak = - conditions.higherPeak > 0 && - IsValid(conditions.higherPeakTime); - bool isHigherPeakBreaked = false; - bool isHigherPeakRejected = false; - - // - if (!hasHigherPeak) - { - // - int higherPeakIDX = -1; - double higherPeak = - decisionCycleHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - decisionXConditions.peaksBuffer[1], - cIndex // - ); - - // - if (higherPeak > 0 && - IsValidIndex(higherPeakIDX)) - { - // - bool hasHigherPeak = higherPeakBar.Init( - symbol, - period, - higherPeakIDX // - ); - - // - if (hasHigherPeak) - { - // - conditions.higherPeakTime = cTime; - conditions.higherPeak = higherPeak; - } - } - } - - // - if (hasHigherPeak) - { - // - isHigherPeakBreaked = IsBarBreak( - conditions.higherPeak, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isHigherPeakRejected = IsBarReject( - conditions.higherPeak, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - XOHCL lowerValeBar; - bool hasLowerVale = - conditions.lowerVale > 0 && - IsValid(conditions.lowerValeTime); - bool isLowerValeBreaked = false; - bool isLowerValeRejected = false; - - // - if (!hasLowerVale) - { - // - int lowerValeIDX = -1; - double lowerVale = - decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - decisionXConditions.valesBuffer[1], - cIndex // - ); - - // - if (lowerVale > 0 && - IsValidIndex(lowerValeIDX)) - { - // - hasLowerVale = lowerValeBar.Init( - symbol, - period, - lowerValeIDX // - ); - - // - if (hasLowerVale) - { - // - conditions.lowerVale = lowerVale; - conditions.lowerValeTime = cTime; - } - } - } - - // - if (hasLowerVale) - { - // - isLowerValeBreaked = IsBarBreak( - conditions.lowerVale, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isLowerValeRejected = IsBarReject( - conditions.lowerVale, - X_DIRECTION_BULLISH, - cBar // - ); - } - - // - double pivotMid = 0; - bool isPivotToUpRejected = false; - bool isPivotToDownRejected = false; - bool isPivotToUpBreaked = false; - bool isPivotToDownBreaked = false; - bool hasPivot = conditions.pivotZone.IsValid(); - - // - if (!hasPivot) - { - // - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - bool hasPeakPivot = - // isSamePeaks && - hasHigherPeak && - isSameCyclePeaks && - (isHigherPeakBreaked || - isHigherPeakRejected); - - // - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - bool hasValePivot = - // isSameVales && - hasLowerVale && - isSameCycleVales && - (isLowerValeBreaked || - isLowerValeRejected); - - // - bool hasPivot = hasPeakPivot || - hasValePivot; - if (hasPivot) - { - // - XPVPivot pivot; - - // - pivot.symbol = symbol; - pivot.period = period; - - // - pivot.upper = decisionXConditions.peaksBuffer[1]; - pivot.lower = decisionXConditions.valesBuffer[1]; - - // - pivot.to = cTime; - pivot.from = cTime; - pivot.repetition = 3; - - // - pivot.type = - hasPeakPivot - ? XPV_PEAK - : XPV_VALE; - - // - hasPivot = pivot.IsValid(); - if (hasPivot) - { - conditions.pivotZone = pivot; - } - } - } - - // - if (hasPivot) - { - // - pivotMid = conditions - .pivotZone - .CalculateMid(); - - // - isPivotToUpRejected = IsBarReject( - pivotMid, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isPivotToDownRejected = IsBarReject( - pivotMid, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotToUpBreaked = IsBarBreak( - pivotMid, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isPivotToDownBreaked = IsBarBreak( - pivotMid, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - // Sar Conditions ... - - // - bool isSarBullishFormed = - ( - // - ( - // - decisionXConditions.isBreakedUpPrevSar && - (decisionXConditions.isSarBullish || - decisionXConditions.isSarSwitchedToBullish) - // - ) - // - ); - - // - bool isSarBearishFormed = - ( - // - ( - // - decisionXConditions.isBreakedDownPrevSar && - (decisionXConditions.isSarBearish || - decisionXConditions.isSarSwitchedToBearish) - // - ) - // - ); - - // - // - // - - // - // Summarize Conditions ... - - // - bool isCondition1Bullish = - // - hasPivot && - // - isCBarBullishFormed && - (isPivotToUpRejected || - isPivotToUpBreaked) && - conditions.pivotZone.IsPeak() && - // - // SAR ... - isSarBullishFormed && - // // - // // STR ... - // !(decisionXConditions.isStrBearish) && - // // - // // VWAP ... - // !(decisionXConditions.isVWapBearishState || - // decisionXConditions.isVWapBearishOrdered) && - // - true - // - ; - - // - bool isCondition1Bearish = - // - hasPivot && - // - isCBarBearishFormed && - (isPivotToDownRejected || - isPivotToDownBreaked) && - conditions.pivotZone.IsVale() && - // - // SAR ... - isSarBearishFormed && - // // - // // STR ... - // !(decisionXConditions.isStrBullish) && - // // - // // VWAP ... - // !(decisionXConditions.isVWapBullishState || - // decisionXConditions.isVWapBullishOrdered) && - // - true - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = pivotMid; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCondition1Bullish - ? conditions.pivotZone.upper - : conditions.pivotZone.lower; - - // - } - - // - // - // - - // - isBullish = - // - // false - isCondition1Bullish - // - ; - - // - isBearish = - // - // false - isCondition1Bearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXSiganlTrigger( - // - X121SMCStrategyXSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - bool isPointBreaked = - isBullish - ? ask > point && bid > point - : ask < point && bid < point; - // bool isPointBreaked = IsBarBreak( - // point, - // setupDir, - // cBar // - // ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - // isPointBreaked && - // isSlopesBullish && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - // isPointBreaked && - // isSlopesBearish && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - iAtr *= 2.5; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_X); - - // - // result = DetectX121SMCGuards( - // provider, - // guards, - // positions, - // triggerCycleHelper, - // decisionCycleHelper, - // analyseCycleHelper, - // verificationCycleHelper, - // consolidationCycleHelper, - // visionCycleHelper // - // ); - - // - return result; -} - -// -int AddX121SMCXConditionsIfNotExists( - X121SMCStrategyXSignalConditions &item, - X121SMCStrategyXSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXConditions( - X121SMCStrategyXSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xobgpv.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xobgpv.signal.lib.mq5 deleted file mode 100644 index bc3329e7..00000000 --- a/Documents/BKP/1/x-121.smc.xobgpv.signal.lib.mq5 +++ /dev/null @@ -1,1020 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XOBGPV -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXOBGPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XFVGOrderBlock fvgOB; - - // - // Constructor ... - X121SMCStrategyXOBGPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - fvgOB.Clean(); - } - - /** - * Update Order Blocks Date ... - */ - void UpdateOrderBlocks() - { - // - datetime cTime = TimeCurrent(); - - // - fvgOB.orderBlock.To(cTime); - fvgOB.fairValueGap.To(cTime); - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXOBGPVSignalConditions mXOBGPVConditions; -X121SMCStrategyXOBGPVSignalConditions mXOBGPVConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXOBGPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXOBGPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - ENUM_X_DIRECTION forDir; - XFVGOrderBlock bullishOrderBlocks[]; - XFVGOrderBlock bearishOrderBlocks[]; - bool isTested = DetectFVGOB( - forDir, - bullishOrderBlocks, - bearishOrderBlocks, - consolidationState, - analyseState // - ); - - // - isBullish = - isTested && - IsBullish(forDir); - // - isBearish = - isTested && - IsBearish(forDir); - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.dir = forDir; - if (isBullish) - { - conditions.fvgOB = bullishOrderBlocks[0]; - } - else - { - conditions.fvgOB = bearishOrderBlocks[0]; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXOBGPVSiganlTrigger( - // - X121SMCStrategyXOBGPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 576 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double isNewDecisionPeak = decisionConditions.x121Conditions.isNewPeak; - - // - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - double isNewDecisionVale = decisionConditions.x121Conditions.isNewVale; - - // - bool isTriggerRSICrossedOverOverSold = triggerConditions.x121Conditions.isRsiCrossedOverOverSold; - bool isTriggerRSICrossedUnderOverBought = triggerConditions.x121Conditions.isRsiCrossedUnderOverBought; - - // - bool isDecisionRSICrossedOverOverSold = decisionConditions.x121Conditions.isRsiCrossedOverOverSold; - bool isDecisionRSICrossedUnderOverBought = decisionConditions.x121Conditions.isRsiCrossedUnderOverBought; - - // - // Waits For Price to Go Inside FVG ... - bool isPriceInsideOB = IsPriceInsideZone( - cBar, - conditions.fvgOB.orderBlock // - ); - - // - bool isPriceInsideFVG = IsPriceInsideZone( - cBar, - conditions.fvgOB.fairValueGap // - ); - - // - result = isPriceInsideOB && - isPriceInsideFVG && - conditions.fvgOB.IsValid(); - if (!result) - { - return result; - } - - // - double fvgOBUpper = 0; - double fvgOBLower = 0; - bool hasBoundary = conditions.fvgOB.GetBoundary( - fvgOBUpper, - fvgOBLower // - ); - result = hasBoundary; - if (!result) - { - return result; - } - - // - // Detect Bullish Conditions ... - isBullish = - isBullish && - cBar.IsBullish() && - decisionVale < fvgOBUpper && - decisionVale > fvgOBLower - // && - // isTriggerRSICrossedOverOverSold - ; - - // - // Detect Bearish Conditions ... - isBearish = - isBearish && - cBar.IsBearish() && - decisionPeak < fvgOBUpper && - decisionPeak > fvgOBLower - // && - // isTriggerRSICrossedUnderOverBought - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - if (conditions.fvgOB.IsValid()) - { - // - Add( - fvgOBUpper, - sls // - ); - - // - Add( - fvgOBLower, - sls // - ); - } - - // - if (isBullish) - { - // - int idx = -1; - double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale( - idx, - vale // - ); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - - // - Add( - vale, - sls // - ); - } - else if (isBearish) - { - // - int idx = -1; - double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak( - idx, - peak // - ); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - - // - Add( - peak, - sls // - ); - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - // Ignore Target ... - target = 0; - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -int AddX121SMCXOBGPVConditionsIfNotExists( - X121SMCStrategyXOBGPVSignalConditions &item, - X121SMCStrategyXOBGPVSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - bool canAdd = !IsValidSize(count); - if (!canAdd) - { - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - bool hasSame = false; - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXOBGPVSignalConditions iItem = items[i]; - - // - hasSame = iItem.fvgOB.IsSameAs(item.fvgOB); - if (hasSame) - { - break; - } - } - - // - canAdd = !hasSame; - } - - // - if (canAdd) - { - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - } - - // - return result; -} - -// -// Draw Signal ... -int DrawX121SMCXOBGPVSiganl( - X121SMCStrategyXOBGPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.dir); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xobspv.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xobspv.signal.lib.mq5 deleted file mode 100644 index 18316cd3..00000000 --- a/Documents/BKP/1/x-121.smc.xobspv.signal.lib.mq5 +++ /dev/null @@ -1,1138 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XOBSPV -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXOBSPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - XPriceZones priceZone; - - // - // Constructor ... - X121SMCStrategyXOBSPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - - // - priceZone.Clean(); - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXOBSPVSignalConditions mXOBSPVConditions; -X121SMCStrategyXOBSPVSignalConditions mXOBSPVConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXOBSPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXOBSPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Waits for new Peak or Vale ... - - // - // Reading Previous Conditions ... - ENUM_XPOI_EVENTS consolidationPoiEventsPrev[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEventsPrev[]; - X121SMCCycleConditions consolidationConditionsPrev; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEventsPrev, - consolidationPoiEventsPrev, - consolidationConditionsPrev, - cIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - - // - // Find Price Inside Zone ... - XPriceZones priceZone = conditions.priceZone; - bool hasPriceZones = conditions.priceZone.IsValid(); - if (!hasPriceZones) - { - // - hasPriceZones = CalculatePriceInsideZones( - priceZone, - analyseState, - cBar // - ); - - // - if (hasPriceZones) - { - // - // Validate Price Zone ... - double upper = 0; - double lower = 0; - hasPriceZones = priceZone.GetBoundary( - X_DIRECTION_ALL, - upper, - lower // - ); - result = hasPriceZones; - if (!result) - { - return result; - } - - // - bool isValid = decisionPeak <= upper || - decisionVale >= lower; - hasPriceZones = isValid; - result = hasPriceZones; - if (!result) - { - return result; - } - - // - conditions.priceZone = priceZone; - } - } - - // - // Detect Str Change Direction ... - - // - bool isDecisionSarBullish = decisionConditions.x121Conditions.isSarBullish; - bool isDecisionSarBearish = decisionConditions.x121Conditions.isSarBearish; - - // - bool isDecisionStrBullish = decisionConditions.x121Conditions.isStrBullish; - bool isDecisionStrBearish = decisionConditions.x121Conditions.isStrBearish; - - // - bool isDecisionSarCrossedOverVale = decisionConditions.x121Conditions.isSarCrossedOverVale; - bool isDecisionSarCrossedUnderPeak = decisionConditions.x121Conditions.isSarCrossedUnderPeak; - - // - bool isDecisionStrCrossedOverVale = decisionConditions.x121Conditions.isStrCrossedOverVale; - bool isDecisionStrCrossedUnderPeak = decisionConditions.x121Conditions.isStrCrossedUnderPeak; - - // - bool isDecisionPeakOverAtrUpper = decisionConditions.x121Conditions.isPeakOverAtrUpper; - bool isDecisionValeUnderAtrLower = decisionConditions.x121Conditions.isValeUnderAtrLower; - - // - bool isDecisionVWapBullishState = decisionConditions.x121Conditions.isVWapBullishState; - bool isDecisionVWapSwitchedToBullishState = decisionConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isDecisionVWapBullishOrdered = decisionConditions.x121Conditions.isVWapBullishOrdered; - bool isDecisionVWapSwitchedToBullishOrdered = decisionConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isDecisionVWapBearishState = decisionConditions.x121Conditions.isVWapBearishState; - bool isDecisionVWapSwitchedToBearishState = decisionConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isDecisionVWapBearishOrdered = decisionConditions.x121Conditions.isVWapBearishOrdered; - bool isDecisionVWapSwitchedToBearishOrdered = decisionConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isDecisionStrUpperOverPeak = decisionConditions.x121Conditions.isStrUpperOverPeak; - bool isDecisionStrLowerOverVale = decisionConditions.x121Conditions.isStrLowerOverVale; - - // - bool isDecisionStrUpperUnderPeak = decisionConditions.x121Conditions.isStrUpperUnderPeak; - bool isDecisionStrLowerUnderVale = decisionConditions.x121Conditions.isStrLowerUnderVale; - - // - bool isDecisionDonLowUpperLesserThanDonCloseUpper = - decisionConditions.x121Conditions.donLowUpperBuffer[1] < - decisionConditions.x121Conditions.donCloseUpperBuffer[1]; - - // - bool isDecisionDonHighLowerGreaterThanDonCloseLower = - decisionConditions.x121Conditions.donHighLowerBuffer[1] < - decisionConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - // Summarize Conditions ... - - // - isBullish = - // - isDecisionValeUnderAtrLower - // - && - // - isDecisionDonHighLowerGreaterThanDonCloseLower - // - && - // - ( - // - isDecisionVWapBullishState || - isDecisionVWapBullishOrdered - // - ) - // - && - // - ( - // - isDecisionStrUpperOverPeak || - isDecisionStrLowerOverVale - // - ) - // - && - // - ( - // - ( - // - isDecisionStrBullish && - isDecisionSarCrossedOverVale - // - ) - // - || - // - ( - // - isDecisionSarBullish && - isDecisionStrCrossedOverVale - // - ) - // - ) - // - ; - - // - isBearish = - // - isDecisionPeakOverAtrUpper - // - && - // - isDecisionDonLowUpperLesserThanDonCloseUpper - // - && - // - ( - // - isDecisionVWapBearishState || - isDecisionVWapBearishOrdered - // - ) - // - && - // - ( - // - isDecisionStrUpperUnderPeak || - isDecisionStrLowerUnderVale - // - ) - // - && - // - ( - // - ( - // - isDecisionStrBearish && - isDecisionSarCrossedUnderPeak - // - ) - // - || - // - ( - // - isDecisionSarBearish && - isDecisionStrCrossedUnderPeak // - ) - // - ) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXOBSPVSiganlTrigger( - // - X121SMCStrategyXOBSPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double decisionLastBullishStr = decisionCycleHelper.mX121Helper.xstrHelper.GetLastSTR(X_DIRECTION_BULLISH); - double decisionLastBearishStr = decisionCycleHelper.mX121Helper.xstrHelper.GetLastSTR(X_DIRECTION_BEARISH); - - // - bool isDecisionLastBearishStrBreakedUp = IsBarBreak( - decisionLastBearishStr, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isDecisionLastBullishStrBreakedDown = IsBarBreak( - decisionLastBullishStr, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Detect Bullish Conditions ... - isBullish = - // - isBullish && - cBar.IsBullish() && - isDecisionLastBearishStrBreakedUp - // - ; - - // - // Detect Bearish Conditions ... - isBearish = - // - isBearish && - cBar.IsBearish() && - isDecisionLastBullishStrBreakedDown - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - double iPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double iVale = decisionConditions.x121Conditions.valesBuffer[1]; - - // - if (isBullish) - { - // - int lowerValeIDX = -1; - double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale( - lowerValeIDX, - iVale // - ); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - - // - Add( - iVale, - sls // - ); - } - else if (isBearish) - { - // - int higherPeakIDX = -1; - double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak( - higherPeakIDX, - iPeak // - ); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - - // - Add( - iPeak, - sls // - ); - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - // Ignore Target ... - target = 0; - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -int AddX121SMCXOBSPVConditionsIfNotExists( - X121SMCStrategyXOBSPVSignalConditions &item, - X121SMCStrategyXOBSPVSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXOBSPVSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXOBSPVSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.1.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.1.signal.lib.mq5 deleted file mode 100644 index 55fb83e4..00000000 --- a/Documents/BKP/1/x-121.smc.xtwpv.old.1.signal.lib.mq5 +++ /dev/null @@ -1,1420 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// // -// const string X121SMCXTWPV_Method_1_Token = "X121SMCXTWPV_1"; -// const string X121SMCXTWPV_Method_2_Token = "X121SMCXTWPV_2"; -// const string X121SMCXTWPV_Method_3_Token = "X121SMCXTWPV_3"; - -// // -// enum ENUM_X_X121SMC_XTWPV_METHODS -// { -// X_X121SMC_XTWPV_METHOD_UNKNOWN, -// X_X121SMC_XTWPV_METHOD_1, -// X_X121SMC_XTWPV_METHOD_2, -// X_X121SMC_XTWPV_METHOD_3, -// }; - -// // -// string ToString(ENUM_X_X121SMC_XTWPV_METHODS value) -// { -// // -// string result = NULL; - -// // -// if (value == X_X121SMC_XTWPV_METHOD_UNKNOWN) -// { -// return result; -// } - -// // -// switch (value) -// { -// // -// case X_X121SMC_XTWPV_METHOD_1: -// result = "Method_1"; -// break; - -// // -// case X_X121SMC_XTWPV_METHOD_2: -// result = "Method_2"; -// break; -// } - -// // -// return result; -// } - -// // -// ENUM_X_X121SMC_XTWPV_METHODS ParseMethod(string value) -// { -// // -// ENUM_X_X121SMC_XTWPV_METHODS result = X_X121SMC_XTWPV_METHOD_UNKNOWN; - -// // -// if (!IsValid(value)) -// { -// return result; -// } - -// // -// if (Contains(X121SMCXTWPV_Method_1_Token, value)) -// { -// result = X_X121SMC_XTWPV_METHOD_1; -// } -// else if (Contains(X121SMCXTWPV_Method_2_Token, value)) -// { -// result = X_X121SMC_XTWPV_METHOD_2; -// } - -// // -// return result; -// } - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XMarketStructure consolidationMarketStructure; - XMarketStructure analyseMarketStructure; - - // - datetime newPeakAboveAtrUpperAt; - datetime newValeBelowAtrLowerAt; - datetime sarSiwtchedToBullishAt; - datetime sarSiwtchedToBearishAt; - datetime rsiCrossedOverOverSoldAt; - datetime rsiCrossedUnderOverBoughtAt; - - // - XPriceZones decisionZone; - XPriceZones peakPriceZone; - XPriceZones valePriceZone; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - decisionZone.Clean(); - peakPriceZone.Clean(); - valePriceZone.Clean(); - - // - analyseMarketStructure.Clean(); - consolidationMarketStructure.Clean(); - - // - newPeakAboveAtrUpperAt = NULL; - newValeBelowAtrLowerAt = NULL; - sarSiwtchedToBullishAt = NULL; - sarSiwtchedToBearishAt = NULL; - rsiCrossedOverOverSoldAt = NULL; - rsiCrossedUnderOverBoughtAt = NULL; - } - - /** - * Check Required Market Strucutre Exists or not ... - * - * @return ( bool ) - */ - bool HasMarketStrucutre() - { - // - bool result = false; - - // - result = - // - analyseMarketStructure.IsValid() && - consolidationMarketStructure.IsValid() - // - && - // - analyseMarketStructure.HasTrend() && - consolidationMarketStructure.HasTrend() - // - && - // - analyseMarketStructure.bias == consolidationMarketStructure.bias - // - ; - - // - return result; - } - - /** - * Check if Conditions Filled ... - * - * @return ( bool ) - */ - bool IsFilled() - { - // - bool result = false; - - // - result = HasMarketStrucutre(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(analyseMarketStructure.bias); - - // - result = - isBullish - ? IsValid(newValeBelowAtrLowerAt) && - IsValid(sarSiwtchedToBullishAt) && - IsValid(rsiCrossedOverOverSoldAt) - : IsValid(newPeakAboveAtrUpperAt) && - IsValid(sarSiwtchedToBearishAt) && - IsValid(rsiCrossedUnderOverBoughtAt); - - // - return result; - } - - /** - * Check if Has Price Zones ... - * - * @return ( bool ) - */ - bool HasPriceZone() - { - // - bool result = false; - - // - result = HasMarketStrucutre(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(analyseMarketStructure.bias); - - // - result = - isBullish - ? valePriceZone.IsValid() - : peakPriceZone.IsValid(); - - // - return result; - } - - /** - * Check if Has Decision Zones ... - * - * @return ( bool ) - */ - bool HasDecisionZone() - { - return HasPriceZone() && - decisionZone.IsValid(); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - bool hasMarketStructure = conditions.HasMarketStrucutre(); - if (!hasMarketStructure) - { - // - bool hasConsolidationMarketStructure = - consolidationCycleHelper - .DetectMarketStructure(conditions.consolidationMarketStructure); - - // - bool hasAnalyseMarketStructure = - analyseCycleHelper - .DetectMarketStructure(conditions.analyseMarketStructure); - - // - hasMarketStructure = conditions.HasMarketStrucutre(); - result = hasMarketStructure; - if (!result) - { - return result; - } - } - - // - // We Are Sure we Have Direct Structure Bias ... - isBullish = IsBullish(conditions.analyseMarketStructure.bias); - isBearish = IsBearish(conditions.analyseMarketStructure.bias); - - // - // RSI ... - double rsi = triggerConditions.x121Conditions.rsiBuffer[1]; - - // - bool isRSICrossedOverOverBought = triggerConditions.x121Conditions.isRSICrossedOverOverBought; - bool isRSICrossedUnderOverBought = triggerConditions.x121Conditions.isRSICrossedUnderOverBought; - - // - bool isRSICrossedOverOverSold = triggerConditions.x121Conditions.isRSICrossedOverOverSold; - bool isRSICrossedUnderOverSold = triggerConditions.x121Conditions.isRSICrossedUnderOverSold; - - // - // PV ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - - // - // ATR ... - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double atrUpper = triggerConditions.x121Conditions.atrUpperBuffer[1]; - double atrLower = triggerConditions.x121Conditions.atrLowerBuffer[1]; - - // - // SAR ... - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Complex Conditions ... - - // - bool isNewPeakAboveAtrUpper = - isNewPeak && - peak > atrUpper; - - // - bool isNewValeBelowAtrLower = - isNewVale && - vale < atrLower; - - // - // Fill Conditions ... - bool isConditionsFilled = conditions.IsFilled(); - if (!isConditionsFilled) - { - // - // Cleanup ... - - // - // Sar ... - - // - // Bullish ... - if (isBullish && - isSarSwitchedToBearish && - IsValid(conditions.sarSiwtchedToBullishAt)) - { - conditions.sarSiwtchedToBullishAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isSarSwitchedToBullish && - IsValid(conditions.sarSiwtchedToBearishAt)) - { - conditions.sarSiwtchedToBearishAt = NULL; - } - - // - // Rsi ... - - // - // Bullish ... - if (isBullish && - isRSICrossedUnderOverSold && - IsValid(conditions.rsiCrossedOverOverSoldAt)) - { - conditions.rsiCrossedOverOverSoldAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isRSICrossedOverOverBought && - IsValid(conditions.rsiCrossedUnderOverBoughtAt)) - { - conditions.rsiCrossedUnderOverBoughtAt = NULL; - } - - // - // Atr Change ... - - // - // Bullish ... - if (isBullish && - isNewPeak && - IsValid(conditions.newValeBelowAtrLowerAt)) - { - conditions.newValeBelowAtrLowerAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isNewVale && - IsValid(conditions.newPeakAboveAtrUpperAt)) - { - conditions.newPeakAboveAtrUpperAt = NULL; - } - - // - // Filling Up ... - - // - // Sar Change ... - - // - // Bullish ... - if (isBullish && - isSarSwitchedToBullish && - !IsValid(conditions.sarSiwtchedToBullishAt)) - { - conditions.sarSiwtchedToBullishAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isSarSwitchedToBearish && - !IsValid(conditions.sarSiwtchedToBearishAt)) - { - conditions.sarSiwtchedToBearishAt = cTime; - } - - // - // Rsi Change ... - - // - // Bullish ... - if (isBullish && - isRSICrossedOverOverSold && - !IsValid(conditions.rsiCrossedOverOverSoldAt)) - { - conditions.rsiCrossedOverOverSoldAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isRSICrossedUnderOverBought && - !IsValid(conditions.rsiCrossedUnderOverBoughtAt)) - { - conditions.rsiCrossedUnderOverBoughtAt = cTime; - } - - // - // Atr Change ... - // New Peaks and Vale ... - - // - // Bullish ... - if (isBullish && - isNewValeBelowAtrLower && - !IsValid(conditions.newValeBelowAtrLowerAt)) - { - conditions.newValeBelowAtrLowerAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isNewPeakAboveAtrUpper && - !IsValid(conditions.newPeakAboveAtrUpperAt)) - { - conditions.newPeakAboveAtrUpperAt = cTime; - } - - // - isConditionsFilled = conditions.IsFilled(); - result = isConditionsFilled; - if (!result) - { - return result; - } - } - - // - // Fill Price Zones ... - bool hasPriceZone = conditions.HasPriceZone(); - if (!hasPriceZone) - { - // - if (isBullish) - { - // - XPriceZones vPZone; - bool hasValeInsideZone = CalculatePriceInsideZones( - vPZone, - analyseState, - vale // - ); - - // - XPriceZones cbPZone; - bool hasPriceInsideZone = CalculatePriceInsideZones( - cbPZone, - analyseState, - cBar // - ); - - // - if (hasValeInsideZone && - hasPriceInsideZone && - vPZone.IsBullish() && - cbPZone.IsBullish()) - { - conditions.valePriceZone = cbPZone; - } - } - else if (isBearish) - { - // - XPriceZones pPZone; - bool hasPeakInsideZone = CalculatePriceInsideZones( - pPZone, - analyseState, - peak // - ); - - // - XPriceZones cbPZone; - bool hasPriceInsideZone = CalculatePriceInsideZones( - cbPZone, - analyseState, - cBar // - ); - - // - if ( - hasPeakInsideZone && - hasPriceInsideZone && - pPZone.IsBearish() && - cbPZone.IsBearish()) - { - conditions.peakPriceZone = cbPZone; - } - } - - // - hasPriceZone = conditions.HasPriceZone(); - result = hasPriceZone; - if (!result) - { - return result; - } - } - - // - // Check for Decision ... - bool hasDecision = conditions.HasDecisionZone(); - if (!hasDecision) - { - // - if (isBullish) - { - // - XPriceZones pZone; - bool hasPZone = CalculatePriceInsideZones( - pZone, - decisionState, - vale // - ); - - // - if (hasPZone && - pZone.IsBullish()) - { - conditions.decisionZone = pZone; - } - } - else if (isBearish) - { - // - XPriceZones pZone; - bool hasPZone = CalculatePriceInsideZones( - pZone, - decisionState, - peak // - ); - - // - if (hasPZone && - pZone.IsBearish()) - { - conditions.decisionZone = pZone; - } - } - - // - hasDecision = conditions.HasDecisionZone(); - result = hasDecision; - if (!result) - { - return result; - } - } - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - if (isBullish) - { - // - double lowerVale = triggerCycleHelper.mX121Helper.GetLowerVale(vale); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - } - else if (isBearish) - { - // - double higherPeak = triggerCycleHelper.mX121Helper.GetHigherPeak(peak); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - } - - // - if (ArraySize(sls) == 0) - { - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -// Draw Signal ... -int DrawX121SMCXTWPVSiganl( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.dir); - - // - XCBaseObject *priceZoneObjs[]; - XCBaseObject *decisionZoneObjs[]; - XCBaseObject *marketStructureObjs[]; - - // - bool hasMarketStructure = conditions.HasMarketStrucutre(); - if (hasMarketStructure) - { - // // - // drawer.DrawMarketStructure( - // conditions.analyseMarketStructure, - // marketStructureObjs // - // ); - } - - // - bool hasPriceZone = conditions.HasPriceZone(); - if (hasPriceZone) - { - // - XPriceZones pZone; - if (isBullish) - { - pZone = conditions.valePriceZone; - } - else - { - pZone = conditions.peakPriceZone; - } - - // - drawer.DrawPriceZone( - pZone, - priceZoneObjs, - conditions.dir // - ); - } - - // - bool hasDecisionZone = conditions.HasDecisionZone(); - if (hasDecisionZone) - { - // - drawer.DrawPriceZone( - conditions.decisionZone, - decisionZoneObjs - // , - // conditions.dir // - ); - } - - // - Copy( - priceZoneObjs, - drawnObjects, - false // - ); - - // - Copy( - decisionZoneObjs, - drawnObjects, - false // - ); - - // - Copy( - marketStructureObjs, - drawnObjects, - false // - ); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.12signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.12signal.lib.mq5 deleted file mode 100644 index a87e49f2..00000000 --- a/Documents/BKP/1/x-121.smc.xtwpv.old.12signal.lib.mq5 +++ /dev/null @@ -1,1367 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XMarketStructure consolidationMarketStructure; - XMarketStructure analyseMarketStructure; - - // - datetime newPeakAboveAtrUpperAt; - datetime newValeBelowAtrLowerAt; - datetime sarSiwtchedToBullishAt; - datetime sarSiwtchedToBearishAt; - datetime rsiCrossedOverOverSoldAt; - datetime rsiCrossedUnderOverBoughtAt; - - // - XPriceZones decisionZone; - XPriceZones peakPriceZone; - XPriceZones valePriceZone; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - decisionZone.Clean(); - peakPriceZone.Clean(); - valePriceZone.Clean(); - - // - analyseMarketStructure.Clean(); - consolidationMarketStructure.Clean(); - - // - newPeakAboveAtrUpperAt = NULL; - newValeBelowAtrLowerAt = NULL; - sarSiwtchedToBullishAt = NULL; - sarSiwtchedToBearishAt = NULL; - rsiCrossedOverOverSoldAt = NULL; - rsiCrossedUnderOverBoughtAt = NULL; - } - - /** - * Check Required Market Strucutre Exists or not ... - * - * @return ( bool ) - */ - bool HasMarketStrucutre() - { - // - bool result = false; - - // - result = - // - analyseMarketStructure.IsValid() && - consolidationMarketStructure.IsValid() - // - && - // - analyseMarketStructure.HasTrend() && - consolidationMarketStructure.HasTrend() - // - && - // - analyseMarketStructure.bias == consolidationMarketStructure.bias - // - ; - - // - return result; - } - - /** - * Check if Conditions Filled ... - * - * @return ( bool ) - */ - bool IsFilled() - { - // - bool result = false; - - // - result = HasMarketStrucutre(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(analyseMarketStructure.bias); - - // - result = - isBullish - ? IsValid(newValeBelowAtrLowerAt) && - IsValid(sarSiwtchedToBullishAt) && - IsValid(rsiCrossedOverOverSoldAt) - : IsValid(newPeakAboveAtrUpperAt) && - IsValid(sarSiwtchedToBearishAt) && - IsValid(rsiCrossedUnderOverBoughtAt); - - // - return result; - } - - /** - * Check if Has Price Zones ... - * - * @return ( bool ) - */ - bool HasPriceZone() - { - // - bool result = false; - - // - result = HasMarketStrucutre(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(analyseMarketStructure.bias); - - // - result = - isBullish - ? valePriceZone.IsValid() - : peakPriceZone.IsValid(); - - // - return result; - } - - /** - * Check if Has Decision Zones ... - * - * @return ( bool ) - */ - bool HasDecisionZone() - { - return HasPriceZone() && - decisionZone.IsValid(); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - bool hasMarketStructure = conditions.HasMarketStrucutre(); - if (!hasMarketStructure) - { - // - bool hasConsolidationMarketStructure = - consolidationCycleHelper - .DetectMarketStructure(conditions.consolidationMarketStructure); - - // - bool hasAnalyseMarketStructure = - analyseCycleHelper - .DetectMarketStructure(conditions.analyseMarketStructure); - - // - hasMarketStructure = conditions.HasMarketStrucutre(); - result = hasMarketStructure; - if (!result) - { - return result; - } - } - - // - // We Are Sure we Have Direct Structure Bias ... - isBullish = IsBullish(conditions.analyseMarketStructure.bias); - isBearish = IsBearish(conditions.analyseMarketStructure.bias); - - // - // RSI ... - double rsi = triggerConditions.x121Conditions.rsiBuffer[1]; - - // - bool isRSICrossedOverOverBought = triggerConditions.x121Conditions.isRSICrossedOverOverBought; - bool isRSICrossedUnderOverBought = triggerConditions.x121Conditions.isRSICrossedUnderOverBought; - - // - bool isRSICrossedOverOverSold = triggerConditions.x121Conditions.isRSICrossedOverOverSold; - bool isRSICrossedUnderOverSold = triggerConditions.x121Conditions.isRSICrossedUnderOverSold; - - // - // PV ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - - // - // ATR ... - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double atrUpper = triggerConditions.x121Conditions.atrUpperBuffer[1]; - double atrLower = triggerConditions.x121Conditions.atrLowerBuffer[1]; - - // - // SAR ... - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Complex Conditions ... - - // - bool isNewPeakAboveAtrUpper = - isNewPeak && - peak > atrUpper; - - // - bool isNewValeBelowAtrLower = - isNewVale && - vale < atrLower; - - // - // Fill Conditions ... - bool isConditionsFilled = conditions.IsFilled(); - if (!isConditionsFilled) - { - // - // Cleanup ... - - // - // Sar ... - - // - // Bullish ... - if (isBullish && - isSarSwitchedToBearish && - IsValid(conditions.sarSiwtchedToBullishAt)) - { - conditions.sarSiwtchedToBullishAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isSarSwitchedToBullish && - IsValid(conditions.sarSiwtchedToBearishAt)) - { - conditions.sarSiwtchedToBearishAt = NULL; - } - - // - // Rsi ... - - // - // Bullish ... - if (isBullish && - isRSICrossedUnderOverSold && - IsValid(conditions.rsiCrossedOverOverSoldAt)) - { - conditions.rsiCrossedOverOverSoldAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isRSICrossedOverOverBought && - IsValid(conditions.rsiCrossedUnderOverBoughtAt)) - { - conditions.rsiCrossedUnderOverBoughtAt = NULL; - } - - // - // Atr Change ... - - // - // Bullish ... - if (isBullish && - isNewPeak && - IsValid(conditions.newValeBelowAtrLowerAt)) - { - conditions.newValeBelowAtrLowerAt = NULL; - } - - // - // Bearish ... - if (isBearish && - isNewVale && - IsValid(conditions.newPeakAboveAtrUpperAt)) - { - conditions.newPeakAboveAtrUpperAt = NULL; - } - - // - // Filling Up ... - - // - // Sar Change ... - - // - // Bullish ... - if (isBullish && - isSarSwitchedToBullish && - !IsValid(conditions.sarSiwtchedToBullishAt)) - { - conditions.sarSiwtchedToBullishAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isSarSwitchedToBearish && - !IsValid(conditions.sarSiwtchedToBearishAt)) - { - conditions.sarSiwtchedToBearishAt = cTime; - } - - // - // Rsi Change ... - - // - // Bullish ... - if (isBullish && - isRSICrossedOverOverSold && - !IsValid(conditions.rsiCrossedOverOverSoldAt)) - { - conditions.rsiCrossedOverOverSoldAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isRSICrossedUnderOverBought && - !IsValid(conditions.rsiCrossedUnderOverBoughtAt)) - { - conditions.rsiCrossedUnderOverBoughtAt = cTime; - } - - // - // Atr Change ... - // New Peaks and Vale ... - - // - // Bullish ... - if (isBullish && - isNewValeBelowAtrLower && - !IsValid(conditions.newValeBelowAtrLowerAt)) - { - conditions.newValeBelowAtrLowerAt = cTime; - } - - // - // Bearish ... - if (isBearish && - isNewPeakAboveAtrUpper && - !IsValid(conditions.newPeakAboveAtrUpperAt)) - { - conditions.newPeakAboveAtrUpperAt = cTime; - } - - // - isConditionsFilled = conditions.IsFilled(); - result = isConditionsFilled; - if (!result) - { - return result; - } - } - - // - // Fill Price Zones ... - bool hasPriceZone = conditions.HasPriceZone(); - if (!hasPriceZone) - { - // - if (isBullish) - { - // - XPriceZones vPZone; - bool hasValeInsideZone = CalculatePriceInsideZones( - vPZone, - analyseState, - vale // - ); - - // - XPriceZones cbPZone; - bool hasPriceInsideZone = CalculatePriceInsideZones( - cbPZone, - analyseState, - cBar // - ); - - // - if (hasValeInsideZone && - hasPriceInsideZone && - vPZone.IsBullish() && - cbPZone.IsBullish()) - { - conditions.valePriceZone = cbPZone; - } - } - else if (isBearish) - { - // - XPriceZones pPZone; - bool hasPeakInsideZone = CalculatePriceInsideZones( - pPZone, - analyseState, - peak // - ); - - // - XPriceZones cbPZone; - bool hasPriceInsideZone = CalculatePriceInsideZones( - cbPZone, - analyseState, - cBar // - ); - - // - if ( - hasPeakInsideZone && - hasPriceInsideZone && - pPZone.IsBearish() && - cbPZone.IsBearish()) - { - conditions.peakPriceZone = cbPZone; - } - } - - // - hasPriceZone = conditions.HasPriceZone(); - result = hasPriceZone; - if (!result) - { - return result; - } - } - - // - // Check for Decision ... - bool hasDecision = conditions.HasDecisionZone(); - if (!hasDecision) - { - // - if (isBullish) - { - // - XPriceZones pZone; - bool hasPZone = CalculatePriceInsideZones( - pZone, - decisionState, - vale // - ); - - // - if (hasPZone && - pZone.IsBullish()) - { - conditions.decisionZone = pZone; - } - } - else if (isBearish) - { - // - XPriceZones pZone; - bool hasPZone = CalculatePriceInsideZones( - pZone, - decisionState, - peak // - ); - - // - if (hasPZone && - pZone.IsBearish()) - { - conditions.decisionZone = pZone; - } - } - - // - hasDecision = conditions.HasDecisionZone(); - result = hasDecision; - if (!result) - { - return result; - } - } - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Detect Bullish Conditions ... - isBullish = - isBullish && - cBar.IsBullish(); - - // - // Detect Bearish Conditions ... - isBearish = - isBearish && - cBar.IsBearish(); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - if (isBullish) - { - // - double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - } - else if (isBearish) - { - // - double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - } - - // - if (ArraySize(sls) == 0) - { - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - // Ignore Target ... - target = 0; - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -// Draw Signal ... -int DrawX121SMCXTWPVSiganl( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.dir); - - // - XCBaseObject *priceZoneObjs[]; - XCBaseObject *decisionZoneObjs[]; - XCBaseObject *marketStructureObjs[]; - - // - bool hasMarketStructure = conditions.HasMarketStrucutre(); - if (hasMarketStructure) - { - // // - // drawer.DrawMarketStructure( - // conditions.analyseMarketStructure, - // marketStructureObjs // - // ); - } - - // - bool hasPriceZone = conditions.HasPriceZone(); - if (hasPriceZone) - { - // - XPriceZones pZone; - if (isBullish) - { - pZone = conditions.valePriceZone; - } - else - { - pZone = conditions.peakPriceZone; - } - - // - drawer.DrawPriceZone( - pZone, - priceZoneObjs, - conditions.dir // - ); - } - - // - bool hasDecisionZone = conditions.HasDecisionZone(); - if (hasDecisionZone) - { - // - drawer.DrawPriceZone( - conditions.decisionZone, - decisionZoneObjs - // , - // conditions.dir // - ); - } - - // - Copy( - priceZoneObjs, - drawnObjects, - false // - ); - - // - Copy( - decisionZoneObjs, - drawnObjects, - false // - ); - - // - Copy( - marketStructureObjs, - drawnObjects, - false // - ); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.3signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.3signal.lib.mq5 deleted file mode 100644 index 154cf57c..00000000 --- a/Documents/BKP/1/x-121.smc.xtwpv.old.3signal.lib.mq5 +++ /dev/null @@ -1,957 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - datetime newPeakOverATRUpperAt; - datetime newValeUnderATRLowerAt; - - // - datetime donHighUpperEqualsToPeakAt; - datetime donLowLowerEqualsToValeAt; - - // - datetime closeOverATRUpperAt; - datetime closeUnderATRLowerAt; - - // - datetime rsiOverSoldAt; - datetime rsiOverBoughtAt; - - // - datetime newPeakOverLastAt; - datetime newValeUnderLastAt; - - // - datetime bullishBarSignAt; - datetime bearishBarSignAt; - - // - XPriceZones priceZone; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - priceZone.Clean(); - - // - newPeakOverATRUpperAt = NULL; - newValeUnderATRLowerAt = NULL; - - // - donHighUpperEqualsToPeakAt = NULL; - donLowLowerEqualsToValeAt = NULL; - - // - closeOverATRUpperAt = NULL; - closeUnderATRLowerAt = NULL; - - // - rsiOverSoldAt = NULL; - rsiOverBoughtAt = NULL; - - // - newPeakOverLastAt = NULL; - newValeUnderLastAt = NULL; - - // - bullishBarSignAt = NULL; - bearishBarSignAt = NULL; - } - - /** - * Check if Conditions Filled ... - * - * @return ( bool ) - */ - bool IsFilled(ENUM_X_DIRECTION &fillDir) - { - // - bool result = false; - - // - fillDir = X_DIRECTION_NONE; - - // - bool hasNewPeakOverATRUpper = IsValid(newPeakOverATRUpperAt); - bool hasNewValeUnderATRLower = IsValid(newValeUnderATRLowerAt); - - // - bool hasDonHighUpperEqualsToPeak = IsValid(donHighUpperEqualsToPeakAt); - bool hasDonLowLowerEqualsToVale = IsValid(donLowLowerEqualsToValeAt); - - // - bool hasCloseOverATRUpper = IsValid(closeOverATRUpperAt); - bool hasCloseUnderATRLower = IsValid(closeUnderATRLowerAt); - - // - bool hasRsiOverSold = IsValid(rsiOverSoldAt); - bool hasRsiOverBought = IsValid(rsiOverBoughtAt); - - // - bool hasNewPeakOverLast = IsValid(newPeakOverLastAt); - bool hasNewValeUnderLast = IsValid(newValeUnderLastAt); - - // - bool hasBullishBarSign = IsValid(bullishBarSignAt); - bool hasBearishBarSign = IsValid(bearishBarSignAt); - - // - bool isBullish = - ( - // - hasRsiOverSold && - hasBullishBarSign && - hasNewValeUnderLast && - hasCloseUnderATRLower && - hasNewValeUnderATRLower && - hasDonLowLowerEqualsToVale - // - ); - - // - bool isBearish = - ( - // - hasRsiOverBought && - hasBearishBarSign && - hasNewPeakOverLast && - hasCloseOverATRUpper && - hasNewPeakOverATRUpper && - hasDonHighUpperEqualsToPeak - // - ); - - // - result = - (isBullish || isBearish) && - !(isBullish && isBearish); - if (result) - { - // - fillDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - bool HasPriceZone() - { - return priceZone.IsValid(); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - result = analyseConditions.x121Conditions.isStrSwitchedToBullish || - analyseConditions.x121Conditions.isStrSwitchedToBearish; - if (!result) - { - return result; - } - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Detect Bullish Conditions ... - isBullish = - isBullish && - cBar.IsBullish(); - - // - // Detect Bearish Conditions ... - isBearish = - isBearish && - cBar.IsBearish(); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - if (isBullish) - { - // - double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - } - else if (isBearish) - { - // - double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - } - - // - if (ArraySize(sls) == 0) - { - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - // Ignore Target ... - target = 0; - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -// Draw Signal ... -int DrawX121SMCXTWPVSiganl( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.dir); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 deleted file mode 100644 index 66a317c2..00000000 --- a/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 +++ /dev/null @@ -1,1083 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XFVGOrderBlock bullishOrderBlocks[]; - XFVGOrderBlock bearishOrderBlocks[]; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - Clean(bullishOrderBlocks); - Clean(bearishOrderBlocks); - } - - /** - * Update Order Blocks Date ... - */ - void UpdateOrderBlocks() - { - // - int count = 0; - datetime cTime = TimeCurrent(); - - // - count = ArraySize(bullishOrderBlocks); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - bullishOrderBlocks[i].orderBlock.To(cTime); - bullishOrderBlocks[i].fairValueGap.To(cTime); - } - } - - // - count = ArraySize(bearishOrderBlocks); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - bearishOrderBlocks[i].orderBlock.To(cTime); - bearishOrderBlocks[i].fairValueGap.To(cTime); - } - } - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - ENUM_X_DIRECTION forDir; - XFVGOrderBlock bullishOrderBlocks[]; - XFVGOrderBlock bearishOrderBlocks[]; - bool isTested = TestPOIState( - forDir, - bullishOrderBlocks, - bearishOrderBlocks, - consolidationState, - analyseState, - decisionState // - ); - - // - isBullish = - isTested && - IsBullish(forDir); - // - isBearish = - isTested && - IsBearish(forDir); - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.dir = forDir; - Copy( - bullishOrderBlocks, - conditions.bullishOrderBlocks // - ); - Copy( - bearishOrderBlocks, - conditions.bearishOrderBlocks // - ); - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 576 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double isNewDecisionPeak = decisionConditions.x121Conditions.isNewPeak; - - // - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - double isNewDecisionVale = decisionConditions.x121Conditions.isNewVale; - - // - // Waits For Price to Go Inside FVG ... - XFVGOrderBlock fvgOrderBlock; - bool isPriceInsideOB = false; - bool isPriceInsideFVG = false; - if (isBullish) - { - // - int count = ArraySize(conditions.bullishOrderBlocks); - for (int i = 0; i < count; i++) - { - // - XFVGOrderBlock iModel = conditions.bullishOrderBlocks[i]; - - // - isPriceInsideOB = IsPriceInsideZone( - cBar, - iModel.orderBlock // - ); - - // - isPriceInsideFVG = IsPriceInsideZone( - cBar, - iModel.fairValueGap // - ); - - // - if (isPriceInsideOB && - isPriceInsideFVG) - { - // - fvgOrderBlock = iModel; - break; - } - - // - isPriceInsideOB = false; - isPriceInsideFVG = false; - } - } - else - { - // - int count = ArraySize(conditions.bearishOrderBlocks); - for (int i = 0; i < count; i++) - { - // - XFVGOrderBlock iModel = conditions.bearishOrderBlocks[i]; - - // - isPriceInsideOB = IsPriceInsideZone( - cBar, - iModel.orderBlock // - ); - - // - isPriceInsideFVG = IsPriceInsideZone( - cBar, - iModel.fairValueGap // - ); - - // - if (isPriceInsideOB && - isPriceInsideFVG) - { - // - fvgOrderBlock = iModel; - break; - } - - // - isPriceInsideOB = false; - isPriceInsideFVG = false; - } - } - - // - result = isPriceInsideOB && - isPriceInsideFVG && - fvgOrderBlock.IsValid(); - if (!result) - { - return result; - } - - // - double fvgOBUpper = 0; - double fvgOBLower = 0; - bool hasBoundary = fvgOrderBlock.GetBoundary( - fvgOBUpper, - fvgOBLower // - ); - result = hasBoundary; - if (!result) - { - return result; - } - - // - // Detect Bullish Conditions ... - isBullish = - isBullish && - cBar.IsBullish() && - isNewDecisionVale; - - // - // Detect Bearish Conditions ... - isBearish = - isBearish && - cBar.IsBearish() && - isNewDecisionPeak; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - - // - double sls[]; - - // - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - if (fvgOrderBlock.IsValid()) - { - // - Add( - fvgOBUpper, - sls // - ); - - // - Add( - fvgOBLower, - sls // - ); - } - - // - if (isBullish) - { - // - double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale); - if (lowerVale > 0) - { - // - Add( - lowerVale, - sls // - ); - } - - // - Add( - vale, - sls // - ); - } - else if (isBearish) - { - // - double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak); - if (higherPeak > 0) - { - // - Add( - higherPeak, - sls // - ); - } - - // - Add( - peak, - sls // - ); - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - target = 0; - - // - } - - // - // Ignore Target ... - target = 0; - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// -int AddX121SMCXTWPVConditionsIfNotExists( - X121SMCStrategyXTWPVSignalConditions &item, - X121SMCStrategyXTWPVSignalConditions &items[] // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - bool canAdd = !IsValidSize(count); - if (!canAdd) - { - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) { - // - X121SMCStrategyXTWPVSignalConditions iItem = items[i]; - - // - if (iItem.dir != item.dir) { - continue; - } - - // - bool isIBullish = IsBullish(iItem); - if (isIBullish) { - // - int iCount = ArraySize(iItem.bullishOrderBlocks); - for (int j = 0; j < iCount; j++) { - // - XFVGOrderBlock jFO = iItem.bullishOrderBlocks[j]; - - } - } else { - - } - } - } - - // - if (canAdd) - { - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - } - - // - result = ArraySize(items); - - // - return result; -} - -// -// Draw Signal ... -int DrawX121SMCXTWPVSiganl( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool isBullish = IsBullish(conditions.dir); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.signal.lib.mq5 deleted file mode 100644 index ba1637da..00000000 --- a/Documents/BKP/1/x-121.smc.xtwpv.old.signal.lib.mq5 +++ /dev/null @@ -1,2060 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -const string X121SMCXTWPV_Method_1_Token = "X121SMCXTWPV_1"; -const string X121SMCXTWPV_Method_2_Token = "X121SMCXTWPV_2"; -const string X121SMCXTWPV_Method_3_Token = "X121SMCXTWPV_3"; - -// -enum ENUM_X_X121SMC_XTWPV_METHODS -{ - X_X121SMC_XTWPV_METHOD_UNKNOWN, - X_X121SMC_XTWPV_METHOD_1, - X_X121SMC_XTWPV_METHOD_2, - X_X121SMC_XTWPV_METHOD_3, -}; - -// -string ToString(ENUM_X_X121SMC_XTWPV_METHODS value) -{ - // - string result = NULL; - - // - if (value == X_X121SMC_XTWPV_METHOD_UNKNOWN) - { - return result; - } - - // - switch (value) - { - // - case X_X121SMC_XTWPV_METHOD_1: - result = "Method_1"; - break; - - // - case X_X121SMC_XTWPV_METHOD_2: - result = "Method_2"; - break; - } - - // - return result; -} - -// -ENUM_X_X121SMC_XTWPV_METHODS ParseMethod(string value) -{ - // - ENUM_X_X121SMC_XTWPV_METHODS result = X_X121SMC_XTWPV_METHOD_UNKNOWN; - - // - if (!IsValid(value)) - { - return result; - } - - // - if (Contains(X121SMCXTWPV_Method_1_Token, value)) - { - result = X_X121SMC_XTWPV_METHOD_1; - } - else if (Contains(X121SMCXTWPV_Method_2_Token, value)) - { - result = X_X121SMC_XTWPV_METHOD_2; - } - - // - return result; -} - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double point; - XPVPivot pivot; - - // - XConsolidationZone consolidationZone; - - // - string method; - - // - bool hasSupportZone; - bool hasResistanceZone; - bool hasSupplyZone; - bool hasDemandZone; - bool hasOrderBlock; - bool hasFairValueGap; - XCSupportZone *supportZone; - XCResistanceZone *resistanceZone; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - XCOrderBlock *orderBlock; - XCFVG *fairValueGap; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - point = 0; - pivot.Clean(); - consolidationZone.Clean(); - - // - method = NULL; - - // - CleanPriceInsideZones(); - } - - /** - * Clean Price Insie Zones ... - */ - void CleanPriceInsideZones() - { - // - hasSupportZone = false; - hasResistanceZone = false; - hasSupplyZone = false; - hasDemandZone = false; - hasOrderBlock = false; - hasFairValueGap = false; - - // - supportZone = NULL; - resistanceZone = NULL; - supplyZone = NULL; - demandZone = NULL; - orderBlock = NULL; - fairValueGap = NULL; - } - - /** - * Count Price Inside Zones ... - * - * @return ( int ) - */ - int CountPriceInsideZones() - { - // - int result = 0; - - // - if (hasSupportZone) - { - result++; - } - - // - if (hasResistanceZone) - { - result++; - } - - // - if (hasSupplyZone) - { - result++; - } - - // - if (hasDemandZone) - { - result++; - } - - // - if (hasOrderBlock) - { - result++; - } - - // - if (hasFairValueGap) - { - result++; - } - - // - return result; - } - - /** - * Check Conditions Has Price Inside Zones ... - * - * @return ( bool ) - */ - bool HasPriceInsideZones() - { - // - bool result = false; - - // - result = IsValidSize(CountPriceInsideZones()); - - // - return result; - } - - /** - * Check Conditions Has Bullish Price Inside Zone ... - * - * @return ( bool ) - */ - bool HasBullishPriceInsideZone() - { - // - bool result = false; - - // - result = - // - HasPriceInsideZones() && - // - (hasDemandZone || - hasSupportZone || - (hasOrderBlock && - orderBlock.IsBullish()) || - (hasFairValueGap && - fairValueGap.IsBullish())) - // - ; - - // - return result; - } - - /** - * Check Conditions Has Bearish Price Inside Zone ... - * - * @return ( bool ) - */ - bool HasBearishPriceInsideZone() - { - // - bool result = false; - - // - result = - // - HasPriceInsideZones() && - // - (hasSupplyZone || - hasResistanceZone || - (hasOrderBlock && - orderBlock.IsBearish()) || - (hasFairValueGap && - fairValueGap.IsBearish())) - // - ; - - // - return result; - } - - /** - * Check has Vald Pivot or not ... - * - * @return ( bool ) - */ - bool HasPivot() - { - return pivot.IsValid(); - } - - /** - * Check Model Has Consolidation Zone or not ... - * - * @return ( bool ) - */ - bool HasConsolidationZone() - { - return consolidationZone.IsValid(); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - XMarketStructure consolidationMarketStructure; - bool hasConsolidationMarketStructure = - consolidationCycleHelper - .DetectMarketStructure(consolidationMarketStructure); - - // - XMarketStructure analyseMarketStructure; - bool hasAnalyseMarketStructure = - analyseCycleHelper - .DetectMarketStructure(analyseMarketStructure); - - // - // Check Same Bias ... - result = - hasAnalyseMarketStructure && - hasConsolidationMarketStructure && - analyseMarketStructure.HasTrend() && - consolidationMarketStructure.HasTrend() && - analyseMarketStructure.bias == consolidationMarketStructure.bias; - if (!result) - { - return result; - } - - // - XOHCL analyseCBar; - result = analyseCycleHelper.GetBar( - cBar, - analyseCBar // - ); - if (!result) - { - return result; - } - - // - XOHCL analysePBar; - result = analyseCBar.GetPreviousBar(analysePBar); - if (!result) - { - return result; - } - - // - double bullishFib = GetFibonacciLevel( - analyseCBar.high, - analyseCBar.low, - GetFiboLevelValue(X_FIBO_LEVEL_382), - -1 // - ); - - // - double bearishFib = GetFibonacciLevel( - analyseCBar.high, - analyseCBar.low, - GetFiboLevelValue(X_FIBO_LEVEL_382), - 1 // - ); - - // - // Detect Market Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = verificationCycleHelper - // .DetectTrend(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - // result = hasBullishTrend || - // hasBearishTrend; - // if (!result) - // { - // return result; - // } - - // - // Detect Trend Based On Peaks and Vales ... - ENUM_X_DIRECTION trend; - bool hasTrend = triggerCycleHelper - .HasPVDirection(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - - // - // Retrieve Active Pivots ... - - // - XPVPivot peakPivot; - bool hasPeakPivot = analyseCycleHelper - .GetActivePeakPivot(peakPivot); - - // - XPVPivot valePivot; - bool hasValePivot = analyseCycleHelper - .GetActiveValePivot(valePivot); - - // - // Check Pivot ... - bool hasPivot = conditions.HasPivot(); - if (!hasPivot) - { - // - if (hasPeakPivot && !hasValePivot) - { - conditions.pivot = peakPivot; - } - else if (hasValePivot && !hasPeakPivot) - { - conditions.pivot = valePivot; - } - else if (hasPeakPivot && hasValePivot) - { - // - if (peakPivot.from > valePivot.from) - { - conditions.pivot = peakPivot; - } - else if (valePivot.from > peakPivot.from) - { - conditions.pivot = valePivot; - } - } - - // - hasPivot = conditions.HasPivot(); - result = hasPivot; - if (!result) - { - return result; - } - } - - // - // Update Pivot States ... - if (hasPivot) - { - // - conditions.pivot.to = cTime; - analyseCycleHelper.FillPivotState(conditions.pivot); - - // - // Check Pivot Renewation ... - bool hasNewPivot = - // - (hasPeakPivot && - peakPivot.from > conditions.pivot.from) || - (hasValePivot && - valePivot.from > conditions.pivot.from) - // - ; - result = !hasNewPivot; - if (!result) - { - // - conditions.pivot.Clean(); - return result; - } - } - - // - // XOHCL Conditions ... - - // - // Fibo Pressure ... - ENUM_X_DIRECTION pBarFiboPressureDir; - bool pBarHasFiboPressure = triggerCycleHelper - .mBarAnalyser - .HasFiboPressure( - pBar, - pBarFiboPressureDir // - ); - bool isPBarHasBullishFiboPressure = - pBarHasFiboPressure && - IsBullish(pBarFiboPressureDir); - bool isPBarHasBearishFiboPressure = - pBarHasFiboPressure && - IsBearish(pBarFiboPressureDir); - - // - // Rejection ... - ENUM_X_DIRECTION pBarRejectionDir; - bool isPBarRejected = triggerCycleHelper - .mBarAnalyser - .IsRejectionBar( - pBar, - pBarRejectionDir, - 0 // - ); - bool isPBarBullishRejected = - isPBarRejected && - IsBullish(pBarRejectionDir); - bool isPBarBearishRejected = - isPBarRejected && - IsBearish(pBarRejectionDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentumBar = triggerCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // - ); - bool isCBarBullishMomentumBar = - isCBarMomentumBar && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentumBar = - isCBarMomentumBar && - IsBearish(cBarMomentumDir); - - // - // Engulfing ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = triggerCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Helper cBar Conditions ... - bool isBearishFiboPassed = bullishFib <= conditions.pivot.lower; - bool isBullishFiboPassed = bearishFib >= conditions.pivot.upper; - - // - // Detect a Zone Which Price Inside it ... - // Helper (Optional) ... - conditions.CleanPriceInsideZones(); - bool hasPriceInsideZones = conditions.HasPriceInsideZones(); - int priceInsideZonesCount = conditions.CountPriceInsideZones(); - if (!hasPriceInsideZones) - { - // - hasPriceInsideZones = DetectPriceInsideZones( - verificationState, - cBar, - priceInsideZonesCount, - conditions.hasSupportZone, - conditions.supportZone, - conditions.hasResistanceZone, - conditions.resistanceZone, - conditions.hasSupplyZone, - conditions.supplyZone, - conditions.hasDemandZone, - conditions.demandZone, - conditions.hasOrderBlock, - conditions.orderBlock, - conditions.hasFairValueGap, - conditions.fairValueGap // - ); - - // - priceInsideZonesCount = conditions.CountPriceInsideZones(); - } - - // - // Check Price Inside Consolidation Zone ... - XConsolidationZone cZone; - bool hasConsolidationZone = conditions - .HasConsolidationZone(); - if (!hasConsolidationZone) - { - // - hasConsolidationZone = triggerCycleHelper - .GetLastConsolidationZone(cZone); - // - if (!hasConsolidationZone) - { - // - XConsolidationZone cZones[]; - int count = triggerCycleHelper - .FillConsolidationZones(cZones); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XConsolidationZone iZone = cZones[i]; - - // - XCZone *iCZone; - bool isInited = ToZone(iZone, iCZone); - if (!isInited) - { - continue; - } - - // - bool isValid = IsPriceInsideZone( - cBar, - iCZone // - ); - if (isValid) - { - cZone = iZone; - } - } - } - - // - conditions.consolidationZone = cZone; - hasConsolidationZone = conditions - .HasConsolidationZone(); - } - } - if (hasConsolidationZone) - { - conditions.consolidationZone = cZone; - } - - // - // PV Conditions ... - - // - double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1]; - double analysePeakPrev = analyseConditions.x121Conditions.peaksBuffer[2]; - double analysePeakDiff = MathAbs(analysePeakPrev - analysePeak); - - // - bool isNewAnalysePeak = analyseConditions.x121Conditions.isNewPeak; - bool isNewAnalysePeakOverLast = analyseConditions.x121Conditions.isNewPeakOverLast; - bool isNewAnalysePeakUnderLast = analyseConditions.x121Conditions.isNewPeakUnderLast; - - // - double analyseVale = analyseConditions.x121Conditions.valesBuffer[1]; - double analyseValePrev = analyseConditions.x121Conditions.valesBuffer[2]; - double analyseValeDiff = MathAbs(analyseValePrev - analyseVale); - - // - bool isNewAnalyseVale = analyseConditions.x121Conditions.isNewVale; - bool isNewAnalyseValeOverLast = analyseConditions.x121Conditions.isNewValeOverLast; - bool isNewAnalyseValeUnderLast = analyseConditions.x121Conditions.isNewValeUnderLast; - - // - double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; - double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isNewTriggerPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewTriggerPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewTriggerPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewTriggerVale = triggerConditions.x121Conditions.isNewVale; - bool isNewTriggerValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewTriggerValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - int condition2MinPVDiffPoint = 30; - bool isAnalysePeakDiffPointPassed = analysePeakDiff >= (condition2MinPVDiffPoint * points); - bool isAnalyseValeDiffPointPassed = analyseValeDiff >= (condition2MinPVDiffPoint * points); - - // - // DONCHAIN Conditions ... - - // - double analyseDonOpenUpper = analyseConditions.x121Conditions.donOpenUpperBuffer[1]; - double analyseDonOpenLower = analyseConditions.x121Conditions.donOpenLowerBuffer[1]; - - // - double analyseDonHighUpper = analyseConditions.x121Conditions.donHighUpperBuffer[1]; - double analyseDonHighLower = analyseConditions.x121Conditions.donHighLowerBuffer[1]; - - // - double analyseDonCloseUpper = analyseConditions.x121Conditions.donCloseUpperBuffer[1]; - double analyseDonCloseLower = analyseConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - double analyseDonLowUpper = analyseConditions.x121Conditions.donLowUpperBuffer[1]; - double analyseDonLowLower = analyseConditions.x121Conditions.donLowLowerBuffer[1]; - - // - // OPEN ... - double triggerDonOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double triggerDonOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - double triggerDonOpenUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2]; - double triggerDonOpenLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2]; - - // - // HIGH ... - double triggerDonHighUpper = triggerConditions.x121Conditions.donHighUpperBuffer[1]; - double triggerDonHighLower = triggerConditions.x121Conditions.donHighLowerBuffer[1]; - double triggerDonHighUpperPrev = triggerConditions.x121Conditions.donHighUpperBuffer[2]; - double triggerDonHighLowerPrev = triggerConditions.x121Conditions.donHighLowerBuffer[2]; - - // - // CLOSE ... - double triggerDonCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double triggerDonCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - double triggerDonCloseUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2]; - double triggerDonCloseLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2]; - - // - // LOW ... - double triggerDonLowUpper = triggerConditions.x121Conditions.donLowUpperBuffer[1]; - double triggerDonLowLower = triggerConditions.x121Conditions.donLowLowerBuffer[1]; - double triggerDonLowUpperPrev = triggerConditions.x121Conditions.donLowUpperBuffer[2]; - double triggerDonLowLowerPrev = triggerConditions.x121Conditions.donLowLowerBuffer[2]; - - // - double triggerAtr = triggerConditions.x121Conditions.atrBuffer[1]; - double triggerUpperAtr = triggerConditions.x121Conditions.atrUpperBuffer[1]; - double triggerLowerAtr = triggerConditions.x121Conditions.atrLowerBuffer[1]; - - // - bool isNewTriggerPeakOverAtrUpper = - // - isNewTriggerPeak && - triggerPeak > triggerUpperAtr - // - ; - - // - bool isNewTriggerValeUnderAtrLower = - // - isNewTriggerVale && - triggerVale < triggerLowerAtr - // - ; - - // - if (isNewTriggerPeakOverAtrUpper || - isNewTriggerValeUnderAtrLower) - { - Print("ATR Break ..."); - } - - // - // Method 1 ... - - // - // Bullish Conditions 1 ... - bool bullishConditions1 = - // - false && - hasBullishTrend && - isBullishFiboPassed && - hasConsolidationZone && - analyseCBar.IsBullish() && - isNewAnalysePeakOverLast && - conditions.pivot.upper < analysePeak && - conditions.pivot.upper < analyseCBar.GetUp() && - conditions.pivot.upper > analyseCBar.GetDown() - // - ; - if (bullishConditions1) - { - // - conditions.point = conditions.pivot.upper; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_1); - } - - // - // Bearish Conditions 1 ... - bool bearishConditions1 = - // - false && - hasBearishTrend && - isBearishFiboPassed && - hasConsolidationZone && - analyseCBar.IsBearish() && - isNewAnalyseValeUnderLast && - conditions.pivot.lower > analyseVale && - conditions.pivot.lower < analyseCBar.GetUp() && - conditions.pivot.lower > analyseCBar.GetDown() - // - ; - if (bearishConditions1) - { - // - conditions.point = conditions.pivot.lower; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_1); - } - - // - // Method 2 ... - - // - // Bullish Conditions 2 ... - bool bullishConditions2 = - // - false && - hasBullishTrend && - isNewAnalyseValeOverLast && - isAnalyseValeDiffPointPassed && - analyseDonCloseLower > analyseVale - // - ; - if (bullishConditions2) - { - // - conditions.point = analyseVale; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_2); - } - - // - // Bearish Conditions 2 ... - bool bearishConditions2 = - // - false && - hasBearishTrend && - isNewAnalysePeakUnderLast && - isAnalysePeakDiffPointPassed && - analyseDonCloseUpper > analysePeak - // - ; - if (bearishConditions2) - { - // - conditions.point = analysePeak; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_2); - } - - // - // Method 3 ... - - // - // Bullish Conditions 3 ... - bool bullishConditions3 = - // - false - // - ; - if (bullishConditions3) - { - // - conditions.point = analyseVale; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3); - } - - // - // Bearish Conditions 3 ... - bool bearishConditions3 = - // - false - // - ; - if (bearishConditions3) - { - // - conditions.point = analysePeak; - conditions.method = ToString(X_X121SMC_XTWPV_METHOD_3); - } - - // - // Summary Conditions ... - - // - isBullish = - // - bullishConditions1 || - bullishConditions2 || - bullishConditions3 - // - ; - - // - isBearish = - // - bearishConditions1 || - bearishConditions2 || - bearishConditions3 - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - XPVPivotPoint pivotPoints[]; - XPVPivotPoint nearestPivotPoint; - bool hasNearestPivotPoint = false; - int pivotPointsCount = triggerCycleHelper - .FillPivotPoints(pivotPoints); - if (IsValidSize(pivotPointsCount)) - { - // - for (int i = 0; i < pivotPointsCount; i++) - { - // - XPVPivotPoint iPoint = pivotPoints[i]; - - // - bool canSet = - (isBullish - ? iPoint.value < conditions.point - : iPoint.value > conditions.point) - // - && - // - (!nearestPivotPoint.IsValid() - ? true - : isBullish - ? nearestPivotPoint.value > iPoint.value - : nearestPivotPoint.value < iPoint.value); - if (canSet) - { - nearestPivotPoint = iPoint; - } - } - - // - hasNearestPivotPoint = nearestPivotPoint.IsValid(); - } - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - - // - double oppositTarget = CalculateTarget( - cBar, - analyseState, - Opposit(setupDir) // - ); - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double atr = triggerConditions.x121Conditions.atrBuffer[1]; - - // - double sls[]; - - // - bool hasConsolidationZone = conditions.HasConsolidationZone(); - if (hasConsolidationZone) - { - // - if (isBullish) - { - Add( - conditions.consolidationZone.lower, - sls // - ); - } - else - { - Add( - conditions.consolidationZone.upper, - sls // - ); - } - } - if (hasNearestPivotPoint) - { - Add( - nearestPivotPoint.value, - sls // - ); - } - if (ArraySize(sls) == 0) - { - // - double pointsDiff = (10 * points); - double pointsPlus = conditions.point + pointsDiff; - double pointsMinus = conditions.point - pointsDiff; - - // - // Force SL ... - Add( - conditions.point, - sls // - ); - - // - Add( - pointsPlus, - sls // - ); - - // - Add( - pointsMinus, - sls // - ); - - // - Add( - oppositTarget, - sls // - ); - } - - // - bool hasPriceInsideZones = conditions.HasPriceInsideZones(); - bool hasBullishPriceInsideZone = conditions.HasBullishPriceInsideZone(); - bool hasBearishPriceInsideZone = conditions.HasBearishPriceInsideZone(); - - // - if ( - isBullish && - hasPriceInsideZones && - hasBullishPriceInsideZone // - ) - { - // - // Demand ... - if (conditions.hasDemandZone) - { - // - Add( - conditions.demandZone.Lower(), - sls // - ); - } - - // - // Support ... - if (conditions.hasSupportZone) - { - // - Add( - conditions.supportZone.Lower(), - sls // - ); - } - - // - // Order Block ... - if (conditions.hasOrderBlock) - { - // - Add( - conditions.orderBlock.Lower(), - sls // - ); - } - - // - // Fair Value Gap ... - if (conditions.hasFairValueGap) - { - // - Add( - conditions.fairValueGap.Lower(), - sls // - ); - } - } - - // - if ( - isBearish && - hasPriceInsideZones && - hasBearishPriceInsideZone // - ) - { - // - // Supply ... - if (conditions.hasSupplyZone) - { - // - Add( - conditions.supplyZone.Upper(), - sls // - ); - } - - // - // Resistance ... - if (conditions.hasResistanceZone) - { - // - Add( - conditions.resistanceZone.Upper(), - sls // - ); - } - - // - // Order Block ... - if (conditions.hasOrderBlock) - { - // - Add( - conditions.orderBlock.Upper(), - sls // - ); - } - - // - // Fair Value Gap ... - if (conditions.hasFairValueGap) - { - // - Add( - conditions.fairValueGap.Upper(), - sls // - ); - } - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - atr - : slsMax + atr; - double risk = MathAbs(entry - sl); - double targetDelta = 2 * (risk / 3); - if (target == 0) - { - // - int minTargetPint = 50; - double minTargetPointValue = minTargetPint * points; - if (targetDelta < minTargetPointValue) - { - targetDelta = minTargetPointValue; - } - - // - // Force Target On Half Risk ... - target = - isBullish - ? entry + targetDelta - : entry - targetDelta; - - // - } - - // - conditions.sl = sl; - conditions.target = 0; // target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -/** - * Draw Conditions Pivot Zone ... - * - * @param conditions: X121SMCStrategyXTWPVSignalConditions instance Reference ... - * @param drawer: XCPOIDrawer pointer ... - * @param drawnObjects: XCBaseObject instance Reference Collection ... - * @param drawState: Boolean ... - * @param drawTicksZone: Boolean ... - * @param ignoreSwingHighs: Boolean ... - * @param ignoreSwingLows: Boolean ... - * @param ignoreSupportZones: Boolean ... - * @param ignoreResistanceZones: Boolean ... - * @param ignoreSupplyZones: Boolean ... - * @param ignoreDemandZones: Boolean ... - * @param ignoreBullishOrderBlocks: Boolean ... - * @param ignoreBearishOrderBlocks: Boolean ... - * @param ignoreBullishFairValueGaps: Boolean ... - * @param ignoreBearishFairValueGaps: Boolean ... - * @param ignoreBullishRejectionBars: Boolean ... - * @param ignoreBearishRejectionBars: Boolean ... - * @param ignoreBullishMomentumBars: Boolean ... - * @param ignoreBearishMomentumBars: Boolean ... - * - * @return ( int ) - */ -int DrawXTWPVPivotZone( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCPOIDrawer *drawer, - XCBaseObject *&drawnObjects[], - bool drawState = false, - bool drawTicksZone = false, - bool ignoreSwingHighs = false, - bool ignoreSwingLows = false, - bool ignoreSupportZones = false, - bool ignoreResistanceZones = false, - bool ignoreSupplyZones = false, - bool ignoreDemandZones = false, - bool ignoreBullishOrderBlocks = false, - bool ignoreBearishOrderBlocks = false, - bool ignoreBullishFairValueGaps = false, - bool ignoreBearishFairValueGaps = false, - bool ignoreBullishRejectionBars = false, - bool ignoreBearishRejectionBars = false, - bool ignoreBullishMomentumBars = false, - bool ignoreBearishMomentumBars = false // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL || - !conditions.HasPivot()) - { - return result; - } - - // - drawer.DrawPivot( - // - conditions.pivot, - drawnObjects, - // - drawState, - drawTicksZone, - ignoreSwingHighs, - ignoreSwingLows, - ignoreSupportZones, - ignoreResistanceZones, - ignoreSupplyZones, - ignoreDemandZones, - ignoreBullishOrderBlocks, - ignoreBearishOrderBlocks, - ignoreBullishFairValueGaps, - ignoreBearishFairValueGaps, - ignoreBullishRejectionBars, - ignoreBearishRejectionBars, - ignoreBullishMomentumBars, - ignoreBearishMomentumBars // - ); - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -/** - * Drw Conditions Price Inside Zones ... - * - * @param conditions: X121SMCStrategyXTWPVSignalConditions instance Reference ... - * @param drawer: XCPOIDrawer pointer ... - * @param drawnObjects: XCBaseObject instance Reference Collection ... - * - * @return ( int ) - */ -int DrawTWPVPriceInsideZones( - X121SMCStrategyXTWPVSignalConditions &conditions, - XCPOIDrawer *drawer, - XCBaseObject *&drawnObjects[] // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if ( - drawer == NULL || - !conditions.HasPriceInsideZones()) - { - return result; - } - - // - // Support ... - if (conditions.hasSupportZone) - { - // - XCSupportZoneObject *iObj; - bool isCreated = drawer.CreateSupportZone( - conditions.supportZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - - // - // Resistance ... - if (conditions.hasResistanceZone) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = drawer.CreateResistanceZone( - conditions.resistanceZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - - // - // Supply ... - if (conditions.hasSupplyZone) - { - // - XCSupplyZoneObject *iObj; - bool isCreated = drawer.CreateSupplyZone( - conditions.supplyZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - - // - // Demand ... - if (conditions.hasDemandZone) - { - // - XCDemandZoneObject *iObj; - bool isCreated = drawer.CreateDemandZone( - conditions.demandZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - - // - // Order Block ... - if (conditions.hasOrderBlock) - { - // - bool isBullish = conditions.orderBlock.IsBullish(); - if (isBullish) - { - // - XCBullishOrderBlockObject *iObj; - bool isCreated = drawer.CreateBullishOrderBlock( - conditions.orderBlock, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - else - { - // - XCBearishOrderBlockObject *iObj; - bool isCreated = drawer.CreateBearishOrderBlock( - conditions.orderBlock, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - - // - // FairValueGap ... - if (conditions.hasFairValueGap) - { - // - bool isBullish = conditions.fairValueGap.IsBullish(); - if (isBullish) - { - // - XCBullishFairValueGapObject *iObj; - bool isCreated = drawer.CreateBullishFairValueGap( - conditions.fairValueGap, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - else - { - // - XCBearishFairValueGapObject *iObj; - bool isCreated = drawer.CreateBearishFairValueGap( - conditions.fairValueGap, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - - // - result = ArraySize(drawnObjects); - - // - return result; -} - -// diff --git a/Documents/BKP/1/x-saherelm.x121.helper.mq5 b/Documents/BKP/1/x-saherelm.x121.helper.mq5 deleted file mode 100644 index e2bb0557..00000000 --- a/Documents/BKP/1/x-saherelm.x121.helper.mq5 +++ /dev/null @@ -1,4636 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XCX121Helper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.x-helper.class.mq5" - -// -// Definitions ... -enum ENUM_X121_BUFFERS -{ - // - // Main Buffers ... - X121_PEAKS_LINE = 0, - X121_VALES_LINE = 1, - X121_SAR_LINE = 2, - X121_ATR_UPPER_LINE = 3, - X121_ATR_LOWER_LINE = 4, - X121_STR_LOWER_LINE = 5, - X121_VWAP_FAST_LINE = 7, - X121_VWAP_MID_LINE = 9, - X121_VWAP_SLOW_LINE = 11, - X121_DON_OPEN_UPPER_LINE = 13, - X121_DON_OPEN_LOWER_LINE = 14, - X121_DON_HIGH_UPPER_LINE = 15, - X121_DON_HIGH_LOWER_LINE = 16, - X121_DON_LOW_UPPER_LINE = 17, - X121_DON_LOW_LOWER_LINE = 18, - X121_DON_CLOSE_UPPER_LINE = 19, - X121_DON_CLOSE_LOWER_LINE = 20, - // - // Data Buffers ... - // - // XPV Data ... - X121_CURRENT_HH_LINE = 21, - X121_CURRENT_LL_LINE = 22, - X121_SHORT_HH_LINE = 23, - X121_SHORT_LL_LINE = 24, - X121_MEDIUM_HH_LINE = 25, - X121_MEDIUM_LL_LINE = 26, - X121_LONG_HH_LINE = 27, - X121_LONG_LL_LINE = 28, - X121_HIND_HH_LINE = 29, - X121_HIND_LL_LINE = 30, - // - // VWAP Data ... - X121_VWAP_VOLUME_LINE = 31, - X121_VWAP_PRICE_LINE = 32, - X121_VWAP_FAST_STATE_LINE = 33, - X121_VWAP_MID_STATE_LINE = 34, - X121_VWAP_SLOW_STATE_LINE = 35, - // - // ATR ... - X121_ATR_LINE = 36, - X121_ATR_UPPER_RAW_LINE = 37, - X121_ATR_LOWER_RAW_LINE = 38, - // - // RSI ... - X121_RSI_LINE = 39, - // - // STR ... - X121_STR_PRICE_LINE = 40, - X121_STR_UP_LINE = 41, - X121_STR_DOWN_LINE = 42, - X121_STR_STATE_LINE = 43, -}; - -// -enum ENUM_XVWAP_STATES -{ - // - XVWAP_STATE_BULLISH = 1, - XVWAP_STATE_BEARISH = 2, - XVWAP_STATE_NEUTURAL = 3, -}; - -// -// Inputs ... -struct X121Inputs -{ - // - // Props ... - - // - // Cycles ... - - // - // Short ... - ENUM_X_PERIOD_METHOD scMethod; // How to Find Period - ENUM_TIMEFRAMES scPeriod; // Time Period - - // - // Medium ... - ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period - ENUM_TIMEFRAMES mcPeriod; // Time Period - - // - // Long ... - ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period - ENUM_TIMEFRAMES lcPeriod; // Time Period - - // - // Hind ... - ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period - ENUM_TIMEFRAMES hcPeriod; // Time Period - - // - // Boundary Detection ... - ENUM_SERIESMODE hhMode; // Highest High Calculation Method - ENUM_SERIESMODE llMode; // Lowest Low Calculation Method - - // - // Parabolic Sar Detection ... - double sarStep; // Step - double sarMax; // Maximum - - // - // RSI ... - int rsiLength; // Length - double rsiOverSoldLevel; // Over Sold Level - double rsiOverBoughtLevel; // Over Bought Level - ENUM_APPLIED_PRICE rsiAppliedTo; // Applied To - - // - // Atr Detection ... - int atrLength; // Length - double atrMultiplier; // Multiplier - ENUM_APPLIED_PRICE atrUpperAppliedTo; // Upper Zone Applied To - ENUM_APPLIED_PRICE atrLowerAppliedTo; // Lower Zone Applied To - ENUM_X_MA_METHOD atrSmoothingMode; // Smoothing Method - - // - // Str Detection ... - ENUM_APPLIED_PRICE strAppliedTo; // Applied To - - // - // VWap Detection ... - int vwapFastLength; // Fast Length - int vwapMidLength; // Mid Length - int vwapSlowLength; // Slow Length - ENUM_APPLIED_PRICE vwapAppliedTo; // Applied To - - // - // Donchain Detection ... - int donchainLength; // Donchain Length - - // - // Presentation ... - - // - int startCalculationForLastBars; // Calculate Last n Bars - - // - int sarArrowCode; // Parabolic Sar Arrow Code - int peaksArrowCode; // Peaks Arrow Code - int valesArrowCode; // Vales Arrow Code - - // - // Global ... - bool showSar; // Show Parabolic Sar - bool showAtr; // Show Atr - bool showStr; // Show Str - bool showPeaks; // Show Peaks - bool showVales; // Show Vales - bool showVWap; // Show VWap - bool showDonchain; // Show Donchain - - // - // Atr Presentation ... - bool showAtrUpper; // Show Upper Zone - bool showAtrLower; // Show Lower Zone - - // - // VWap Presentation ... - bool showVWapFast; // Show VWap Fast - bool showVWapMedium; // Show VWap Medium - bool showVWapSlow; // Show VWap Slow - - // - // Donchain Presentation ... - - // - bool showUpper; // Show Upper Band - bool showLower; // Show Lower Band - - // - bool showOpen; // Show Open - bool showHigh; // Show High - bool showClose; // Show Close - bool showLow; // Show Low - - // - // Constructor ... - X121Inputs() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - // Cycles ... - - // - // Short ... - scMethod = X_PERIOD_NOTHING; - scPeriod = NULL; - - // - // Medium ... - mcMethod = X_PERIOD_NOTHING; - mcPeriod = NULL; - - // - // Long ... - lcMethod = X_PERIOD_NOTHING; - lcPeriod = NULL; - - // - // Hind ... - hcMethod = X_PERIOD_NOTHING; - hcPeriod = NULL; - - // - // Boundary Detection ... - hhMode = MODE_HIGH; - llMode = MODE_LOW; - - // - // RSI ... - rsiLength = 0; - rsiOverSoldLevel = 0; - rsiOverBoughtLevel = 0; - rsiAppliedTo = PRICE_CLOSE; - - // - // Paraboli Sar Detection ... - sarStep = 0; - sarMax = 0; - - // - // Atr Detection ... - atrLength = 0; // Length - atrMultiplier = 0; // Multiplier - atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To - atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To - atrSmoothingMode = X_MA_MODE_NONE; // Smoothing Method - - // - // Str Detection ... - strAppliedTo = PRICE_MEDIAN; - - // - // VWap Detection ... - vwapFastLength = 0; - vwapMidLength = 0; - vwapSlowLength = 0; - vwapAppliedTo = PRICE_CLOSE; - - // - // Donchain Detection ... - donchainLength = 0; - - // - // Presentation ... - - // - startCalculationForLastBars = 0; - - // - sarArrowCode = 0; - peaksArrowCode = 0; - valesArrowCode = 0; - - // - // Globals ... - showSar = false; - showAtr = false; - showStr = false; - showPeaks = false; - showVales = false; - showVWap = false; - showDonchain = false; - - // - // Atr Presentation ... - showAtrUpper = false; // Show Upper Zone - showAtrLower = false; // Show Lower Zone - - // - // VWap Presentation ... - showVWapFast = false; - showVWapMedium = false; - showVWapSlow = false; - - // - // Donchain Presentation ... - - // - showUpper = false; - showLower = false; - - // - showOpen = false; - showHigh = false; - showClose = false; - showLow = false; - } - - /** - * Set Default Values ... - */ - void Default() - { - // - // Cycles ... - - // - // Short ... - scMethod = X_PERIOD_AUTO; - scPeriod = NULL; - - // - // Medium ... - mcMethod = X_PERIOD_AUTO; - mcPeriod = NULL; - - // - // Long ... - lcMethod = X_PERIOD_AUTO; - lcPeriod = NULL; - - // - // Hind ... - hcMethod = X_PERIOD_AUTO; - hcPeriod = NULL; - - // - // Boundary Detection ... - hhMode = MODE_HIGH; - llMode = MODE_LOW; - - // - // RSI ... - rsiLength = 14; - rsiOverSoldLevel = 30; - rsiOverBoughtLevel = 70; - rsiAppliedTo = PRICE_CLOSE; - - // - // Paraboli Sar Detection ... - sarStep = 0.02; - sarMax = 0.2; - - // - // Atr Detection ... - atrLength = 14; // Length - atrMultiplier = 1; // Multiplier - atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To - atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To - atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method - - // - // Str Detection ... - strAppliedTo = PRICE_MEDIAN; - - // - // VWap Detection ... - vwapFastLength = 20; - vwapMidLength = 40; - vwapSlowLength = 60; - vwapAppliedTo = PRICE_CLOSE; - - // - // Donchain Detection ... - donchainLength = 40; - - // - // Presentation ... - - // - startCalculationForLastBars = 1500; - - // - sarArrowCode = 159; - peaksArrowCode = 159; - valesArrowCode = 159; - - // - // Globals ... - showSar = true; - showAtr = true; - showStr = true; - showPeaks = true; - showVales = true; - showVWap = false; - showDonchain = false; - - // - // Atr Presentation ... - showAtrUpper = true; // Show Upper Zone - showAtrLower = true; // Show Lower Zone - - // - // VWap Presentation ... - showVWapFast = true; - showVWapMedium = true; - showVWapSlow = true; - - // - // Donchain Presentation ... - - // - showUpper = true; - showLower = true; - - // - showOpen = true; - showHigh = false; - showClose = true; - showLow = false; - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - // RSI ... - rsiLength > 0 && - rsiOverSoldLevel > 0 && - rsiOverBoughtLevel > 0 && - rsiOverSoldLevel < rsiOverBoughtLevel && - // PSAR ... - sarMax > 0 && - sarStep > 0 && - sarMax > sarStep && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // XDON ... - donchainLength > 0 && - // - // VWAP ... - vwapFastLength > 2 && - vwapMidLength > vwapFastLength && - vwapSlowLength > vwapMidLength && - // - // XPV ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; - } - - /** - * Extract Max Input Length ... - * - * @return ( int ) - */ - int Max() - { - // - int result = 0; - - // - // VWAP ... - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapMidLength); - - // - // ATR ... - result = MathMax(result, atrLength); - result = MathMax(result, rsiLength); - - // - return result; - } -}; - -// -// Conditions ... -struct X121Conditions -{ - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Buffers ... - double peaksBuffer[]; - double valesBuffer[]; - double sarBuffer[]; - double atrUpperBuffer[]; - double atrLowerBuffer[]; - double vwapFastBuffer[]; - double vwapMidBuffer[]; - double vwapSlowBuffer[]; - double donOpenUpperBuffer[]; - double donOpenLowerBuffer[]; - double donCloseUpperBuffer[]; - double donCloseLowerBuffer[]; - double donHighUpperBuffer[]; - double donHighLowerBuffer[]; - double donLowUpperBuffer[]; - double donLowLowerBuffer[]; - double cHHBuffer[]; - double cLLBuffer[]; - double sHHBuffer[]; - double sLLBuffer[]; - double mHHBuffer[]; - double mLLBuffer[]; - double lHHBuffer[]; - double lLLBuffer[]; - double hHHBuffer[]; - double hLLBuffer[]; - double atrBuffer[]; - double atrUpperRawBuffer[]; - double atrLowerRawBuffer[]; - double vwapVolumeBuffer[]; - double vwapPriceBuffer[]; - double vwapFastStateBuffer[]; - double vwapMidStateBuffer[]; - double vwapSlowStateBuffer[]; - double rsiBuffer[]; - double strBuffer[]; - double strStateBuffer[]; - - // - // Conditions ... - - // - // STR ... - - // - bool isStrBullish; - bool isStrSwitchedToBullish; - - // - bool isStrBearish; - bool isStrSwitchedToBearish; - - // - // XRSI ... - - // - bool isRSIOverBought; - bool isRSICrossedOverOverBought; - bool isRSICrossedUnderOverBought; - - // - bool isRSIOverSold; - bool isRSICrossedUnderOverSold; - bool isRSICrossedOverOverSold; - - // - // XSAR ... - - // - bool isSarBullish; - bool isSarBearish; - - // - bool isSarSwitchedToBullish; - bool isSarSwitchedToBearish; - - // - // XPV ... - - // - bool isNewPeak; - bool isNewPeakOverLast; - bool isNewPeakUnderLast; - - // - bool isNewVale; - bool isNewValeOverLast; - bool isNewValeUnderLast; - - // - // XVWAP ... - - // - bool isVWapFastBullish; - bool isVWapFastBearish; - bool isVWapFastNeutural; - - // - bool isVWapMidBullish; - bool isVWapMidBearish; - bool isVWapMidNeutural; - - // - bool isVWapSlowBullish; - bool isVWapSlowBearish; - bool isVWapSlowNeutural; - - // - bool isVWapFastOverMid; - bool isVWapMidOverSlow; - - // - bool isVWapFastUnderMid; - bool isVWapMidUnderSlow; - - // - bool isVWapBullishState; - bool isVWapBearishState; - bool isVWapNeuturalState; - - // - bool isVWapBullishOrdered; - bool isVWapBearishOrdered; - - // - bool isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered; - - // - bool isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState; - bool isVWapSwitchedToNeuturalState; - - // - // XDON ... - - // - // bool isCloseLower - - // - // Constructor ... - X121Conditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - // Commons ... - symbol = NULL; - period = NULL; - time = NULL; - - // - // Buffers ... - - // - Clean(peaksBuffer); - Clean(valesBuffer); - Clean(sarBuffer); - Clean(atrUpperBuffer); - Clean(atrLowerBuffer); - Clean(vwapFastBuffer); - Clean(vwapMidBuffer); - Clean(vwapSlowBuffer); - Clean(donOpenUpperBuffer); - Clean(donOpenLowerBuffer); - Clean(donCloseUpperBuffer); - Clean(donCloseLowerBuffer); - Clean(donHighUpperBuffer); - Clean(donHighLowerBuffer); - Clean(donLowUpperBuffer); - Clean(donLowLowerBuffer); - Clean(cHHBuffer); - Clean(cLLBuffer); - Clean(sHHBuffer); - Clean(sLLBuffer); - Clean(mHHBuffer); - Clean(mLLBuffer); - Clean(lHHBuffer); - Clean(lLLBuffer); - Clean(hHHBuffer); - Clean(hLLBuffer); - Clean(atrBuffer); - Clean(atrUpperRawBuffer); - Clean(atrLowerRawBuffer); - Clean(vwapVolumeBuffer); - Clean(vwapPriceBuffer); - Clean(vwapFastStateBuffer); - Clean(vwapMidStateBuffer); - Clean(vwapSlowStateBuffer); - Clean(rsiBuffer); - Clean(strBuffer); - Clean(strStateBuffer); - - // - ArraySetAsSeries(peaksBuffer, true); - ArraySetAsSeries(valesBuffer, true); - ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(atrUpperBuffer, true); - ArraySetAsSeries(atrLowerBuffer, true); - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(donOpenUpperBuffer, true); - ArraySetAsSeries(donOpenLowerBuffer, true); - ArraySetAsSeries(donCloseUpperBuffer, true); - ArraySetAsSeries(donCloseLowerBuffer, true); - ArraySetAsSeries(donHighUpperBuffer, true); - ArraySetAsSeries(donHighLowerBuffer, true); - ArraySetAsSeries(donLowUpperBuffer, true); - ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(cHHBuffer, true); - ArraySetAsSeries(cLLBuffer, true); - ArraySetAsSeries(sHHBuffer, true); - ArraySetAsSeries(sLLBuffer, true); - ArraySetAsSeries(mHHBuffer, true); - ArraySetAsSeries(mLLBuffer, true); - ArraySetAsSeries(lHHBuffer, true); - ArraySetAsSeries(lLLBuffer, true); - ArraySetAsSeries(hHHBuffer, true); - ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(atrBuffer, true); - ArraySetAsSeries(atrUpperRawBuffer, true); - ArraySetAsSeries(atrLowerRawBuffer, true); - ArraySetAsSeries(vwapVolumeBuffer, true); - ArraySetAsSeries(vwapPriceBuffer, true); - ArraySetAsSeries(vwapFastStateBuffer, true); - ArraySetAsSeries(vwapMidStateBuffer, true); - ArraySetAsSeries(vwapSlowStateBuffer, true); - ArraySetAsSeries(rsiBuffer, true); - ArraySetAsSeries(strBuffer, true); - ArraySetAsSeries(strStateBuffer, true); - - // - // Conditions ... - - // - // STR ... - - // - isStrBullish = false; - isStrSwitchedToBullish = false; - - // - isStrBearish = false; - isStrSwitchedToBearish = false; - - // - // XRSI ... - - // - isRSIOverBought = false; - isRSICrossedUnderOverBought = false; - isRSICrossedOverOverBought = false; - - // - isRSIOverSold = false; - isRSICrossedOverOverSold = false; - isRSICrossedUnderOverSold = false; - - // - // XSAR ... - - // - isSarBullish = false; - isSarBearish = false; - - // - isSarSwitchedToBullish = false; - isSarSwitchedToBearish = false; - - // - // XPV ... - - // - isNewPeak = false; - isNewPeakOverLast = false; - isNewPeakUnderLast = false; - - // - isNewVale = false; - isNewValeOverLast = false; - isNewValeUnderLast = false; - - // - // XVWAP ... - - // - isVWapFastBullish = false; - isVWapFastBearish = false; - isVWapFastNeutural = false; - - // - isVWapMidBullish = false; - isVWapMidBearish = false; - isVWapMidNeutural = false; - - // - isVWapSlowBullish = false; - isVWapSlowBearish = false; - isVWapSlowNeutural = false; - - // - isVWapFastOverMid = false; - isVWapMidOverSlow = false; - - // - isVWapFastUnderMid = false; - isVWapMidUnderSlow = false; - - // - isVWapBullishState = false; - isVWapBearishState = false; - isVWapNeuturalState = false; - - // - isVWapBullishOrdered = false; - isVWapBearishOrdered = false; - - // - isVWapSwitchedToBullishOrdered = false; - isVWapSwitchedToBearishOrdered = false; - - // - isVWapSwitchedToBullishState = false; - isVWapSwitchedToBearishState = false; - isVWapSwitchedToNeuturalState = false; - - // - // XDON ... - } - - /** - * Generate Conditions Scores ... - * - * @param bullishScore: Double, Directional Scores Reference ... - * @param bearishScore: Double, Directional Scores Reference ... - */ - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - // TODO: Implement if Required ... - } - - /** - * Generate Summary String for Represent Conditions State ... - * - * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... - * @param onlyConditions: Boolean, Just Generate Only Conditions ... - * @param includeScores: Boolean, Attach Scores Representations on Result ... - * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... - * @param separator: String, Separate Lines ... - * - * @return ( string ) - */ - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string scoresStr = - // - "Scores: " + separator + - "---------------" + separator + - "Bullish: " + ToString(bullishScore) + separator + - "Bearish: " + ToString(bearishScore) + separator + - "" - // - ; - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores // - ); - - // - // TODO: Implement this if required ... - string conditionsStr = - // - // STR ... - ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) + - ToString("isStrSwitchedToBullish", isStrSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isStrBearish", isStrBearish, ignoreFalseConditions, separator) + - ToString("isStrSwitchedToBearish", isStrSwitchedToBearish, ignoreFalseConditions, separator) + - // - // XSAR ... - ToString("isSarBullish", isSarBullish, ignoreFalseConditions, separator) + - ToString("isSarBearish", isSarBearish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBullish", isSarSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBearish", isSarSwitchedToBearish, ignoreFalseConditions, separator) + - // - // XPV ... - ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + - ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + - ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + - ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + - ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + - ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + - // - // RSI ... - ToString("isRSIOverBought", isRSIOverBought, ignoreFalseConditions, separator) + - ToString("isRSICrossedOverOverBought", isRSICrossedOverOverBought, ignoreFalseConditions, separator) + - ToString("isRSICrossedUnderOverBought", isRSICrossedUnderOverBought, ignoreFalseConditions, separator) + - ToString("isRSIOverSold", isRSIOverSold, ignoreFalseConditions, separator) + - ToString("isRSICrossedUnderOverSold", isRSICrossedUnderOverSold, ignoreFalseConditions, separator) + - ToString("isRSICrossedOverOverSold", isRSICrossedOverOverSold, ignoreFalseConditions, separator) + - // - // XVWAP ... - ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) + - ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) + - ToString("isVWapFastNeutural", isVWapFastNeutural, ignoreFalseConditions, separator) + - ToString("isVWapMidBullish", isVWapMidBullish, ignoreFalseConditions, separator) + - ToString("isVWapMidBearish", isVWapMidBearish, ignoreFalseConditions, separator) + - ToString("isVWapMidNeutural", isVWapMidNeutural, ignoreFalseConditions, separator) + - ToString("isVWapSlowBullish", isVWapSlowBullish, ignoreFalseConditions, separator) + - ToString("isVWapSlowBearish", isVWapSlowBearish, ignoreFalseConditions, separator) + - ToString("isVWapSlowNeutural", isVWapSlowNeutural, ignoreFalseConditions, separator) + - ToString("isVWapFastOverMid", isVWapFastOverMid, ignoreFalseConditions, separator) + - ToString("isVWapMidOverSlow", isVWapMidOverSlow, ignoreFalseConditions, separator) + - ToString("isVWapFastUnderMid", isVWapFastUnderMid, ignoreFalseConditions, separator) + - ToString("isVWapMidUnderSlow", isVWapMidUnderSlow, ignoreFalseConditions, separator) + - ToString("isVWapBullishState", isVWapBullishState, ignoreFalseConditions, separator) + - ToString("isVWapBearishState", isVWapBearishState, ignoreFalseConditions, separator) + - ToString("isVWapNeuturalState", isVWapNeuturalState, ignoreFalseConditions, separator) + - ToString("isVWapBullishOrdered", isVWapBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapBearishOrdered", isVWapBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishOrdered", isVWapSwitchedToBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishOrdered", isVWapSwitchedToBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishState", isVWapSwitchedToBullishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) + - // - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - (onlyConditions - ? "" - : commonStr) + - (!includeScores - ? "" - : scoresStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - /** - * Retrieve nique Tag Identifier ... - * - * @return ( string ) - */ - string GetTag() - { - return GetTypeName(this); - } - - // -}; - -// -// Implementation ... - -class XCX121Helper : public XCBaseHelper -{ - // - public: - // - - // - // Constructors ... - XCX121Helper() - : XCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XCX121Helper() - { - } - - // - // Tools ... - - /** - * Initialize Indicator Helper ... - * - * @param symbol: String, Symbol ... - * @param period: ENUM_TIMEFRAMES member, Period ... - * @param inputs: X121Inputs instance, Indicator Inputs ... - * - * @return ( bool ) - */ - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - X121Inputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - // Validate Inputs ... - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - // Setting Arrays As Series ... - ArraySetAsSeries(peaksBuffer, true); - ArraySetAsSeries(valesBuffer, true); - ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(atrUpperBuffer, true); - ArraySetAsSeries(atrLowerBuffer, true); - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(donOpenUpperBuffer, true); - ArraySetAsSeries(donOpenLowerBuffer, true); - ArraySetAsSeries(donCloseUpperBuffer, true); - ArraySetAsSeries(donCloseLowerBuffer, true); - ArraySetAsSeries(donHighUpperBuffer, true); - ArraySetAsSeries(donHighLowerBuffer, true); - ArraySetAsSeries(donLowUpperBuffer, true); - ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(cHHBuffer, true); - ArraySetAsSeries(cLLBuffer, true); - ArraySetAsSeries(sHHBuffer, true); - ArraySetAsSeries(sLLBuffer, true); - ArraySetAsSeries(mHHBuffer, true); - ArraySetAsSeries(mLLBuffer, true); - ArraySetAsSeries(lHHBuffer, true); - ArraySetAsSeries(lLLBuffer, true); - ArraySetAsSeries(hHHBuffer, true); - ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(atrBuffer, true); - ArraySetAsSeries(atrUpperRawBuffer, true); - ArraySetAsSeries(atrLowerRawBuffer, true); - ArraySetAsSeries(vwapVolumeBuffer, true); - ArraySetAsSeries(vwapPriceBuffer, true); - ArraySetAsSeries(vwapFastStateBuffer, true); - ArraySetAsSeries(vwapMidStateBuffer, true); - ArraySetAsSeries(vwapSlowStateBuffer, true); - ArraySetAsSeries(rsiBuffer, true); - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.x121", - // - // Inputs ... - // - // Cycles ... - "", - // - // Short ... - "", - mInputs.scMethod, - mInputs.scPeriod, - // - // Medium ... - "", - mInputs.mcMethod, - mInputs.mcPeriod, - // - // Long ... - "", - mInputs.lcMethod, - mInputs.lcPeriod, - // - // Hind ... - "", - mInputs.hcMethod, - mInputs.hcPeriod, - // - // Boundary Detection ... - "", - mInputs.hhMode, - mInputs.llMode, - // - // Rsi Detection ... - "", - mInputs.rsiLength, - mInputs.rsiAppliedTo, - // - // Parabolic Sar Detection ... - "", - mInputs.sarStep, - mInputs.sarMax, - // - // Atr Detection ... - "", - mInputs.atrLength, - mInputs.atrMultiplier, - mInputs.atrUpperAppliedTo, - mInputs.atrLowerAppliedTo, - mInputs.atrSmoothingMode, - // - // VWap Detection ... - "", - mInputs.vwapFastLength, - mInputs.vwapMidLength, - mInputs.vwapSlowLength, - mInputs.vwapAppliedTo, - // - // Donchain Detection ... - "", - mInputs.donchainLength, - // - // Presentation ... - "", - mInputs.startCalculationForLastBars, - mInputs.sarArrowCode, - mInputs.peaksArrowCode, - mInputs.valesArrowCode, - // - // Commons ... - mInputs.showSar, - mInputs.showAtr, - mInputs.showPeaks, - mInputs.showVales, - mInputs.showVWap, - mInputs.showDonchain, - // - // Atr Presentation ... - "", - mInputs.showAtrUpper, - mInputs.showAtrLower, - // - // VWap Presentation ... - "", - mInputs.showVWapFast, - mInputs.showVWapMedium, - mInputs.showVWapSlow, - // - // Donchain Presentation ... - "", - mInputs.showUpper, - mInputs.showLower, - mInputs.showOpen, - mInputs.showHigh, - mInputs.showClose, - mInputs.showLow - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Retrieve Current Indicator Configs ... - * - * @return ( Inputs ) - */ - X121Inputs GetInputs() - { - return mInputs; - } - - /** - * Set New Indicator Inputs ... - * - * @param inputs: X121Inputs instance, Indicator Inputs ... - * - * @return ( bool ) - */ - bool SetInputs( - X121Inputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Implement Value Getters ... - - // - // XRSI ... - - // - double GetRSI( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(rsiBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return rsiBuffer[barIndex]; - } - - // - int CopyRSI( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - rsiBuffer, - buffer, - forceClean - // - ); - } - - // - // SAR ... - - // - double GetSar( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sarBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sarBuffer[barIndex]; - } - - // - int CopySar( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sarBuffer, - buffer, - forceClean - // - ); - } - - // - // ATR ... - - // - // Common ... - - // - double GetAtr( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrBuffer[barIndex]; - } - - // - int CopyAtr( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrUpperBuffer[barIndex]; - } - - // - int CopyAtrUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrUpperBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrUpperRaw( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrUpperRawBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrUpperRawBuffer[barIndex]; - } - - // - int CopyAtrUpperRaw( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrUpperRawBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrLowerBuffer[barIndex]; - } - - // - int CopyAtrLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrLowerBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrLowerRaw( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrLowerRawBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrLowerRawBuffer[barIndex]; - } - - // - int CopyAtrLowerRaw( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrLowerRawBuffer, - buffer, - forceClean - // - ); - } - - // - // PV ... - - // - // PEAKS ... - - // - double GetPeak( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(peaksBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return peaksBuffer[barIndex]; - } - - // - int CopyPeak( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - peaksBuffer, - buffer, - forceClean - // - ); - } - - // - // VALES ... - - // - double GetVale( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(valesBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return valesBuffer[barIndex]; - } - - // - int CopyVale( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - valesBuffer, - buffer, - forceClean - // - ); - } - - // - // - // - - // - double GetHigherPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (peak <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetPeak(index); - if (iValue > peak) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetLowerPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (peak <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetPeak(index); - if (iValue < peak) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetHigherVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (vale <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetVale(index); - if (iValue > vale) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetLowerVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (vale <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetVale(index); - if (iValue < vale) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - // - // - - // - double GetLowestPeak( - int barIndex, - int &index, - double &vale, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - vale = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetPeak(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result >= iPeak)) - { - // - index = i; - result = iPeak; - vale = GetVale(index); - } - } - - // - return result; - } - - // - double GetHighestPeak( - int barIndex, - int &index, - double &vale, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - vale = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetPeak(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result <= iPeak)) - { - // - index = i; - result = iPeak; - vale = GetVale(index); - } - } - - // - return result; - } - - // - double GetLowestVale( - int barIndex, - int &index, - double &peak, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - peak = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetVale(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result >= iPeak)) - { - // - index = i; - result = iPeak; - peak = GetPeak(index); - } - } - - // - return result; - } - - // - double GetHighestVale( - int barIndex, - int &index, - double &peak, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - peak = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetVale(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result <= iPeak)) - { - // - index = i; - result = iPeak; - peak = GetPeak(index); - } - } - - // - return result; - } - - // - // CURRENT ... - - // - // HH ... - - // - double GetCHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cHHBuffer[barIndex]; - } - - // - int CopyCHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - cHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetCLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cLLBuffer[barIndex]; - } - - // - int CopyCLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - cLLBuffer, - buffer, - forceClean - // - ); - } - - // - // SHORT ... - - // - // HH ... - - // - double GetSHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sHHBuffer[barIndex]; - } - - // - int CopySHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetSLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sLLBuffer[barIndex]; - } - - // - int CopySLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sLLBuffer, - buffer, - forceClean - // - ); - } - - // - // MEDIUM ... - - // - // HH ... - - // - double GetMHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mHHBuffer[barIndex]; - } - - // - int CopyMHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - mHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetMLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mLLBuffer[barIndex]; - } - - // - int CopyMLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - mLLBuffer, - buffer, - forceClean - // - ); - } - - // - // LONG ... - - // - // HH ... - - // - double GetLHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lHHBuffer[barIndex]; - } - - // - int CopyLHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - lHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetLLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lLLBuffer[barIndex]; - } - - // - int CopyLLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - lLLBuffer, - buffer, - forceClean - // - ); - } - - // - // HIND ... - - // - // HH ... - - // - double GetHHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hHHBuffer[barIndex]; - } - - // - int CopyHHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - hHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetHLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hLLBuffer[barIndex]; - } - - // - int CopyHLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - hLLBuffer, - buffer, - forceClean - // - ); - } - - // - // VWAP ... - - // - // FAST ... - - // - double GetVWapFast( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapFastBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapFastBuffer[barIndex]; - } - - // - int CopyVWapFast( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapFastBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE FAST ... - - // - double GetVWapFastState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapFastStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapFastStateBuffer[barIndex]; - } - - // - int CopyVWapFastState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapFastStateBuffer, - buffer, - forceClean - // - ); - } - - // - // MID ... - - // - double GetVWapMid( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapMidBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapMidBuffer[barIndex]; - } - - // - int CopyVWapMid( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapMidBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE MID ... - - // - double GetVWapMidState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapMidStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapMidStateBuffer[barIndex]; - } - - // - int CopyVWapMidState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapMidStateBuffer, - buffer, - forceClean - // - ); - } - - // - // SLOW ... - - // - double GetVWapSlowBuffer( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapSlowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapSlowBuffer[barIndex]; - } - - // - int CopyVWapSlow( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapSlowBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE SLOW ... - - // - double GetVWapSlowState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapSlowStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapSlowStateBuffer[barIndex]; - } - - // - int CopyVWapSlowState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapSlowStateBuffer, - buffer, - forceClean - // - ); - } - - // - // VOLUME ... - - // - double GetVWapVolume( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapVolumeBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapVolumeBuffer[barIndex]; - } - - // - int CopyVWapVolume( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapVolumeBuffer, - buffer, - forceClean - // - ); - } - - // - // PRICE ... - - // - double GetVWapPrice( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapPriceBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapPriceBuffer[barIndex]; - } - - // - int CopyVWapPrice( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapPriceBuffer, - buffer, - forceClean - // - ); - } - - // - // Converts to State ... - ENUM_XVWAP_STATES ToVWAPState(double value) - { - // - ENUM_XVWAP_STATES result = - value == 1 - ? XVWAP_STATE_BULLISH - : value == 2 - ? XVWAP_STATE_BEARISH - : XVWAP_STATE_NEUTURAL; - - // - return result; - } - - // - bool IsVWAPBullish(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_BULLISH; - - // - return result; - } - - // - bool IsVWAPBearish(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_BEARISH; - - // - return result; - } - - // - bool IsVWAPNeutural(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_NEUTURAL; - - // - return result; - } - - // - // XDON ... - - // - // OPEN ... - - // - // UPPER ... - - // - double GetDonOpenUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donOpenUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donOpenUpperBuffer[barIndex]; - } - - // - int CopyDonOpenUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donOpenUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonOpenLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donOpenLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donOpenLowerBuffer[barIndex]; - } - - // - int CopyDonOpenLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donOpenLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // CLOSE ... - - // - // UPPER ... - - // - double GetDonCloseUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donCloseUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donCloseUpperBuffer[barIndex]; - } - - // - int CopyDonCloseUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donCloseUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonCloseLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donCloseLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donCloseLowerBuffer[barIndex]; - } - - // - int CopyDonCloseLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donCloseLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // HIGH ... - - // - // UPPER ... - - // - double GetDonHighUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donHighUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donHighUpperBuffer[barIndex]; - } - - // - int CopyDonHighUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donHighUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonHighLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donHighLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donHighLowerBuffer[barIndex]; - } - - // - int CopyDonHighLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donHighLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // LOW ... - - // - // UPPER ... - - // - double GetDonLowUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donLowUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donLowUpperBuffer[barIndex]; - } - - // - int CopyDonLowUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donLowUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonLoweLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donLowLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donLowLowerBuffer[barIndex]; - } - - // - int CopyDonLoweLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donLowLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // Conditions Generation ... - - bool GetConditions( - X121Conditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = true; - - // - if (loopback < 5) - { - loopback = 5; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - XOHCL zBar; - result = zBar.Init( - mSymbol, - mPeriod, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - mSymbol, - mPeriod, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - mSymbol, - mPeriod, - pIndex // - ); - if (!result) - { - return result; - } - - // - // Buffers ... - - // - CopyRSI( - zIndex, - loopback, - conditions.rsiBuffer // - ); - - // - CopySar( - zIndex, - loopback, - conditions.sarBuffer // - ); - - // - CopyAtr( - zIndex, - loopback, - conditions.atrBuffer // - ); - - // - CopyAtrUpper( - zIndex, - loopback, - conditions.atrUpperBuffer // - ); - - // - CopyAtrUpperRaw( - zIndex, - loopback, - conditions.atrUpperRawBuffer // - ); - - // - CopyAtrLower( - zIndex, - loopback, - conditions.atrLowerBuffer // - ); - - // - CopyAtrLowerRaw( - zIndex, - loopback, - conditions.atrLowerRawBuffer // - ); - - // - CopyPeak( - zIndex, - loopback, - conditions.peaksBuffer // - ); - - // - CopyVale( - zIndex, - loopback, - conditions.valesBuffer // - ); - - // - CopyCHH( - zIndex, - loopback, - conditions.cHHBuffer // - ); - - // - CopyCLL( - zIndex, - loopback, - conditions.cLLBuffer // - ); - - // - CopySHH( - zIndex, - loopback, - conditions.sHHBuffer // - ); - - // - CopySLL( - zIndex, - loopback, - conditions.sLLBuffer // - ); - - // - CopyMHH( - zIndex, - loopback, - conditions.mHHBuffer // - ); - - // - CopyMLL( - zIndex, - loopback, - conditions.mLLBuffer // - ); - - // - CopyLHH( - zIndex, - loopback, - conditions.lHHBuffer // - ); - - // - CopyLLL( - zIndex, - loopback, - conditions.lLLBuffer // - ); - - // - CopyHHH( - zIndex, - loopback, - conditions.hHHBuffer // - ); - - // - CopyHLL( - zIndex, - loopback, - conditions.hLLBuffer // - ); - - // - CopyVWapFast( - zIndex, - loopback, - conditions.vwapFastBuffer // - ); - - // - CopyVWapFastState( - zIndex, - loopback, - conditions.vwapFastStateBuffer // - ); - - // - CopyVWapMid( - zIndex, - loopback, - conditions.vwapMidBuffer // - ); - - // - CopyVWapMidState( - zIndex, - loopback, - conditions.vwapMidStateBuffer // - ); - - // - CopyVWapSlow( - zIndex, - loopback, - conditions.vwapSlowBuffer // - ); - - // - CopyVWapSlowState( - zIndex, - loopback, - conditions.vwapSlowStateBuffer // - ); - - // - CopyVWapVolume( - zIndex, - loopback, - conditions.vwapVolumeBuffer // - ); - - // - CopyVWapPrice( - zIndex, - loopback, - conditions.vwapPriceBuffer // - ); - - // - CopyDonOpenUpper( - zIndex, - loopback, - conditions.donOpenUpperBuffer // - ); - - // - CopyDonOpenLower( - zIndex, - loopback, - conditions.donOpenLowerBuffer // - ); - - // - CopyDonCloseUpper( - zIndex, - loopback, - conditions.donCloseUpperBuffer // - ); - - // - CopyDonCloseLower( - zIndex, - loopback, - conditions.donCloseLowerBuffer // - ); - - // - CopyDonHighUpper( - zIndex, - loopback, - conditions.donHighUpperBuffer // - ); - - // - CopyDonHighLower( - zIndex, - loopback, - conditions.donHighLowerBuffer // - ); - - // - CopyDonLowUpper( - zIndex, - loopback, - conditions.donLowUpperBuffer // - ); - - // - CopyDonLoweLower( - zIndex, - loopback, - conditions.donLowLowerBuffer // - ); - - // - // Conditions ... - - // - int cIDX = 1; - int pIDX = cIDX + 1; - - // - // XRSI ... - - // - bool isRSIOverBought = conditions.rsiBuffer[cIDX] > mInputs.rsiOverBoughtLevel; - bool isRSIOverBoughtPrev = conditions.rsiBuffer[pIDX] > mInputs.rsiOverBoughtLevel; - - // - bool isRSICrossedOverOverBought = isRSIOverBought && - !isRSIOverBoughtPrev; - bool isRSICrossedUnderOverBought = !isRSIOverBought && - isRSIOverBoughtPrev; - - // - bool isRSIOverSold = conditions.rsiBuffer[cIDX] < mInputs.rsiOverSoldLevel; - bool isRSIOverSoldPrev = conditions.rsiBuffer[pIDX] < mInputs.rsiOverSoldLevel; - - // - bool isRSICrossedUnderOverSold = isRSIOverSold && - !isRSIOverSoldPrev; - bool isRSICrossedOverOverSold = !isRSIOverSold && - isRSIOverSoldPrev; - - // - // XSAR ... - - // - bool isSarBullish = conditions.sarBuffer[cIDX] < cBar.low; - bool isSarBullishPrev = conditions.sarBuffer[pIDX] < pBar.low; - - // - bool isSarBearish = conditions.sarBuffer[cIDX] > cBar.high; - bool isSarBearishPrev = conditions.sarBuffer[pIDX] > pBar.high; - - // - bool isSarSwitchedToBullish = isSarBullish && - !isSarBullishPrev; - bool isSarSwitchedToBearish = isSarBearish && - !isSarBearishPrev; - - // - // XPV ... - - // - bool isNewPeak = conditions.peaksBuffer[cIDX] != conditions.peaksBuffer[pIDX]; - bool isNewPeakOverLast = isNewPeak && - conditions.peaksBuffer[cIDX] > conditions.peaksBuffer[pIDX]; - bool isNewPeakUnderLast = isNewPeak && - conditions.peaksBuffer[cIDX] < conditions.peaksBuffer[pIDX]; - - // - bool isNewVale = conditions.valesBuffer[cIDX] != conditions.valesBuffer[pIDX]; - bool isNewValeOverLast = isNewVale && - conditions.valesBuffer[cIDX] > conditions.valesBuffer[pIDX]; - bool isNewValeUnderLast = isNewVale && - conditions.valesBuffer[cIDX] < conditions.valesBuffer[pIDX]; - - // - // XVWAP ... - - // - bool isVWapFastBullish = IsVWAPBullish(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastBullishPrev = IsVWAPBullish(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapFastBearish = IsVWAPBearish(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastBearishPrev = IsVWAPBearish(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapFastNeutural = IsVWAPNeutural(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastNeuturalPrev = IsVWAPNeutural(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapMidBullish = IsVWAPBullish(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidBullishPrev = IsVWAPBullish(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapMidBearish = IsVWAPBearish(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidBearishPrev = IsVWAPBearish(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapMidNeutural = IsVWAPNeutural(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidNeuturalPrev = IsVWAPNeutural(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapSlowBullish = IsVWAPBullish(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowBullishPrev = IsVWAPBullish(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapSlowBearish = IsVWAPBearish(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowBearishPrev = IsVWAPBearish(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapSlowNeutural = IsVWAPNeutural(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowNeuturalPrev = IsVWAPNeutural(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapFastOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; - bool isVWapFastOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapMidOverSlow = conditions.vwapMidBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; - bool isVWapMidOverSlowPrev = conditions.vwapMidBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFastUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; - bool isVWapFastUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapMidUnderSlow = conditions.vwapMidBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; - bool isVWapMidUnderSlowPrev = conditions.vwapMidBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapBullishState = isVWapFastBullish && - isVWapMidBullish && - isVWapSlowBullish; - bool isVWapBullishStatePrev = isVWapFastBullishPrev && - isVWapMidBullishPrev && - isVWapSlowBullishPrev; - - // - bool isVWapBearishState = isVWapFastBearish && - isVWapMidBearish && - isVWapSlowBearish; - bool isVWapBearishStatePrev = isVWapFastBearishPrev && - isVWapMidBearishPrev && - isVWapSlowBearishPrev; - - // - bool isVWapNeuturalState = isVWapFastNeutural && - isVWapMidNeutural && - isVWapSlowNeutural; - bool isVWapNeuturalStatePrev = isVWapFastNeuturalPrev && - isVWapMidNeuturalPrev && - isVWapSlowNeuturalPrev; - - // - bool isVWapBullishOrdered = isVWapFastOverMid && - isVWapMidOverSlow; - bool isVWapBullishOrderedPrev = isVWapFastOverMidPrev && - isVWapMidOverSlowPrev; - - // - bool isVWapBearishOrdered = isVWapFastUnderMid && - isVWapMidUnderSlow; - bool isVWapBearishOrderedPrev = isVWapFastUnderMidPrev && - isVWapMidUnderSlowPrev; - - // - bool isVWapSwitchedToBullishOrdered = isVWapBullishOrdered && - !isVWapBullishOrderedPrev; - bool isVWapSwitchedToBearishOrdered = isVWapBearishOrdered && - !isVWapBearishOrderedPrev; - - // - bool isVWapSwitchedToBullishState = isVWapBullishState && - !isVWapBullishStatePrev; - bool isVWapSwitchedToBearishState = isVWapBearishState && - !isVWapBearishStatePrev; - bool isVWapSwitchedToNeuturalState = isVWapNeuturalState && - !isVWapNeuturalStatePrev; - - // - // XDON ... - - // - // Set ... - conditions.isRSIOverBought = isRSIOverBought; - conditions.isRSICrossedOverOverBought = isRSICrossedOverOverBought; - conditions.isRSICrossedUnderOverBought = isRSICrossedUnderOverBought; - conditions.isRSIOverSold = isRSIOverSold; - conditions.isRSICrossedUnderOverSold = isRSICrossedUnderOverSold; - conditions.isRSICrossedOverOverSold = isRSICrossedOverOverSold; - conditions.isSarBullish = isSarBullish; - conditions.isSarBearish = isSarBearish; - conditions.isSarSwitchedToBullish = isSarSwitchedToBullish; - conditions.isSarSwitchedToBearish = isSarSwitchedToBearish; - conditions.isNewPeak = isNewPeak; - conditions.isNewPeakOverLast = isNewPeakOverLast; - conditions.isNewPeakUnderLast = isNewPeakUnderLast; - conditions.isNewVale = isNewVale; - conditions.isNewValeOverLast = isNewValeOverLast; - conditions.isNewValeUnderLast = isNewValeUnderLast; - conditions.isVWapFastBullish = isVWapFastBullish; - conditions.isVWapFastBearish = isVWapFastBearish; - conditions.isVWapFastNeutural = isVWapFastNeutural; - conditions.isVWapMidBullish = isVWapMidBullish; - conditions.isVWapMidBearish = isVWapMidBearish; - conditions.isVWapMidNeutural = isVWapMidNeutural; - conditions.isVWapSlowBullish = isVWapSlowBullish; - conditions.isVWapSlowBearish = isVWapSlowBearish; - conditions.isVWapSlowNeutural = isVWapSlowNeutural; - conditions.isVWapFastOverMid = isVWapFastOverMid; - conditions.isVWapMidOverSlow = isVWapMidOverSlow; - conditions.isVWapFastUnderMid = isVWapFastUnderMid; - conditions.isVWapMidUnderSlow = isVWapMidUnderSlow; - conditions.isVWapBullishState = isVWapBullishState; - conditions.isVWapBearishState = isVWapBearishState; - conditions.isVWapNeuturalState = isVWapNeuturalState; - conditions.isVWapBullishOrdered = isVWapBullishOrdered; - conditions.isVWapBearishOrdered = isVWapBearishOrdered; - conditions.isVWapSwitchedToBullishOrdered = isVWapSwitchedToBullishOrdered; - conditions.isVWapSwitchedToBearishOrdered = isVWapSwitchedToBearishOrdered; - conditions.isVWapSwitchedToBullishState = isVWapSwitchedToBullishState; - conditions.isVWapSwitchedToBearishState = isVWapSwitchedToBearishState; - conditions.isVWapSwitchedToNeuturalState = isVWapSwitchedToNeuturalState; - - // - return result; - } - - // - protected: - // - - // - private: - // - // Props ... - X121Inputs mInputs; // Inputs ... - - // - // Buffers ... - double peaksBuffer[]; - double valesBuffer[]; - double sarBuffer[]; - double atrUpperBuffer[]; - double atrLowerBuffer[]; - double vwapFastBuffer[]; - double vwapMidBuffer[]; - double vwapSlowBuffer[]; - double donOpenUpperBuffer[]; - double donOpenLowerBuffer[]; - double donCloseUpperBuffer[]; - double donCloseLowerBuffer[]; - double donHighUpperBuffer[]; - double donHighLowerBuffer[]; - double donLowUpperBuffer[]; - double donLowLowerBuffer[]; - double cHHBuffer[]; - double cLLBuffer[]; - double sHHBuffer[]; - double sLLBuffer[]; - double mHHBuffer[]; - double mLLBuffer[]; - double lHHBuffer[]; - double lLLBuffer[]; - double hHHBuffer[]; - double hLLBuffer[]; - double atrBuffer[]; - double atrUpperRawBuffer[]; - double atrLowerRawBuffer[]; - double vwapVolumeBuffer[]; - double vwapPriceBuffer[]; - double vwapFastStateBuffer[]; - double vwapMidStateBuffer[]; - double vwapSlowStateBuffer[]; - double rsiBuffer[]; - - // - // Tools ... - - /** - * Calculate Buffers ... - */ - void Calculate() - { - // - int totalBars = CountBars(); - if (totalBars > 1000) - { - totalBars = 1000; - } - - // - // Buffers ... - - // - // RSI ... - CopyBuffer( - mHandler, - X121_RSI_LINE, - 0, - totalBars, - rsiBuffer - // - ); - - // - // XSAR ... - CopyBuffer( - mHandler, - X121_SAR_LINE, - 0, - totalBars, - sarBuffer - // - ); - - // - // ATR ... - - // - CopyBuffer( - mHandler, - X121_ATR_UPPER_LINE, - 0, - totalBars, - atrUpperBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LOWER_LINE, - 0, - totalBars, - atrLowerBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LINE, - 0, - totalBars, - atrBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_UPPER_RAW_LINE, - 0, - totalBars, - atrUpperRawBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LOWER_RAW_LINE, - 0, - totalBars, - atrLowerRawBuffer - // - ); - - // - // XPV ... - - // - // PEAKS ... - CopyBuffer( - mHandler, - X121_PEAKS_LINE, - 0, - totalBars, - peaksBuffer - // - ); - - // - // VALES ... - CopyBuffer( - mHandler, - X121_VALES_LINE, - 0, - totalBars, - valesBuffer - // - ); - - // - // CURRENT ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_CURRENT_HH_LINE, - 0, - totalBars, - cHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_CURRENT_LL_LINE, - 0, - totalBars, - cLLBuffer - // - ); - - // - // SHORT ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_SHORT_HH_LINE, - 0, - totalBars, - sHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_SHORT_LL_LINE, - 0, - totalBars, - sLLBuffer - // - ); - - // - // MEDIUM ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_MEDIUM_HH_LINE, - 0, - totalBars, - mHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_MEDIUM_LL_LINE, - 0, - totalBars, - mLLBuffer - // - ); - - // - // LONG ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_LONG_HH_LINE, - 0, - totalBars, - lHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_LONG_LL_LINE, - 0, - totalBars, - lLLBuffer - // - ); - - // - // HIND ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_HIND_HH_LINE, - 0, - totalBars, - hHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_HIND_LL_LINE, - 0, - totalBars, - hLLBuffer - // - ); - - // - // XVWAP ... - - // - // FAST ... - CopyBuffer( - mHandler, - X121_VWAP_FAST_LINE, - 0, - totalBars, - vwapFastBuffer - // - ); - - // - // FAST STATE ... - CopyBuffer( - mHandler, - X121_VWAP_FAST_STATE_LINE, - 0, - totalBars, - vwapFastStateBuffer - // - ); - - // - // MID ... - CopyBuffer( - mHandler, - X121_VWAP_MID_LINE, - 0, - totalBars, - vwapMidBuffer - // - ); - - // - // MID STATE ... - CopyBuffer( - mHandler, - X121_VWAP_MID_STATE_LINE, - 0, - totalBars, - vwapMidStateBuffer - // - ); - - // - // SLOW ... - CopyBuffer( - mHandler, - X121_VWAP_SLOW_LINE, - 0, - totalBars, - vwapSlowBuffer - // - ); - - // - // SLOW STATE ... - CopyBuffer( - mHandler, - X121_VWAP_SLOW_STATE_LINE, - 0, - totalBars, - vwapSlowStateBuffer - // - ); - - // - // VOLUME ... - CopyBuffer( - mHandler, - X121_VWAP_VOLUME_LINE, - 0, - totalBars, - vwapVolumeBuffer - // - ); - - // - // PRICE ... - CopyBuffer( - mHandler, - X121_VWAP_PRICE_LINE, - 0, - totalBars, - vwapPriceBuffer - // - ); - - // - // XDON ... - - // - // OPEN ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_OPEN_UPPER_LINE, - 0, - totalBars, - donOpenUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_OPEN_LOWER_LINE, - 0, - totalBars, - donOpenLowerBuffer - // - ); - - // - // CLOSE ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_CLOSE_UPPER_LINE, - 0, - totalBars, - donCloseUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_CLOSE_LOWER_LINE, - 0, - totalBars, - donCloseLowerBuffer - // - ); - - // - // HIGH ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_HIGH_UPPER_LINE, - 0, - totalBars, - donHighUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_HIGH_LOWER_LINE, - 0, - totalBars, - donHighLowerBuffer - // - ); - - // - // LOW ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_LOW_UPPER_LINE, - 0, - totalBars, - donLowUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_LOW_LOWER_LINE, - 0, - totalBars, - donLowLowerBuffer - // - ); - } -}; - -// \ No newline at end of file diff --git a/Documents/BKP/1/x-saherelm.x121.mq5 b/Documents/BKP/1/x-saherelm.x121.mq5 deleted file mode 100644 index 4a240372..00000000 --- a/Documents/BKP/1/x-saherelm.x121.mq5 +++ /dev/null @@ -1,2407 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 -// Description: Peaks and Vales ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121" - -// -// Includes Common Library ... -#include "../Classes/x-saherelm.x-poi.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -input group "Makret Cycles"; - -// -input group "Short"; -input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period - -// -input group "Medium"; -input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period - -// -input group "Long"; -input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period - -// -input group "Hind"; -input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period - -// -input group "Boundary Detection"; -input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method -input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method - -// -input group "Rsi Detection"; -input int rsiLength = 14; // Length -input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To - -// -input group "Parabolic Sar Detection"; -input double sarStep = 0.02; // Step -input double sarMax = 0.2; // Maximum - -// -input group "Atr Detection"; -input int atrLength = 14; // Length -input double atrMultiplier = 1; // Multiplier -input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To -input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To -input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method - -// -input group "Str Detecttion"; -input ENUM_APPLIED_PRICE strAppliedTo = PRICE_MEDIAN; // Applied To - -// -input group "VWap Detection"; -input int vwapFastLength = 20; // Fast Length -input int vwapMidLength = 40; // Mid Length -input int vwapSlowLength = 60; // Slow Length -input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To - -// -input group "Donchain Detection"; -input int donchainLength = 40; // Donchain Length - -// -input group "Presentation"; - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -input int sarArrowCode = 159; // Parabolic Sar Arrow Code -input int peaksArrowCode = 159; // Peaks Arrow Code -input int valesArrowCode = 159; // Vales Arrow Code - -// -input bool showSar = true; // Show Parabolic Sar -input bool showAtr = true; // Show Atr -input bool showStr = true; // Show Str -input bool showPeaks = true; // Show Peaks -input bool showVales = true; // Show Vales -input bool showVWap = true; // Show VWap -input bool showDonchain = true; // Show Donchain - -// -input group "Atr Presentation"; -input bool showAtrUpper = true; // Show Upper Zone -input bool showAtrLower = true; // Show Lower Zone - -// -input group "VWap Presentation"; -input bool showVWapFast = true; // Show VWap Fast -input bool showVWapMedium = true; // Show VWap Medium -input bool showVWapSlow = true; // Show VWap Slow - -// -input group "Donchain Presentation"; -input bool showUpper = true; // Show Upper Band -input bool showLower = true; // Show Lower Band -input bool showOpen = true; // Show Open -input bool showHigh = false; // Show High -input bool showClose = true; // Show Close -input bool showLow = false; // Show Low - -// -// Buffers ... - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -#property indicator_chart_window - -// -#property indicator_buffers 44 -#property indicator_plots 17 - -// -// PEAKS ... - -// -#define peaksBufferIndex 0 -double peaksBuffer[]; - -// -#property indicator_label1 "X121 PEAKS" -#property indicator_type1 DRAW_ARROW -#property indicator_color1 clrAqua -#property indicator_width1 1 - -// -// VALES ... - -// -#define valesBufferIndex 1 -double valesBuffer[]; - -// -#property indicator_label2 "X121 VALES" -#property indicator_type2 DRAW_ARROW -#property indicator_color2 clrMagenta -#property indicator_width2 1 - -// -// SAR ... - -// -#define sarBufferIndex 2 -double sarBuffer[]; - -// -#property indicator_label3 "X121 SAR" -#property indicator_type3 DRAW_ARROW -#property indicator_color3 clrYellow -#property indicator_width3 1 - -// -// ATR ... - -// -// Upper ... - -// -#define atrUpperBufferIndex 3 -double atrUpperBuffer[]; - -#property indicator_label4 "X121 ATRU" -#property indicator_type4 DRAW_LINE -#property indicator_color4 clrYellow -#property indicator_style4 STYLE_DOT -#property indicator_width4 2 - -// -// Lower ... - -// -#define atrLowerBufferIndex 4 -double atrLowerBuffer[]; - -#property indicator_label5 "X121 ATRL" -#property indicator_type5 DRAW_LINE -#property indicator_color5 clrYellow -#property indicator_style5 STYLE_DOT -#property indicator_width5 2 - -// -// STR ... -#define strBufferIndex 5 -double strBuffer[]; - -#define strColorBufferIndex 6 -double strColorBuffer[]; - -// -#define strPlotBufferIndex 5 -#property indicator_label6 "X121 STR" -#property indicator_type6 DRAW_COLOR_LINE -#property indicator_color6 CLR_NONE, clrLime, clrRed, clrGray -#property indicator_style6 STYLE_SOLID -#property indicator_width6 2 - -// -// VWAP ... - -// -// FAST ... -#define vwapFastBufferIndex 7 -double vwapFastBuffer[]; - -#define vwapFastColorBufferIndex 8 -double vwapFastColorBuffer[]; - -// -#define vwapFastPlotBufferIndex 6 -#property indicator_label7 "X121 VWF" -#property indicator_type7 DRAW_COLOR_LINE -#property indicator_color7 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style7 STYLE_SOLID -#property indicator_width7 2 - -// -// MID ... -#define vwapMidBufferIndex 9 -double vwapMidBuffer[]; - -#define vwapMidColorBufferIndex 10 -double vwapMidColorBuffer[]; - -// -#define vwapMidPlotBufferIndex 7 -#property indicator_label8 "X121 VWM" -#property indicator_type8 DRAW_COLOR_LINE -#property indicator_color8 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style8 STYLE_SOLID -#property indicator_width8 2 - -// -// SLOW ... -#define vwapSlowBufferIndex 11 -double vwapSlowBuffer[]; - -#define vwapSlowColorBufferIndex 12 -double vwapSlowColorBuffer[]; - -// -#define vwapSlowPlotBufferIndex 8 -#property indicator_label9 "X121 VWS" -#property indicator_type9 DRAW_COLOR_LINE -#property indicator_color9 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray -#property indicator_style9 STYLE_SOLID -#property indicator_width9 2 - -// -// XDON ... - -// -// Open ... - -// -#define donOpenUpperBufferIndex 13 -double donOpenUpperBuffer[]; - -// -#define donOpenUpperPlotBufferIndex 9 -#property indicator_label10 "X121 O U" -#property indicator_type10 DRAW_LINE -#property indicator_color10 clrCornflowerBlue -#property indicator_width10 1 - -// -#define donOpenLowerBufferIndex 14 -double donOpenLowerBuffer[]; - -// -#define donOpenLowerPlotBufferIndex 10 -#property indicator_label11 "X121 O L" -#property indicator_type11 DRAW_LINE -#property indicator_color11 clrCornflowerBlue -#property indicator_width11 1 - -// -// High ... - -// -#define donHighUpperBufferIndex 15 -double donHighUpperBuffer[]; - -// -#define donHighUpperPlotBufferIndex 11 -#property indicator_label12 "X121 H U" -#property indicator_type12 DRAW_LINE -#property indicator_color12 clrAquamarine -#property indicator_width12 1 - -// -#define donHighLowerBufferIndex 16 -double donHighLowerBuffer[]; - -// -#define donHighLowerPlotBufferIndex 12 -#property indicator_label13 "X121 H L" -#property indicator_type13 DRAW_LINE -#property indicator_color13 clrAquamarine -#property indicator_width13 1 - -// -// Low ... - -// -#define donLowUpperBufferIndex 17 -double donLowUpperBuffer[]; - -// -#define donLowUpperPlotBufferIndex 13 -#property indicator_label14 "X121 L U" -#property indicator_type14 DRAW_LINE -#property indicator_color14 clrDarkOrchid -#property indicator_width14 1 - -// -#define donLowLowerBufferIndex 18 -double donLowLowerBuffer[]; - -// -#define donLowLowerPlotBufferIndex 14 -#property indicator_label15 "X121 L L" -#property indicator_type15 DRAW_LINE -#property indicator_color15 clrDarkOrchid -#property indicator_width15 1 - -// -// Close ... - -// -#define donCloseUpperBufferIndex 19 -double donCloseUpperBuffer[]; - -// -#define donCloseUpperPlotBufferIndex 15 -#property indicator_label16 "X121 C U" -#property indicator_type16 DRAW_LINE -#property indicator_color16 clrCoral -#property indicator_width16 1 - -// -#define donCloseLowerBufferIndex 20 -double donCloseLowerBuffer[]; - -// -#define donCloseLowerPlotBufferIndex 16 -#property indicator_label17 "X121 C L" -#property indicator_type17 DRAW_LINE -#property indicator_color17 clrCoral -#property indicator_width17 1 - -// -// Data Buffers ... - -// -int mLastBufferIndex = 20; - -// -// CURRENT ... - -// -#define cHHBufferIndex mLastBufferIndex + 1 -double cHHBuffer[]; - -// -#define cLLBufferIndex mLastBufferIndex + 2 -double cLLBuffer[]; - -// -// SHORT ... - -// -#define sHHBufferIndex mLastBufferIndex + 3 -double sHHBuffer[]; - -// -#define sLLBufferIndex mLastBufferIndex + 4 -double sLLBuffer[]; - -// -// MEDIUM ... - -// -#define mHHBufferIndex mLastBufferIndex + 5 -double mHHBuffer[]; - -// -#define mLLBufferIndex mLastBufferIndex + 6 -double mLLBuffer[]; - -// -// LONG ... - -// -#define lHHBufferIndex mLastBufferIndex + 7 -double lHHBuffer[]; - -// -#define lLLBufferIndex mLastBufferIndex + 8 -double lLLBuffer[]; - -// -// HIND ... - -// -#define hHHBufferIndex mLastBufferIndex + 9 -double hHHBuffer[]; - -// -#define hLLBufferIndex mLastBufferIndex + 10 -double hLLBuffer[]; - -// -// VWAP ... -#define vwapVolumeBufferIndex mLastBufferIndex + 11 -double vwapVolumeBuffer[]; - -// -// Price ... -#define vwapPriceBufferIndex mLastBufferIndex + 12 -double vwapPriceBuffer[]; - -// -// Fast State ... -#define vwapFastStateBufferIndex mLastBufferIndex + 13 -double vwapFastStateBuffer[]; - -// -// Mid State ... -#define vwapMidStateBufferIndex mLastBufferIndex + 14 -double vwapMidStateBuffer[]; - -// -// Slow State ... -#define vwapSlowStateBufferIndex mLastBufferIndex + 15 -double vwapSlowStateBuffer[]; - -// -// ATR ... - -#define atrBufferIndex mLastBufferIndex + 16 -double atrBuffer[]; - -#define atrUpperRawBufferIndex mLastBufferIndex + 17 -double atrUpperRawBuffer[]; - -#define atrLowerRawBufferIndex mLastBufferIndex + 18 -double atrLowerRawBuffer[]; - -// -// RSI ... -#define rsiBufferIndex mLastBufferIndex + 19 -double rsiBuffer[]; - -// -// STR ... - -// -// Price ... -#define strPriceBufferIndex mLastBufferIndex + 20 -double strPriceBuffer[]; - -// -// Up ... -#define strUpBufferIndex mLastBufferIndex + 21 -double strUpBuffer[]; - -// -// Down ... -#define strDownBufferIndex mLastBufferIndex + 22 -double strDownBuffer[]; - -// -// Trend ... -#define strStateBufferIndex mLastBufferIndex + 23 -double strStateBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; -int rlimit; - -// -int maxLength; - -// -// RSI Handler ... -int rsiHandler = INVALID_HANDLE; - -// -// SAR Handler ... -int sarHandler = INVALID_HANDLE; - -// -// ATR Handler ... -int atrHandler = INVALID_HANDLE; - -// -bool isStrTrendChanged; -bool isStrStartBearishTrend; -bool isStrStartBullishTrend; - -// -// XMarketCycle sc; -int mSCLength = 0; -ENUM_TIMEFRAMES mSCPeriod = NULL; - -// -// XMarketCycle mc; -int mMCLength = 0; -ENUM_TIMEFRAMES mMCPeriod = NULL; - -// -// XMarketCycle lc; -int mLCLength = 0; -ENUM_TIMEFRAMES mLCPeriod = NULL; - -// -// XMarketCycle hc; -int mHCLength = 0; -ENUM_TIMEFRAMES mHCPeriod = NULL; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // RSI ... - rsiHandler = iRSI( - _Symbol, - _Period, - rsiLength, - rsiAppliedTo // - ); - bool isInited = rsiHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // SAR ... - sarHandler = iSAR( - _Symbol, - _Period, - sarStep, - sarMax // - ); - isInited = sarHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ATR ... - atrHandler = iATR( - _Symbol, - _Period, - atrLength // - ); - isInited = atrHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - if (!InitMarketCycles()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -/** - * De Initialize Indicator ... - * - * @param reason: Integer, De Initialization Reason ... - */ -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed - - // - IndicatorRelease(rsiHandler); - IndicatorRelease(sarHandler); - IndicatorRelease(atrHandler); -} - -/** - * Calculate Bars ... - * - * @param rates_total: Integer, Total Bars on Chart ... - * @param prev_calculated: Integer, Total Calculated Bars on Charts ... - * @param time: DateTime Array, History of Open Time ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param low: Double Array, History of Low Prices ... - * @param close: Double Array, History of Close Prices ... - * @param tick_volume: Long, History of Tick Volumes on Bar ... - * @param volume: Long, History of Trade Volumes ... - * @param spread: Double, History of Spread Price ... - * - * @return ( int ) - */ -int OnCalculate( - const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[] // -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // Fill All Buffers by Zero ... - if (prev_calculated == 0) - { - // - ArrayInitialize(peaksBuffer, 0); - ArrayInitialize(valesBuffer, 0); - ArrayInitialize(sarBuffer, 0); - } - - // - // Validate Calculated Bars ... - - // - // RSI ... - int rsiCalculatedBars = BarsCalculated(rsiHandler); - - // - // SAR ... - int sarCalculatedBars = BarsCalculated(sarHandler); - - // - // ATR ... - int atrCalculatedBars = BarsCalculated(atrHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // RSI ... - rsiCalculatedBars >= maxLength && - // - // SAR ... - sarCalculatedBars >= maxLength && - // - // ATR ... - sarCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - rlimit = (prev_calculated > rates_total || prev_calculated <= 0) - ? maxLength - : prev_calculated - 1; - - // - // Buffers Copy ... - - // - // RSI ... - int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer); - - // - // SAR ... - int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); - - // - // ATR ... - int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // - // RSI ... - copiedRsis > 0 && - // - // SAR ... - copiedSars > 0 && - // - // ATR ... - copiedAtrs > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// Functions ... - -/** - * Validate Input Args for Initialization ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = - // - // RSI ... - rsiLength > 0 && - // - // PSAR ... - sarMax > 0 && - sarStep > 0 && - sarMax > sarStep && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // XDON ... - donchainLength > 0 && - // - // VWAP ... - vwapFastLength > 2 && - vwapMidLength > vwapFastLength && - vwapSlowLength > vwapMidLength && - // - // XPV ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - // XPV ... - result = MathMax(mSCLength, mMCLength); - result = MathMax(result, mLCLength); - result = MathMax(result, mHCLength); - - // - // XVWAP ... - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapMidLength); - result = MathMax(result, vwapSlowLength); - - // - // ATR ... - result = MathMax(result, atrLength); - - // - // RSI ... - result = MathMax(result, rsiLength); - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // PEAKS ... - - // - ENUM_DRAW_TYPE peaksDrawType = showPeaks ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(peaksBuffer, true); - SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaks); - PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, peaksDrawType); - - // - PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, peaksArrowCode); - - // - // VALES ... - - // - ENUM_DRAW_TYPE valesDrawType = showVales ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(valesBuffer, true); - SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showVales); - PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, valesDrawType); - - // - PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, valesArrowCode); - - // - // SAR ... - - // - ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(sarBuffer, true); - SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar); - PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); - - // - PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); - - // - // ATR ... - - // - // UPPER ... - bool canShowAtrUpper = showAtr && showAtrUpper; - ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrUpperBuffer, true); - SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType); - - // - // LOWER ... - bool canShowAtrLower = showAtr && showAtrLower; - ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrLowerBuffer, true); - SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType); - - // - // STR ... - ArraySetAsSeries(strBuffer, true); - ArraySetAsSeries(strColorBuffer, true); - SetIndexBuffer(strBufferIndex, strBuffer, INDICATOR_DATA); - SetIndexBuffer(strColorBufferIndex, strColorBuffer, INDICATOR_COLOR_INDEX); - - // - // XVWAP ... - - // - // Fast ... - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapFastColorBuffer, true); - SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Mid ... - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapMidColorBuffer, true); - SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Slow ... - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(vwapSlowColorBuffer, true); - SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX); - - // - // XDON ... - - // - // Open ... - - // - // UPPER ... - bool canShowCOpenUpper = showDonchain && showUpper && showOpen; - ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donOpenUpperBuffer, true); - SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); - PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType); - - // - // LOWER ... - bool canShowCOpenLower = showDonchain && showLower && showOpen; - ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donOpenLowerBuffer, true); - SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); - PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType); - - // - // Close ... - - // - // UPPER ... - bool canShowCCloseUpper = showDonchain && showUpper && showClose; - ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donCloseUpperBuffer, true); - SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); - PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType); - - // - // LOWER ... - bool canShowCCloseLower = showDonchain && showLower && showClose; - ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donCloseLowerBuffer, true); - SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); - PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType); - - // - // High ... - - // - // UPPER ... - bool canShowCHighUpper = showDonchain && showUpper && showHigh; - ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donHighUpperBuffer, true); - SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); - PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType); - - // - // LOWER ... - bool canShowCHighLower = showDonchain && showLower && showHigh; - ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donHighLowerBuffer, true); - SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); - PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType); - - // - // Low ... - - // - // UPPER ... - bool canShowCLowUpper = showDonchain && showUpper && showLow; - ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donLowUpperBuffer, true); - SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); - PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType); - - // - // LOWER ... - bool canShowCLowLower = showDonchain && showLower && showLow; - ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donLowLowerBuffer, true); - SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); - PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType); - - // - // Data Buffers ... - - // - // CURRENT ... - - // - ArraySetAsSeries(cHHBuffer, true); - SetIndexBuffer(cHHBufferIndex, cHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(cLLBuffer, true); - SetIndexBuffer(cLLBufferIndex, cLLBuffer, INDICATOR_CALCULATIONS); - - // - // SHORT ... - - // - ArraySetAsSeries(sHHBuffer, true); - SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(sLLBuffer, true); - SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS); - - // - // MEDIUM ... - - // - ArraySetAsSeries(mHHBuffer, true); - SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(mLLBuffer, true); - SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS); - - // - // LONG ... - - // - ArraySetAsSeries(lHHBuffer, true); - SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(lLLBuffer, true); - SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS); - - // - // HIND ... - - // - ArraySetAsSeries(hHHBuffer, true); - SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(hLLBuffer, true); - SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS); - - // - // XVWAP ... - - // - // Volumes ... - ArraySetAsSeries(vwapVolumeBuffer, true); - SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS); - - // - // Price ... - ArraySetAsSeries(vwapPriceBuffer, true); - SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS); - - // - // Fast State ... - ArraySetAsSeries(vwapFastStateBuffer, true); - SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS); - - // - // Mid State ... - ArraySetAsSeries(vwapMidStateBuffer, true); - SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS); - - // - // Slow State ... - ArraySetAsSeries(vwapSlowStateBuffer, true); - SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS); - - // - // ATR ... - - // - ArraySetAsSeries(atrBuffer, true); - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(atrUpperRawBuffer, true); - SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(atrLowerRawBuffer, true); - SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); - - // - // RSI ... - - // - ArraySetAsSeries(rsiBuffer, true); - SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); - - // - // STR ... - - // - ArraySetAsSeries(strPriceBuffer, true); - SetIndexBuffer(strPriceBufferIndex, strPriceBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(strUpBuffer, true); - SetIndexBuffer(strUpBufferIndex, strUpBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(strDownBuffer, true); - SetIndexBuffer(strDownBufferIndex, strDownBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(strStateBuffer, true); - SetIndexBuffer(strStateBufferIndex, strStateBuffer, INDICATOR_CALCULATIONS); -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Calculate Custom Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int barsLimit = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : 0; - // - // bool canCalculate = true; - bool canCalculate = - barsLimit == 0 || - bar_index <= barsLimit; - if (canCalculate) - { - // - // Calculate Cycles ... - CalculateCycles(bar_index); - - // - // Calculate Peaks and Vales ... - CalculatePeaksAndVales(bar_index); - - // - CalculateDonchains( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateAtrZones( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low // - ); - - // - CalculateStr( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low // - ); - - // - // Calculate Required VWAP Data Buffers ... - if (ratesTotal - bar_index <= maxLength) - { - // - CalculateVWAPDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - // Prevent Moving Forward ... - } - else - { - // - CalculateVWAPDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateVWAPS( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - } - else - { - FillBuffersZero(bar_index); - } -} - -// -// Custom ... - -/** - * Initial Market Cycles ... - * - * @return ( bool ) - */ -bool InitMarketCycles() -{ - // - bool result = false; - - // - int cPeriodSeconds = PeriodSeconds(_Period); - - // - // Find Cycle Period ... - if (scMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mSCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_SHORT, - _Period // - ); - } - else - { - mSCPeriod = scPeriod; - } - - // - if (IsValid(mSCPeriod)) - { - mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (mcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mMCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_MEDIUM, - _Period // - ); - } - else - { - mMCPeriod = mcPeriod; - } - - // - if (IsValid(mMCPeriod)) - { - mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (lcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mLCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_LONG, - _Period // - ); - } - else - { - mLCPeriod = lcPeriod; - } - - // - if (IsValid(mLCPeriod)) - { - mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (hcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mHCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_HIND, - _Period // - ); - } - else - { - mHCPeriod = hcPeriod; - } - - // - if (IsValid(mHCPeriod)) - { - mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; - } - - // - result = mSCLength > 0 && - mMCLength > mSCLength && - mLCLength > mMCLength && - mHCLength > mLCLength; - - // - return result; -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - // CURRENT ... - cHHBuffer[barIndex] = 0; - cLLBuffer[barIndex] = 0; - - // - // SHORT ... - sHHBuffer[barIndex] = 0; - sLLBuffer[barIndex] = 0; - - // - // MEDIUM ... - mHHBuffer[barIndex] = 0; - mLLBuffer[barIndex] = 0; - - // - // LONG ... - lHHBuffer[barIndex] = 0; - lLLBuffer[barIndex] = 0; - - // - // HIND ... - hHHBuffer[barIndex] = 0; - hLLBuffer[barIndex] = 0; - - // - // PEAKS ... - peaksBuffer[barIndex] = 0; - - // - // VALES ... - valesBuffer[barIndex] = 0; - - // - // SARS ... - sarBuffer[barIndex] = 0; - - // - // RSIS ... - rsiBuffer[barIndex] = 0; - - // - // ATRS ... - atrBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrUpperRawBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrLowerRawBuffer[barIndex] = 0; - - // - // STR ... - strBuffer[barIndex] = 0; - strUpBuffer[barIndex] = 0; - strDownBuffer[barIndex] = 0; - strPriceBuffer[barIndex] = 0; - strColorBuffer[barIndex] = hideColorIDX; - strStateBuffer[barIndex] = hideColorIDX; - - // - // VWAP ... - - // - vwapFastBuffer[barIndex] = 0; - vwapMidBuffer[barIndex] = 0; - vwapSlowBuffer[barIndex] = 0; - vwapVolumeBuffer[barIndex] = 0; - vwapPriceBuffer[barIndex] = 0; - - // - vwapFastColorBuffer[barIndex] = hideColorIDX; - vwapMidColorBuffer[barIndex] = hideColorIDX; - vwapSlowColorBuffer[barIndex] = hideColorIDX; - vwapFastStateBuffer[barIndex] = hideColorIDX; - vwapMidStateBuffer[barIndex] = hideColorIDX; - vwapSlowStateBuffer[barIndex] = hideColorIDX; - - // - donOpenUpperBuffer[barIndex] = 0; - donOpenLowerBuffer[barIndex] = 0; - donCloseUpperBuffer[barIndex] = 0; - donCloseLowerBuffer[barIndex] = 0; - donHighUpperBuffer[barIndex] = 0; - donHighLowerBuffer[barIndex] = 0; - donLowUpperBuffer[barIndex] = 0; - donLowLowerBuffer[barIndex] = 0; -} - -/** - * Calculate Specified Market Cycle Info ... - * - * @param barIndex: Integer, Bar Index ... - * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... - * @param hhBuffer: Highest High Buffer Reference ... - * @param llBuffer: Lowest Low Buffer Reference ... - */ -void CalculateCycle( - int barIndex, - ENUM_X_MARKET_CYCLES cycle, - double &hhBuffer[], - double &llBuffer[] // -) -{ - // - XOHCL bar; - bool isBarInited = bar.Init( - _Symbol, - _Period, - barIndex - // - ); - if (!isBarInited) - { - return; - } - - // - int mLength = 0; - switch (cycle) - { - // - case X_MARKET_CYCLE_SHORT: - mLength = mSCLength; - break; - - // - case X_MARKET_CYCLE_MEDIUM: - mLength = mMCLength; - break; - - // - case X_MARKET_CYCLE_LONG: - mLength = mLCLength; - break; - - // - case X_MARKET_CYCLE_HIND: - mLength = mHCLength; - break; - } - - // - if (mLength == 0) - { - return; - } - - // - // Find Highest High ... - double hhValue = bar.FindHighest( - mLength, - hhMode - // - ); - hhBuffer[barIndex] = hhValue; - - // - // Find Lowest Low ... - double llValue = bar.FindLowest( - mLength, - llMode - // - ); - llBuffer[barIndex] = llValue; -} - -/** - * Claculate Cycles ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculateCycles(int barIndex) -{ - // - // SHORT ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_SHORT, - sHHBuffer, - sLLBuffer // - ); - - // - // MEDIUM ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_MEDIUM, - mHHBuffer, - mLLBuffer // - ); - - // - // LONG ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_LONG, - lHHBuffer, - lLLBuffer // - ); - - // - // HIND ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_HIND, - hHHBuffer, - hLLBuffer // - ); -} - -/** - * Calculate Peaks and Vales ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculatePeaksAndVales(int barIndex) -{ - // - int lastIndex = barIndex + 1; - int barsCount = iBars(_Symbol, _Period); - - // - // PEAKS ... - double lastPeak = - lastIndex < barsCount - ? peaksBuffer[lastIndex] - : 0; - - // - double isHH = sHHBuffer[barIndex]; - double imHH = mHHBuffer[barIndex]; - double ilHH = lHHBuffer[barIndex]; - double ihHH = hHHBuffer[barIndex]; - - // - double iHHs[4] = { - isHH, - imHH, - ilHH, - ihHH // - }; - double rValue = GetAverage(iHHs); - bool isPeak = rValue == isHH && - isHH == imHH && - imHH == ilHH && - ilHH == ihHH; - double iPeak = - isPeak - ? rValue - : lastPeak; - peaksBuffer[barIndex] = iPeak; - - // - // VALES ... - double lastVale = - lastIndex < barsCount - ? valesBuffer[lastIndex] - : 0; - - // - double isLL = sLLBuffer[barIndex]; - double imLL = mLLBuffer[barIndex]; - double ilLL = lLLBuffer[barIndex]; - double ihLL = hLLBuffer[barIndex]; - - // - double iLLs[4] = { - isLL, - imLL, - ilLL, - ihLL // - }; - double sValue = GetAverage(iLLs); - bool isVale = sValue == isLL && - isLL == imLL && - imLL == ilLL && - ilLL == ihLL; - double iVale = - isVale - ? sValue - : lastVale; - valesBuffer[barIndex] = iVale; -} - -/** - * Calculate VWAP Value for Specified Bar ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - * @param _length: Integer, Specified VWAP Length ... - * @param _show: Boolean, Specified Show Buffer or not ... - * @param _buffer: Double Array Reference, Points to Buffer ... - * @param _colorBuffer: Double Array Reference, Points to Color Buffer ... - * @param _stateBuffer: Double Array Reference, Points to State Buffer ... - */ -void CalculateVWAP( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[], - // - int _length, // Calculation Length - bool _show, - double &_buffer[], - double &_colorBuffer[], - double &_stateBuffer[] // -) -{ - // - double vSum = 0; - double pSum = 0; - double mSum = 0; - for (int x = 0; x < _length; x++) - { - // - pSum += vwapPriceBuffer[x + bar_index]; - vSum += vwapVolumeBuffer[x + bar_index]; - mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index]; - } - - // - double iValue = mSum / vSum; - iValue = NormalizeDouble(iValue, _Digits); - - // - _buffer[bar_index] = iValue; - - // - bool isBullish = low[bar_index] > iValue; - bool isBearish = high[bar_index] < iValue; - - // - double iColor = - isBullish - ? bullishColorIDX - : isBearish - ? bearishColorIDX - : neuturalColorIDX; - - // - _colorBuffer[bar_index] = hideColorIDX; - _stateBuffer[bar_index] = iColor; - if (showVWap && _show) - { - _colorBuffer[bar_index] = iColor; - } -} - -/** - * Calculate Donchain ... - * - * @param bar_index: Integer, Bar Index ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - * @param _length: Integer, Donchain Length ... - * @param _ouBuffer: Double Array Reference ... - * @param _olBuffer: Double Array Reference ... - * @param _huBuffer: Double Array Reference ... - * @param _hlBuffer: Double Array Reference ... - * @param _luBuffer: Double Array Reference ... - * @param _llBuffer: Double Array Reference ... - * @param _cuBuffer: Double Array Reference ... - * @param _clBuffer: Double Array Reference ... - */ -void CalculateDonchain( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - // - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[], - // - int _length, - // - double &_ouBuffer[], - double &_olBuffer[], - double &_huBuffer[], - double &_hlBuffer[], - double &_luBuffer[], - double &_llBuffer[], - double &_cuBuffer[], - double &_clBuffer[] // -) -{ - // - double iUpper = 0; - double iLower = 0; - - // - // OPEN ... - - // - int from = bar_index; - - // - iUpper = open[ArrayMaximum(open, from, _length)]; - iLower = open[ArrayMinimum(open, from, _length)]; - - // - _ouBuffer[bar_index] = iUpper; - _olBuffer[bar_index] = iLower; - - // - // HIGH ... - - // - iUpper = high[ArrayMaximum(high, from, _length)]; - iLower = high[ArrayMinimum(high, from, _length)]; - - // - _huBuffer[bar_index] = iUpper; - _hlBuffer[bar_index] = iLower; - - // - // LOW ... - - // - iUpper = low[ArrayMaximum(low, from, _length)]; - iLower = low[ArrayMinimum(low, from, _length)]; - - // - _luBuffer[bar_index] = iUpper; - _llBuffer[bar_index] = iLower; - - // - // CLOSE ... - - // - iUpper = close[ArrayMaximum(close, from, _length)]; - iLower = close[ArrayMinimum(close, from, _length)]; - - // - _cuBuffer[bar_index] = iUpper; - _clBuffer[bar_index] = iLower; -} - -/** - * Calculate VWAP Required Data Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateVWAPDataBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - double price = GetAppliedPrice( - vwapAppliedTo, - open, - high, - low, - close, - bar_index // - ); - vwapPriceBuffer[bar_index] = price; - vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index]; -} - -/** - * Calculate Different VWaps ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateVWAPS( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapFastLength, - showVWapFast, - vwapFastBuffer, - vwapFastColorBuffer, - vwapFastStateBuffer // - ); - - // - // Mid ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapMidLength, - showVWapMedium, - vwapMidBuffer, - vwapMidColorBuffer, - vwapMidStateBuffer // - ); - - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapSlowLength, - showVWapSlow, - vwapSlowBuffer, - vwapSlowColorBuffer, - vwapSlowStateBuffer // - ); -} - -/** - * Calculate Different VWaps ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateDonchains( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - CalculateDonchain( - // - bar_index, - prevCalculated, - ratesTotal, - // - open, - high, - close, - low, - tickVolume, - // - donchainLength, - // - donOpenUpperBuffer, - donOpenLowerBuffer, - donHighUpperBuffer, - donHighLowerBuffer, - donLowUpperBuffer, - donLowLowerBuffer, - donCloseUpperBuffer, - donCloseLowerBuffer // - ); -} - -/** - * Calculate ATR Zones ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - */ -void CalculateAtrZones( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[] // -) -{ - // - // Select ATr Value ... - double atrValue = atrBuffer[bar_index]; - double appliedAtrMultiplierValue = atrValue * atrMultiplier; - - // - // Select Upper Price ... - double upperPrice = GetAppliedPrice( - atrUpperAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Select Lower Price ... - double lowerPrice = GetAppliedPrice( - atrLowerAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Calculate Raw Atrs ... - - // - // Upper ... - double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue; - atrUpperRawBuffer[bar_index] = atrUpperRawValue; - - // - // Lower ... - double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue; - atrLowerRawBuffer[bar_index] = atrLowerRawValue; - - // - bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE; - if (canSmooth) - { - // - // Upper ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrUpperRawBuffer, - atrUpperBuffer, - atrSmoothingMode // - ); - - // - // Lower ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrLowerRawBuffer, - atrLowerBuffer, - atrSmoothingMode // - ); - } - else - { - // - // Use Raw Values ... - atrUpperBuffer[bar_index] = atrUpperRawValue; - atrLowerBuffer[bar_index] = atrLowerRawValue; - } -} - -/** - * Calculate STR ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - */ -void CalculateStr( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[] // -) -{ - // - // Calculated Price ... - double price = GetAppliedPrice( - strAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - strPriceBuffer[bar_index] = price; - - // - double atr = atrBuffer[bar_index]; - - // - double appliedAtr = (atrMultiplier * atr); - double strUp = price + appliedAtr; - double strDown = price - appliedAtr; - - // - strUpBuffer[bar_index] = strUp; - strDownBuffer[bar_index] = strDown; - - // - int currIDX = bar_index; - int prevIDX = currIDX + 1; - int prevOfPrevIDX = prevIDX + 1; - - // - double prevState = strStateBuffer[prevIDX]; - bool isCloseOverUp = close[currIDX] > strUpBuffer[prevIDX]; - bool isCloseUnderDown = close[currIDX] < strUpBuffer[prevIDX]; - - // - if (isCloseOverUp) - { - // - strStateBuffer[currIDX] = 1; - if (strStateBuffer[prevIDX] == -1) - { - isStrTrendChanged = true; - } - } - else if (isCloseUnderDown) - { - // - strStateBuffer[currIDX] = -1; - if (strStateBuffer[prevIDX] == 1) - { - isStrTrendChanged = true; - } - } - else if (strStateBuffer[prevIDX] == 1) - { - // - isStrTrendChanged = false; - strStateBuffer[currIDX] = 1; - } - else if (strStateBuffer[prevIDX] == -1) - { - // - isStrTrendChanged = false; - strStateBuffer[currIDX] = -1; - } - - // - // Calculate Trend Starting ... - - // - if (strStateBuffer[currIDX] < 0 && - strStateBuffer[prevIDX] > 0) - { - isStrStartBearishTrend = true; - } - else - { - isStrStartBearishTrend = false; - } - - // - if (strStateBuffer[currIDX] > 0 && - strStateBuffer[prevIDX] < 0) - { - isStrStartBullishTrend = true; - } - else - { - isStrStartBullishTrend = false; - } - - // - // Re new Up and Down Buffer ... - - // - if (strStateBuffer[currIDX] > 0 && - strDownBuffer[currIDX] < strDownBuffer[prevIDX]) - { - strDownBuffer[currIDX] = strDownBuffer[prevIDX]; - } - - // - if (strStateBuffer[currIDX] < 0 && - strUpBuffer[currIDX] > strUpBuffer[prevIDX]) - { - strUpBuffer[currIDX] = strUpBuffer[prevIDX]; - } - - // - // Handle Strat Trends ... - - // - if (isStrStartBearishTrend) - { - strUpBuffer[currIDX] = strPriceBuffer[currIDX] + (atrMultiplier * atr); - } - - // - if (isStrStartBullishTrend) - { - strDownBuffer[currIDX] = strPriceBuffer[currIDX] - (atrMultiplier * atr); - } - - // - double clr = hideColorIDX; - double state = hideColorIDX; - - // - if (strStateBuffer[currIDX] == 1) - { - // - strBuffer[currIDX] = strDownBuffer[currIDX]; - if (isStrTrendChanged) - { - // - isStrTrendChanged = false; - strBuffer[prevIDX] = strBuffer[prevOfPrevIDX]; - } - - // - clr = bullishColorIDX; - } - else if (state == -1) - { - // - strBuffer[currIDX] = strUpBuffer[currIDX]; - if (isStrTrendChanged) - { - // - isStrTrendChanged = false; - strBuffer[prevIDX] = strBuffer[prevOfPrevIDX]; - } - - // - clr = bearishColorIDX; - } - - // - if (!showStr) - { - clr = hideColorIDX; - } - - // - strColorBuffer[bar_index] = clr; - - // -} - -// \ No newline at end of file diff --git a/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 b/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 deleted file mode 100644 index cbb3bf10..00000000 --- a/Documents/BKP/1/x-saherelm.x121.old.helper.mq5 +++ /dev/null @@ -1,5171 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XCX121Helper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.x-helper.class.mq5" - -// -// Definitions ... -enum ENUM_X121_BUFFERS -{ - // - // Main Buffers ... - X121_PEAKS_LINE = 0, - X121_VALES_LINE = 1, - X121_SAR_LINE = 2, - X121_ATR_UPPER_LINE = 3, - X121_ATR_LOWER_LINE = 4, - X121_VWAP_FAST_LINE = 5, - X121_VWAP_MID_LINE = 7, - X121_VWAP_SLOW_LINE = 9, - X121_DON_OPEN_UPPER_LINE = 11, - X121_DON_OPEN_LOWER_LINE = 12, - X121_DON_HIGH_UPPER_LINE = 13, - X121_DON_HIGH_LOWER_LINE = 14, - X121_DON_LOW_UPPER_LINE = 15, - X121_DON_LOW_LOWER_LINE = 16, - X121_DON_CLOSE_UPPER_LINE = 17, - X121_DON_CLOSE_LOWER_LINE = 18, - X121_FIB_LEVEL_1_LINE = 19, - X121_FIB_LEVEL_2_LINE = 20, - X121_FIB_LEVEL_3_LINE = 21, - X121_FIB_LEVEL_4_LINE = 22, - X121_FIB_LEVEL_5_LINE = 23, - // - // Data Buffers ... - // - // XPV Data ... - X121_CURRENT_HH_LINE = 24, - X121_CURRENT_LL_LINE = 25, - X121_SHORT_HH_LINE = 26, - X121_SHORT_LL_LINE = 27, - X121_MEDIUM_HH_LINE = 28, - X121_MEDIUM_LL_LINE = 29, - X121_LONG_HH_LINE = 30, - X121_LONG_LL_LINE = 31, - X121_HIND_HH_LINE = 32, - X121_HIND_LL_LINE = 33, - // - // VWAP Data ... - X121_VWAP_VOLUME_LINE = 34, - X121_VWAP_PRICE_LINE = 35, - X121_VWAP_FAST_STATE_LINE = 36, - X121_VWAP_MID_STATE_LINE = 37, - X121_VWAP_SLOW_STATE_LINE = 38, - // - // ATR ... - X121_ATR_LINE = 39, - X121_ATR_UPPER_RAW_LINE = 40, - X121_ATR_LOWER_RAW_LINE = 41, -}; - -// -enum ENUM_XVWAP_STATES -{ - // - XVWAP_STATE_BULLISH = 1, - XVWAP_STATE_BEARISH = 2, - XVWAP_STATE_NEUTURAL = 3, -}; - -// -// Inputs ... -struct X121Inputs -{ - // - // Props ... - - // - // Cycles ... - - // - // Short ... - ENUM_X_PERIOD_METHOD scMethod; // How to Find Period - ENUM_TIMEFRAMES scPeriod; // Time Period - - // - // Medium ... - ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period - ENUM_TIMEFRAMES mcPeriod; // Time Period - - // - // Long ... - ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period - ENUM_TIMEFRAMES lcPeriod; // Time Period - - // - // Hind ... - ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period - ENUM_TIMEFRAMES hcPeriod; // Time Period - - // - // Boundary Detection ... - ENUM_SERIESMODE hhMode; // Highest High Calculation Method - ENUM_SERIESMODE llMode; // Lowest Low Calculation Method - - // - // Parabolic Sar Detection ... - double sarStep; // Step - double sarMax; // Maximum - - // - // RSI ... - int rsiLength; // RSI Length - double rsiOverSoldLevel; // RSI Over Sold Level - double rsiOverBoughtLevel; // RSI Over Bought Level - - // - // Atr Detection ... - int atrLength; // Length - double atrMultiplier; // Multiplier - ENUM_APPLIED_PRICE atrUpperAppliedTo; // Upper Zone Applied To - ENUM_APPLIED_PRICE atrLowerAppliedTo; // Lower Zone Applied To - ENUM_X_MA_METHOD atrSmoothingMode; // Smoothing Method - - // - // VWap Detection ... - int vwapFastLength; // Fast Length - int vwapMidLength; // Mid Length - int vwapSlowLength; // Slow Length - ENUM_APPLIED_PRICE vwapAppliedTo; // Applied To - - // - // Donchain Detection ... - int donchainLength; // Donchain Length - - // - // Fibonacci ... - double fiboLevel1; // Fibio 1st Level - double fiboLevel2; // Fibio 2st Level - double fiboLevel3; // Fibio 3rd Level - double fiboLevel4; // Fibio 4th Level - double fiboLevel5; // Fibio 5th Level - - // - // Presentation ... - - // - int startCalculationForLastBars; // Calculate Last n Bars - - // - int sarArrowCode; // Parabolic Sar Arrow Code - int peaksArrowCode; // Peaks Arrow Code - int valesArrowCode; // Vales Arrow Code - - // - // Global ... - bool showSar; // Show Parabolic Sar - bool showAtr; // Show Atr - bool showPeaks; // Show Peaks - bool showVales; // Show Vales - bool showVWap; // Show VWap - bool showDonchain; // Show Donchain - - // - // Fibonachi Presentation ... - bool showFibo1Levels; // Show Fibo 1st Level - bool showFibo2Levels; // Show Fibo 2nd Level - bool showFibo3Levels; // Show Fibo 3rd Level - bool showFibo4Levels; // Show Fibo 4th Level - bool showFibo5Levels; // Show Fibo 5th Level - - // - // Atr Presentation ... - bool showAtrUpper; // Show Upper Zone - bool showAtrLower; // Show Lower Zone - - // - // VWap Presentation ... - bool showVWapFast; // Show VWap Fast - bool showVWapMedium; // Show VWap Medium - bool showVWapSlow; // Show VWap Slow - - // - // Donchain Presentation ... - - // - bool showUpper; // Show Upper Band - bool showLower; // Show Lower Band - - // - bool showOpen; // Show Open - bool showHigh; // Show High - bool showClose; // Show Close - bool showLow; // Show Low - - // - // Constructor ... - X121Inputs() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - // Cycles ... - - // - // Short ... - scMethod = X_PERIOD_NOTHING; - scPeriod = NULL; - - // - // Medium ... - mcMethod = X_PERIOD_NOTHING; - mcPeriod = NULL; - - // - // Long ... - lcMethod = X_PERIOD_NOTHING; - lcPeriod = NULL; - - // - // Hind ... - hcMethod = X_PERIOD_NOTHING; - hcPeriod = NULL; - - // - // Boundary Detection ... - hhMode = MODE_HIGH; - llMode = MODE_LOW; - - // - // RSI ... - rsiLength = 0; - rsiOverSoldLevel = 0; - rsiOverBoughtLevel = 0; - - // - // Paraboli Sar Detection ... - sarStep = 0; - sarMax = 0; - - // - // Atr Detection ... - atrLength = 0; // Length - atrMultiplier = 0; // Multiplier - atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To - atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To - atrSmoothingMode = X_MA_MODE_NONE; // Smoothing Method - - // - // VWap Detection ... - vwapFastLength = 0; - vwapMidLength = 0; - vwapSlowLength = 0; - vwapAppliedTo = PRICE_CLOSE; - - // - // Donchain Detection ... - donchainLength = 0; - - // - // Fibonacci ... - fiboLevel1 = 0; - fiboLevel2 = 0; - fiboLevel3 = 0; - fiboLevel4 = 0; - fiboLevel5 = 0; - - // - // Presentation ... - - // - startCalculationForLastBars = 0; - - // - sarArrowCode = 0; - peaksArrowCode = 0; - valesArrowCode = 0; - - // - // Globals ... - showSar = false; - showAtr = false; - showPeaks = false; - showVales = false; - showVWap = false; - showDonchain = false; - - // - // Fibonachi Presentation ... - showFibo1Levels = false; - showFibo2Levels = false; - showFibo3Levels = false; - showFibo4Levels = false; - showFibo5Levels = false; - - // - // Atr Presentation ... - showAtrUpper = false; // Show Upper Zone - showAtrLower = false; // Show Lower Zone - - // - // VWap Presentation ... - showVWapFast = false; - showVWapMedium = false; - showVWapSlow = false; - - // - // Donchain Presentation ... - - // - showUpper = false; - showLower = false; - - // - showOpen = false; - showHigh = false; - showClose = false; - showLow = false; - } - - /** - * Set Default Values ... - */ - void Default() - { - // - // Cycles ... - - // - // Short ... - scMethod = X_PERIOD_AUTO; - scPeriod = NULL; - - // - // Medium ... - mcMethod = X_PERIOD_AUTO; - mcPeriod = NULL; - - // - // Long ... - lcMethod = X_PERIOD_AUTO; - lcPeriod = NULL; - - // - // Hind ... - hcMethod = X_PERIOD_AUTO; - hcPeriod = NULL; - - // - // Boundary Detection ... - hhMode = MODE_HIGH; - llMode = MODE_LOW; - - // - // RSI ... - rsiLength = 14; - rsiOverSoldLevel = 30; - rsiOverBoughtLevel = 70; - - // - // Paraboli Sar Detection ... - sarStep = 0.02; - sarMax = 0.2; - - // - // Atr Detection ... - atrLength = 14; // Length - atrMultiplier = 1; // Multiplier - atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To - atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To - atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method - - // - // VWap Detection ... - vwapFastLength = 20; - vwapMidLength = 40; - vwapSlowLength = 60; - vwapAppliedTo = PRICE_CLOSE; - - // - // Donchain Detection ... - donchainLength = 40; - - // - // Fibonacci ... - fiboLevel1 = 0.236; - fiboLevel2 = 0.382; - fiboLevel3 = 0.5; - fiboLevel4 = 0.618; - fiboLevel5 = 0.764; - - // - // Presentation ... - - // - startCalculationForLastBars = 1500; - - // - sarArrowCode = 159; - peaksArrowCode = 159; - valesArrowCode = 159; - - // - // Globals ... - showSar = true; - showAtr = true; - showPeaks = true; - showVales = true; - showVWap = true; - showDonchain = true; - - // - // Fibonachi Presentation ... - showFibo1Levels = false; - showFibo2Levels = false; - showFibo3Levels = true; - showFibo4Levels = false; - showFibo5Levels = false; - - // - // Atr Presentation ... - showAtrUpper = true; // Show Upper Zone - showAtrLower = true; // Show Lower Zone - - // - // VWap Presentation ... - showVWapFast = true; - showVWapMedium = true; - showVWapSlow = true; - - // - // Donchain Presentation ... - - // - showUpper = true; - showLower = true; - - // - showOpen = true; - showHigh = false; - showClose = true; - showLow = false; - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - // RSI ... - rsiLength > 0 && - rsiOverSoldLevel > 0 && - rsiOverBoughtLevel > 0 && - rsiOverSoldLevel < rsiOverBoughtLevel && - // PSAR ... - sarMax > 0 && - sarStep > 0 && - sarMax > sarStep && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // XDON ... - donchainLength > 0 && - // - // VWAP ... - vwapFastLength > 2 && - vwapMidLength > vwapFastLength && - vwapSlowLength > vwapMidLength && - // - // XPV ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; - } - - /** - * Extract Max Input Length ... - * - * @return ( int ) - */ - int Max() - { - // - int result = 0; - - // - // VWAP ... - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapMidLength); - - // - // ATR ... - result = MathMax(result, atrLength); - result = MathMax(result, rsiLength); - - // - return result; - } -}; - -// -// Conditions ... -struct X121Conditions -{ - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Buffers ... - double peaksBuffer[]; - double valesBuffer[]; - double sarBuffer[]; - double atrUpperBuffer[]; - double atrLowerBuffer[]; - double vwapFastBuffer[]; - double vwapMidBuffer[]; - double vwapSlowBuffer[]; - double donOpenUpperBuffer[]; - double donOpenLowerBuffer[]; - double donCloseUpperBuffer[]; - double donCloseLowerBuffer[]; - double donHighUpperBuffer[]; - double donHighLowerBuffer[]; - double donLowUpperBuffer[]; - double donLowLowerBuffer[]; - double fl1Buffer[]; - double fl2Buffer[]; - double fl3Buffer[]; - double fl4Buffer[]; - double fl5Buffer[]; - double cHHBuffer[]; - double cLLBuffer[]; - double sHHBuffer[]; - double sLLBuffer[]; - double mHHBuffer[]; - double mLLBuffer[]; - double lHHBuffer[]; - double lLLBuffer[]; - double hHHBuffer[]; - double hLLBuffer[]; - double atrBuffer[]; - double atrUpperRawBuffer[]; - double atrLowerRawBuffer[]; - double vwapVolumeBuffer[]; - double vwapPriceBuffer[]; - double vwapFastStateBuffer[]; - double vwapMidStateBuffer[]; - double vwapSlowStateBuffer[]; - double rsiBuffer[]; - - // - // Conditions ... - - // - // XRSI ... - - // - bool isRSIOverBought; - bool isRSICrossedOverOverBought; - bool isRSICrossedUnderOverBought; - - // - bool isRSIOverSold; - bool isRSICrossedUnderOverSold; - bool isRSICrossedOverOverSold; - - // - // XSAR ... - - // - bool isSarBullish; - bool isSarBearish; - - // - bool isSarSwitchedToBullish; - bool isSarSwitchedToBearish; - - // - // XPV ... - - // - bool isNewPeak; - bool isNewPeakOverLast; - bool isNewPeakUnderLast; - - // - bool isNewVale; - bool isNewValeOverLast; - bool isNewValeUnderLast; - - // - // XVWAP ... - - // - bool isVWapFastBullish; - bool isVWapFastBearish; - bool isVWapFastNeutural; - - // - bool isVWapMidBullish; - bool isVWapMidBearish; - bool isVWapMidNeutural; - - // - bool isVWapSlowBullish; - bool isVWapSlowBearish; - bool isVWapSlowNeutural; - - // - bool isVWapFastOverMid; - bool isVWapMidOverSlow; - - // - bool isVWapFastUnderMid; - bool isVWapMidUnderSlow; - - // - bool isVWapBullishState; - bool isVWapBearishState; - bool isVWapNeuturalState; - - // - bool isVWapBullishOrdered; - bool isVWapBearishOrdered; - - // - bool isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered; - - // - bool isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState; - bool isVWapSwitchedToNeuturalState; - - // - // XDON ... - - // - // bool isCloseLower - - // - // XFIBONACCI ... - - // - bool isOerFib1; - bool isOerFib2; - bool isOerFib3; - bool isOerFib4; - bool isOerFib5; - - // - bool isUnderFib1; - bool isUnderFib2; - bool isUnderFib3; - bool isUnderFib4; - bool isUnderFib5; - - // - bool isCloseOerFib1; - bool isCloseOerFib2; - bool isCloseOerFib3; - bool isCloseOerFib4; - bool isCloseOerFib5; - - // - bool isCloseUnderFib1; - bool isCloseUnderFib2; - bool isCloseUnderFib3; - bool isCloseUnderFib4; - bool isCloseUnderFib5; - - // - // Constructor ... - X121Conditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - // Commons ... - symbol = NULL; - period = NULL; - time = NULL; - - // - // Buffers ... - - // - Clean(peaksBuffer); - Clean(valesBuffer); - Clean(sarBuffer); - Clean(atrUpperBuffer); - Clean(atrLowerBuffer); - Clean(vwapFastBuffer); - Clean(vwapMidBuffer); - Clean(vwapSlowBuffer); - Clean(donOpenUpperBuffer); - Clean(donOpenLowerBuffer); - Clean(donCloseUpperBuffer); - Clean(donCloseLowerBuffer); - Clean(donHighUpperBuffer); - Clean(donHighLowerBuffer); - Clean(donLowUpperBuffer); - Clean(donLowLowerBuffer); - Clean(fl1Buffer); - Clean(fl2Buffer); - Clean(fl3Buffer); - Clean(fl4Buffer); - Clean(fl5Buffer); - Clean(cHHBuffer); - Clean(cLLBuffer); - Clean(sHHBuffer); - Clean(sLLBuffer); - Clean(mHHBuffer); - Clean(mLLBuffer); - Clean(lHHBuffer); - Clean(lLLBuffer); - Clean(hHHBuffer); - Clean(hLLBuffer); - Clean(atrBuffer); - Clean(atrUpperRawBuffer); - Clean(atrLowerRawBuffer); - Clean(vwapVolumeBuffer); - Clean(vwapPriceBuffer); - Clean(vwapFastStateBuffer); - Clean(vwapMidStateBuffer); - Clean(vwapSlowStateBuffer); - Clean(rsiBuffer); - - // - ArraySetAsSeries(peaksBuffer, true); - ArraySetAsSeries(valesBuffer, true); - ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(atrUpperBuffer, true); - ArraySetAsSeries(atrLowerBuffer, true); - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(donOpenUpperBuffer, true); - ArraySetAsSeries(donOpenLowerBuffer, true); - ArraySetAsSeries(donCloseUpperBuffer, true); - ArraySetAsSeries(donCloseLowerBuffer, true); - ArraySetAsSeries(donHighUpperBuffer, true); - ArraySetAsSeries(donHighLowerBuffer, true); - ArraySetAsSeries(donLowUpperBuffer, true); - ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(fl1Buffer, true); - ArraySetAsSeries(fl2Buffer, true); - ArraySetAsSeries(fl3Buffer, true); - ArraySetAsSeries(fl4Buffer, true); - ArraySetAsSeries(fl5Buffer, true); - ArraySetAsSeries(cHHBuffer, true); - ArraySetAsSeries(cLLBuffer, true); - ArraySetAsSeries(sHHBuffer, true); - ArraySetAsSeries(sLLBuffer, true); - ArraySetAsSeries(mHHBuffer, true); - ArraySetAsSeries(mLLBuffer, true); - ArraySetAsSeries(lHHBuffer, true); - ArraySetAsSeries(lLLBuffer, true); - ArraySetAsSeries(hHHBuffer, true); - ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(atrBuffer, true); - ArraySetAsSeries(atrUpperRawBuffer, true); - ArraySetAsSeries(atrLowerRawBuffer, true); - ArraySetAsSeries(vwapVolumeBuffer, true); - ArraySetAsSeries(vwapPriceBuffer, true); - ArraySetAsSeries(vwapFastStateBuffer, true); - ArraySetAsSeries(vwapMidStateBuffer, true); - ArraySetAsSeries(vwapSlowStateBuffer, true); - ArraySetAsSeries(rsiBuffer, true); - - // - // Conditions ... - - // - // XRSI ... - - // - isRSIOverBought = false; - isRSICrossedUnderOverBought = false; - isRSICrossedOverOverBought = false; - - // - isRSIOverSold = false; - isRSICrossedOverOverSold = false; - isRSICrossedUnderOverSold = false; - - // - // XSAR ... - - // - isSarBullish = false; - isSarBearish = false; - - // - isSarSwitchedToBullish = false; - isSarSwitchedToBearish = false; - - // - // XPV ... - - // - isNewPeak = false; - isNewPeakOverLast = false; - isNewPeakUnderLast = false; - - // - isNewVale = false; - isNewValeOverLast = false; - isNewValeUnderLast = false; - - // - // XVWAP ... - - // - isVWapFastBullish = false; - isVWapFastBearish = false; - isVWapFastNeutural = false; - - // - isVWapMidBullish = false; - isVWapMidBearish = false; - isVWapMidNeutural = false; - - // - isVWapSlowBullish = false; - isVWapSlowBearish = false; - isVWapSlowNeutural = false; - - // - isVWapFastOverMid = false; - isVWapMidOverSlow = false; - - // - isVWapFastUnderMid = false; - isVWapMidUnderSlow = false; - - // - isVWapBullishState = false; - isVWapBearishState = false; - isVWapNeuturalState = false; - - // - isVWapBullishOrdered = false; - isVWapBearishOrdered = false; - - // - isVWapSwitchedToBullishOrdered = false; - isVWapSwitchedToBearishOrdered = false; - - // - isVWapSwitchedToBullishState = false; - isVWapSwitchedToBearishState = false; - isVWapSwitchedToNeuturalState = false; - - // - // XDON ... - - // - // XFIBONACCI ... - - // - isOerFib1 = false; - isOerFib2 = false; - isOerFib3 = false; - isOerFib4 = false; - isOerFib5 = false; - - // - isUnderFib1 = false; - isUnderFib2 = false; - isUnderFib3 = false; - isUnderFib4 = false; - isUnderFib5 = false; - - // - isCloseOerFib1 = false; - isCloseOerFib2 = false; - isCloseOerFib3 = false; - isCloseOerFib4 = false; - isCloseOerFib5 = false; - - // - isCloseUnderFib1 = false; - isCloseUnderFib2 = false; - isCloseUnderFib3 = false; - isCloseUnderFib4 = false; - isCloseUnderFib5 = false; - } - - /** - * Generate Conditions Scores ... - * - * @param bullishScore: Double, Directional Scores Reference ... - * @param bearishScore: Double, Directional Scores Reference ... - */ - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - // TODO: Implement if Required ... - } - - /** - * Generate Summary String for Represent Conditions State ... - * - * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... - * @param onlyConditions: Boolean, Just Generate Only Conditions ... - * @param includeScores: Boolean, Attach Scores Representations on Result ... - * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... - * @param separator: String, Separate Lines ... - * - * @return ( string ) - */ - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string scoresStr = - // - "Scores: " + separator + - "---------------" + separator + - "Bullish: " + ToString(bullishScore) + separator + - "Bearish: " + ToString(bearishScore) + separator + - "" - // - ; - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores // - ); - - // - // TODO: Implement this if required ... - string conditionsStr = - // - // XSAR ... - ToString("isSarBullish", isSarBullish, ignoreFalseConditions, separator) + - ToString("isSarBearish", isSarBearish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBullish", isSarSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBearish", isSarSwitchedToBearish, ignoreFalseConditions, separator) + - // - // XPV ... - ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + - ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + - ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + - ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + - ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + - ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + - // - // XVWAP ... - ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) + - ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) + - ToString("isVWapFastNeutural", isVWapFastNeutural, ignoreFalseConditions, separator) + - ToString("isVWapMidBullish", isVWapMidBullish, ignoreFalseConditions, separator) + - ToString("isVWapMidBearish", isVWapMidBearish, ignoreFalseConditions, separator) + - ToString("isVWapMidNeutural", isVWapMidNeutural, ignoreFalseConditions, separator) + - ToString("isVWapSlowBullish", isVWapSlowBullish, ignoreFalseConditions, separator) + - ToString("isVWapSlowBearish", isVWapSlowBearish, ignoreFalseConditions, separator) + - ToString("isVWapSlowNeutural", isVWapSlowNeutural, ignoreFalseConditions, separator) + - ToString("isVWapFastOverMid", isVWapFastOverMid, ignoreFalseConditions, separator) + - ToString("isVWapMidOverSlow", isVWapMidOverSlow, ignoreFalseConditions, separator) + - ToString("isVWapFastUnderMid", isVWapFastUnderMid, ignoreFalseConditions, separator) + - ToString("isVWapMidUnderSlow", isVWapMidUnderSlow, ignoreFalseConditions, separator) + - ToString("isVWapBullishState", isVWapBullishState, ignoreFalseConditions, separator) + - ToString("isVWapBearishState", isVWapBearishState, ignoreFalseConditions, separator) + - ToString("isVWapNeuturalState", isVWapNeuturalState, ignoreFalseConditions, separator) + - ToString("isVWapBullishOrdered", isVWapBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapBearishOrdered", isVWapBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishOrdered", isVWapSwitchedToBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishOrdered", isVWapSwitchedToBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishState", isVWapSwitchedToBullishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) + - // - // XFIBONACCI ... - ToString("isOerFib1", isOerFib1, ignoreFalseConditions, separator) + - ToString("isOerFib2", isOerFib2, ignoreFalseConditions, separator) + - ToString("isOerFib3", isOerFib3, ignoreFalseConditions, separator) + - ToString("isOerFib4", isOerFib4, ignoreFalseConditions, separator) + - ToString("isOerFib5", isOerFib5, ignoreFalseConditions, separator) + - ToString("isUnderFib1", isUnderFib1, ignoreFalseConditions, separator) + - ToString("isUnderFib2", isUnderFib2, ignoreFalseConditions, separator) + - ToString("isUnderFib3", isUnderFib3, ignoreFalseConditions, separator) + - ToString("isUnderFib4", isUnderFib4, ignoreFalseConditions, separator) + - ToString("isUnderFib5", isUnderFib5, ignoreFalseConditions, separator) + - ToString("isCloseOerFib1", isCloseOerFib1, ignoreFalseConditions, separator) + - ToString("isCloseOerFib2", isCloseOerFib2, ignoreFalseConditions, separator) + - ToString("isCloseOerFib3", isCloseOerFib3, ignoreFalseConditions, separator) + - ToString("isCloseOerFib4", isCloseOerFib4, ignoreFalseConditions, separator) + - ToString("isCloseOerFib5", isCloseOerFib5, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib1", isCloseUnderFib1, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib2", isCloseUnderFib2, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib3", isCloseUnderFib3, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib4", isCloseUnderFib4, ignoreFalseConditions, separator) + - ToString("isCloseUnderFib5", isCloseUnderFib5, ignoreFalseConditions, separator) + - // - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - (onlyConditions - ? "" - : commonStr) + - (!includeScores - ? "" - : scoresStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - /** - * Retrieve nique Tag Identifier ... - * - * @return ( string ) - */ - string GetTag() - { - return GetTypeName(this); - } - - // -}; - -// -// Implementation ... - -class XCX121Helper : public XCBaseHelper -{ - // - public: - // - - // - // Constructors ... - XCX121Helper() - : XCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XCX121Helper() - { - IndicatorRelease(mRSIHandler); - } - - // - // Tools ... - - /** - * Initialize Indicator Helper ... - * - * @param symbol: String, Symbol ... - * @param period: ENUM_TIMEFRAMES member, Period ... - * @param inputs: X121Inputs instance, Indicator Inputs ... - * - * @return ( bool ) - */ - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - X121Inputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - // Validate Inputs ... - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - // Setting Arrays As Series ... - ArraySetAsSeries(peaksBuffer, true); - ArraySetAsSeries(valesBuffer, true); - ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(atrUpperBuffer, true); - ArraySetAsSeries(atrLowerBuffer, true); - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(donOpenUpperBuffer, true); - ArraySetAsSeries(donOpenLowerBuffer, true); - ArraySetAsSeries(donCloseUpperBuffer, true); - ArraySetAsSeries(donCloseLowerBuffer, true); - ArraySetAsSeries(donHighUpperBuffer, true); - ArraySetAsSeries(donHighLowerBuffer, true); - ArraySetAsSeries(donLowUpperBuffer, true); - ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(fl1Buffer, true); - ArraySetAsSeries(fl2Buffer, true); - ArraySetAsSeries(fl3Buffer, true); - ArraySetAsSeries(fl4Buffer, true); - ArraySetAsSeries(fl5Buffer, true); - ArraySetAsSeries(cHHBuffer, true); - ArraySetAsSeries(cLLBuffer, true); - ArraySetAsSeries(sHHBuffer, true); - ArraySetAsSeries(sLLBuffer, true); - ArraySetAsSeries(mHHBuffer, true); - ArraySetAsSeries(mLLBuffer, true); - ArraySetAsSeries(lHHBuffer, true); - ArraySetAsSeries(lLLBuffer, true); - ArraySetAsSeries(hHHBuffer, true); - ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(atrBuffer, true); - ArraySetAsSeries(atrUpperRawBuffer, true); - ArraySetAsSeries(atrLowerRawBuffer, true); - ArraySetAsSeries(vwapVolumeBuffer, true); - ArraySetAsSeries(vwapPriceBuffer, true); - ArraySetAsSeries(vwapFastStateBuffer, true); - ArraySetAsSeries(vwapMidStateBuffer, true); - ArraySetAsSeries(vwapSlowStateBuffer, true); - ArraySetAsSeries(rsiBuffer, true); - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.x121", - // - // Inputs ... - // - // Cycles ... - "", - // - // Short ... - "", - mInputs.scMethod, - mInputs.scPeriod, - // - // Medium ... - "", - mInputs.mcMethod, - mInputs.mcPeriod, - // - // Long ... - "", - mInputs.lcMethod, - mInputs.lcPeriod, - // - // Hind ... - "", - mInputs.hcMethod, - mInputs.hcPeriod, - // - // Boundary Detection ... - "", - mInputs.hhMode, - mInputs.llMode, - // - // Parabolic Sar Detection ... - "", - mInputs.sarStep, - mInputs.sarMax, - // - // Atr Detection ... - "", - mInputs.atrLength, - mInputs.atrMultiplier, - mInputs.atrUpperAppliedTo, - mInputs.atrLowerAppliedTo, - mInputs.atrSmoothingMode, - // - // VWap Detection ... - "", - mInputs.vwapFastLength, - mInputs.vwapMidLength, - mInputs.vwapSlowLength, - mInputs.vwapAppliedTo, - // - // Donchain Detection ... - "", - mInputs.donchainLength, - // - // Presentation ... - "", - mInputs.startCalculationForLastBars, - // - // Commons ... - mInputs.showSar, - mInputs.showAtr, - mInputs.showPeaks, - mInputs.showVales, - mInputs.showVWap, - mInputs.showDonchain, - // - // Fibonachi Presentation ... - "", - mInputs.showFibo1Levels, - mInputs.showFibo2Levels, - mInputs.showFibo3Levels, - mInputs.showFibo4Levels, - mInputs.showFibo5Levels, - // - // Atr Presentation ... - "", - mInputs.showAtrUpper, - mInputs.showAtrLower, - // - // VWap Presentation ... - "", - mInputs.showVWapFast, - mInputs.showVWapMedium, - mInputs.showVWapSlow, - // - // Donchain Presentation ... - "", - mInputs.showUpper, - mInputs.showLower, - mInputs.showOpen, - mInputs.showHigh, - mInputs.showClose, - mInputs.showLow - // - // Non Important Inpust ... - // - // Fibonacci ... - // "", - // mInputs.fiboLevel1, - // mInputs.fiboLevel2, - // mInputs.fiboLevel3, - // mInputs.fiboLevel4, - // mInputs.fiboLevel5, - // // - // mInputs.sarArrowCode, - // mInputs.peaksArrowCode, - // mInputs.valesArrowCode - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - mRSIHandler = iRSI( - symbol, - period, - mInputs.rsiLength, - PRICE_CLOSE // - ); - result = mRSIHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Retrieve Current Indicator Configs ... - * - * @return ( Inputs ) - */ - X121Inputs GetInputs() - { - return mInputs; - } - - /** - * Set New Indicator Inputs ... - * - * @param inputs: X121Inputs instance, Indicator Inputs ... - * - * @return ( bool ) - */ - bool SetInputs( - X121Inputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Implement Value Getters ... - - // - // XRSI ... - - // - double GetRSI( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(rsiBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return rsiBuffer[barIndex]; - } - - // - int CopyRSI( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - rsiBuffer, - buffer, - forceClean - // - ); - } - - // - // SAR ... - - // - double GetSar( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sarBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sarBuffer[barIndex]; - } - - // - int CopySar( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sarBuffer, - buffer, - forceClean - // - ); - } - - // - // ATR ... - - // - // Common ... - - // - double GetAtr( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrBuffer[barIndex]; - } - - // - int CopyAtr( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrUpperBuffer[barIndex]; - } - - // - int CopyAtrUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrUpperBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrUpperRaw( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrUpperRawBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrUpperRawBuffer[barIndex]; - } - - // - int CopyAtrUpperRaw( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrUpperRawBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrLowerBuffer[barIndex]; - } - - // - int CopyAtrLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrLowerBuffer, - buffer, - forceClean - // - ); - } - - // - double GetAtrLowerRaw( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(atrLowerRawBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return atrLowerRawBuffer[barIndex]; - } - - // - int CopyAtrLowerRaw( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - atrLowerRawBuffer, - buffer, - forceClean - // - ); - } - - // - // PV ... - - // - // PEAKS ... - - // - double GetPeak( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(peaksBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return peaksBuffer[barIndex]; - } - - // - int CopyPeak( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - peaksBuffer, - buffer, - forceClean - // - ); - } - - // - // VALES ... - - // - double GetVale( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(valesBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return valesBuffer[barIndex]; - } - - // - int CopyVale( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - valesBuffer, - buffer, - forceClean - // - ); - } - - // - // - // - - // - double GetHigherPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (peak <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetPeak(index); - if (iValue > peak) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetLowerPeak( - double peak, // Peak Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (peak <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetPeak(index); - if (iValue < peak) - { - // - result = iValue; - break; - } - - // - canContinue = index < barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetHigherVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (vale <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetVale(index); - if (iValue > vale) - { - // - result = iValue; - break; - } - - // - canContinue = index > barIndex + loopback; - index++; - } - - // - return result; - } - - // - double GetLowerVale( - double vale, // Vale Source - int barIndex = 0, // Bar Index - int loopback = 576 // Max Allowed Loopback - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - if (vale <= 0) - { - return result; - } - - // - double iValue = 0; - int index = barIndex; - bool canContinue = true; - while (canContinue) - { - // - iValue = GetVale(index); - if (iValue < vale) - { - // - result = iValue; - break; - } - - // - canContinue = index > barIndex + loopback; - index++; - } - - // - return result; - } - - // - // - // - - // - double GetLowestPeak( - int barIndex, - int &index, - double &vale, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - vale = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetPeak(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result >= iPeak)) - { - // - index = i; - result = iPeak; - vale = GetVale(index); - } - } - - // - return result; - } - - // - double GetHighestPeak( - int barIndex, - int &index, - double &vale, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - vale = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetPeak(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result <= iPeak)) - { - // - index = i; - result = iPeak; - vale = GetVale(index); - } - } - - // - return result; - } - - // - double GetLowestVale( - int barIndex, - int &index, - double &peak, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - peak = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetVale(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result >= iPeak)) - { - // - index = i; - result = iPeak; - peak = GetPeak(index); - } - } - - // - return result; - } - - // - double GetHighestVale( - int barIndex, - int &index, - double &peak, - int loopback = 576 // - ) - { - // - double result = 0; - - // - index = -1; - peak = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 576) - { - loopback = 576; - } - - // - Calculate(); - - // - for (int i = 0; i < barIndex + loopback; i++) - { - // - double iPeak = GetVale(i); - if (iPeak == 0) - { - break; - } - - // - if (iPeak > 0 && (result == 0 || - result <= iPeak)) - { - // - index = i; - result = iPeak; - peak = GetPeak(index); - } - } - - // - return result; - } - - // - // CURRENT ... - - // - // HH ... - - // - double GetCHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cHHBuffer[barIndex]; - } - - // - int CopyCHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - cHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetCLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cLLBuffer[barIndex]; - } - - // - int CopyCLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - cLLBuffer, - buffer, - forceClean - // - ); - } - - // - // SHORT ... - - // - // HH ... - - // - double GetSHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sHHBuffer[barIndex]; - } - - // - int CopySHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetSLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sLLBuffer[barIndex]; - } - - // - int CopySLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - sLLBuffer, - buffer, - forceClean - // - ); - } - - // - // MEDIUM ... - - // - // HH ... - - // - double GetMHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mHHBuffer[barIndex]; - } - - // - int CopyMHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - mHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetMLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mLLBuffer[barIndex]; - } - - // - int CopyMLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - mLLBuffer, - buffer, - forceClean - // - ); - } - - // - // LONG ... - - // - // HH ... - - // - double GetLHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lHHBuffer[barIndex]; - } - - // - int CopyLHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - lHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetLLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lLLBuffer[barIndex]; - } - - // - int CopyLLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - lLLBuffer, - buffer, - forceClean - // - ); - } - - // - // HIND ... - - // - // HH ... - - // - double GetHHH( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hHHBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hHHBuffer[barIndex]; - } - - // - int CopyHHH( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - hHHBuffer, - buffer, - forceClean - // - ); - } - - // - // LL ... - - // - double GetHLL( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hLLBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hLLBuffer[barIndex]; - } - - // - int CopyHLL( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - hLLBuffer, - buffer, - forceClean - // - ); - } - - // - // VWAP ... - - // - // FAST ... - - // - double GetVWapFast( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapFastBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapFastBuffer[barIndex]; - } - - // - int CopyVWapFast( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapFastBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE FAST ... - - // - double GetVWapFastState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapFastStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapFastStateBuffer[barIndex]; - } - - // - int CopyVWapFastState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapFastStateBuffer, - buffer, - forceClean - // - ); - } - - // - // MID ... - - // - double GetVWapMid( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapMidBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapMidBuffer[barIndex]; - } - - // - int CopyVWapMid( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapMidBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE MID ... - - // - double GetVWapMidState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapMidStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapMidStateBuffer[barIndex]; - } - - // - int CopyVWapMidState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapMidStateBuffer, - buffer, - forceClean - // - ); - } - - // - // SLOW ... - - // - double GetVWapSlowBuffer( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapSlowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapSlowBuffer[barIndex]; - } - - // - int CopyVWapSlow( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapSlowBuffer, - buffer, - forceClean - // - ); - } - - // - // STATE SLOW ... - - // - double GetVWapSlowState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapSlowStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapSlowStateBuffer[barIndex]; - } - - // - int CopyVWapSlowState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapSlowStateBuffer, - buffer, - forceClean - // - ); - } - - // - // VOLUME ... - - // - double GetVWapVolume( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapVolumeBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapVolumeBuffer[barIndex]; - } - - // - int CopyVWapVolume( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapVolumeBuffer, - buffer, - forceClean - // - ); - } - - // - // PRICE ... - - // - double GetVWapPrice( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(vwapPriceBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return vwapPriceBuffer[barIndex]; - } - - // - int CopyVWapPrice( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - vwapPriceBuffer, - buffer, - forceClean - // - ); - } - - // - // Converts to State ... - ENUM_XVWAP_STATES ToVWAPState(double value) - { - // - ENUM_XVWAP_STATES result = - value == 1 - ? XVWAP_STATE_BULLISH - : value == 2 - ? XVWAP_STATE_BEARISH - : XVWAP_STATE_NEUTURAL; - - // - return result; - } - - // - bool IsVWAPBullish(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_BULLISH; - - // - return result; - } - - // - bool IsVWAPBearish(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_BEARISH; - - // - return result; - } - - // - bool IsVWAPNeutural(double value) - { - // - bool result = false; - - // - result = ToVWAPState(value) == XVWAP_STATE_NEUTURAL; - - // - return result; - } - - // - // XDON ... - - // - // OPEN ... - - // - // UPPER ... - - // - double GetDonOpenUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donOpenUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donOpenUpperBuffer[barIndex]; - } - - // - int CopyDonOpenUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donOpenUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonOpenLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donOpenLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donOpenLowerBuffer[barIndex]; - } - - // - int CopyDonOpenLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donOpenLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // CLOSE ... - - // - // UPPER ... - - // - double GetDonCloseUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donCloseUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donCloseUpperBuffer[barIndex]; - } - - // - int CopyDonCloseUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donCloseUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonCloseLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donCloseLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donCloseLowerBuffer[barIndex]; - } - - // - int CopyDonCloseLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donCloseLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // HIGH ... - - // - // UPPER ... - - // - double GetDonHighUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donHighUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donHighUpperBuffer[barIndex]; - } - - // - int CopyDonHighUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donHighUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonHighLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donHighLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donHighLowerBuffer[barIndex]; - } - - // - int CopyDonHighLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donHighLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // LOW ... - - // - // UPPER ... - - // - double GetDonLowUpper( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donLowUpperBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donLowUpperBuffer[barIndex]; - } - - // - int CopyDonLowUpper( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donLowUpperBuffer, - buffer, - forceClean - // - ); - } - - // - // LOWER ... - - // - double GetDonLoweLower( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(donLowLowerBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return donLowLowerBuffer[barIndex]; - } - - // - int CopyDonLoweLower( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - donLowLowerBuffer, - buffer, - forceClean - // - ); - } - - // - // FIBONACCHI ... - - // - // LEVEL 1 ... - - // - double GetFiboLevel1( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl1Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl1Buffer[barIndex]; - } - - // - int CopyFiboLevel1( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl1Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 2 ... - - // - double GetFiboLevel2( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl2Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl2Buffer[barIndex]; - } - - // - int CopyFiboLevel2( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl2Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 3 ... - - // - double GetFiboLevel3( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl3Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl3Buffer[barIndex]; - } - - // - int CopyFiboLevel3( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl3Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 4 ... - - // - double GetFiboLevel4( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl4Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl4Buffer[barIndex]; - } - - // - int CopyFiboLevel4( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl4Buffer, - buffer, - forceClean - // - ); - } - - // - // LEVEL 5 ... - - // - double GetFiboLevel5( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fl5Buffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fl5Buffer[barIndex]; - } - - // - int CopyFiboLevel5( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // FiboLevel To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fl5Buffer, - buffer, - forceClean - // - ); - } - - // - // Conditions Generation ... - - bool GetConditions( - X121Conditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = true; - - // - if (loopback < 5) - { - loopback = 5; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - XOHCL zBar; - result = zBar.Init( - mSymbol, - mPeriod, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - mSymbol, - mPeriod, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - mSymbol, - mPeriod, - pIndex // - ); - if (!result) - { - return result; - } - - // - // Buffers ... - - // - CopyRSI( - zIndex, - loopback, - conditions.rsiBuffer // - ); - - // - CopySar( - zIndex, - loopback, - conditions.sarBuffer // - ); - - // - CopyAtr( - zIndex, - loopback, - conditions.atrBuffer // - ); - - // - CopyAtrUpper( - zIndex, - loopback, - conditions.atrUpperBuffer // - ); - - // - CopyAtrUpperRaw( - zIndex, - loopback, - conditions.atrUpperRawBuffer // - ); - - // - CopyAtrLower( - zIndex, - loopback, - conditions.atrLowerBuffer // - ); - - // - CopyAtrLowerRaw( - zIndex, - loopback, - conditions.atrLowerRawBuffer // - ); - - // - CopyPeak( - zIndex, - loopback, - conditions.peaksBuffer // - ); - - // - CopyVale( - zIndex, - loopback, - conditions.valesBuffer // - ); - - // - CopyCHH( - zIndex, - loopback, - conditions.cHHBuffer // - ); - - // - CopyCLL( - zIndex, - loopback, - conditions.cLLBuffer // - ); - - // - CopySHH( - zIndex, - loopback, - conditions.sHHBuffer // - ); - - // - CopySLL( - zIndex, - loopback, - conditions.sLLBuffer // - ); - - // - CopyMHH( - zIndex, - loopback, - conditions.mHHBuffer // - ); - - // - CopyMLL( - zIndex, - loopback, - conditions.mLLBuffer // - ); - - // - CopyLHH( - zIndex, - loopback, - conditions.lHHBuffer // - ); - - // - CopyLLL( - zIndex, - loopback, - conditions.lLLBuffer // - ); - - // - CopyHHH( - zIndex, - loopback, - conditions.hHHBuffer // - ); - - // - CopyHLL( - zIndex, - loopback, - conditions.hLLBuffer // - ); - - // - CopyVWapFast( - zIndex, - loopback, - conditions.vwapFastBuffer // - ); - - // - CopyVWapFastState( - zIndex, - loopback, - conditions.vwapFastStateBuffer // - ); - - // - CopyVWapMid( - zIndex, - loopback, - conditions.vwapMidBuffer // - ); - - // - CopyVWapMidState( - zIndex, - loopback, - conditions.vwapMidStateBuffer // - ); - - // - CopyVWapSlow( - zIndex, - loopback, - conditions.vwapSlowBuffer // - ); - - // - CopyVWapSlowState( - zIndex, - loopback, - conditions.vwapSlowStateBuffer // - ); - - // - CopyVWapVolume( - zIndex, - loopback, - conditions.vwapVolumeBuffer // - ); - - // - CopyVWapPrice( - zIndex, - loopback, - conditions.vwapPriceBuffer // - ); - - // - CopyDonOpenUpper( - zIndex, - loopback, - conditions.donOpenUpperBuffer // - ); - - // - CopyDonOpenLower( - zIndex, - loopback, - conditions.donOpenLowerBuffer // - ); - - // - CopyDonCloseUpper( - zIndex, - loopback, - conditions.donCloseUpperBuffer // - ); - - // - CopyDonCloseLower( - zIndex, - loopback, - conditions.donCloseLowerBuffer // - ); - - // - CopyDonHighUpper( - zIndex, - loopback, - conditions.donHighUpperBuffer // - ); - - // - CopyDonHighLower( - zIndex, - loopback, - conditions.donHighLowerBuffer // - ); - - // - CopyDonLowUpper( - zIndex, - loopback, - conditions.donLowUpperBuffer // - ); - - // - CopyDonLoweLower( - zIndex, - loopback, - conditions.donLowLowerBuffer // - ); - - // - CopyFiboLevel1( - zIndex, - loopback, - conditions.fl1Buffer // - ); - - // - CopyFiboLevel2( - zIndex, - loopback, - conditions.fl2Buffer // - ); - - // - CopyFiboLevel3( - zIndex, - loopback, - conditions.fl3Buffer // - ); - - // - CopyFiboLevel4( - zIndex, - loopback, - conditions.fl4Buffer // - ); - - // - CopyFiboLevel5( - zIndex, - loopback, - conditions.fl5Buffer // - ); - - // - // Conditions ... - - // - int cIDX = 1; - int pIDX = cIDX + 1; - - // - // XRSI ... - - // - bool isRSIOverBought = conditions.rsiBuffer[cIDX] > mInputs.rsiOverBoughtLevel; - bool isRSIOverBoughtPrev = conditions.rsiBuffer[pIDX] > mInputs.rsiOverBoughtLevel; - - // - bool isRSICrossedOverOverBought = isRSIOverBought && - !isRSIOverBoughtPrev; - bool isRSICrossedUnderOverBought = !isRSIOverBought && - isRSIOverBoughtPrev; - - // - bool isRSIOverSold = conditions.rsiBuffer[cIDX] < mInputs.rsiOverSoldLevel; - bool isRSIOverSoldPrev = conditions.rsiBuffer[pIDX] < mInputs.rsiOverSoldLevel; - - // - bool isRSICrossedUnderOverSold = isRSIOverSold && - !isRSIOverSoldPrev; - bool isRSICrossedOverOverSold = !isRSIOverSold && - isRSIOverSoldPrev; - - // - // XSAR ... - - // - bool isSarBullish = conditions.sarBuffer[cIDX] < cBar.low; - bool isSarBullishPrev = conditions.sarBuffer[pIDX] < pBar.low; - - // - bool isSarBearish = conditions.sarBuffer[cIDX] > cBar.high; - bool isSarBearishPrev = conditions.sarBuffer[pIDX] > pBar.high; - - // - bool isSarSwitchedToBullish = isSarBullish && - !isSarBullishPrev; - bool isSarSwitchedToBearish = isSarBearish && - !isSarBearishPrev; - - // - // XPV ... - - // - bool isNewPeak = conditions.peaksBuffer[cIDX] != conditions.peaksBuffer[pIDX]; - bool isNewPeakOverLast = isNewPeak && - conditions.peaksBuffer[cIDX] > conditions.peaksBuffer[pIDX]; - bool isNewPeakUnderLast = isNewPeak && - conditions.peaksBuffer[cIDX] < conditions.peaksBuffer[pIDX]; - - // - bool isNewVale = conditions.valesBuffer[cIDX] != conditions.valesBuffer[pIDX]; - bool isNewValeOverLast = isNewVale && - conditions.valesBuffer[cIDX] > conditions.valesBuffer[pIDX]; - bool isNewValeUnderLast = isNewVale && - conditions.valesBuffer[cIDX] < conditions.valesBuffer[pIDX]; - - // - // XVWAP ... - - // - bool isVWapFastBullish = IsVWAPBullish(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastBullishPrev = IsVWAPBullish(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapFastBearish = IsVWAPBearish(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastBearishPrev = IsVWAPBearish(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapFastNeutural = IsVWAPNeutural(conditions.vwapFastStateBuffer[cIDX]); - bool isVWapFastNeuturalPrev = IsVWAPNeutural(conditions.vwapFastStateBuffer[pIDX]); - - // - bool isVWapMidBullish = IsVWAPBullish(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidBullishPrev = IsVWAPBullish(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapMidBearish = IsVWAPBearish(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidBearishPrev = IsVWAPBearish(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapMidNeutural = IsVWAPNeutural(conditions.vwapMidStateBuffer[cIDX]); - bool isVWapMidNeuturalPrev = IsVWAPNeutural(conditions.vwapMidStateBuffer[pIDX]); - - // - bool isVWapSlowBullish = IsVWAPBullish(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowBullishPrev = IsVWAPBullish(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapSlowBearish = IsVWAPBearish(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowBearishPrev = IsVWAPBearish(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapSlowNeutural = IsVWAPNeutural(conditions.vwapSlowStateBuffer[cIDX]); - bool isVWapSlowNeuturalPrev = IsVWAPNeutural(conditions.vwapSlowStateBuffer[pIDX]); - - // - bool isVWapFastOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; - bool isVWapFastOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapMidOverSlow = conditions.vwapMidBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; - bool isVWapMidOverSlowPrev = conditions.vwapMidBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFastUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; - bool isVWapFastUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapMidUnderSlow = conditions.vwapMidBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; - bool isVWapMidUnderSlowPrev = conditions.vwapMidBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapBullishState = isVWapFastBullish && - isVWapMidBullish && - isVWapSlowBullish; - bool isVWapBullishStatePrev = isVWapFastBullishPrev && - isVWapMidBullishPrev && - isVWapSlowBullishPrev; - - // - bool isVWapBearishState = isVWapFastBearish && - isVWapMidBearish && - isVWapSlowBearish; - bool isVWapBearishStatePrev = isVWapFastBearishPrev && - isVWapMidBearishPrev && - isVWapSlowBearishPrev; - - // - bool isVWapNeuturalState = isVWapFastNeutural && - isVWapMidNeutural && - isVWapSlowNeutural; - bool isVWapNeuturalStatePrev = isVWapFastNeuturalPrev && - isVWapMidNeuturalPrev && - isVWapSlowNeuturalPrev; - - // - bool isVWapBullishOrdered = isVWapFastOverMid && - isVWapMidOverSlow; - bool isVWapBullishOrderedPrev = isVWapFastOverMidPrev && - isVWapMidOverSlowPrev; - - // - bool isVWapBearishOrdered = isVWapFastUnderMid && - isVWapMidUnderSlow; - bool isVWapBearishOrderedPrev = isVWapFastUnderMidPrev && - isVWapMidUnderSlowPrev; - - // - bool isVWapSwitchedToBullishOrdered = isVWapBullishOrdered && - !isVWapBullishOrderedPrev; - bool isVWapSwitchedToBearishOrdered = isVWapBearishOrdered && - !isVWapBearishOrderedPrev; - - // - bool isVWapSwitchedToBullishState = isVWapBullishState && - !isVWapBullishStatePrev; - bool isVWapSwitchedToBearishState = isVWapBearishState && - !isVWapBearishStatePrev; - bool isVWapSwitchedToNeuturalState = isVWapNeuturalState && - !isVWapNeuturalStatePrev; - - // - // XDON ... - - // - // XFIBONACCI ... - - // - bool isOerFib1 = cBar.low > conditions.fl1Buffer[cIDX]; - bool isOerFib2 = cBar.low > conditions.fl2Buffer[cIDX]; - bool isOerFib3 = cBar.low > conditions.fl3Buffer[cIDX]; - bool isOerFib4 = cBar.low > conditions.fl4Buffer[cIDX]; - bool isOerFib5 = cBar.low > conditions.fl5Buffer[cIDX]; - - // - bool isUnderFib1 = cBar.high < conditions.fl1Buffer[cIDX]; - bool isUnderFib2 = cBar.high < conditions.fl2Buffer[cIDX]; - bool isUnderFib3 = cBar.high < conditions.fl3Buffer[cIDX]; - bool isUnderFib4 = cBar.high < conditions.fl4Buffer[cIDX]; - bool isUnderFib5 = cBar.high < conditions.fl5Buffer[cIDX]; - - // - bool isCloseOerFib1 = cBar.close > conditions.fl1Buffer[cIDX]; - bool isCloseOerFib2 = cBar.close > conditions.fl2Buffer[cIDX]; - bool isCloseOerFib3 = cBar.close > conditions.fl3Buffer[cIDX]; - bool isCloseOerFib4 = cBar.close > conditions.fl4Buffer[cIDX]; - bool isCloseOerFib5 = cBar.close > conditions.fl5Buffer[cIDX]; - - // - bool isCloseUnderFib1 = cBar.close < conditions.fl1Buffer[cIDX]; - bool isCloseUnderFib2 = cBar.close < conditions.fl2Buffer[cIDX]; - bool isCloseUnderFib3 = cBar.close < conditions.fl3Buffer[cIDX]; - bool isCloseUnderFib4 = cBar.close < conditions.fl4Buffer[cIDX]; - bool isCloseUnderFib5 = cBar.close < conditions.fl5Buffer[cIDX]; - - // - - // - // Set ... - conditions.isRSIOverBought = isRSIOverBought; - conditions.isRSICrossedOverOverBought = isRSICrossedOverOverBought; - conditions.isRSICrossedUnderOverBought = isRSICrossedUnderOverBought; - conditions.isRSIOverSold = isRSIOverSold; - conditions.isRSICrossedUnderOverSold = isRSICrossedUnderOverSold; - conditions.isRSICrossedOverOverSold = isRSICrossedOverOverSold; - conditions.isSarBullish = isSarBullish; - conditions.isSarBearish = isSarBearish; - conditions.isSarSwitchedToBullish = isSarSwitchedToBullish; - conditions.isSarSwitchedToBearish = isSarSwitchedToBearish; - conditions.isNewPeak = isNewPeak; - conditions.isNewPeakOverLast = isNewPeakOverLast; - conditions.isNewPeakUnderLast = isNewPeakUnderLast; - conditions.isNewVale = isNewVale; - conditions.isNewValeOverLast = isNewValeOverLast; - conditions.isNewValeUnderLast = isNewValeUnderLast; - conditions.isVWapFastBullish = isVWapFastBullish; - conditions.isVWapFastBearish = isVWapFastBearish; - conditions.isVWapFastNeutural = isVWapFastNeutural; - conditions.isVWapMidBullish = isVWapMidBullish; - conditions.isVWapMidBearish = isVWapMidBearish; - conditions.isVWapMidNeutural = isVWapMidNeutural; - conditions.isVWapSlowBullish = isVWapSlowBullish; - conditions.isVWapSlowBearish = isVWapSlowBearish; - conditions.isVWapSlowNeutural = isVWapSlowNeutural; - conditions.isVWapFastOverMid = isVWapFastOverMid; - conditions.isVWapMidOverSlow = isVWapMidOverSlow; - conditions.isVWapFastUnderMid = isVWapFastUnderMid; - conditions.isVWapMidUnderSlow = isVWapMidUnderSlow; - conditions.isVWapBullishState = isVWapBullishState; - conditions.isVWapBearishState = isVWapBearishState; - conditions.isVWapNeuturalState = isVWapNeuturalState; - conditions.isVWapBullishOrdered = isVWapBullishOrdered; - conditions.isVWapBearishOrdered = isVWapBearishOrdered; - conditions.isVWapSwitchedToBullishOrdered = isVWapSwitchedToBullishOrdered; - conditions.isVWapSwitchedToBearishOrdered = isVWapSwitchedToBearishOrdered; - conditions.isVWapSwitchedToBullishState = isVWapSwitchedToBullishState; - conditions.isVWapSwitchedToBearishState = isVWapSwitchedToBearishState; - conditions.isVWapSwitchedToNeuturalState = isVWapSwitchedToNeuturalState; - conditions.isOerFib1 = isOerFib1; - conditions.isOerFib2 = isOerFib2; - conditions.isOerFib3 = isOerFib3; - conditions.isOerFib4 = isOerFib4; - conditions.isOerFib5 = isOerFib5; - conditions.isUnderFib1 = isUnderFib1; - conditions.isUnderFib2 = isUnderFib2; - conditions.isUnderFib3 = isUnderFib3; - conditions.isUnderFib4 = isUnderFib4; - conditions.isUnderFib5 = isUnderFib5; - conditions.isCloseOerFib1 = isCloseOerFib1; - conditions.isCloseOerFib2 = isCloseOerFib2; - conditions.isCloseOerFib3 = isCloseOerFib3; - conditions.isCloseOerFib4 = isCloseOerFib4; - conditions.isCloseOerFib5 = isCloseOerFib5; - conditions.isCloseUnderFib1 = isCloseUnderFib1; - conditions.isCloseUnderFib2 = isCloseUnderFib2; - conditions.isCloseUnderFib3 = isCloseUnderFib3; - conditions.isCloseUnderFib4 = isCloseUnderFib4; - conditions.isCloseUnderFib5 = isCloseUnderFib5; - - // - return result; - } - - // - protected: - // - - // - private: - // - // Props ... - X121Inputs mInputs; // Inputs ... - - // - // Buffers ... - - // - int mRSIHandler; // RSI Handler ... - - // - // Buffers ... - double peaksBuffer[]; - double valesBuffer[]; - double sarBuffer[]; - double atrUpperBuffer[]; - double atrLowerBuffer[]; - double vwapFastBuffer[]; - double vwapMidBuffer[]; - double vwapSlowBuffer[]; - double donOpenUpperBuffer[]; - double donOpenLowerBuffer[]; - double donCloseUpperBuffer[]; - double donCloseLowerBuffer[]; - double donHighUpperBuffer[]; - double donHighLowerBuffer[]; - double donLowUpperBuffer[]; - double donLowLowerBuffer[]; - double fl1Buffer[]; - double fl2Buffer[]; - double fl3Buffer[]; - double fl4Buffer[]; - double fl5Buffer[]; - double cHHBuffer[]; - double cLLBuffer[]; - double sHHBuffer[]; - double sLLBuffer[]; - double mHHBuffer[]; - double mLLBuffer[]; - double lHHBuffer[]; - double lLLBuffer[]; - double hHHBuffer[]; - double hLLBuffer[]; - double atrBuffer[]; - double atrUpperRawBuffer[]; - double atrLowerRawBuffer[]; - double vwapVolumeBuffer[]; - double vwapPriceBuffer[]; - double vwapFastStateBuffer[]; - double vwapMidStateBuffer[]; - double vwapSlowStateBuffer[]; - double rsiBuffer[]; - - // - // Tools ... - - /** - * Calculate Buffers ... - */ - void Calculate() - { - // - int totalBars = CountBars(); - if (totalBars > 1000) - { - totalBars = 1000; - } - - // - // Buffers ... - - // - // RSI ... - CopyBuffer( - mRSIHandler, - 0, - 0, - totalBars, - rsiBuffer - // - ); - - // - // XSAR ... - CopyBuffer( - mHandler, - X121_SAR_LINE, - 0, - totalBars, - sarBuffer - // - ); - - // - // ATR ... - - // - CopyBuffer( - mHandler, - X121_ATR_UPPER_LINE, - 0, - totalBars, - atrUpperBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LOWER_LINE, - 0, - totalBars, - atrLowerBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LINE, - 0, - totalBars, - atrBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_UPPER_RAW_LINE, - 0, - totalBars, - atrUpperRawBuffer - // - ); - - // - CopyBuffer( - mHandler, - X121_ATR_LOWER_RAW_LINE, - 0, - totalBars, - atrLowerRawBuffer - // - ); - - // - // XPV ... - - // - // PEAKS ... - CopyBuffer( - mHandler, - X121_PEAKS_LINE, - 0, - totalBars, - peaksBuffer - // - ); - - // - // VALES ... - CopyBuffer( - mHandler, - X121_VALES_LINE, - 0, - totalBars, - valesBuffer - // - ); - - // - // CURRENT ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_CURRENT_HH_LINE, - 0, - totalBars, - cHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_CURRENT_LL_LINE, - 0, - totalBars, - cLLBuffer - // - ); - - // - // SHORT ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_SHORT_HH_LINE, - 0, - totalBars, - sHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_SHORT_LL_LINE, - 0, - totalBars, - sLLBuffer - // - ); - - // - // MEDIUM ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_MEDIUM_HH_LINE, - 0, - totalBars, - mHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_MEDIUM_LL_LINE, - 0, - totalBars, - mLLBuffer - // - ); - - // - // LONG ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_LONG_HH_LINE, - 0, - totalBars, - lHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_LONG_LL_LINE, - 0, - totalBars, - lLLBuffer - // - ); - - // - // HIND ... - - // - // HH ... - CopyBuffer( - mHandler, - X121_HIND_HH_LINE, - 0, - totalBars, - hHHBuffer - // - ); - - // - // LL ... - CopyBuffer( - mHandler, - X121_HIND_LL_LINE, - 0, - totalBars, - hLLBuffer - // - ); - - // - // XVWAP ... - - // - // FAST ... - CopyBuffer( - mHandler, - X121_VWAP_FAST_LINE, - 0, - totalBars, - vwapFastBuffer - // - ); - - // - // FAST STATE ... - CopyBuffer( - mHandler, - X121_VWAP_FAST_STATE_LINE, - 0, - totalBars, - vwapFastStateBuffer - // - ); - - // - // MID ... - CopyBuffer( - mHandler, - X121_VWAP_MID_LINE, - 0, - totalBars, - vwapMidBuffer - // - ); - - // - // MID STATE ... - CopyBuffer( - mHandler, - X121_VWAP_MID_STATE_LINE, - 0, - totalBars, - vwapMidStateBuffer - // - ); - - // - // SLOW ... - CopyBuffer( - mHandler, - X121_VWAP_SLOW_LINE, - 0, - totalBars, - vwapSlowBuffer - // - ); - - // - // SLOW STATE ... - CopyBuffer( - mHandler, - X121_VWAP_SLOW_STATE_LINE, - 0, - totalBars, - vwapSlowStateBuffer - // - ); - - // - // VOLUME ... - CopyBuffer( - mHandler, - X121_VWAP_VOLUME_LINE, - 0, - totalBars, - vwapVolumeBuffer - // - ); - - // - // PRICE ... - CopyBuffer( - mHandler, - X121_VWAP_PRICE_LINE, - 0, - totalBars, - vwapPriceBuffer - // - ); - - // - // FIBONACCI ... - - // - // LEVEL 1 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_1_LINE, - 0, - totalBars, - fl1Buffer - // - ); - - // - // LEVEL 2 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_2_LINE, - 0, - totalBars, - fl2Buffer - // - ); - - // - // LEVEL 3 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_3_LINE, - 0, - totalBars, - fl3Buffer - // - ); - - // - // LEVEL 4 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_4_LINE, - 0, - totalBars, - fl4Buffer - // - ); - - // - // LEVEL 5 ... - CopyBuffer( - mHandler, - X121_FIB_LEVEL_5_LINE, - 0, - totalBars, - fl5Buffer - // - ); - - // - // XDON ... - - // - // OPEN ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_OPEN_UPPER_LINE, - 0, - totalBars, - donOpenUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_OPEN_LOWER_LINE, - 0, - totalBars, - donOpenLowerBuffer - // - ); - - // - // CLOSE ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_CLOSE_UPPER_LINE, - 0, - totalBars, - donCloseUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_CLOSE_LOWER_LINE, - 0, - totalBars, - donCloseLowerBuffer - // - ); - - // - // HIGH ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_HIGH_UPPER_LINE, - 0, - totalBars, - donHighUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_HIGH_LOWER_LINE, - 0, - totalBars, - donHighLowerBuffer - // - ); - - // - // LOW ... - - // - // Upper ... - CopyBuffer( - mHandler, - X121_DON_LOW_UPPER_LINE, - 0, - totalBars, - donLowUpperBuffer - // - ); - - // - // Lower ... - CopyBuffer( - mHandler, - X121_DON_LOW_LOWER_LINE, - 0, - totalBars, - donLowLowerBuffer - // - ); - } -}; - -// \ No newline at end of file diff --git a/Documents/BKP/1/x-saherelm.x121.old.mq5 b/Documents/BKP/1/x-saherelm.x121.old.mq5 deleted file mode 100644 index 241e0133..00000000 --- a/Documents/BKP/1/x-saherelm.x121.old.mq5 +++ /dev/null @@ -1,2321 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 -// Description: Peaks and Vales ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121" - -// -// Includes Common Library ... -#include "../Classes/x-saherelm.x-poi.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -input group "Makret Cycles"; - -// -input group "Short"; -input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period - -// -input group "Medium"; -input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period - -// -input group "Long"; -input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period - -// -input group "Hind"; -input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period - -// -input group "Boundary Detection"; -input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method -input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method - -// -input group "Parabolic Sar Detection"; -input double sarStep = 0.02; // Step -input double sarMax = 0.2; // Maximum - -// -input group "Atr Detection"; -input int atrLength = 14; // Length -input double atrMultiplier = 1; // Multiplier -input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To -input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To -input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method - -// -input group "VWap Detection"; -input int vwapFastLength = 20; // Fast Length -input int vwapMidLength = 40; // Mid Length -input int vwapSlowLength = 60; // Slow Length -input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To - -// -input group "Donchain Detection"; -input int donchainLength = 40; // Donchain Length - -// -input group "Presentation"; - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -input bool showSar = true; // Show Parabolic Sar -input bool showAtr = true; // Show Atr -input bool showPeaks = true; // Show Peaks -input bool showVales = true; // Show Vales -input bool showVWap = true; // Show VWap -input bool showDonchain = true; // Show Donchain - -// -input group "Fibonachi Presentation"; -input bool showFibo1Levels = false; // Show Fibo 1st Level -input bool showFibo2Levels = false; // Show Fibo 2nd Level -input bool showFibo3Levels = false; // Show Fibo 3rd Level -input bool showFibo4Levels = false; // Show Fibo 4th Level -input bool showFibo5Levels = false; // Show Fibo 5th Level - -// -input group "Atr Presentation"; -input bool showAtrUpper = true; // Show Upper Zone -input bool showAtrLower = true; // Show Lower Zone - -// -input group "VWap Presentation"; -input bool showVWapFast = true; // Show VWap Fast -input bool showVWapMedium = true; // Show VWap Medium -input bool showVWapSlow = true; // Show VWap Slow - -// -input group "Donchain Presentation"; -input bool showUpper = true; // Show Upper Band -input bool showLower = true; // Show Lower Band -input bool showOpen = true; // Show Open -input bool showHigh = false; // Show High -input bool showClose = true; // Show Close -input bool showLow = false; // Show Low - -// -// Non Important Inputs ... - -// -input group "Fibonacci"; -input double fiboLevel1 = 0.236; // Fibio 1st Level -input double fiboLevel2 = 0.382; // Fibio 2st Level -input double fiboLevel3 = 0.5; // Fibio 3rd Level -input double fiboLevel4 = 0.618; // Fibio 4th Level -input double fiboLevel5 = 0.764; // Fibio 5th Level - -// -input int sarArrowCode = 159; // Parabolic Sar Arrow Code -input int peaksArrowCode = 159; // Peaks Arrow Code -input int valesArrowCode = 159; // Vales Arrow Code - -// -// Buffers ... - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -#property indicator_chart_window - -// -#property indicator_buffers 42 -#property indicator_plots 21 - -// -// PEAKS ... - -// -#define peaksBufferIndex 0 -double peaksBuffer[]; - -// -#property indicator_label1 "X121 PEAKS" -#property indicator_type1 DRAW_ARROW -#property indicator_color1 clrAqua -#property indicator_width1 1 - -// -// VALES ... - -// -#define valesBufferIndex 1 -double valesBuffer[]; - -// -#property indicator_label2 "X121 VALES" -#property indicator_type2 DRAW_ARROW -#property indicator_color2 clrMagenta -#property indicator_width2 1 - -// -// SAR ... - -// -#define sarBufferIndex 2 -double sarBuffer[]; - -// -#property indicator_label3 "X121 SAR" -#property indicator_type3 DRAW_ARROW -#property indicator_color3 clrYellow -#property indicator_width3 1 - -// -// ATR ... - -// -// Upper ... - -// -#define atrUpperBufferIndex 3 -double atrUpperBuffer[]; - -#property indicator_label4 "X121 ATRU" -#property indicator_type4 DRAW_LINE -#property indicator_color4 clrYellow -#property indicator_style4 STYLE_DOT -#property indicator_width4 2 - -// -// Lower ... - -// -#define atrLowerBufferIndex 4 -double atrLowerBuffer[]; - -#property indicator_label5 "X121 ATRL" -#property indicator_type5 DRAW_LINE -#property indicator_color5 clrYellow -#property indicator_style5 STYLE_DOT -#property indicator_width5 2 - -// -// VWAP ... - -// -// FAST ... -#define vwapFastBufferIndex 5 -double vwapFastBuffer[]; - -#define vwapFastColorBufferIndex 6 -double vwapFastColorBuffer[]; - -// -#define vwapFastPlotBufferIndex 5 -#property indicator_label6 "X121 VWF" -#property indicator_type6 DRAW_COLOR_LINE -#property indicator_color6 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style6 STYLE_SOLID -#property indicator_width6 2 - -// -// MID ... -#define vwapMidBufferIndex 7 -double vwapMidBuffer[]; - -#define vwapMidColorBufferIndex 8 -double vwapMidColorBuffer[]; - -// -#define vwapMidPlotBufferIndex 6 -#property indicator_label7 "X121 VWM" -#property indicator_type7 DRAW_COLOR_LINE -#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style7 STYLE_SOLID -#property indicator_width7 2 - -// -// SLOW ... -#define vwapSlowBufferIndex 9 -double vwapSlowBuffer[]; - -#define vwapSlowColorBufferIndex 10 -double vwapSlowColorBuffer[]; - -// -#define vwapSlowPlotBufferIndex 7 -#property indicator_label8 "X121 VWS" -#property indicator_type8 DRAW_COLOR_LINE -#property indicator_color8 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray -#property indicator_style8 STYLE_SOLID -#property indicator_width8 2 - -// -// XDON ... - -// -// Open ... - -// -#define donOpenUpperBufferIndex 11 -double donOpenUpperBuffer[]; - -// -#define donOpenUpperPlotBufferIndex 8 -#property indicator_label9 "X121 O U" -#property indicator_type9 DRAW_LINE -#property indicator_color9 clrCornflowerBlue -#property indicator_width9 1 - -// -#define donOpenLowerBufferIndex 12 -double donOpenLowerBuffer[]; - -// -#define donOpenLowerPlotBufferIndex 9 -#property indicator_label10 "X121 O L" -#property indicator_type10 DRAW_LINE -#property indicator_color10 clrCornflowerBlue -#property indicator_width10 1 - -// -// High ... - -// -#define donHighUpperBufferIndex 13 -double donHighUpperBuffer[]; - -// -#define donHighUpperPlotBufferIndex 10 -#property indicator_label11 "X121 H U" -#property indicator_type11 DRAW_LINE -#property indicator_color11 clrAquamarine -#property indicator_width11 1 - -// -#define donHighLowerBufferIndex 14 -double donHighLowerBuffer[]; - -// -#define donHighLowerPlotBufferIndex 11 -#property indicator_label12 "X121 H L" -#property indicator_type12 DRAW_LINE -#property indicator_color12 clrAquamarine -#property indicator_width12 1 - -// -// Low ... - -// -#define donLowUpperBufferIndex 15 -double donLowUpperBuffer[]; - -// -#define donLowUpperPlotBufferIndex 12 -#property indicator_label13 "X121 L U" -#property indicator_type13 DRAW_LINE -#property indicator_color13 clrDarkOrchid -#property indicator_width13 1 - -// -#define donLowLowerBufferIndex 16 -double donLowLowerBuffer[]; - -// -#define donLowLowerPlotBufferIndex 13 -#property indicator_label14 "X121 L L" -#property indicator_type14 DRAW_LINE -#property indicator_color14 clrDarkOrchid -#property indicator_width14 1 - -// -// Close ... - -// -#define donCloseUpperBufferIndex 17 -double donCloseUpperBuffer[]; - -// -#define donCloseUpperPlotBufferIndex 14 -#property indicator_label15 "X121 C U" -#property indicator_type15 DRAW_LINE -#property indicator_color15 clrCoral -#property indicator_width15 1 - -// -#define donCloseLowerBufferIndex 18 -double donCloseLowerBuffer[]; - -// -#define donCloseLowerPlotBufferIndex 15 -#property indicator_label16 "X121 C L" -#property indicator_type16 DRAW_LINE -#property indicator_color16 clrCoral -#property indicator_width16 1 - -// -// FIBONACCI ... - -// -// FIBBO Level 1 ... - -// -#define fl1BufferIndex 19 -double fl1Buffer[]; - -// -#define fl1PlotBufferIndex 16 -#property indicator_label17 "X121 FL1" -#property indicator_type17 DRAW_LINE -#property indicator_color17 clrGold -#property indicator_style17 STYLE_DASHDOTDOT -#property indicator_width17 1 - -// -// FIBBO Level 2 ... - -// -#define fl2BufferIndex 20 -double fl2Buffer[]; - -// -#define fl2PlotBufferIndex 17 -#property indicator_label18 "X121 FL2" -#property indicator_type18 DRAW_LINE -#property indicator_color18 clrGold -#property indicator_style18 STYLE_DASHDOTDOT -#property indicator_width18 1 - -// -// FIBBO Level 3 ... - -// -#define fl3BufferIndex 21 -double fl3Buffer[]; - -// -#define fl3PlotBufferIndex 18 -#property indicator_label19 "X121 FL3" -#property indicator_type19 DRAW_LINE -#property indicator_color19 clrGold -#property indicator_style19 STYLE_DASHDOTDOT -#property indicator_width19 1 - -// -// FIBBO Level 4 ... - -// -#define fl4BufferIndex 22 -double fl4Buffer[]; - -// -#define fl4PlotBufferIndex 19 -#property indicator_label20 "X121 FL4" -#property indicator_type20 DRAW_LINE -#property indicator_color20 clrGold -#property indicator_style20 STYLE_DASHDOTDOT -#property indicator_width20 1 - -// -// FIBBO Level 5 ... - -// -#define fl5BufferIndex 23 -double fl5Buffer[]; - -// -#define fl5PlotBufferIndex 20 -#property indicator_label21 "X121 FL5" -#property indicator_type21 DRAW_LINE -#property indicator_color21 clrGold -#property indicator_style21 STYLE_DASHDOTDOT -#property indicator_width21 1 - -// -// Data Buffers ... - -// -int mLastBufferIndex = 23; - -// -// CURRENT ... - -// -#define cHHBufferIndex mLastBufferIndex + 1 -double cHHBuffer[]; - -// -#define cLLBufferIndex mLastBufferIndex + 2 -double cLLBuffer[]; - -// -// SHORT ... - -// -#define sHHBufferIndex mLastBufferIndex + 3 -double sHHBuffer[]; - -// -#define sLLBufferIndex mLastBufferIndex + 4 -double sLLBuffer[]; - -// -// MEDIUM ... - -// -#define mHHBufferIndex mLastBufferIndex + 5 -double mHHBuffer[]; - -// -#define mLLBufferIndex mLastBufferIndex + 6 -double mLLBuffer[]; - -// -// LONG ... - -// -#define lHHBufferIndex mLastBufferIndex + 7 -double lHHBuffer[]; - -// -#define lLLBufferIndex mLastBufferIndex + 8 -double lLLBuffer[]; - -// -// HIND ... - -// -#define hHHBufferIndex mLastBufferIndex + 9 -double hHHBuffer[]; - -// -#define hLLBufferIndex mLastBufferIndex + 10 -double hLLBuffer[]; - -// -// VOLUME ... -#define vwapVolumeBufferIndex mLastBufferIndex + 11 -double vwapVolumeBuffer[]; - -// -// Price ... -#define vwapPriceBufferIndex mLastBufferIndex + 12 -double vwapPriceBuffer[]; - -// -// Fast State ... -#define vwapFastStateBufferIndex mLastBufferIndex + 13 -double vwapFastStateBuffer[]; - -// -// Mid State ... -#define vwapMidStateBufferIndex mLastBufferIndex + 14 -double vwapMidStateBuffer[]; - -// -// Slow State ... -#define vwapSlowStateBufferIndex mLastBufferIndex + 15 -double vwapSlowStateBuffer[]; - -// -// ATR ... - -#define atrBufferIndex mLastBufferIndex + 16 -double atrBuffer[]; - -#define atrUpperRawBufferIndex mLastBufferIndex + 17 -double atrUpperRawBuffer[]; - -#define atrLowerRawBufferIndex mLastBufferIndex + 18 -double atrLowerRawBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int maxLength; - -// -// SAR Handler ... -int sarHandler = INVALID_HANDLE; - -// -// ATR Handler ... -int atrHandler = INVALID_HANDLE; - -// -double mHideColorIDX = 0; - -// -// XMarketCycle sc; -int mSCLength = 0; -ENUM_TIMEFRAMES mSCPeriod = NULL; - -// -// XMarketCycle mc; -int mMCLength = 0; -ENUM_TIMEFRAMES mMCPeriod = NULL; - -// -// XMarketCycle lc; -int mLCLength = 0; -ENUM_TIMEFRAMES mLCPeriod = NULL; - -// -// XMarketCycle hc; -int mHCLength = 0; -ENUM_TIMEFRAMES mHCPeriod = NULL; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // SAR ... - sarHandler = iSAR( - _Symbol, - _Period, - sarStep, - sarMax // - ); - bool isInited = sarHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ATR ... - atrHandler = iATR( - _Symbol, - _Period, - atrLength // - ); - isInited = atrHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - if (!InitMarketCycles()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -/** - * De Initialize Indicator ... - * - * @param reason: Integer, De Initialization Reason ... - */ -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed - - // - IndicatorRelease(sarHandler); - IndicatorRelease(atrHandler); -} - -/** - * Calculate Bars ... - * - * @param rates_total: Integer, Total Bars on Chart ... - * @param prev_calculated: Integer, Total Calculated Bars on Charts ... - * @param time: DateTime Array, History of Open Time ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param low: Double Array, History of Low Prices ... - * @param close: Double Array, History of Close Prices ... - * @param tick_volume: Long, History of Tick Volumes on Bar ... - * @param volume: Long, History of Trade Volumes ... - * @param spread: Double, History of Spread Price ... - * - * @return ( int ) - */ -int OnCalculate( - const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[] // -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // Fill All Buffers by Zero ... - if (prev_calculated == 0) - { - // - ArrayInitialize(peaksBuffer, 0); - ArrayInitialize(valesBuffer, 0); - ArrayInitialize(sarBuffer, 0); - } - - // - // Validate Calculated Bars ... - - // - // SAR ... - int sarCalculatedBars = BarsCalculated(sarHandler); - - // - // ATR ... - int atrCalculatedBars = BarsCalculated(atrHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // SAR ... - sarCalculatedBars >= maxLength && - // - // ATR... - sarCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // SAR ... - int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); - - // - // ATR ... - int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // - // SAR ... - copiedSars > 0 && - copiedAtrs > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// Functions ... - -/** - * Validate Input Args for Initialization ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = - // - // PSAR ... - sarMax > 0 && - sarStep > 0 && - sarMax > sarStep && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // XDON ... - donchainLength > 0 && - // - // VWAP ... - vwapFastLength > 2 && - vwapMidLength > vwapFastLength && - vwapSlowLength > vwapMidLength && - // - // XPV ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - // XPV ... - result = MathMax(mSCLength, mMCLength); - result = MathMax(result, mLCLength); - result = MathMax(result, mHCLength); - - // - // XVWAP ... - result = MathMax(result, vwapFastLength); - result = MathMax(result, vwapMidLength); - result = MathMax(result, vwapSlowLength); - - // - // ATR ... - result = MathMax(result, atrLength); - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // PEAKS ... - - // - ENUM_DRAW_TYPE peaksDrawType = showPeaks ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(peaksBuffer, true); - SetIndexBuffer(peaksBufferIndex, peaksBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peaksBufferIndex, PLOT_SHOW_DATA, showPeaks); - PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, peaksDrawType); - - // - PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, peaksArrowCode); - - // - // VALES ... - - // - ENUM_DRAW_TYPE valesDrawType = showVales ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(valesBuffer, true); - SetIndexBuffer(valesBufferIndex, valesBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valesBufferIndex, PLOT_SHOW_DATA, showVales); - PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, valesDrawType); - - // - PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, valesArrowCode); - - // - // SAR ... - - // - ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(sarBuffer, true); - SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar); - PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); - - // - PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); - - // - // ATR ... - - // - // UPPER ... - bool canShowAtrUpper = showAtr && showAtrUpper; - ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrUpperBuffer, true); - SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType); - - // - // LOWER ... - bool canShowAtrLower = showAtr && showAtrLower; - ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrLowerBuffer, true); - SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType); - - // - // XVWAP ... - - // - // Fast ... - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapFastColorBuffer, true); - SetIndexBuffer(vwapFastBufferIndex, vwapFastBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapFastColorBufferIndex, vwapFastColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Mid ... - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(vwapMidColorBuffer, true); - SetIndexBuffer(vwapMidBufferIndex, vwapMidBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapMidColorBufferIndex, vwapMidColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Slow ... - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(vwapSlowColorBuffer, true); - SetIndexBuffer(vwapSlowBufferIndex, vwapSlowBuffer, INDICATOR_DATA); - SetIndexBuffer(vwapSlowColorBufferIndex, vwapSlowColorBuffer, INDICATOR_COLOR_INDEX); - - // - // XDON ... - - // - // Open ... - - // - // UPPER ... - bool canShowCOpenUpper = showDonchain && showUpper && showOpen; - ENUM_DRAW_TYPE donOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donOpenUpperBuffer, true); - SetIndexBuffer(donOpenUpperBufferIndex, donOpenUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donOpenUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); - PlotIndexSetInteger(donOpenUpperPlotBufferIndex, PLOT_DRAW_TYPE, donOpenUpperDrawType); - - // - // LOWER ... - bool canShowCOpenLower = showDonchain && showLower && showOpen; - ENUM_DRAW_TYPE donOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donOpenLowerBuffer, true); - SetIndexBuffer(donOpenLowerBufferIndex, donOpenLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donOpenLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); - PlotIndexSetInteger(donOpenLowerPlotBufferIndex, PLOT_DRAW_TYPE, donOpenLowerDrawType); - - // - // Close ... - - // - // UPPER ... - bool canShowCCloseUpper = showDonchain && showUpper && showClose; - ENUM_DRAW_TYPE donCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donCloseUpperBuffer, true); - SetIndexBuffer(donCloseUpperBufferIndex, donCloseUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donCloseUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); - PlotIndexSetInteger(donCloseUpperPlotBufferIndex, PLOT_DRAW_TYPE, donCloseUpperDrawType); - - // - // LOWER ... - bool canShowCCloseLower = showDonchain && showLower && showClose; - ENUM_DRAW_TYPE donCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donCloseLowerBuffer, true); - SetIndexBuffer(donCloseLowerBufferIndex, donCloseLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donCloseLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); - PlotIndexSetInteger(donCloseLowerPlotBufferIndex, PLOT_DRAW_TYPE, donCloseLowerDrawType); - - // - // High ... - - // - // UPPER ... - bool canShowCHighUpper = showDonchain && showUpper && showHigh; - ENUM_DRAW_TYPE donHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donHighUpperBuffer, true); - SetIndexBuffer(donHighUpperBufferIndex, donHighUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donHighUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); - PlotIndexSetInteger(donHighUpperPlotBufferIndex, PLOT_DRAW_TYPE, donHighUpperDrawType); - - // - // LOWER ... - bool canShowCHighLower = showDonchain && showLower && showHigh; - ENUM_DRAW_TYPE donHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donHighLowerBuffer, true); - SetIndexBuffer(donHighLowerBufferIndex, donHighLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donHighLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); - PlotIndexSetInteger(donHighLowerPlotBufferIndex, PLOT_DRAW_TYPE, donHighLowerDrawType); - - // - // Low ... - - // - // UPPER ... - bool canShowCLowUpper = showDonchain && showUpper && showLow; - ENUM_DRAW_TYPE donLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donLowUpperBuffer, true); - SetIndexBuffer(donLowUpperBufferIndex, donLowUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donLowUpperPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); - PlotIndexSetInteger(donLowUpperPlotBufferIndex, PLOT_DRAW_TYPE, donLowUpperDrawType); - - // - // LOWER ... - bool canShowCLowLower = showDonchain && showLower && showLow; - ENUM_DRAW_TYPE donLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(donLowLowerBuffer, true); - SetIndexBuffer(donLowLowerBufferIndex, donLowLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(donLowLowerPlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); - PlotIndexSetInteger(donLowLowerPlotBufferIndex, PLOT_DRAW_TYPE, donLowLowerDrawType); - - // - // FIBONNACI ... - - // - // LEVEL 1 ... - bool canShowFl1 = showFibo1Levels; - ENUM_DRAW_TYPE fl1DrawType = canShowFl1 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl1Buffer, true); - SetIndexBuffer(fl1BufferIndex, fl1Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl1PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_SHOW_DATA, canShowFl1); - PlotIndexSetInteger(fl1PlotBufferIndex, PLOT_DRAW_TYPE, fl1DrawType); - - // - // LEVEL 2 ... - bool canShowFl2 = showFibo2Levels; - ENUM_DRAW_TYPE fl2DrawType = canShowFl2 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl2Buffer, true); - SetIndexBuffer(fl2BufferIndex, fl2Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl2PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_SHOW_DATA, canShowFl2); - PlotIndexSetInteger(fl2PlotBufferIndex, PLOT_DRAW_TYPE, fl2DrawType); - - // - // LEVEL 3 ... - bool canShowFl3 = showFibo3Levels; - ENUM_DRAW_TYPE fl3DrawType = canShowFl3 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl3Buffer, true); - SetIndexBuffer(fl3BufferIndex, fl3Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl3PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_SHOW_DATA, canShowFl3); - PlotIndexSetInteger(fl3PlotBufferIndex, PLOT_DRAW_TYPE, fl3DrawType); - - // - // LEVEL 4 ... - bool canShowFl4 = showFibo4Levels; - ENUM_DRAW_TYPE fl4DrawType = canShowFl4 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl4Buffer, true); - SetIndexBuffer(fl4BufferIndex, fl4Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl4PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_SHOW_DATA, canShowFl4); - PlotIndexSetInteger(fl4PlotBufferIndex, PLOT_DRAW_TYPE, fl4DrawType); - - // - // LEVEL 5 ... - bool canShowFl5 = showFibo5Levels; - ENUM_DRAW_TYPE fl5DrawType = canShowFl5 ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fl5Buffer, true); - SetIndexBuffer(fl5BufferIndex, fl5Buffer, INDICATOR_DATA); - PlotIndexSetDouble(fl5PlotBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_SHOW_DATA, canShowFl5); - PlotIndexSetInteger(fl5PlotBufferIndex, PLOT_DRAW_TYPE, fl5DrawType); - - // - // Data Buffers ... - - // - // CURRENT ... - - // - ArraySetAsSeries(cHHBuffer, true); - SetIndexBuffer(cHHBufferIndex, cHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(cLLBuffer, true); - SetIndexBuffer(cLLBufferIndex, cLLBuffer, INDICATOR_CALCULATIONS); - - // - // SHORT ... - - // - ArraySetAsSeries(sHHBuffer, true); - SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(sLLBuffer, true); - SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_CALCULATIONS); - - // - // MEDIUM ... - - // - ArraySetAsSeries(mHHBuffer, true); - SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(mLLBuffer, true); - SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_CALCULATIONS); - - // - // LONG ... - - // - ArraySetAsSeries(lHHBuffer, true); - SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(lLLBuffer, true); - SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_CALCULATIONS); - - // - // HIND ... - - // - ArraySetAsSeries(hHHBuffer, true); - SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(hLLBuffer, true); - SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS); - - // - // XVWAP ... - - // - // Volumes ... - ArraySetAsSeries(vwapVolumeBuffer, true); - SetIndexBuffer(vwapVolumeBufferIndex, vwapVolumeBuffer, INDICATOR_CALCULATIONS); - - // - // Price ... - ArraySetAsSeries(vwapPriceBuffer, true); - SetIndexBuffer(vwapPriceBufferIndex, vwapPriceBuffer, INDICATOR_CALCULATIONS); - - // - // Fast State ... - ArraySetAsSeries(vwapFastStateBuffer, true); - SetIndexBuffer(vwapFastStateBufferIndex, vwapFastStateBuffer, INDICATOR_CALCULATIONS); - - // - // Mid State ... - ArraySetAsSeries(vwapMidStateBuffer, true); - SetIndexBuffer(vwapMidStateBufferIndex, vwapMidStateBuffer, INDICATOR_CALCULATIONS); - - // - // Slow State ... - ArraySetAsSeries(vwapSlowStateBuffer, true); - SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS); - - // - // ATR ... - - // - ArraySetAsSeries(atrBuffer, true); - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(atrUpperRawBuffer, true); - SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(atrLowerRawBuffer, true); - SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Calculate Custom Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int barsLimit = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : 0; - // - // bool canCalculate = true; - bool canCalculate = - barsLimit == 0 || - bar_index <= barsLimit; - if (canCalculate) - { - // - // Calculate Cycles ... - CalculateCycles(bar_index); - - // - // Calculate Peaks and Vales ... - CalculatePeaksAndVales(bar_index); - - // - CalculateDonchains( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateAtrZones( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low // - ); - - // - CalculateFibonacci( - bar_index // - ); - - // - // Calculate Required VWAP Data Buffers ... - if (ratesTotal - bar_index <= maxLength) - { - // - CalculateVWAPDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - // Prevent Moving Forward ... - } - else - { - // - CalculateVWAPDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateVWAPS( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - } - else - { - FillBuffersZero(bar_index); - } -} - -// -// Custom ... - -/** - * Initial Market Cycles ... - * - * @return ( bool ) - */ -bool InitMarketCycles() -{ - // - bool result = false; - - // - int cPeriodSeconds = PeriodSeconds(_Period); - - // - // Find Cycle Period ... - if (scMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mSCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_SHORT, - _Period // - ); - } - else - { - mSCPeriod = scPeriod; - } - - // - if (IsValid(mSCPeriod)) - { - mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (mcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mMCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_MEDIUM, - _Period // - ); - } - else - { - mMCPeriod = mcPeriod; - } - - // - if (IsValid(mMCPeriod)) - { - mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (lcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mLCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_LONG, - _Period // - ); - } - else - { - mLCPeriod = lcPeriod; - } - - // - if (IsValid(mLCPeriod)) - { - mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (hcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mHCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_HIND, - _Period // - ); - } - else - { - mHCPeriod = hcPeriod; - } - - // - if (IsValid(mHCPeriod)) - { - mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; - } - - // - result = mSCLength > 0 && - mMCLength > mSCLength && - mLCLength > mMCLength && - mHCLength > mLCLength; - - // - return result; -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - // CURRENT ... - cHHBuffer[barIndex] = 0; - cLLBuffer[barIndex] = 0; - - // - // SHORT ... - sHHBuffer[barIndex] = 0; - sLLBuffer[barIndex] = 0; - - // - // MEDIUM ... - mHHBuffer[barIndex] = 0; - mLLBuffer[barIndex] = 0; - - // - // LONG ... - lHHBuffer[barIndex] = 0; - lLLBuffer[barIndex] = 0; - - // - // HIND ... - hHHBuffer[barIndex] = 0; - hLLBuffer[barIndex] = 0; - - // - // PEAKS ... - peaksBuffer[barIndex] = 0; - - // - // VALES ... - valesBuffer[barIndex] = 0; - - // - // SARS ... - sarBuffer[barIndex] = 0; - - // - // ATRS ... - atrBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrUpperRawBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrLowerRawBuffer[barIndex] = 0; - - // - // VWAP ... - - // - vwapFastBuffer[barIndex] = 0; - vwapMidBuffer[barIndex] = 0; - vwapSlowBuffer[barIndex] = 0; - vwapVolumeBuffer[barIndex] = 0; - vwapPriceBuffer[barIndex] = 0; - - // - vwapFastColorBuffer[barIndex] = hideColorIDX; - vwapMidColorBuffer[barIndex] = hideColorIDX; - vwapSlowColorBuffer[barIndex] = hideColorIDX; - vwapFastStateBuffer[barIndex] = hideColorIDX; - vwapMidStateBuffer[barIndex] = hideColorIDX; - vwapSlowStateBuffer[barIndex] = hideColorIDX; - - // - donOpenUpperBuffer[barIndex] = 0; - donOpenLowerBuffer[barIndex] = 0; - donCloseUpperBuffer[barIndex] = 0; - donCloseLowerBuffer[barIndex] = 0; - donHighUpperBuffer[barIndex] = 0; - donHighLowerBuffer[barIndex] = 0; - donLowUpperBuffer[barIndex] = 0; - donLowLowerBuffer[barIndex] = 0; - - // - fl1Buffer[barIndex] = 0; - fl2Buffer[barIndex] = 0; - fl3Buffer[barIndex] = 0; - fl4Buffer[barIndex] = 0; - fl5Buffer[barIndex] = 0; -} - -/** - * Calculate Specified Market Cycle Info ... - * - * @param barIndex: Integer, Bar Index ... - * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... - * @param hhBuffer: Highest High Buffer Reference ... - * @param llBuffer: Lowest Low Buffer Reference ... - */ -void CalculateCycle( - int barIndex, - ENUM_X_MARKET_CYCLES cycle, - double &hhBuffer[], - double &llBuffer[] // -) -{ - // - XOHCL bar; - bool isBarInited = bar.Init( - _Symbol, - _Period, - barIndex - // - ); - if (!isBarInited) - { - return; - } - - // - int mLength = 0; - switch (cycle) - { - // - case X_MARKET_CYCLE_SHORT: - mLength = mSCLength; - break; - - // - case X_MARKET_CYCLE_MEDIUM: - mLength = mMCLength; - break; - - // - case X_MARKET_CYCLE_LONG: - mLength = mLCLength; - break; - - // - case X_MARKET_CYCLE_HIND: - mLength = mHCLength; - break; - } - - // - if (mLength == 0) - { - return; - } - - // - // Find Highest High ... - double hhValue = bar.FindHighest( - mLength, - hhMode - // - ); - hhBuffer[barIndex] = hhValue; - - // - // Find Lowest Low ... - double llValue = bar.FindLowest( - mLength, - llMode - // - ); - llBuffer[barIndex] = llValue; -} - -/** - * Claculate Cycles ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculateCycles(int barIndex) -{ - // - // SHORT ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_SHORT, - sHHBuffer, - sLLBuffer // - ); - - // - // MEDIUM ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_MEDIUM, - mHHBuffer, - mLLBuffer // - ); - - // - // LONG ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_LONG, - lHHBuffer, - lLLBuffer // - ); - - // - // HIND ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_HIND, - hHHBuffer, - hLLBuffer // - ); -} - -/** - * Calculate Peaks and Vales ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculatePeaksAndVales(int barIndex) -{ - // - int lastIndex = barIndex + 1; - int barsCount = iBars(_Symbol, _Period); - - // - // PEAKS ... - double lastPeak = - lastIndex < barsCount - ? peaksBuffer[lastIndex] - : 0; - - // - double isHH = sHHBuffer[barIndex]; - double imHH = mHHBuffer[barIndex]; - double ilHH = lHHBuffer[barIndex]; - double ihHH = hHHBuffer[barIndex]; - - // - double iHHs[4] = { - isHH, - imHH, - ilHH, - ihHH // - }; - double rValue = GetAverage(iHHs); - bool isPeak = rValue == isHH && - isHH == imHH && - imHH == ilHH && - ilHH == ihHH; - double iPeak = - isPeak - ? rValue - : lastPeak; - peaksBuffer[barIndex] = iPeak; - - // - // VALES ... - double lastVale = - lastIndex < barsCount - ? valesBuffer[lastIndex] - : 0; - - // - double isLL = sLLBuffer[barIndex]; - double imLL = mLLBuffer[barIndex]; - double ilLL = lLLBuffer[barIndex]; - double ihLL = hLLBuffer[barIndex]; - - // - double iLLs[4] = { - isLL, - imLL, - ilLL, - ihLL // - }; - double sValue = GetAverage(iLLs); - bool isVale = sValue == isLL && - isLL == imLL && - imLL == ilLL && - ilLL == ihLL; - double iVale = - isVale - ? sValue - : lastVale; - valesBuffer[barIndex] = iVale; -} - -/** - * Calculate VWAP Value for Specified Bar ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - * @param _length: Integer, Specified VWAP Length ... - * @param _show: Boolean, Specified Show Buffer or not ... - * @param _buffer: Double Array Reference, Points to Buffer ... - * @param _colorBuffer: Double Array Reference, Points to Color Buffer ... - * @param _stateBuffer: Double Array Reference, Points to State Buffer ... - */ -void CalculateVWAP( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[], - // - int _length, // Calculation Length - bool _show, - double &_buffer[], - double &_colorBuffer[], - double &_stateBuffer[] // -) -{ - // - double vSum = 0; - double pSum = 0; - double mSum = 0; - for (int x = 0; x < _length; x++) - { - // - pSum += vwapPriceBuffer[x + bar_index]; - vSum += vwapVolumeBuffer[x + bar_index]; - mSum += vwapPriceBuffer[x + bar_index] * vwapVolumeBuffer[x + bar_index]; - } - - // - double iValue = mSum / vSum; - iValue = NormalizeDouble(iValue, _Digits); - - // - _buffer[bar_index] = iValue; - - // - bool isBullish = low[bar_index] > iValue; - bool isBearish = high[bar_index] < iValue; - - // - double iColor = - isBullish - ? bullishColorIDX - : isBearish - ? bearishColorIDX - : neuturalColorIDX; - - // - _colorBuffer[bar_index] = hideColorIDX; - _stateBuffer[bar_index] = iColor; - if (showVWap && _show) - { - _colorBuffer[bar_index] = iColor; - } -} - -/** - * Calculate Donchain ... - * - * @param bar_index: Integer, Bar Index ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - * @param _length: Integer, Donchain Length ... - * @param _ouBuffer: Double Array Reference ... - * @param _olBuffer: Double Array Reference ... - * @param _huBuffer: Double Array Reference ... - * @param _hlBuffer: Double Array Reference ... - * @param _luBuffer: Double Array Reference ... - * @param _llBuffer: Double Array Reference ... - * @param _cuBuffer: Double Array Reference ... - * @param _clBuffer: Double Array Reference ... - */ -void CalculateDonchain( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - // - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[], - // - int _length, - // - double &_ouBuffer[], - double &_olBuffer[], - double &_huBuffer[], - double &_hlBuffer[], - double &_luBuffer[], - double &_llBuffer[], - double &_cuBuffer[], - double &_clBuffer[] // -) -{ - // - double iUpper = 0; - double iLower = 0; - - // - // OPEN ... - - // - int from = bar_index; - - // - iUpper = open[ArrayMaximum(open, from, _length)]; - iLower = open[ArrayMinimum(open, from, _length)]; - - // - _ouBuffer[bar_index] = iUpper; - _olBuffer[bar_index] = iLower; - - // - // HIGH ... - - // - iUpper = high[ArrayMaximum(high, from, _length)]; - iLower = high[ArrayMinimum(high, from, _length)]; - - // - _huBuffer[bar_index] = iUpper; - _hlBuffer[bar_index] = iLower; - - // - // LOW ... - - // - iUpper = low[ArrayMaximum(low, from, _length)]; - iLower = low[ArrayMinimum(low, from, _length)]; - - // - _luBuffer[bar_index] = iUpper; - _llBuffer[bar_index] = iLower; - - // - // CLOSE ... - - // - iUpper = close[ArrayMaximum(close, from, _length)]; - iLower = close[ArrayMinimum(close, from, _length)]; - - // - _cuBuffer[bar_index] = iUpper; - _clBuffer[bar_index] = iLower; -} - -/** - * Calculate VWAP Required Data Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateVWAPDataBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - double price = GetAppliedPrice( - vwapAppliedTo, - open, - high, - low, - close, - bar_index // - ); - vwapPriceBuffer[bar_index] = price; - vwapVolumeBuffer[bar_index] = (double)tickVolume[bar_index]; -} - -/** - * Calculate Different VWaps ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateVWAPS( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapFastLength, - showVWapFast, - vwapFastBuffer, - vwapFastColorBuffer, - vwapFastStateBuffer // - ); - - // - // Mid ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapMidLength, - showVWapMedium, - vwapMidBuffer, - vwapMidColorBuffer, - vwapMidStateBuffer // - ); - - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - vwapSlowLength, - showVWapSlow, - vwapSlowBuffer, - vwapSlowColorBuffer, - vwapSlowStateBuffer // - ); -} - -/** - * Calculate Different VWaps ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateDonchains( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - CalculateDonchain( - // - bar_index, - prevCalculated, - ratesTotal, - // - open, - high, - close, - low, - tickVolume, - // - donchainLength, - // - donOpenUpperBuffer, - donOpenLowerBuffer, - donHighUpperBuffer, - donHighLowerBuffer, - donLowUpperBuffer, - donLowLowerBuffer, - donCloseUpperBuffer, - donCloseLowerBuffer // - ); -} - -/** - * Calculate Different VWaps ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - */ -void CalculateAtrZones( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[] // -) -{ - // - // Select ATr Value ... - double atrValue = atrBuffer[bar_index]; - double appliedAtrMultiplierValue = atrValue * atrMultiplier; - - // - // Select Upper Price ... - double upperPrice = GetAppliedPrice( - atrUpperAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Select Lower Price ... - double lowerPrice = GetAppliedPrice( - atrLowerAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Calculate Raw Atrs ... - - // - // Upper ... - double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue; - atrUpperRawBuffer[bar_index] = atrUpperRawValue; - - // - // Lower ... - double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue; - atrLowerRawBuffer[bar_index] = atrLowerRawValue; - - // - bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE; - if (canSmooth) - { - // - // Upper ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrUpperRawBuffer, - atrUpperBuffer, - atrSmoothingMode // - ); - - // - // Lower ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrLowerRawBuffer, - atrLowerBuffer, - atrSmoothingMode // - ); - } - else - { - // - // Use Raw Values ... - atrUpperBuffer[bar_index] = atrUpperRawValue; - atrLowerBuffer[bar_index] = atrLowerRawValue; - } -} - -/** - * Calculate Fibonacci Levels ... - * - * @param bar_index: Integer, current Bar Index ... - */ -void CalculateFibonacci( - int bar_index // -) -{ - // - double fiboUpper = 0; - double fiboLower = 0; - - // - fiboUpper = peaksBuffer[bar_index]; - fiboLower = valesBuffer[bar_index]; - - // - // Level 1 ... - bool canCalculateFiboLevel1 = fiboLevel1 > 0; - if (canCalculateFiboLevel1) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel1, - 1 // - ); - - // - fl1Buffer[bar_index] = iFib; - } - - // - // Level 2 ... - bool canCalculateFiboLevel2 = fiboLevel2 > 0; - if (canCalculateFiboLevel2) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel2, - 1 // - ); - - // - fl2Buffer[bar_index] = iFib; - } - - // - // Level 3 ... - bool canCalculateFiboLevel3 = fiboLevel3 > 0; - if (canCalculateFiboLevel3) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel3, - 1 // - ); - - // - fl3Buffer[bar_index] = iFib; - } - - // - // Level 4 ... - bool canCalculateFiboLevel4 = fiboLevel4 > 0; - if (canCalculateFiboLevel4) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel4, - 1 // - ); - - // - fl4Buffer[bar_index] = iFib; - } - - // - // Level 5 ... - bool canCalculateFiboLevel5 = fiboLevel5 > 0; - if (canCalculateFiboLevel5) - { - // - double iFib = GetFibonacciLevel( - fiboUpper, - fiboLower, - fiboLevel5, - 1 // - ); - - // - fl5Buffer[bar_index] = iFib; - } - - // -} - -// \ No newline at end of file diff --git a/Documents/BKP/1/x-saherelm.x121.xempty.mq5 b/Documents/BKP/1/x-saherelm.x121.xempty.mq5 deleted file mode 100644 index bec347c3..00000000 --- a/Documents/BKP/1/x-saherelm.x121.xempty.mq5 +++ /dev/null @@ -1,325 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 ??? -// Description: ??? ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 ??? Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121 ???" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -// Market ... -input group "Market"; - -// -// Presentation ... -input group "Presentation"; - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -// Buffers ... - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -#property indicator_chart_window - -// -#property indicator_buffers 0 -#property indicator_plots 0 - -// -// Plot Buffers ... - -// -// Data Buffers ... - -// -int mLastBufferIndex = 20; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int maxLength; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -/** - * De Initialize Indicator ... - * - * @param reason: Integer, De Initialization Reason ... - */ -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed -} - -/** - * Calculate Bars ... - * - * @param rates_total: Integer, Total Bars on Chart ... - * @param prev_calculated: Integer, Total Calculated Bars on Charts ... - * @param time: DateTime Array, History of Open Time ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param low: Double Array, History of Low Prices ... - * @param close: Double Array, History of Close Prices ... - * @param tick_volume: Long, History of Tick Volumes on Bar ... - * @param volume: Long, History of Trade Volumes ... - * @param spread: Double, History of Spread Price ... - * - * @return ( int ) - */ -int OnCalculate( - const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[] // -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // Validate Calculated Bars ... - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// Functions ... - -/** - * Validate Input Args for Initialization ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = false; - - // - result = - // - false - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // Data Buffers ... -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Calculate Custom Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int barsLimit = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : 0; - // - // bool canCalculate = true; - bool canCalculate = - barsLimit == 0 || - bar_index <= barsLimit; - if (canCalculate) - { - } - else - { - FillBuffersZero(bar_index); - } -} - -// -// Custom ... - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ -} - -// \ No newline at end of file diff --git a/Documents/BKP/2/tmp.signalling.mq5 b/Documents/BKP/2/tmp.signalling.mq5 deleted file mode 100644 index 7b176004..00000000 --- a/Documents/BKP/2/tmp.signalling.mq5 +++ /dev/null @@ -1,1302 +0,0 @@ - - // - // X Signal ... - bool DetectXSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_X; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXConditions.setupTime; - bool isSetuped = mXConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXSiganlSetup( - symbol, - period, - mXConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXConditions.dir; - setupTime = mXConditions.setupTime; - - // // - // bool hasPivot = mXConditions.pivotZone.IsValid(); - // if (hasPivot) - // { - // // - // XCBaseObject *drawnObjects[]; - // int drawnCount = DrawX121SMCXConditions( - // mXConditions, - // drawnObjects, - // mPOIDrawer // - // ); - // if (IsValidSize(drawnCount)) - // { - // AddObjectsIfNotExists(drawnObjects); - // } - // } - - // - if (isSetuped) - { - // - int items = AddX121SMCXConditionsIfNotExists( - mXConditions, - mXConditionsCollection // - ); - - // - mXConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXSignalConditions mTmpConditions[]; - Copy( - mXConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXSignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXSiganlTrigger( - mTmpConditions[i], - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - return result; - } - - // - // XPZ Signal ... - bool DetectXPZSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPZ; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPZConditions.setupTime; - bool isSetuped = mXPZConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPZConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPZSiganlSetup( - symbol, - period, - mXPZConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPZConditions.dir; - setupTime = mXPZConditions.setupTime; - - // - if (isSetuped) - { - // - int items = AddX121SMCXPZConditionsIfNotExists( - mXPZConditions, - mXPZConditionsCollection // - ); - - // - mXPZConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXPZConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXPZSignalConditions mTmpConditions[]; - Copy( - mXPZConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXPZSignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPZSiganlTrigger( - mTmpConditions[i], - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXPZConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXPZConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - return result; - } - - // - // XPVT Signal ... - bool DetectXPVTSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVT; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVTConditions.setupTime; - bool isSetuped = mXPVTConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVTConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVTSiganlSetup( - symbol, - period, - mXPVTConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPVTConditions.dir; - setupTime = mXPVTConditions.setupTime; - - // - if (isSetuped) - { - // - int items = AddX121SMCXPVTConditionsIfNotExists( - mXPVTConditions, - mXPVTConditionsCollection // - ); - - // - mXPVTConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXPVTConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXPVTSignalConditions mTmpConditions[]; - Copy( - mXPVTConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXPVTSignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVTSiganlTrigger( - mTmpConditions[i], - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXPVTConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXPVTConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - return result; - } - - // - // XSTRPV Signal ... - bool DetectXSTRPVSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSTRPV; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXSTRPVConditions.setupTime; - bool isSetuped = mXSTRPVConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXSTRPVConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXSTRPVSiganlSetup( - symbol, - period, - mXSTRPVConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXSTRPVConditions.dir; - setupTime = mXSTRPVConditions.setupTime; - - // - if (isSetuped) - { - // - int items = AddX121SMCXSTRPVConditionsIfNotExists( - mXSTRPVConditions, - mXSTRPVConditionsCollection // - ); - - // - mXSTRPVConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXSTRPVConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXSTRPVSignalConditions mTmpConditions[]; - Copy( - mXSTRPVConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXSTRPVSignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXSTRPVSiganlTrigger( - mTmpConditions[i], - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXSTRPVConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXSTRPVConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - return result; - } - - // - // XRSPVI Signal ... - bool DetectXRSPVISignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XRSPVI; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXRSPVIConditions.setupTime; - bool isSetuped = mXRSPVIConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXRSPVIConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXRSPVISiganlSetup( - symbol, - period, - mXRSPVIConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXRSPVIConditions.dir; - setupTime = mXRSPVIConditions.setupTime; - - // - if (isSetuped) - { - // - int items = AddX121SMCXRSPVIConditionsIfNotExists( - mXRSPVIConditions, - mXRSPVIConditionsCollection // - ); - - // - mXRSPVIConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXRSPVIConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXRSPVISignalConditions mTmpConditions[]; - Copy( - mXRSPVIConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXRSPVISignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXRSPVISiganlTrigger( - mTmpConditions[i], - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXRSPVIConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXRSPVIConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - return result; - } - -//////////////////////////////////////////////////////// - - - // - // X Signal ... - if (useXSignal && !hasSignal) - { - // - hasXSignal = DetectXSignal(conditions); - hasSignal = hasXSignal; - } - - // - // XPZ Signal ... - if (useXPZSignal && !hasSignal) - { - // - hasXPZSignal = DetectXPZSignal(conditions); - hasSignal = hasXPZSignal; - } - - // - // XPVT Signal ... - if (useXPVTSignal && !hasSignal) - { - // - hasXPVTSignal = DetectXPVTSignal(conditions); - hasSignal = hasXPVTSignal; - } - - // - // XRSPVI Signal ... - if (useXRSPVISignal && !hasSignal) - { - // - hasXRSPVISignal = DetectXRSPVISignal(conditions); - hasSignal = hasXRSPVISignal; - } - - // - // XSTRPV Signal ... - if (useXSTRPVSignal && !hasSignal) - { - // - hasXSTRPVSignal = DetectXSTRPVSignal(conditions); - hasSignal = hasXSTRPVSignal; - } - - -///////////////////////////////////////////////////////////////// - - - // - // X Guard Detection ... - if (useXSignal) - { - // - bool hasGuard = DetectX121SMCXGuards( - guards, - positions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - } - - // - // XPZ Guard Detection ... - if (useXPZSignal) - { - // - bool hasGuard = DetectX121SMCXPZGuards( - guards, - positions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - } - - // - // XPVT Guard Detection ... - if (useXPVTSignal) - { - // - bool hasGuard = DetectX121SMCXPVTGuards( - guards, - positions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - } - - // - // XSTRPV Guard Detection ... - if (useXSTRPVSignal) - { - // - bool hasGuard = DetectX121SMCXSTRPVGuards( - guards, - positions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - } - - // - // XRSPVI Guard Detection ... - if (useXRSPVISignal) - { - // - bool hasGuard = DetectX121SMCXRSPVIGuards( - guards, - positions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - } - -////////////////////////////////////////////////// - -const string X121SMCXPVTToken = "X121XPVT"; -const string X121SMCXRSPVIToken = "X121XRSPVI"; -const string X121SMCXSTRPVToken = "X121XSTRPV"; -const string X121SMCXPZToken = "X121XPZ"; - - // - switch (value) - { - // - case X_121_SMC_PROVIDER_X: - result = X121SMCXToken; - break; - - // - case X_121_SMC_PROVIDER_XPZ: - result = X121SMCXOBPVToken; - break; - - // - case X_121_SMC_PROVIDER_XPVT: - result = X121SMCXPVTToken; - break; - - // - case X_121_SMC_PROVIDER_XRSPVI: - result = X121SMCXRSPVIToken; - break; - - // - case X_121_SMC_PROVIDER_XSTRPV: - result = X121SMCXSTRPVToken; - break; - } - - // - if (Contains(X121SMCXToken, value)) - { - result = X_121_SMC_PROVIDER_X; - } - else if (Contains(X121SMCXOBPVToken, value)) - { - result = X_121_SMC_PROVIDER_XOBPV; - } - else if (Contains(X121SMCXPVTToken, value)) - { - result = X_121_SMC_PROVIDER_XPVT; - } - else if (Contains(X121SMCXRSPVIToken, value)) - { - result = X_121_SMC_PROVIDER_XRSPVI; - } - else if (Contains(X121SMCXSTRPVToken, value)) - { - result = X_121_SMC_PROVIDER_XSTRPV; - } diff --git a/Documents/BKP/2/x-121.smc.xpvt.signal.lib.mq5 b/Documents/BKP/2/x-121.smc.xpvt.signal.lib.mq5 deleted file mode 100644 index 51ea129c..00000000 --- a/Documents/BKP/2/x-121.smc.xpvt.signal.lib.mq5 +++ /dev/null @@ -1,2484 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: X -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVTSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - double peak; - datetime peakTime; - - // - double higherPeak; - datetime higherPeakTime; - - // - double vale; - datetime valeTime; - - // - double lowerVale; - datetime lowerValeTime; - - // - ENUM_XPV_PIVOTS pvType; - - // - XPVPivot pivotZone; - - // - // Constructor ... - X121SMCStrategyXPVTSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - pvType = XPV_NONE; - - // - peak = 0; - peakTime = NULL; - - // - higherPeak = 0; - higherPeakTime = NULL; - - // - vale = 0; - valeTime = NULL; - - // - lowerVale = 0; - lowerValeTime = NULL; - - // - pivotZone.Clean(); - } - - // - bool HasPeak() - { - // - bool result = false; - - // - result = - peak > 0 && - IsValid(peakTime); - - // - return result; - } - - // - bool HasHigherPeak() - { - // - bool result = false; - - // - result = - higherPeak > 0 && - IsValid(higherPeakTime); - - // - return result; - } - - // - bool HasVale() - { - // - bool result = false; - - // - result = - vale > 0 && - IsValid(valeTime); - - // - return result; - } - - // - bool HasLowerVale() - { - // - bool result = false; - - // - result = - lowerVale > 0 && - IsValid(lowerValeTime); - - // - return result; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXPVTSignalConditions mXPVTConditions; -X121SMCStrategyXPVTSignalConditions mXPVTConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVTSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVTSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - // zBar.Init( - // symbol, - // period, - // zIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - // cBar.Init( - // symbol, - // period, - // cIndex // - // ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - // pBar.Init( - // symbol, - // period, - // pIndex // - // ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - ENUM_X_DIRECTION consolidationTrendDir; - bool hasConsolidationTrend = - consolidationCycleHelper - .DetectMarketStructure( - consolidationTrendDir // - ); - bool hasConsolidationBullishTrend = - hasConsolidationTrend && - IsBullish(consolidationTrendDir); - bool hasConsolidationBearishTrend = - hasConsolidationTrend && - IsBearish(consolidationTrendDir); - - // - // Verification ... - ENUM_X_DIRECTION verificationTrendDir; - bool hasVerificationTrend = - verificationCycleHelper - .DetectMarketStructure( - verificationTrendDir // - ); - bool hasVerificationBullishTrend = - hasVerificationTrend && - IsBullish(verificationTrendDir); - bool hasVerificationBearishTrend = - hasVerificationTrend && - IsBearish(verificationTrendDir); - - // - // Analyse ... - ENUM_X_DIRECTION analyseTrendDir; - bool hasAnalyseTrend = - analyseCycleHelper - .DetectMarketStructure( - analyseTrendDir // - ); - bool hasAnalyseBullishTrend = - hasAnalyseTrend && - IsBullish(analyseTrendDir); - bool hasAnalyseBearishTrend = - hasAnalyseTrend && - IsBearish(analyseTrendDir); - - // - // Decision ... - ENUM_X_DIRECTION decisionTrendDir; - bool hasDecisionTrend = - decisionCycleHelper - .DetectMarketStructure( - decisionTrendDir // - ); - bool hasDecisionBullishTrend = - hasDecisionTrend && - IsBullish(decisionTrendDir); - bool hasDecisionBearishTrend = - hasDecisionTrend && - IsBearish(decisionTrendDir); - - // - // Detect Bar State ... - - // - // PinBar ... - ENUM_X_DIRECTION cBarPinDir; - bool isCBarPin = decisionCycleHelper - .mBarAnalyser - .IsPinBar( - cBar, - cBarPinDir, - 1 // - ); - bool isCBarBullishPin = - isCBarPin && - IsBullish(cBarPinDir); - bool isCBarBearishPin = - isCBarPin && - IsBearish(cBarPinDir); - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // Pull Back ... - ENUM_X_DIRECTION cBarPullbackDir; - bool isCBarPullbacked = - decisionCycleHelper - .mBarAnalyser - .HasPullBack( - cBarPullbackDir, - cBar // - ); - bool isCBarBullishPullbacked = - isCBarPullbacked && - IsBullish(cBarPullbackDir); - bool isCBarBearishPullbacked = - isCBarPullbacked && - IsBearish(cBarPullbackDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bars Pattern and Power and Pressures ... - - // - bool hasCBarBullishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBullishPattern( - cBar, - 2 // - ); - - // - bool hasCBarBearishPattern = - decisionCycleHelper - .mBarAnalyser - .HasBearishPattern( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPower = - decisionCycleHelper - .mBarAnalyser - .HasBullishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPower = - decisionCycleHelper - .mBarAnalyser - .HasBearishPower( - cBar, - 2 // - ); - - // - bool isCBarHasBullishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBullishPressure( - cBar, - 2 // - ); - - // - bool isCBarHasBearishPressure = - decisionCycleHelper - .mBarAnalyser - .HasBearishPressure( - cBar, - 2 // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - ( - // - hasCBarBullishPattern && - isCBarHasBullishPower && - isCBarHasBullishPressure - // - ) - // - || - // - ( - // - isCBarBullishPin || - isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ) - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - ( - // - hasCBarBearishPattern && - isCBarHasBearishPower && - isCBarHasBearishPressure - // - ) - // - || - // - ( - // - isCBarBearishPin || - isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ) - // - ; - - // - // Now we Have to Detect Higher Peak and Lower Vale - // Zones ... - - // - bool hasPeak = conditions.HasPeak(); - bool hasVale = conditions.HasVale(); - - // - int higherPeakIDX = -1; - int higherPeakStartIDX = -1; - datetime higherPeakTime = NULL; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - decisionXConditions.peaksBuffer[1] // - ); - bool hasHigherPeak = - higherPeak > 0 && - IsValidIndex(higherPeakIDX); - if (hasHigherPeak) - { - // - // Detect Higher Peak Start Index ... - int idx = higherPeakIDX; - bool canContinue = true; - while (canContinue) - { - // - double iPeak = decisionCycleHelper - .mX121Helper - .xpvHelper - .GetPeak(idx); - canContinue = iPeak == higherPeak; - if (!canContinue) - { - break; - } - - // - idx++; - } - - // - if (idx > higherPeakIDX) - { - higherPeakStartIDX = idx - 1; - } - } - - // - int lowerValeIDX = -1; - int lowerValeStartIDX = -1; - datetime lowerValeTime = NULL; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - decisionXConditions.valesBuffer[1] // - ); - bool hasLowerVale = - lowerVale > 0 && - IsValidIndex(lowerValeIDX); - if (hasLowerVale) - { - // - // Detect Lower Vale Start Index ... - int idx = lowerValeIDX; - bool canContinue = true; - while (canContinue) - { - // - double iVale = decisionCycleHelper - .mX121Helper - .xpvHelper - .GetVale(idx); - canContinue = iVale == lowerVale; - if (!canContinue) - { - break; - } - - // - idx++; - } - - // - if (idx > lowerValeIDX) - { - lowerValeStartIDX = idx - 1; - } - } - - // - if (hasHigherPeak) - { - // - XOHCL higherPeakStartBar; - bool isInited = higherPeakStartBar.Init( - symbol, - period, - higherPeakStartIDX // - ); - if (isInited) - { - higherPeakTime = higherPeakStartBar.time; - } - } - - // - if (hasLowerVale) - { - // - XOHCL lowerValeStartBar; - bool isInited = lowerValeStartBar.Init( - symbol, - period, - lowerValeStartIDX // - ); - if (isInited) - { - lowerValeTime = lowerValeStartBar.time; - } - } - - // - // Detect Pivot ... - - // - double pivotPremiumDiscount = 0; - - // - bool isPivotUpperUpBreaked = false; - bool isPivotUpperDownBreaked = false; - bool isPivotUpperDownRejected = false; - - // - bool isPivotLowerUpBreaked = false; - bool isPivotLowerUpRejected = false; - bool isPivotLowerDownBreaked = false; - - // - bool isPriceInPivotPremium = false; - bool isPriceInPivotDiscount = false; - - // - bool isPivotPremiumUpBreaked = false; - bool isPivotPremiumDownBreaked = false; - bool isPivotPremiumUpRejected = false; - bool isPivotPremiumDownRejected = false; - - // - bool isPivotDiscountUpBreaked = false; - bool isPivotDiscountDownBreaked = false; - bool isPivotDiscountUpRejected = false; - bool isPivotDiscountDownRejected = false; - - // - bool hasPivot = conditions.pivotZone.IsValid(); - - // - if (!hasPivot) - { - // - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - // - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - - // - bool isNewPeak = - !hasPeak && - hasLowerVale && - hasHigherPeak && - decisionXConditions.isNewPeakUnderLast; - if (isNewPeak) - { - // - conditions.pvType = XPV_PEAK; - - // - conditions.peakTime = cTime; - conditions.peak = decisionXConditions.peaksBuffer[1]; - - // - conditions.higherPeakTime = higherPeakTime; - conditions.higherPeak = higherPeak; - - // - conditions.valeTime = cTime; - conditions.vale = decisionXConditions.valesBuffer[1]; - - // - conditions.lowerValeTime = lowerValeTime; - conditions.lowerVale = lowerVale; - - // - hasPeak = conditions.HasPeak(); - hasVale = conditions.HasVale(); - } - - // - bool isNewVale = - !hasVale && - !isNewPeak && - hasLowerVale && - hasHigherPeak && - decisionXConditions.isNewValeOverLast; - if (isNewVale) - { - // - conditions.pvType = XPV_PEAK; - - // - conditions.peakTime = cTime; - conditions.peak = decisionXConditions.peaksBuffer[1]; - - // - conditions.higherPeakTime = higherPeakTime; - conditions.higherPeak = higherPeak; - - // - conditions.valeTime = cTime; - conditions.vale = decisionXConditions.valesBuffer[1]; - - // - conditions.lowerValeTime = lowerValeTime; - conditions.lowerVale = lowerVale; - - // - hasPeak = conditions.HasPeak(); - hasVale = conditions.HasVale(); - } - - // - if (isNewPeak || isNewVale) - { - // - XPVPivot pivot; - - // - pivot.symbol = symbol; - pivot.period = period; - - // - pivot.repetition = MathMax( - higherPeakIDX, - lowerValeIDX // - ); - pivot.type = conditions.pvType; - - // - pivot.upper = higherPeak; - pivot.lower = lowerVale; - - // - bool isHigherPeakOlder = - conditions.higherPeakTime < conditions.lowerValeTime; - - // - pivot.to = cTime; - pivot.from = - isHigherPeakOlder - ? conditions.higherPeakTime - : conditions.lowerValeTime; - - // - pivot.type = - isHigherPeakOlder - ? XPV_PEAK - : XPV_VALE; - - // - hasPivot = pivot.IsValid(); - if (hasPivot) - { - conditions.pivotZone = pivot; - } - - // - } - - // - // Has Pivot ... - hasPivot = conditions.pivotZone.IsValid(); - } - - // - if (hasPivot) - { - // - // Check Pivot Validation ... - - // - bool isPivotDied = - // - (cBar.low > conditions.pivotZone.upper && - cBar.close > conditions.pivotZone.upper) - // - || - // - (cBar.high < conditions.pivotZone.lower && - cBar.close < conditions.pivotZone.lower) - // - ; - if (isPivotDied) - { - conditions.Clean(); - } - - // - hasPivot = conditions.pivotZone.IsValid(); - if (hasPivot) - { - // - // Detect Pivot States ... - - // - XPOIState analysePivotState; - DetectPivotPOIs( - conditions.pivotZone, - analyseState, - analysePivotState // - ); - - // - XPOIState decisionPivotState; - DetectPivotPOIs( - conditions.pivotZone, - decisionState, - decisionPivotState // - ); - - // - // Combine two State ... - XPOIState combinedPivotState; - XPOIState iStates[]; - // AddRef( - // analysePivotState, - // iStates // - // ); - AddRef( - decisionPivotState, - iStates // - ); - CombineStates( - combinedPivotState, - iStates // - ); - combinedPivotState = decisionPivotState; - - // - ArrayFree(iStates); - - // - combinedPivotState.time = decisionPivotState.time; - combinedPivotState.symbol = decisionPivotState.symbol; - combinedPivotState.period = decisionPivotState.period; - - // - // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... - FilterPivotState( - conditions.pivotZone, - combinedPivotState // - ); - - // - conditions.pivotZone.state = combinedPivotState; - - // - // Calculate Pivot Ticks Zone ... - - // - int ticksLevels = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneLevel(); - int ticksRange = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneRange(); - - // - CalculatePivotTickZone( - conditions.pivotZone, - ticksLevels, - ticksRange // - ); - - // - // Try to Fill up Pivot Conditions ... - - // - XOHCL pivotCBar; - bool isCInited = triggerCycleHelper.GetBar( - pivotCBar, - cIndex // - ); - - // - XOHCL pivotPBar; - bool isPInited = triggerCycleHelper.GetBar( - pivotPBar, - pIndex // - ); - - // - double upper = conditions.pivotZone.upper; - double lower = conditions.pivotZone.lower; - pivotPremiumDiscount = conditions.pivotZone.CalculateMid(); - - // - // Pivot Upper ... - - // - isPivotUpperUpBreaked = - isCInited && - IsBarBreak( - upper, - X_DIRECTION_BULLISH, - pivotCBar // - ); - - // - isPivotUpperDownBreaked = - isCInited && - IsBarBreak( - upper, - X_DIRECTION_BEARISH, - pivotCBar // - ); - - // - isPivotUpperDownRejected = - isCInited && - IsBarReject( - upper, - X_DIRECTION_BEARISH, - pivotCBar // - ); - - // - // Pivot Lower ... - - // - isPivotLowerUpBreaked = - isCInited && - IsBarBreak( - lower, - X_DIRECTION_BULLISH, - pivotCBar // - ); - - // - isPivotLowerUpRejected = - isCInited && - IsBarReject( - lower, - X_DIRECTION_BULLISH, - pivotCBar // - ); - - // - isPivotLowerDownBreaked = - isCInited && - IsBarBreak( - lower, - X_DIRECTION_BEARISH, - pivotCBar // - ); - - // - // Pivot Premium / Discount ... - - // - bool isPriceInPivotPremium = - isCInited && - ask < upper && - bid < upper && - ask > pivotPremiumDiscount && - bid > pivotPremiumDiscount; - - // - bool isPriceInPivotDiscount = - isCInited && - ask > lower && - bid > lower && - ask < pivotPremiumDiscount && - bid < pivotPremiumDiscount; - - // - // - // - - // - isPivotPremiumUpBreaked = - isCInited && - isPInited && - IsBarBreak( - pivotPremiumDiscount, - X_DIRECTION_BULLISH, - pivotCBar // - ) && - pivotPBar.high > pivotPremiumDiscount; - - // - isPivotPremiumDownBreaked = - isCInited && - isPInited && - IsBarBreak( - pivotPremiumDiscount, - X_DIRECTION_BEARISH, - pivotCBar // - ) && - pivotPBar.high > pivotPremiumDiscount; - - // - isPivotPremiumUpRejected = - isCInited && - isPInited && - IsBarReject( - pivotPremiumDiscount, - X_DIRECTION_BULLISH, - pivotCBar // - ) && - pivotPBar.high > pivotPremiumDiscount; - - // - isPivotPremiumDownRejected = - isCInited && - isPInited && - IsBarReject( - pivotPremiumDiscount, - X_DIRECTION_BEARISH, - pivotCBar // - ) && - pivotPBar.high > pivotPremiumDiscount; - - // - // - // - - // - isPivotDiscountUpBreaked = - isCInited && - isPInited && - IsBarBreak( - pivotPremiumDiscount, - X_DIRECTION_BULLISH, - pivotCBar // - ) && - pivotPBar.low < pivotPremiumDiscount; - - // - isPivotDiscountDownBreaked = - isCInited && - isPInited && - IsBarBreak( - pivotPremiumDiscount, - X_DIRECTION_BEARISH, - pivotCBar // - ) && - pivotPBar.low < pivotPremiumDiscount; - - // - isPivotDiscountUpRejected = - isCInited && - isPInited && - IsBarReject( - pivotPremiumDiscount, - X_DIRECTION_BULLISH, - pivotCBar // - ) && - pivotPBar.low < pivotPremiumDiscount; - - // - isPivotDiscountDownRejected = - isCInited && - isPInited && - IsBarReject( - pivotPremiumDiscount, - X_DIRECTION_BEARISH, - pivotCBar // - ) && - pivotPBar.low < pivotPremiumDiscount; - - // - // Detect Bar Patterns ... - - // - if (isCBarBullishRejected) - { - // - int count = conditions.pivotZone.state.CountBullishRejectionBars(); - isCBarBullishRejected = IsValidSize(count); - if (isCBarBullishRejected) - { - // - bool hasBar = false; - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iBar = conditions.pivotZone.state.bullishRejectionBars[i]; - - // - hasBar = iBar.BarTime() == cBar.time; - if (hasBar) - { - break; - } - } - - // - isCBarBullishRejected = hasBar; - } - } - - // - if (isCBarBearishRejected) - { - // - int count = conditions.pivotZone.state.CountBearishRejectionBars(); - isCBarBearishRejected = IsValidSize(count); - if (isCBarBearishRejected) - { - // - bool hasBar = false; - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iBar = conditions.pivotZone.state.bearishRejectionBars[i]; - - // - hasBar = iBar.BarTime() == cBar.time; - if (hasBar) - { - break; - } - } - - // - isCBarBearishRejected = hasBar; - } - } - - // - // Draw Pivot ... - // XCBaseObject *drawnObjects[]; - // triggerCycleHelper.mPOIDetector.mDrawer.DrawPivot( - // conditions.pivotZone, - // drawnObjects, - // true, // Draw State ... - // false, // State As Box ... - // true // Tick Zone ... - // ); - } - } - - // - // - // - - // - // Summarize Conditions ... - - // - bool isCondition1Bullish = - // - hasPivot && - // - // XSTR ... - decisionXConditions.isStrBullish && - // - // XCHE ... - (consolidationXConditions.isCheBullish && - consolidationXConditions.isClosedOverCheMin && - cBar.low > consolidationXConditions.cheMax) && - // - // XPV ... - (isCBarBullishRejected && - pBar.open > cBar.close && - decisionXConditions.isNewValeUnderLast && - decisionXConditions.valesBuffer[1] > conditions.pivotZone.lower) && - // - true - // - ; - - // - bool isCondition1Bearish = - // - hasPivot && - // - // XSTR ... - decisionXConditions.isStrBearish && - // - // XCHE ... - (consolidationXConditions.isCheBearish && - consolidationXConditions.isClosedUnderCheMin && - cBar.high < consolidationXConditions.cheMin) && - // - // XPV ... - (isCBarBearishRejected && - pBar.open < cBar.close && - decisionXConditions.isNewPeakOverLast && - decisionXConditions.peaksBuffer[1] < conditions.pivotZone.upper) && - // - true - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = pivotPremiumDiscount; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCondition1Bullish - ? conditions.pivotZone.upper - : conditions.pivotZone.lower; - - // - // conditions.Clean(); - // isCondition1Bullish = false; - // isCondition1Bearish = false; - } - - // - // - // - - // - isBullish = - // - isCondition1Bullish - // - ; - - // - isBearish = - // - isCondition1Bearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVTSiganlTrigger( - // - X121SMCStrategyXPVTSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - // bool isPointBreaked = - // isBullish - // ? ask > point && bid > point - // : ask < point && bid < point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - // isPointBreaked && - // isSlopesBullish && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - // isPointBreaked && - // isSlopesBearish && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - iAtr *= 1.5; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXPVTGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_X); - - // - // result = DetectX121SMCGuards( - // provider, - // guards, - // positions, - // triggerCycleHelper, - // decisionCycleHelper, - // analyseCycleHelper, - // verificationCycleHelper, - // consolidationCycleHelper, - // visionCycleHelper // - // ); - - // - return result; -} - -// -int AddX121SMCXPVTConditionsIfNotExists( - X121SMCStrategyXPVTSignalConditions &item, - X121SMCStrategyXPVTSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXPVTSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXPVTSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXPVTConditions( - X121SMCStrategyXPVTSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool hasPivot = conditions.pivotZone.IsValid(); - if (hasPivot) - { - // - XCBaseObject *pivotObjects[]; - drawer.DrawPivot( - conditions.pivotZone, - pivotObjects, - true, // State ... - false, // State as Box ... - false // Ticks Zone ... - ); - - // - Copy( - pivotObjects, - drawnObjects, - false // - ); - } - - // - return result; -} - -// diff --git a/Documents/BKP/2/x-121.smc.xpz.signal.lib.mq5 b/Documents/BKP/2/x-121.smc.xpz.signal.lib.mq5 deleted file mode 100644 index 25d660f6..00000000 --- a/Documents/BKP/2/x-121.smc.xpz.signal.lib.mq5 +++ /dev/null @@ -1,1700 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XPZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - XPriceZones priceZone; - bool isPriceZoneValidForPeak; - bool isPriceZoneValidForVale; - - // - // Constructor ... - X121SMCStrategyXPZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - priceZone.Clean(); - isPriceZoneValidForPeak = false; - isPriceZoneValidForVale = false; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXPZSignalConditions mXPZConditions; -X121SMCStrategyXPZSignalConditions mXPZConditionsCollection[]; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPZSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPZSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - ENUM_X_DIRECTION consolidationTrendDir; - bool hasConsolidationTrend = - consolidationCycleHelper - .DetectMarketStructure( - consolidationTrendDir // - ); - bool hasConsolidationBullishTrend = - hasConsolidationTrend && - IsBullish(consolidationTrendDir); - bool hasConsolidationBearishTrend = - hasConsolidationTrend && - IsBearish(consolidationTrendDir); - - // - // Verification ... - ENUM_X_DIRECTION verificationTrendDir; - bool hasVerificationTrend = - verificationCycleHelper - .DetectMarketStructure( - verificationTrendDir // - ); - bool hasVerificationBullishTrend = - hasVerificationTrend && - IsBullish(verificationTrendDir); - bool hasVerificationBearishTrend = - hasVerificationTrend && - IsBearish(verificationTrendDir); - - // - // Analyse ... - ENUM_X_DIRECTION analyseTrendDir; - bool hasAnalyseTrend = - analyseCycleHelper - .DetectMarketStructure( - analyseTrendDir // - ); - bool hasAnalyseBullishTrend = - hasAnalyseTrend && - IsBullish(analyseTrendDir); - bool hasAnalyseBearishTrend = - hasAnalyseTrend && - IsBearish(analyseTrendDir); - - // - // Decision ... - ENUM_X_DIRECTION decisionTrendDir; - bool hasDecisionTrend = - decisionCycleHelper - .DetectMarketStructure( - decisionTrendDir // - ); - bool hasDecisionBullishTrend = - hasDecisionTrend && - IsBullish(decisionTrendDir); - bool hasDecisionBearishTrend = - hasDecisionTrend && - IsBearish(decisionTrendDir); - - // - // Detect Bar State ... - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ; - - // - // Detect Price Zone ... - - // - double pzPeak = decisionXConditions.peaksBuffer[1]; - double pzVale = decisionXConditions.valesBuffer[1]; - - // - // Detecting Decision Price ones ... - XPriceZones decisionPriceZone; - bool hasDecisionPriceZone = CalculatePriceInsideZones( - decisionPriceZone, - decisionState, - cBar // - ); - double decisionPriceZoneUpper = 0; - double decisionPriceZoneLower = 0; - bool isDecisionPriceZoneValidForPeak = false; - bool isDecisionPriceZoneValidForVale = false; - if (hasDecisionPriceZone) - { - // - bool hasBoundary = decisionPriceZone.GetBoundary( - X_DIRECTION_ALL, - decisionPriceZoneUpper, - decisionPriceZoneLower // - ); - - // - isDecisionPriceZoneValidForPeak = - hasBoundary && - pzPeak <= decisionPriceZoneUpper && - pzPeak >= decisionPriceZoneLower; - - // - isDecisionPriceZoneValidForVale = - hasBoundary && - pzVale <= decisionPriceZoneUpper && - pzVale >= decisionPriceZoneLower; - } - - // - // Detecting Analyse Price ones ... - XPriceZones analysePriceZone; - bool hasAnalysePriceZone = CalculatePriceInsideZones( - analysePriceZone, - analyseState, - cBar // - ); - double analysePriceZoneUpper = 0; - double analysePriceZoneLower = 0; - bool isAnalysePriceZoneValidForPeak = false; - bool isAnalysePriceZoneValidForVale = false; - if (hasAnalysePriceZone) - { - // - bool hasBoundary = analysePriceZone.GetBoundary( - X_DIRECTION_ALL, - analysePriceZoneUpper, - analysePriceZoneLower // - ); - - // - isAnalysePriceZoneValidForPeak = - hasBoundary && - pzPeak <= analysePriceZoneUpper && - pzPeak >= analysePriceZoneLower; - - // - isAnalysePriceZoneValidForVale = - hasBoundary && - pzVale <= analysePriceZoneUpper && - pzVale >= analysePriceZoneLower; - } - - // - // Detecting Verification Price ones ... - XPriceZones verificationPriceZone; - bool hasVerificationPriceZone = CalculatePriceInsideZones( - verificationPriceZone, - verificationState, - cBar // - ); - double verificationPriceZoneUpper = 0; - double verificationPriceZoneLower = 0; - bool isVerificationPriceZoneValidForPeak = false; - bool isVerificationPriceZoneValidForVale = false; - if (hasVerificationPriceZone) - { - // - bool hasBoundary = verificationPriceZone.GetBoundary( - X_DIRECTION_ALL, - verificationPriceZoneUpper, - verificationPriceZoneLower // - ); - - // - isVerificationPriceZoneValidForPeak = - hasBoundary && - pzPeak <= verificationPriceZoneUpper && - pzPeak >= verificationPriceZoneLower; - - // - isVerificationPriceZoneValidForVale = - hasBoundary && - pzVale <= verificationPriceZoneUpper && - pzVale >= verificationPriceZoneLower; - } - - // - // - // - - // - // Summarize Conditions ... - - // - double decisionPVMiddle = decisionXConditions.valesBuffer[1] + - (decisionXConditions.peaksBuffer[1] - decisionXConditions.valesBuffer[1]) / 2; - bool isInDecisionPremium = - // - ask > decisionPVMiddle && - bid > decisionPVMiddle && - // - ask < decisionXConditions.peaksBuffer[1] && - bid < decisionXConditions.peaksBuffer[1] - // - ; - bool isInDecisionDiscount = - // - ask < decisionPVMiddle && - bid < decisionPVMiddle && - // - ask < decisionXConditions.valesBuffer[1] && - bid < decisionXConditions.valesBuffer[1] - // - ; - - // - bool isPriceZoneBullish = - // - hasVerificationBullishTrend && - hasAnalyseBullishTrend && - hasDecisionBullishTrend && - // - hasAnalysePriceZone && - analysePriceZone.IsBullish() && - isAnalysePriceZoneValidForVale && - // - isCBarBullishFormed && - isInDecisionDiscount && - decisionXConditions.isAtrLowerUnderVale && - decisionXConditions.isAtrLowerSlopeBullish && - // - true - // - ; - - // - bool isPriceZoneBearish = - // - hasVerificationBearishTrend && - hasAnalyseBearishTrend && - hasDecisionBearishTrend && - // - hasAnalysePriceZone && - analysePriceZone.IsBearish() && - isAnalysePriceZoneValidForPeak && - // - isInDecisionPremium && - isCBarBearishFormed && - decisionXConditions.isAtrUpperOverPeak && - decisionXConditions.isAtrUpperSlopeBearish && - // - true - // - ; - - // - bool hasPriceZoneCondition = isPriceZoneBullish || - isPriceZoneBearish; - if (hasPriceZoneCondition) - { - // - ENUM_X_DIRECTION pzDir = - isPriceZoneBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - conditions.priceZone = analysePriceZone; - conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale; - - // - pzPeak = analysePriceZoneUpper; - pzVale = analysePriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - // point = - // isPriceZoneBullish ? pzPeak - // : pzVale; - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isPriceZoneBullish - ? pzVale - : pzPeak; - } - - // - // - // - - // - isBullish = - isPriceZoneBullish; - - // - isBearish = - isPriceZoneBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPZSiganlTrigger( - // - X121SMCStrategyXPZSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked && - // isSlopesBullish && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked && - // isSlopesBearish && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXPZGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_XPZ); - - // - result = DetectX121SMCGuards( - provider, - guards, - positions, - triggerCycleHelper, - decisionCycleHelper, - analyseCycleHelper, - verificationCycleHelper, - consolidationCycleHelper, - visionCycleHelper // - ); - - // - return result; -} - -// -int AddX121SMCXPZConditionsIfNotExists( - X121SMCStrategyXPZSignalConditions &item, - X121SMCStrategyXPZSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXPZSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXPZSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXPZConditions( - X121SMCStrategyXPZSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool hasPriceZone = conditions.priceZone.IsValid(); - if (!hasPriceZone) - { - return result; - } - - // - int zonesObjCount = drawer.DrawPriceZone( - conditions.priceZone, - drawnObjects, - conditions.dir // - ); - result = zonesObjCount; - - // - return result; -} - -// diff --git a/Documents/BKP/2/x-121.smc.xrspvi.signal.lib.mq5 b/Documents/BKP/2/x-121.smc.xrspvi.signal.lib.mq5 deleted file mode 100644 index 8d156d5d..00000000 --- a/Documents/BKP/2/x-121.smc.xrspvi.signal.lib.mq5 +++ /dev/null @@ -1,2483 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XRSPVI -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -enum ENUM_X121_SMC_XRSPVI_CONDITIONS -{ - // - X121_SMC_XRSPVI_CONDITION_NONE, - X121_SMC_XRSPVI_CONDITION_1, - X121_SMC_XRSPVI_CONDITION_2, - X121_SMC_XRSPVI_CONDITION_3, - X121_SMC_XRSPVI_CONDITION_4, - X121_SMC_XRSPVI_CONDITION_5, -}; - -// -// Definitions ... -struct X121SMCStrategyXRSPVISignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - XPriceZones priceZone; - bool isPriceZoneValidForPeak; - bool isPriceZoneValidForVale; - - // - XPVPivot pivotZone; - XConsolidationZone consolidationZone; - - // - ENUM_X121_SMC_XRSPVI_CONDITIONS mode; - - // - // Constructor ... - X121SMCStrategyXRSPVISignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - pivotZone.Clean(); - priceZone.Clean(); - consolidationZone.Clean(); - isPriceZoneValidForPeak = false; - isPriceZoneValidForVale = false; - - // - mode = X121_SMC_XRSPVI_CONDITION_NONE; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXRSPVISignalConditions mXRSPVIConditions; -X121SMCStrategyXRSPVISignalConditions mXRSPVIConditionsCollection[]; - -// -double X121SMCXRSPVIPivotPeak; -double X121SMCXRSPVIPivotVale; -datetime X121SMCXRSPVIPivotEnd; -datetime X121SMCXRSPVIPivotStart; -ENUM_XPV_PIVOTS X121SMCXRSPVIPivotType = XPV_NONE; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXRSPVISiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXRSPVISignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - ENUM_X_DIRECTION consolidationTrendDir; - bool hasConsolidationTrend = - consolidationCycleHelper - .DetectMarketStructure( - consolidationTrendDir // - ); - bool hasConsolidationBullishTrend = - hasConsolidationTrend && - IsBullish(consolidationTrendDir); - bool hasConsolidationBearishTrend = - hasConsolidationTrend && - IsBearish(consolidationTrendDir); - - // - // Verification ... - ENUM_X_DIRECTION verificationTrendDir; - bool hasVerificationTrend = - verificationCycleHelper - .DetectMarketStructure( - verificationTrendDir // - ); - bool hasVerificationBullishTrend = - hasVerificationTrend && - IsBullish(verificationTrendDir); - bool hasVerificationBearishTrend = - hasVerificationTrend && - IsBearish(verificationTrendDir); - - // - // Analyse ... - ENUM_X_DIRECTION analyseTrendDir; - bool hasAnalyseTrend = - analyseCycleHelper - .DetectMarketStructure( - analyseTrendDir // - ); - bool hasAnalyseBullishTrend = - hasAnalyseTrend && - IsBullish(analyseTrendDir); - bool hasAnalyseBearishTrend = - hasAnalyseTrend && - IsBearish(analyseTrendDir); - - // - // Decision ... - ENUM_X_DIRECTION decisionTrendDir; - bool hasDecisionTrend = - decisionCycleHelper - .DetectMarketStructure( - decisionTrendDir // - ); - bool hasDecisionBullishTrend = - hasDecisionTrend && - IsBullish(decisionTrendDir); - bool hasDecisionBearishTrend = - hasDecisionTrend && - IsBearish(decisionTrendDir); - - // - // Detect Bar State ... - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ; - - // - // Detect Price Zone ... - - // - double pzPeak = decisionXConditions.peaksBuffer[1]; - double pzVale = decisionXConditions.valesBuffer[1]; - - // - // Detecting Decision Price ones ... - XPriceZones decisionPriceZone; - bool hasDecisionPriceZone = CalculatePriceInsideZones( - decisionPriceZone, - decisionState, - cBar // - ); - double decisionPriceZoneUpper = 0; - double decisionPriceZoneLower = 0; - bool isDecisionPriceZoneBullish = false; - bool isDecisionPriceZoneBearish = false; - bool isDecisionPriceZoneValidForPeak = false; - bool isDecisionPriceZoneValidForVale = false; - - // - if (hasDecisionPriceZone) - { - // - bool hasBoundary = decisionPriceZone.GetBoundary( - X_DIRECTION_ALL, - decisionPriceZoneUpper, - decisionPriceZoneLower // - ); - - // - isDecisionPriceZoneValidForPeak = - hasBoundary && - pzPeak <= decisionPriceZoneUpper && - pzPeak >= decisionPriceZoneLower; - - // - isDecisionPriceZoneValidForVale = - hasBoundary && - pzVale <= decisionPriceZoneUpper && - pzVale >= decisionPriceZoneLower; - - // - isDecisionPriceZoneBullish = - hasBoundary && - decisionPriceZone.IsBullish(); - - // - isDecisionPriceZoneBearish = - hasBoundary && - decisionPriceZone.IsBearish(); - } - - // - // Detecting Analyse Price ones ... - XPriceZones analysePriceZone; - bool hasAnalysePriceZone = CalculatePriceInsideZones( - analysePriceZone, - analyseState, - cBar // - ); - double analysePriceZoneUpper = 0; - double analysePriceZoneLower = 0; - bool isAnalysePriceZoneBullish = false; - bool isAnalysePriceZoneBearish = false; - bool isAnalysePriceZoneValidForPeak = false; - bool isAnalysePriceZoneValidForVale = false; - - // - if (hasAnalysePriceZone) - { - // - bool hasBoundary = analysePriceZone.GetBoundary( - X_DIRECTION_ALL, - analysePriceZoneUpper, - analysePriceZoneLower // - ); - - // - isAnalysePriceZoneValidForPeak = - hasBoundary && - pzPeak <= analysePriceZoneUpper && - pzPeak >= analysePriceZoneLower; - - // - isAnalysePriceZoneValidForVale = - hasBoundary && - pzVale <= analysePriceZoneUpper && - pzVale >= analysePriceZoneLower; - - // - isAnalysePriceZoneBullish = - hasBoundary && - analysePriceZone.IsBullish(); - - // - isAnalysePriceZoneBearish = - hasBoundary && - analysePriceZone.IsBearish(); - } - - // - // Detecting Verification Price ones ... - XPriceZones verificationPriceZone; - bool hasVerificationPriceZone = CalculatePriceInsideZones( - verificationPriceZone, - verificationState, - cBar // - ); - double verificationPriceZoneUpper = 0; - double verificationPriceZoneLower = 0; - bool isVerificationPriceZoneBullish = false; - bool isVerificationPriceZoneBearish = false; - bool isVerificationPriceZoneValidForPeak = false; - bool isVerificationPriceZoneValidForVale = false; - - // - if (hasVerificationPriceZone) - { - // - bool hasBoundary = verificationPriceZone.GetBoundary( - X_DIRECTION_ALL, - verificationPriceZoneUpper, - verificationPriceZoneLower // - ); - - // - isVerificationPriceZoneValidForPeak = - hasBoundary && - pzPeak <= verificationPriceZoneUpper && - pzPeak >= verificationPriceZoneLower; - - // - isVerificationPriceZoneValidForVale = - hasBoundary && - pzVale <= verificationPriceZoneUpper && - pzVale >= verificationPriceZoneLower; - - // - isVerificationPriceZoneBullish = - hasBoundary && - verificationPriceZone.IsBullish(); - - // - isVerificationPriceZoneBearish = - hasBoundary && - verificationPriceZone.IsBearish(); - } - - // - // Detect Consolidation Zone ... - int decisionConsolidationLoopback = 7; - double decisionConsolidationZoneLower = 0; - double decisionConsolidationZoneUpper = 0; - bool isDecisionConsolidationZoneBreaked = false; - bool isDecisionConsolidationZoneBreakedUp = false; - bool isDecisionConsolidationZoneBreakedDown = false; - bool hasDecisionConsolidationZone = conditions.consolidationZone.IsValid(); - - // - if (!hasDecisionConsolidationZone) - { - // - XOHCL decisionCBar; - bool isInited = decisionCBar.Init( - decisionCycleHelper.GetSymbol(), - decisionCycleHelper.GetPeriod(), - cIndex // - ); - - // - if (isInited) - { - // - double upper = 0; - double lower = 0; - hasDecisionConsolidationZone = - triggerCycleHelper - .mBarAnalyser - .IsConsolidate( - decisionCBar, - upper, - lower, - decisionConsolidationLoopback // - ); - - // - if (hasDecisionConsolidationZone) - { - // - hasDecisionConsolidationZone = conditions.consolidationZone.Init( - cBar.symbol, - cBar.period, - upper, - lower, - decisionConsolidationLoopback // - ); - } - } - } - - // - if (hasDecisionConsolidationZone) - { - // - conditions.consolidationZone.Update(); - - // - decisionConsolidationZoneLower = conditions.consolidationZone.upper; - decisionConsolidationZoneUpper = conditions.consolidationZone.lower; - - // - isDecisionConsolidationZoneBreaked = conditions.consolidationZone.IsBreaked(); - isDecisionConsolidationZoneBreakedUp = - isDecisionConsolidationZoneBreaked && - IsBullish(conditions.consolidationZone.breakDirection); - isDecisionConsolidationZoneBreakedDown = - isDecisionConsolidationZoneBreaked && - IsBearish(conditions.consolidationZone.breakDirection); - - // - decisionConsolidationZoneLower = triggerXConditions.peaksBuffer[1]; - decisionConsolidationZoneUpper = triggerXConditions.valesBuffer[1]; - - // - if (isDecisionConsolidationZoneBreaked) - { - conditions.consolidationZone.Clean(); - } - } - - // - // - // - - // - double decisionPVMiddle = decisionXConditions.valesBuffer[1] + - (decisionXConditions.peaksBuffer[1] - decisionXConditions.valesBuffer[1]) / 2; - bool isInDecisionPremium = - // - ask > decisionPVMiddle && - bid > decisionPVMiddle && - // - ask < decisionXConditions.peaksBuffer[1] && - bid < decisionXConditions.peaksBuffer[1] - // - ; - bool isInDecisionDiscount = - // - ask < decisionPVMiddle && - bid < decisionPVMiddle && - // - ask < decisionXConditions.valesBuffer[1] && - bid < decisionXConditions.valesBuffer[1] - // - ; - - // - double analysePVMiddle = analyseXConditions.valesBuffer[1] + - (analyseXConditions.peaksBuffer[1] - analyseXConditions.valesBuffer[1]) / 2; - bool isInAnalysePremium = - // - ask > analysePVMiddle && - bid > analysePVMiddle && - // - ask < analyseXConditions.peaksBuffer[1] && - bid < analyseXConditions.peaksBuffer[1] - // - ; - bool isInAnalyseDiscount = - // - ask < analysePVMiddle && - bid < analysePVMiddle && - // - ask < analyseXConditions.valesBuffer[1] && - bid < analyseXConditions.valesBuffer[1] - // - ; - - // - double verificationPVMiddle = verificationXConditions.valesBuffer[1] + - (verificationXConditions.peaksBuffer[1] - verificationXConditions.valesBuffer[1]) / 2; - bool isInVerificationPremium = - // - ask > verificationPVMiddle && - bid > verificationPVMiddle && - // - ask < verificationXConditions.peaksBuffer[1] && - bid < verificationXConditions.peaksBuffer[1] - // - ; - bool isInVerificationDiscount = - // - ask < verificationPVMiddle && - bid < verificationPVMiddle && - // - ask < verificationXConditions.valesBuffer[1] && - bid < verificationXConditions.valesBuffer[1] - // - ; - - // - // Detect PV Pivot ... - - // - bool isPivotPeakZoneRejected = false; - bool isPivotPeakZoneBreakedUp = false; - bool isPivotPeakZoneBreakedDown = false; - bool isPivotValeZoneRejected = false; - bool isPivotValeZoneBreakedUp = false; - bool isPivotValeZoneBreakedDown = false; - bool hasPivot = conditions.pivotZone.IsValid(); - if (!hasPivot) - { - // - hasPivot = IsValid(X121SMCXRSPVIPivotStart); - if (!hasPivot) - { - // - bool isNewVale = decisionXConditions.isNewVale; - bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; - bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - - // - bool isNewPeak = decisionXConditions.isNewPeak; - bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; - bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - - // - bool isValeStart = - // isSameVales; - isSameVales && - isSameCycleVales; - bool isPeakStart = - // isSamePeaks; - isSamePeaks && - isSameCyclePeaks; - - // - bool isStart = isPeakStart || - isValeStart; - if (isStart) - { - // - X121SMCXRSPVIPivotStart = cTime; - X121SMCXRSPVIPivotType = - isPeakStart - ? XPV_PEAK - : XPV_VALE; - - // - X121SMCXRSPVIPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXRSPVIPivotVale = decisionXConditions.valesBuffer[1]; - } - - // - hasPivot = IsValid(X121SMCXRSPVIPivotStart); - - // - // Create XPVPivot instance ... - if (hasPivot) - { - // - conditions.pivotZone.symbol = symbol; - conditions.pivotZone.period = period; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition = 3; - - // - conditions.pivotZone.upper = X121SMCXRSPVIPivotPeak; - conditions.pivotZone.lower = X121SMCXRSPVIPivotVale; - - // - conditions.pivotZone.type = X121SMCXRSPVIPivotType; - conditions.pivotZone.from = X121SMCXRSPVIPivotStart; - } - } - } - - // - if (hasPivot) - { - // - bool isBreaked = X121SMCXRSPVIPivotType == XPV_PEAK - ? decisionXConditions.isBreakedUpPrevPeak - : decisionXConditions.isBreakedDownPrevVale; - - // - if (!isBreaked) - { - // - X121SMCXRSPVIPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXRSPVIPivotVale = decisionXConditions.valesBuffer[1]; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition++; - conditions.pivotZone.upper = X121SMCXRSPVIPivotPeak; - conditions.pivotZone.lower = X121SMCXRSPVIPivotVale; - } - else - { - // - X121SMCXRSPVIPivotEnd = cTime; - conditions.pivotZone.to = cTime; - } - - // - // Fill Pivot State ... - - // - XPOIState analysePivotState; - DetectPivotPOIs( - conditions.pivotZone, - analyseState, - analysePivotState // - ); - - // - XPOIState decisionPivotState; - DetectPivotPOIs( - conditions.pivotZone, - decisionState, - decisionPivotState // - ); - - // - // Combine two State ... - XPOIState combinedPivotState; - XPOIState iStates[]; - AddRef( - analysePivotState, - iStates // - ); - AddRef( - decisionPivotState, - iStates // - ); - CombineStates( - combinedPivotState, - iStates // - ); - combinedPivotState = decisionPivotState; - - // - ArrayFree(iStates); - - // - combinedPivotState.time = decisionPivotState.time; - combinedPivotState.symbol = decisionPivotState.symbol; - combinedPivotState.period = decisionPivotState.period; - - // - // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... - FilterPivotState( - conditions.pivotZone, - combinedPivotState // - ); - - // - conditions.pivotZone.state = combinedPivotState; - - // - double peakUpper = 0; - double peakLower = 0; - double valeUpper = 0; - double valeLower = 0; - - // - datetime peakTo = NULL; - datetime valeTo = NULL; - datetime peakFrom = NULL; - datetime valeFrom = NULL; - - // - bool hasBoxData = DetectPivotStateBoxData( - conditions.pivotZone, - peakUpper, - peakLower, - peakFrom, - peakTo, - valeUpper, - valeLower, - valeFrom, - valeTo // - ); - - // - // Calculate Pivot Tick Zones ... - - // - int ticksLevels = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneLevel(); - int ticksRange = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneRange(); - - // - CalculatePivotTickZone( - conditions.pivotZone, - ticksLevels, - ticksRange // - ); - - // - isPivotPeakZoneRejected = - hasBoxData && - ( - // - IsBarReject( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - peakUpper, - X_DIRECTION_BEARISH, - cBar // - ) - // - ); - isPivotPeakZoneBreakedUp = - hasBoxData && - IsBarBreak( - peakUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotPeakZoneBreakedDown = - hasBoxData && - IsBarBreak( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotValeZoneRejected = - hasBoxData && - ( - // - IsBarReject( - valeLower, - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ) - // - ); - isPivotValeZoneBreakedUp = - hasBoxData && - IsBarBreak( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotValeZoneBreakedDown = - hasBoxData && - IsBarBreak( - valeLower, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - bool isPivotEnded = IsValid(X121SMCXRSPVIPivotEnd); - if (isPivotEnded) - { - // - X121SMCXRSPVIPivotPeak = 0; - X121SMCXRSPVIPivotVale = 0; - X121SMCXRSPVIPivotEnd = NULL; - X121SMCXRSPVIPivotStart = NULL; - X121SMCXRSPVIPivotType = XPV_NONE; - - // - conditions.pivotZone.Clean(); - } - - // - // Summarize Conditions ... - - // - bool isCond1Bullish = - // - isInAnalyseDiscount && - isInDecisionDiscount && - isCBarBullishFormed && - // - hasAnalysePriceZone && - isAnalysePriceZoneBullish && - isAnalysePriceZoneValidForVale && - // - analyseXConditions.isRsiCrossedOverOverSold && - // - true - // - ; - - // - bool isCond1Bearish = - // - isInAnalysePremium && - isInDecisionPremium && - isCBarBearishFormed && - // - hasAnalysePriceZone && - isAnalysePriceZoneBearish && - isAnalysePriceZoneValidForPeak && - // - analyseXConditions.isRsiCrossedUnderOverBought && - // - true - // - ; - - // - bool hasCond1Condition = isCond1Bullish || - isCond1Bearish; - if (hasCond1Condition) - { - // - conditions.mode = X121_SMC_XRSPVI_CONDITION_1; - - // - ENUM_X_DIRECTION pzDir = - isCond1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - conditions.priceZone = analysePriceZone; - conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale; - - // - pzPeak = analysePriceZoneUpper; - pzVale = analysePriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCond1Bullish - ? pzVale - : pzPeak; - } - - // - // - // - - // - bool isCond2Bullish = - // - hasDecisionBullishTrend && - // - isCBarBullishFormed && - isInAnalyseDiscount && - isInVerificationDiscount && - // - hasVerificationPriceZone && - isVerificationPriceZoneBullish && - isVerificationPriceZoneValidForVale && - // - verificationXConditions.isRsiCrossedOverOverSold && - // - true - // - ; - - // - bool isCond2Bearish = - // - hasDecisionBearishTrend && - // - isCBarBearishFormed && - isInAnalysePremium && - isInVerificationPremium && - // - hasVerificationPriceZone && - isVerificationPriceZoneBearish && - isVerificationPriceZoneValidForPeak && - // - verificationXConditions.isRsiCrossedUnderOverBought && - // - true - // - ; - - // - bool hasCond2Condition = isCond2Bullish || - isCond2Bearish; - if (hasCond2Condition) - { - // - conditions.mode = X121_SMC_XRSPVI_CONDITION_2; - - // - ENUM_X_DIRECTION pzDir = - isCond2Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - conditions.priceZone = verificationPriceZone; - conditions.isPriceZoneValidForPeak = isVerificationPriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isVerificationPriceZoneValidForVale; - - // - pzPeak = verificationPriceZoneUpper; - pzVale = verificationPriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - // Manipulate Conditions Point ... - - // - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isCond2Bullish - ? pzVale - : pzPeak; - } - - // - // - // - - // - bool isCond3Bullish = - // - isCBarBullishFormed && - hasDecisionBullishTrend && - decisionXConditions.isSarBullish && - decisionXConditions.isStrCrossedOverVale && - // - true - // - ; - - // - bool isCond3Bearish = - // - isCBarBearishFormed && - hasDecisionBearishTrend && - decisionXConditions.isSarBearish && - decisionXConditions.isStrCrossedUnderPeak && - // - true - // - ; - - // - bool hasCond3Conditions = isCond3Bullish || - isCond3Bearish; - if (hasCond3Conditions) - { - // - conditions.mode = X121_SMC_XRSPVI_CONDITION_3; - - // - ENUM_X_DIRECTION pzDir = - isCond3Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Manipulate Conditions Point ... - - // - conditions.point = decisionXConditions.strBuffer[1]; - - // - // Manipulate Conditions Pivot ... - - // - double pivot = decisionXConditions.sarBuffer[1]; - pivot = (decisionXConditions.sarBuffer[1] + decisionXConditions.strBuffer[1]) / 2; - - // - conditions.pivot = - isCond3Bullish - ? pivot - : pivot; - } - - // - // - // - - // - bool isCond4Bullish = - // - isCBarBullishFormed && - isInDecisionDiscount && - hasDecisionBullishTrend && - hasDecisionConsolidationZone && - isDecisionConsolidationZoneBreakedUp && - // - true - // - ; - - // - bool isCond4Bearish = - // - isInDecisionPremium && - isCBarBearishFormed && - hasDecisionBearishTrend && - hasDecisionConsolidationZone && - isDecisionConsolidationZoneBreakedDown && - // - true - // - ; - - // - bool hasCond4Conditions = isCond4Bullish || - isCond4Bearish; - if (hasCond4Conditions) - { - // - conditions.mode = X121_SMC_XRSPVI_CONDITION_4; - - // - ENUM_X_DIRECTION pzDir = - isCond4Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Manipulate Conditions Point ... - - // - double point = GetEntry( - conditions.symbol, - pzDir // - ); - - // - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - pzPeak = decisionConsolidationZoneUpper; - pzVale = decisionConsolidationZoneLower; - - // - conditions.pivot = - isCond4Bullish - ? pzVale - : pzPeak; - } - - // - // - // - - // - bool isCond5Bullish = - // - hasDecisionBullishTrend && - isPivotValeZoneRejected - // - ; - - // - bool isCond5Bearish = - // - hasDecisionBearishTrend && - isPivotPeakZoneRejected - // - ; - - // - bool hasCond5Conditions = isCond5Bullish || - isCond5Bearish; - - // - isBullish = - isCond5Bullish && - (isCond1Bullish || - isCond2Bullish || - isCond3Bullish || - isCond4Bullish); - - // - isBearish = - isCond5Bearish && - (isCond1Bearish || - isCond2Bearish || - isCond3Bearish || - isCond4Bearish); - - // - result = isBullish || - isBearish; - if (!result) - { - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXRSPVISiganlTrigger( - // - X121SMCStrategyXRSPVISignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - bool isCond124 = - // - conditions.mode == X121_SMC_XRSPVI_CONDITION_1 || - conditions.mode == X121_SMC_XRSPVI_CONDITION_2 || - conditions.mode == X121_SMC_XRSPVI_CONDITION_4 - // - ; - - // - // Summary ... - - // - isBullish = - // - isBullish && - isSlopesBullish && - cBar.IsBullish() && - ( - // - (isCond124 && - isPointBreaked) - // - || - // - (!isCond124 && - decisionXConditions.isStrBullish && - decisionXConditions.isStrSlopeBullish && - decisionXConditions.strBuffer[1] > conditions.point && - decisionXConditions.strBuffer[1] > decisionXConditions.strBuffer[2]) - // - ) - // - ; - - // - isBearish = - // - isBearish && - isSlopesBearish && - cBar.IsBearish() && - ( - // - (isCond124 && - isPointBreaked) - // - || - // - (!isCond124 && - decisionXConditions.isStrBearish && - decisionXConditions.isStrSlopeBearish && - decisionXConditions.strBuffer[1] < conditions.point && - decisionXConditions.strBuffer[1] < decisionXConditions.strBuffer[2]) - // - ) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXRSPVIGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_XRSPVI); - - // - result = DetectX121SMCGuards( - provider, - guards, - positions, - triggerCycleHelper, - decisionCycleHelper, - analyseCycleHelper, - verificationCycleHelper, - consolidationCycleHelper, - visionCycleHelper // - ); - - // - return result; -} - -// -int AddX121SMCXRSPVIConditionsIfNotExists( - X121SMCStrategyXRSPVISignalConditions &item, - X121SMCStrategyXRSPVISignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXRSPVISignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXRSPVISignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXRSPVIConditions( - X121SMCStrategyXRSPVISignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool hasPriceZone = conditions.priceZone.IsValid(); - if (!hasPriceZone) - { - return result; - } - - // - int zonesObjCount = drawer.DrawPriceZone( - conditions.priceZone, - drawnObjects, - conditions.dir // - ); - result = zonesObjCount; - - // - return result; -} - -// diff --git a/Documents/BKP/2/x-121.smc.xstrpv.signal.lib.mq5 b/Documents/BKP/2/x-121.smc.xstrpv.signal.lib.mq5 deleted file mode 100644 index 7f774b2b..00000000 --- a/Documents/BKP/2/x-121.smc.xstrpv.signal.lib.mq5 +++ /dev/null @@ -1,2097 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XSTRPV -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Libraries/x-121.smc.guard.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXSTRPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - XPriceZones priceZone; - bool isPriceZoneValidForPeak; - bool isPriceZoneValidForVale; - - // - XPVPivot pivotZone; - - // - // Constructor ... - X121SMCStrategyXSTRPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - priceZone.Clean(); - pivotZone.Clean(); - isPriceZoneValidForPeak = false; - isPriceZoneValidForVale = false; - } - - // -}; - -// -// Signaller Data Sources ... -X121SMCStrategyXSTRPVSignalConditions mXSTRPVConditions; -X121SMCStrategyXSTRPVSignalConditions mXSTRPVConditionsCollection[]; - -// -double X121SMCXSTRPVPivotPeak; -double X121SMCXSTRPVPivotVale; -datetime X121SMCXSTRPVPivotEnd; -datetime X121SMCXSTRPVPivotStart; -ENUM_XPV_PIVOTS X121SMCXSTRPVPivotType = XPV_NONE; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXSTRPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXSTRPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 3; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Detect Trend ... - - // - // Consolidation ... - ENUM_X_DIRECTION consolidationTrendDir; - bool hasConsolidationTrend = - consolidationCycleHelper - .DetectMarketStructure( - consolidationTrendDir // - ); - bool hasConsolidationBullishTrend = - hasConsolidationTrend && - IsBullish(consolidationTrendDir); - bool hasConsolidationBearishTrend = - hasConsolidationTrend && - IsBearish(consolidationTrendDir); - - // - // Verification ... - ENUM_X_DIRECTION verificationTrendDir; - bool hasVerificationTrend = - verificationCycleHelper - .DetectMarketStructure( - verificationTrendDir // - ); - bool hasVerificationBullishTrend = - hasVerificationTrend && - IsBullish(verificationTrendDir); - bool hasVerificationBearishTrend = - hasVerificationTrend && - IsBearish(verificationTrendDir); - - // - // Analyse ... - ENUM_X_DIRECTION analyseTrendDir; - bool hasAnalyseTrend = - analyseCycleHelper - .DetectMarketStructure( - analyseTrendDir // - ); - bool hasAnalyseBullishTrend = - hasAnalyseTrend && - IsBullish(analyseTrendDir); - bool hasAnalyseBearishTrend = - hasAnalyseTrend && - IsBearish(analyseTrendDir); - - // - // Decision ... - ENUM_X_DIRECTION decisionTrendDir; - bool hasDecisionTrend = - decisionCycleHelper - .DetectMarketStructure( - decisionTrendDir // - ); - bool hasDecisionBullishTrend = - hasDecisionTrend && - IsBullish(decisionTrendDir); - bool hasDecisionBearishTrend = - hasDecisionTrend && - IsBearish(decisionTrendDir); - - // - // Detect Bar State ... - - // - // Engulf ... - ENUM_X_DIRECTION cBarEngulfDir; - bool isCBarEngulfed = decisionCycleHelper - .mBarAnalyser - .IsEngulfBar( - cBar, - cBarEngulfDir, - 0 // Extended ... - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarEngulfDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarEngulfDir); - - // - // Momentum ... - ENUM_X_DIRECTION cBarMomentumDir; - bool isCBarMomentum = decisionCycleHelper - .mBarAnalyser - .IsMomentumBar( - cBar, - cBarMomentumDir, - 0 // Extended ... - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarMomentumDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarMomentumDir); - - // - // Reject ... - ENUM_X_DIRECTION cBarRejectDir; - bool isCBarRejected = decisionCycleHelper - .mBarAnalyser - .IsRejectionBar( - cBar, - cBarRejectDir, - 0 // Extended ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarRejectDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarRejectDir); - - // - // HH/LL Break ... - - // - bool isCBarBreaksUpHH = IsBarBreak( - hh, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isCBarBreaksDownLL = IsBarBreak( - hh, - X_DIRECTION_BEARISH, - cBar // - ); - - // - // Bar Checking Summary ... - - // - // Bullish ... - bool isCBarBullishFormed = - // - isCBarBreaksUpHH || - isCBarBullishEngulfed || - isCBarBullishMomentum || - isCBarBullishRejected - // - ; - - // - // Bearish ... - bool isCBarBearishFormed = - // - isCBarBreaksDownLL || - isCBarBearishEngulfed || - isCBarBearishMomentum || - isCBarBearishRejected - // - ; - - // - // Detect PV Pivot ... - - // - bool isPivotPeakZoneRejected = false; - bool isPivotPeakZoneBreakedUp = false; - bool isPivotPeakZoneBreakedDown = false; - bool isPivotValeZoneRejected = false; - bool isPivotValeZoneBreakedUp = false; - bool isPivotValeZoneBreakedDown = false; - bool hasPivot = conditions.pivotZone.IsValid(); - if (!hasPivot) - { - // - hasPivot = IsValid(X121SMCXSTRPVPivotStart); - if (!hasPivot) - { - // - bool isNewVale = decisionXConditions.isNewVale; - bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; - bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - - // - bool isNewPeak = decisionXConditions.isNewPeak; - bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; - bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - - // - bool isValeStart = - // isSameVales; - isSameVales && - isSameCycleVales; - bool isPeakStart = - // isSamePeaks; - isSamePeaks && - isSameCyclePeaks; - - // - bool isStart = isPeakStart || - isValeStart; - if (isStart) - { - // - X121SMCXSTRPVPivotStart = cTime; - X121SMCXSTRPVPivotType = - isPeakStart - ? XPV_PEAK - : XPV_VALE; - - // - X121SMCXSTRPVPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXSTRPVPivotVale = decisionXConditions.valesBuffer[1]; - } - - // - hasPivot = IsValid(X121SMCXSTRPVPivotStart); - - // - // Create XPVPivot instance ... - if (hasPivot) - { - // - conditions.pivotZone.symbol = symbol; - conditions.pivotZone.period = period; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition = 3; - - // - conditions.pivotZone.upper = X121SMCXSTRPVPivotPeak; - conditions.pivotZone.lower = X121SMCXSTRPVPivotVale; - - // - conditions.pivotZone.type = X121SMCXSTRPVPivotType; - conditions.pivotZone.from = X121SMCXSTRPVPivotStart; - } - } - } - - // - if (hasPivot) - { - // - bool isBreaked = X121SMCXSTRPVPivotType == XPV_PEAK - ? decisionXConditions.isBreakedUpPrevPeak - : decisionXConditions.isBreakedDownPrevVale; - - // - if (!isBreaked) - { - // - X121SMCXSTRPVPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXSTRPVPivotVale = decisionXConditions.valesBuffer[1]; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition++; - conditions.pivotZone.upper = X121SMCXSTRPVPivotPeak; - conditions.pivotZone.lower = X121SMCXSTRPVPivotVale; - } - else - { - // - X121SMCXSTRPVPivotEnd = cTime; - conditions.pivotZone.to = cTime; - } - - // - // Fill Pivot State ... - - // - XPOIState analysePivotState; - DetectPivotPOIs( - conditions.pivotZone, - analyseState, - analysePivotState // - ); - - // - XPOIState decisionPivotState; - DetectPivotPOIs( - conditions.pivotZone, - decisionState, - decisionPivotState // - ); - - // - // Combine two State ... - XPOIState combinedPivotState; - XPOIState iStates[]; - AddRef( - analysePivotState, - iStates // - ); - AddRef( - decisionPivotState, - iStates // - ); - CombineStates( - combinedPivotState, - iStates // - ); - combinedPivotState = decisionPivotState; - - // - ArrayFree(iStates); - - // - combinedPivotState.time = decisionPivotState.time; - combinedPivotState.symbol = decisionPivotState.symbol; - combinedPivotState.period = decisionPivotState.period; - - // - // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... - FilterPivotState( - conditions.pivotZone, - combinedPivotState // - ); - - // - conditions.pivotZone.state = combinedPivotState; - - // - double peakUpper = 0; - double peakLower = 0; - double valeUpper = 0; - double valeLower = 0; - - // - datetime peakTo = NULL; - datetime valeTo = NULL; - datetime peakFrom = NULL; - datetime valeFrom = NULL; - - // - bool hasBoxData = DetectPivotStateBoxData( - conditions.pivotZone, - peakUpper, - peakLower, - peakFrom, - peakTo, - valeUpper, - valeLower, - valeFrom, - valeTo // - ); - - // - // Calculate Pivot Tick Zones ... - - // - int ticksLevels = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneLevel(); - int ticksRange = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneRange(); - - // - CalculatePivotTickZone( - conditions.pivotZone, - ticksLevels, - ticksRange // - ); - - // - isPivotPeakZoneRejected = - hasBoxData && - ( - // - IsBarReject( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - peakUpper, - X_DIRECTION_BEARISH, - cBar // - ) - // - ); - isPivotPeakZoneBreakedUp = - hasBoxData && - IsBarBreak( - peakUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotPeakZoneBreakedDown = - hasBoxData && - IsBarBreak( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotValeZoneRejected = - hasBoxData && - ( - // - IsBarReject( - valeLower, - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ) - // - ); - isPivotValeZoneBreakedUp = - hasBoxData && - IsBarBreak( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotValeZoneBreakedDown = - hasBoxData && - IsBarBreak( - valeLower, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - bool isPivotEnded = IsValid(X121SMCXSTRPVPivotEnd); - if (isPivotEnded) - { - // - X121SMCXSTRPVPivotPeak = 0; - X121SMCXSTRPVPivotVale = 0; - X121SMCXSTRPVPivotEnd = NULL; - X121SMCXSTRPVPivotStart = NULL; - X121SMCXSTRPVPivotType = XPV_NONE; - - // - conditions.pivotZone.Clean(); - } - - // - // Detect Price Zone ... - - // - double pzPeak = decisionXConditions.peaksBuffer[1]; - double pzVale = decisionXConditions.valesBuffer[1]; - - // - // Detecting Analyse Price ones ... - XPriceZones analysePriceZone; - bool hasAnalysePriceZone = CalculatePriceInsideZones( - analysePriceZone, - analyseState, - cBar // - ); - double analysePriceZoneUpper = 0; - double analysePriceZoneLower = 0; - bool isAnalysePriceZoneValidForPeak = false; - bool isAnalysePriceZoneValidForVale = false; - if (hasAnalysePriceZone) - { - // - bool hasBoundary = analysePriceZone.GetBoundary( - X_DIRECTION_ALL, - analysePriceZoneUpper, - analysePriceZoneLower // - ); - - // - isAnalysePriceZoneValidForPeak = - hasBoundary && - pzPeak <= analysePriceZoneUpper && - pzPeak >= analysePriceZoneLower; - - // - isAnalysePriceZoneValidForVale = - hasBoundary && - pzVale <= analysePriceZoneUpper && - pzVale >= analysePriceZoneLower; - } - - // - // Detecting Verification Price ones ... - XPriceZones verificationPriceZone; - bool hasVerificationPriceZone = CalculatePriceInsideZones( - verificationPriceZone, - verificationState, - cBar // - ); - double verificationPriceZoneUpper = 0; - double verificationPriceZoneLower = 0; - bool isVerificationPriceZoneValidForPeak = false; - bool isVerificationPriceZoneValidForVale = false; - if (hasVerificationPriceZone) - { - // - bool hasBoundary = verificationPriceZone.GetBoundary( - X_DIRECTION_ALL, - verificationPriceZoneUpper, - verificationPriceZoneLower // - ); - - // - isVerificationPriceZoneValidForPeak = - hasBoundary && - pzPeak <= verificationPriceZoneUpper && - pzPeak >= verificationPriceZoneLower; - - // - isVerificationPriceZoneValidForVale = - hasBoundary && - pzVale <= verificationPriceZoneUpper && - pzVale >= verificationPriceZoneLower; - } - - // - // - // - - // - // Summarize Conditions ... - - // - // Decision Conditions ... - - // - bool isDecisionBullish = - // - hasPivot && - // - hasAnalysePriceZone && - analysePriceZone.IsBullish() && - isAnalysePriceZoneValidForVale && - // - // Decision ... - hasVerificationBullishTrend && - hasAnalyseBullishTrend && - hasDecisionBullishTrend && - decisionXConditions.isBreakedDownPrevAtrUpper && - ( - // - ((decisionXConditions.isSarBullish && - decisionXConditions.isCheBullish && - decisionXConditions.isBreakedUpPrevStr && - decisionXConditions.isStrSwitchedToBullish) || - (decisionXConditions.isStrBullish && - decisionXConditions.isSarBullish && - decisionXConditions.isBreakedUpPrevCheMax && - decisionXConditions.isCheSwitchedToBullish) || - (decisionXConditions.isStrBullish && - decisionXConditions.isCheBullish && - decisionXConditions.isBreakedUpPrevSar && - decisionXConditions.isSarSwitchedToBullish)) - // - ) - // - ; - - // - bool isDecisionBearish = - // - hasPivot && - // - hasAnalysePriceZone && - analysePriceZone.IsBearish() && - isAnalysePriceZoneValidForPeak && - // - // Decision ... - hasVerificationBearishTrend && - hasAnalyseBearishTrend && - hasDecisionBearishTrend && - decisionXConditions.isBreakedDownPrevAtrLower && - ( - // - ((decisionXConditions.isSarBearish && - decisionXConditions.isCheBearish && - decisionXConditions.isBreakedDownPrevStr && - decisionXConditions.isStrSwitchedToBearish) || - (decisionXConditions.isStrBearish && - decisionXConditions.isSarBearish && - decisionXConditions.isCheSwitchedToBearish && - decisionXConditions.isBreakedDownPrevCheMin) || - (decisionXConditions.isStrBearish && - decisionXConditions.isCheBearish && - decisionXConditions.isBreakedDownPrevSar && - decisionXConditions.isSarSwitchedToBearish)) - // - ) - // - ; - - // - bool hasDecisionCondition = isDecisionBullish || - isDecisionBearish; - if (hasDecisionCondition) - { - // - conditions.priceZone = analysePriceZone; - conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale; - - // - pzPeak = analysePriceZoneUpper; - pzVale = analysePriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - conditions.dir // - ); - - // - // Manipulate Conditions Point ... - - // - point = - isDecisionBullish ? pzPeak - : pzVale; - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isDecisionBullish - ? pzVale - : pzPeak; - } - - // - // Analyse Conditions ... - - // - bool isAnalyseBullish = - // - hasPivot && - // - !hasDecisionCondition && - // - hasVerificationPriceZone && - verificationPriceZone.IsBullish() && - isVerificationPriceZoneValidForVale && - // - hasConsolidationBullishTrend && - hasVerificationBullishTrend && - hasAnalyseBullishTrend && - analyseXConditions.isBreakedDownPrevAtrUpper && - // - ( - // - ((analyseXConditions.isSarBullish && - analyseXConditions.isCheBullish && - analyseXConditions.isBreakedUpPrevStr && - analyseXConditions.isStrSwitchedToBullish) || - (analyseXConditions.isStrBullish && - analyseXConditions.isSarBullish && - analyseXConditions.isBreakedUpPrevCheMax && - analyseXConditions.isCheSwitchedToBullish) || - (analyseXConditions.isStrBullish && - analyseXConditions.isCheBullish && - analyseXConditions.isBreakedUpPrevSar && - analyseXConditions.isSarSwitchedToBullish)) - // - ) - // - ; - - // - bool isAnalyseBearish = - // - hasPivot && - // - !hasDecisionCondition && - // - hasVerificationPriceZone && - verificationPriceZone.IsBearish() && - isVerificationPriceZoneValidForPeak && - // - hasConsolidationBearishTrend && - hasVerificationBearishTrend && - hasAnalyseBearishTrend && - analyseXConditions.isBreakedDownPrevAtrLower && - // - ( - // - ((analyseXConditions.isSarBearish && - analyseXConditions.isCheBearish && - analyseXConditions.isBreakedDownPrevStr && - analyseXConditions.isStrSwitchedToBearish) || - (analyseXConditions.isStrBearish && - analyseXConditions.isSarBearish && - analyseXConditions.isCheSwitchedToBearish && - analyseXConditions.isBreakedDownPrevCheMin) || - (analyseXConditions.isStrBearish && - analyseXConditions.isCheBearish && - analyseXConditions.isBreakedDownPrevSar && - analyseXConditions.isSarSwitchedToBearish)) - // - ) - // - ; - - // - bool hasAnalyseCondition = isAnalyseBullish || - isAnalyseBearish; - if (hasAnalyseCondition) - { - // - conditions.priceZone = analysePriceZone; - conditions.isPriceZoneValidForPeak = isVerificationPriceZoneValidForPeak; - conditions.isPriceZoneValidForVale = isVerificationPriceZoneValidForVale; - - // - pzPeak = analysePriceZoneUpper; - pzVale = analysePriceZoneLower; - - // - double point = GetEntry( - conditions.symbol, - conditions.dir // - ); - - // - // Manipulate Conditions Point ... - - // - point = - isAnalyseBullish ? pzPeak - : pzVale; - conditions.point = point; - - // - // Manipulate Conditions Pivot ... - - // - conditions.pivot = - isAnalyseBullish - ? pzVale - : pzPeak; - } - - // - // - // - - // - isBullish = - isAnalyseBullish || - isDecisionBullish; - - // - isBearish = - isAnalyseBearish || - isDecisionBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXSTRPVSiganlTrigger( - // - X121SMCStrategyXSTRPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions triggerXConditions = triggerConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions verificationXConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - // SAR ... - double sar = decisionXConditions.sarBuffer[1]; - - // - // STR ... - double str = decisionXConditions.strBuffer[1]; - - // - // CHE ... - double le1 = decisionXConditions.le1Buffer[1]; - double le2 = decisionXConditions.le2Buffer[1]; - double se1 = decisionXConditions.se1Buffer[1]; - double se2 = decisionXConditions.se2Buffer[1]; - - // - // ATR ... - double atrUpper = decisionXConditions.atrUpperBuffer[1]; - double atrLower = decisionXConditions.atrLowerBuffer[1]; - - // - // PV ... - double peak = decisionXConditions.peaksBuffer[1]; - double vale = decisionXConditions.valesBuffer[1]; - - // - int higherPeakIDX = -1; - double higherPeak = decisionCycleHelper - .mX121Helper - .xpvHelper.GetHigherPeak( - higherPeakIDX, - peak // - ); - - // - int lowerValeIDX = -1; - double lowerVale = decisionCycleHelper - .mX121Helper - .xpvHelper.GetLowerVale( - lowerValeIDX, - vale // - ); - - // - // Slopes ... - - // - bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; - - // - bool isSlopesBullish = - isRsiSlopeBullish && - isStrSlopeBullish && - isAtrUpperSlopeBullish && - isAtrLowerSlopeBullish && - isVwapFastSlopeBullish && - isVwapMidSlopeBullish && - isVwapSlowSlopeBullish; - - // - bool isSlopesBearish = - isRsiSlopeBearish && - isStrSlopeBearish && - isAtrUpperSlopeBearish && - isAtrLowerSlopeBearish && - isVwapFastSlopeBearish && - isVwapMidSlopeBearish && - isVwapSlowSlopeBearish; - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked && - isSlopesBullish && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked && - isSlopesBearish && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - // Detect Target ... - double target = CalculateTarget( - cBar, - decisionState, - setupDir // - ); - if (target == 0) - { - // - target = CalculateTarget( - cBar, - analyseState, - setupDir // - ); - - // - if (target == 0) - { - // - target = CalculateTarget( - cBar, - verificationState, - setupDir // - ); - } - } - target = 0; - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Filling SL Candidates ... - double momentumBarPointsDif = 30 * points; - - // - // Bullish Momentum Bar Selection ... - XOHCL bullishMomentumBar; - int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); - if (IsValidSize(bullishMomentumBarsCount)) - { - // - for (int i = 0; i < bullishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bullishMomentumBar.IsValid() || - (bullishMomentumBar.IsValid() && - bullishMomentumBar.low < entry && - bullishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bullishMomentumBar = iBar; - } - } - } - - // - // Bearish Momentum Bar Selection ... - XOHCL bearishMomentumBar; - int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); - if (IsValidSize(bearishMomentumBarsCount)) - { - // - for (int i = 0; i < bearishMomentumBarsCount; i++) - { - // - XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; - if (!isValidDistane) - { - continue; - } - - // - bool isIndexPassed = iBar.Index() <= 5; - if (!isIndexPassed) - { - continue; - } - - // - bool canSet = - !bearishMomentumBar.IsValid() || - (bearishMomentumBar.IsValid() && - bearishMomentumBar.high > entry && - bearishMomentumBar.Index() > iBar.Index()); - if (canSet) - { - bearishMomentumBar = iBar; - } - } - } - - // - double sls[]; - Add( - sar, - sls // - ); - Add( - str, - sls // - ); - - // - if (isBullish) - { - // - Add( - atrLower, - sls // - ); - - // // - // Add( - // vale, - // sls // - // ); - - // - if (bullishMomentumBar.IsValid()) - { - // - Add( - bullishMomentumBar.low, - sls // - ); - } - - // // - // if (IsValidIndex(lowerValeIDX)) - // { - // // - // Add( - // lowerVale, - // sls // - // ); - // } - - // - if (le1 != EMPTY_VALUE) - { - // - Add( - le1, - sls // - ); - } - - // - if (le2 != EMPTY_VALUE) - { - // - Add( - le2, - sls // - ); - } - } - else - { - // - Add( - atrUpper, - sls // - ); - - // // - // Add( - // peak, - // sls // - // ); - - // - if (bearishMomentumBar.IsValid()) - { - // - Add( - bearishMomentumBar.high, - sls // - ); - } - - // - // if (IsValidIndex(higherPeakIDX)) - // { - // // - // Add( - // higherPeak, - // sls // - // ); - // } - - // - if (se1 != EMPTY_VALUE) - { - // - Add( - se1, - sls // - ); - } - - // - if (se2 != EMPTY_VALUE) - { - // - Add( - se2, - sls // - ); - } - } - - // - double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - double riskInPoints = risk / points; - if (riskInPoints >= 150) - { - // - target = - isBullish - ? entry + (points * 200) - : entry - (points * 200); - - // - target = 0; - } - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.target = target; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Cleanup Arrays ... - ArrayFree(triggerPoiEvents); - ArrayFree(triggerCycleEvents); - ArrayFree(decisionPoiEvents); - ArrayFree(decisionCycleEvents); - ArrayFree(analysePoiEvents); - ArrayFree(analyseCycleEvents); - ArrayFree(verificationPoiEvents); - ArrayFree(verificationCycleEvents); - ArrayFree(consolidationPoiEvents); - ArrayFree(consolidationCycleEvents); - ArrayFree(visionPoiEvents); - ArrayFree(visionCycleEvents); - - // - return result; -} - -// -bool DetectX121SMCXSTRPVGuards( - X121SMCGuard &guards[], - const XPosition &positions[], - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper // -) -{ - // - bool result = false; - - // - string provider = ToString(X_121_SMC_PROVIDER_XSTRPV); - - // - result = DetectX121SMCGuards( - provider, - guards, - positions, - triggerCycleHelper, - decisionCycleHelper, - analyseCycleHelper, - verificationCycleHelper, - consolidationCycleHelper, - visionCycleHelper // - ); - - // - return result; -} - -// -int AddX121SMCXSTRPVConditionsIfNotExists( - X121SMCStrategyXSTRPVSignalConditions &item, - X121SMCStrategyXSTRPVSignalConditions &items[], - int maxAllowed = 10 // -) -{ - // - int result = 0; - - // - bool isSetuped = IsValid(item.setupTime) && - HasDirection(item.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(items); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXSTRPVSignalConditions tmpItems[]; - Copy( - items, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(item.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXSTRPVSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = item.dir == iItem.dir && - item.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - items, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - item, - items // - ); - - // - // Remove Olds ... - CleanupArray( - items, - maxAllowed // - ); - - // - result = ArraySize(items); - - // - return result; -} - -// -int DrawX121SMCXSTRPVConditions( - X121SMCStrategyXSTRPVSignalConditions &conditions, - XCBaseObject *&drawnObjects[], - XCPOIDrawer *drawer // -) -{ - // - int result = 0; - - // - Clean(drawnObjects); - - // - if (drawer == NULL) - { - return result; - } - - // - bool isSetuped = conditions.IsSetuped(); - if (!isSetuped) - { - return result; - } - - // - bool hasPriceZone = conditions.priceZone.IsValid(); - if (!hasPriceZone) - { - return result; - } - - // - int zonesObjCount = drawer.DrawPriceZone( - conditions.priceZone, - drawnObjects, - conditions.dir // - ); - result = zonesObjCount; - - // - return result; -} - -//