Get MovingAverages on Histogram

Created at 16 Jan 2024, 10:59
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AH

ahmadtrader448

Joined 29.11.2023

Get MovingAverages on Histogram
16 Jan 2024, 10:59


 

hello guys,

I calculated histograms over the higher timeframe of 15 minutes timeframe and fitted them on a lower timeframe of 5 minutes,

Is there any way to get a moving average on the higher timeframe histograms of 15 minutes on a lower timeframe of 5 minutes? 


@ahmadtrader448
Replies

PanagiotisCharalampous
17 Jan 2024, 07:00

Responded here 

https://ctrader.com/forum/announcements/1463#post-106931


@PanagiotisCharalampous

ahmadtrader448
18 Jan 2024, 13:41

RE: Get MovingAverages on Histogram

Hi Panag,

I wanna get the moving average on the Histogram time series which is calculated on higher timeframes such as (15 minutes) on a lower timeframe chart (5 Min), I got the histogram time series on a higher timeframe(15 minutes)  correct, but when trying to get Moving averages on that histogram not return the correct data values ( data values of Movingaverage on 15 Min Histograme on lower time frame chart (5 min) not equal  data values of Movingaverage on 15 Min Histograme on higher timeframe chart (15 min) ), and to be more specific I will set part of my code to check my processes.

all processes return correct data values, expect Movingaverages  on Histogram, Knowing as i drop that indicator 2 time first time on 5 minutes chart ana second time on 15 minutes chart

//-----------------------------------------------------------------------------------------------------------------------------------------

// import required libraries
//-------------------------- 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

// Main Function 
namespace cAlgo
{
   
