From 492dcf5789249fc9e99539243189d877edf26190 Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Fri, 15 Aug 2025 11:39:51 +0200 Subject: [PATCH] new files added --- .../FisherTransform_HeikenAshi.mq5 | 187 ++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Indicators/MyIndicators/FisherTransform_HeikenAshi.mq5 diff --git a/Indicators/MyIndicators/FisherTransform_HeikenAshi.mq5 b/Indicators/MyIndicators/FisherTransform_HeikenAshi.mq5 new file mode 100644 index 0000000..8d536d7 --- /dev/null +++ b/Indicators/MyIndicators/FisherTransform_HeikenAshi.mq5 @@ -0,0 +1,187 @@ +//+------------------------------------------------------------------+ +//| FisherTransform_HeikenAshi.mq5 | +//| Copyright 2025, xxxxxxxx | +//| | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, xxxxxxxx" +#property link "" +#property version "1.00" +#property description "Fisher Transform Oscillator on Heiken Ashi data" + +//--- Custom Toolkit Include --- +#include + +//--- Indicator Window and Level Properties --- +#property indicator_separate_window +#property indicator_level1 1.5 +#property indicator_level2 0.75 +#property indicator_level3 0.0 +#property indicator_level4 -0.75 +#property indicator_level5 -1.5 +#property indicator_levelstyle STYLE_DOT + +//--- Buffers and Plots --- +#property indicator_buffers 3 // Fisher, Trigger, and 1 calculation buffer +#property indicator_plots 2 + +//--- Plot 1: Fisher line +#property indicator_label1 "HA_Fisher" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +//--- Plot 2: Trigger line +#property indicator_label2 "HA_Trigger" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrange +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +//--- Input Parameters --- +input int InpLength = 9; // Length + +//--- Indicator Buffers --- +double BufferHA_Fisher[]; +double BufferHA_Trigger[]; +double BufferValue[]; // Calculation buffer for the intermediate 'value' + +//--- Global Objects and Variables --- +int ExtLength; +CHA_Calculator g_ha_calculator; + +//--- Forward declarations for helper functions --- +double Highest(const double &array[], int period, int current_pos); +double Lowest(const double &array[], int period, int current_pos); + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function. | +//+------------------------------------------------------------------+ +void OnInit() + { +//--- Validate and store input + ExtLength = (InpLength < 1) ? 1 : InpLength; + +//--- Map the buffers + SetIndexBuffer(0, BufferHA_Fisher, INDICATOR_DATA); + SetIndexBuffer(1, BufferHA_Trigger, INDICATOR_DATA); + SetIndexBuffer(2, BufferValue, INDICATOR_CALCULATIONS); + +//--- Set all buffers to non-timeseries for stable calculation + ArraySetAsSeries(BufferHA_Fisher, false); + ArraySetAsSeries(BufferHA_Trigger, false); + ArraySetAsSeries(BufferValue, false); + +//--- Set indicator properties + IndicatorSetInteger(INDICATOR_DIGITS, 4); + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ExtLength); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ExtLength + 1); + IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("HA_Fisher(%d)", ExtLength)); + } + +//+------------------------------------------------------------------+ +//| Fisher Transform on Heiken Ashi calculation 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[]) + { +//--- Check for enough data + if(rates_total < ExtLength) + return(0); + +//--- STEP 1: Calculate Heiken Ashi bars using our toolkit + if(!g_ha_calculator.Calculate(rates_total, 0, open, high, low, close)) + return(0); + +//--- STEP 2: Create a buffer for Heiken Ashi HL2 price + double ha_hl2[]; + ArrayResize(ha_hl2, rates_total); + for(int i=0; i 0) + price_pos = (ha_hl2[i] - low_) / range - 0.5; + + BufferValue[i] = 0.33 * 2 * price_pos + 0.67 * BufferValue[i-1]; + + if(BufferValue[i] > 0.999) + BufferValue[i] = 0.999; + if(BufferValue[i] < -0.999) + BufferValue[i] = -0.999; + + // Calculate the Fisher Transform value + double log_val = 0.5 * MathLog((1 + BufferValue[i]) / (1 - BufferValue[i])); + BufferHA_Fisher[i] = log_val + 0.5 * BufferHA_Fisher[i-1]; + + // The trigger is the previous Fisher value + BufferHA_Trigger[i] = BufferHA_Fisher[i-1]; + } + + return(rates_total); + } + +//+------------------------------------------------------------------+ +//| Finds the highest value in a given period of an array. | +//+------------------------------------------------------------------+ +double Highest(const double &array[], int period, int current_pos) + { + double res = array[current_pos]; + for(int i = 1; i < period; i++) + { + int index = current_pos - i; + if(index < 0) + break; + if(res < array[index]) + res = array[index]; + } + return(res); + } + +//+------------------------------------------------------------------+ +//| Finds the lowest value in a given period of an array. | +//+------------------------------------------------------------------+ +double Lowest(const double &array[], int period, int current_pos) + { + double res = array[current_pos]; + for(int i = 1; i < period; i++) + { + int index = current_pos - i; + if(index < 0) + break; + if(res > array[index]) + res = array[index]; + } + return(res); + } +//+------------------------------------------------------------------+ +//+------------------------------------------------------------------+