   [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None ,AutoRescale = false)]
   public class MAsON_MTFHistograms : Indicator
   {
       // Get Bars for MTFs Histogram Field prices:
       private Bars baseBarsMTFHistogramFP   ;
       // Get Bars for MTFs Histogram Movingaverages:
       private Bars baseBarsMTFHistogramMAs  ;
       //-------------------------------------------------
       //-------------------------------------------------
       // TFs Selector Paramters ::
       [Parameter("MTFs", DefaultValue = "Minute15", Group = "MTF Histogram Calcu Paramters")]
       public TimeFrame TFS { get; set; }

       // MTFS Histograms Field Prices Selector ::      
       [Parameter("MTF Histogram Applied Price", DefaultValue = FPs.Close,Group = "MTF Histogram Calcu Paramters")]
       public FPs MTFHistogramFP { get; set; }
       // MTFs Histogram MAs Methods:
       [Parameter("MTF Histogram MAs Method"   , DefaultValue = MovingAverageType.Simple, Group = "MTF Histogram Calcu Paramters")]   
       public MovingAverageType MTFHistogramMAsMethod { get; set; }
       //   MTFs Histogram MAs Field Price:
       [Parameter("MTF Histogram MAs FP"       , DefaultValue = DataSeriesType.Close,Group = "MTF Histogram Calcu Paramters")]
       public DataSeriesType MTFHistogramMAsFP { get; set; }
       //   MTFs Histogram MAs Periodicity:
       [Parameter("MTF Histogram MAs Period"   , DefaultValue = 14, MinValue = 1, Group = "MTF Histogram Calcu Paramters")]
       public int MTFHistogramMAsPeriod { get; set; }
       //-------------------------------------------------------------------------------------
       //-------------------------------------------------------------------------------------
       //   MAs on MTFs Histograms Method  : 
       [Parameter("MAs on MTFHistogram Method", DefaultValue = MovingAverageType.Simple, Group = "MAs on MTF Histogram Calcu Paramters")]   
       public MovingAverageType MAsonMTFHistogramMethod { get; set; }
       //   MAs on MTFs Histograms Periodicity  : 
       [Parameter("MAs on MTFHistogram Period", DefaultValue = 14, MinValue = 1, Group = "MAs on MTF Histogram Calcu Paramters")]
       public int MAsonMTFHistogramPeriod { get; set; }
       //-----------------------------------------------------------------------------------------------------
       //-----------------------------------------------------------------------------------------------------
       // Out Put VAloies to precient values :
       [Output("Validate_Values"  , LineColor = "Green", PlotType = PlotType.Line, Thickness = 3)]
       public IndicatorDataSeries Validate_Values { get; set; }
//================================================================================================ 
       // MTFHistogram  MAs intialization as Movingaverages :
       private MovingAverage MTFHistogramMAs;
       // MTFHistogram intialization as DataSeries :
       private IndicatorDataSeries MTFHistogram;
       // MTFHistogram intialization as Movingaverages :
       private MovingAverage MAsonMTFHistogram;
//================================================================================================ 
       protected override void Initialize()
       {
           // Get Bars MTFS Histograms Field prices:
           baseBarsMTFHistogramFP    = MarketData.GetBars(TFS);
           // Get Bars MTFS Histograms Moving averages :
           baseBarsMTFHistogramMAs  = MarketData.GetBars(TFS);
           var baseSeriesDevMAsBTFs = GetBaseSeriesMTFHistogramMAs();
           MTFHistogramMAs  = Indicators.MovingAverage(baseSeriesDevMAsBTFs    , MTFHistogramMAsPeriod , MTFHistogramMAsMethod);
           // MTFs MAs onDev calcu 
           MTFHistogram         = CreateDataSeries();
           MAsonMTFHistogram    = Indicators.MovingAverage(MTFHistogram  , MAsonMTFHistogramPeriod  , MAsonMTFHistogramMethod);
       }
//================================================================================================ 
       public override void Calculate(int i)
       {
           
           // MTFs DevFPs 
           var MTFHIstogramFPindx   = baseBarsMTFHistogramFP.OpenTimes.GetIndexByTime(Bars.OpenTimes[i]);
           var MTFHIstogramFPBTF_Val = 0.0;
            switch (MTFHistogramFP)
            {
                case FPs.Open:
                   MTFHIstogramFPBTF_Val =  baseBarsMTFHistogramFP.OpenPrices[MTFHIstogramFPindx] ;
                   break;
                case FPs.High:
                   MTFHIstogramFPBTF_Val =  baseBarsMTFHistogramFP.HighPrices[MTFHIstogramFPindx];
                   break;
                case FPs.Low:
                   MTFHIstogramFPBTF_Val =  baseBarsMTFHistogramFP.LowPrices[MTFHIstogramFPindx] ;
                   break;
                case FPs.Close:
                   MTFHIstogramFPBTF_Val =  baseBarsMTFHistogramFP.ClosePrices[MTFHIstogramFPindx] ;
                   break;  
            }
           //----------------------------------------------------------------------------------------------
           // MTFs Histogram CAlculations :
           var MTFHIstogramMAsindx    = baseBarsMTFHistogramMAs.OpenTimes.GetIndexByTime(Bars.OpenTimes[i]);
           MTFHistogram[i]            = MTFHIstogramFPBTF_Val  - MTFHistogramMAs.Result[MTFHIstogramMAsindx];
           // MAs on MTF HIstograms Calcu ::
           Validate_Values[i]         = MAsonMTFHistogram.Result[i];
           //-----------------------------------------------------------------------------------------------

       } // End of the Processes function ::
//================================================================================================ 
       // Get Field Prices Based on Drop down list of Field Prices paramters :
       //---------------------------------
       private DataSeries GetBaseSeriesMTFHistogramMAs()
       {
           switch (MTFHistogramMAsFP)
           {
               case DataSeriesType.Open:
                   return baseBarsMTFHistogramMAs.OpenPrices;
                   
               case DataSeriesType.High:
                   return baseBarsMTFHistogramMAs.HighPrices;

               case DataSeriesType.Low:
                   return baseBarsMTFHistogramMAs.LowPrices;

               case DataSeriesType.Close:
                   return baseBarsMTFHistogramMAs.ClosePrices;
               default:

                   throw new ArgumentOutOfRangeException("DataSeriesType");
           }
       }
//================================================================================================ 

   } // End
//================================================================================================ 
//================================================================================================ 
    // drop down list fo FPs:
    public enum DataSeriesType
    {
        Open,
        High,
        Low,
        Close
    }
   //-------------------------
    // drop down list fo FPs:
    public enum FPs
    {
        Open,
        High,
        Low,
        Close
    }
   //-------------------------
}

//------------------------------------------------------------------------------------------------------------------------------------------

 

Best regards,

Ahmad

 


@ahmadtrader448