Define the type of MA in combination with several Timeframes.

Created at 13 Mar 2022, 20:18
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!
JM

jmmslagter

Joined 17.11.2021

Define the type of MA in combination with several Timeframes.
13 Mar 2022, 20:18


I  have an MQL5 background and can read different MA values in various  Timeframes with, for example, the definition

int iTEMADefinitionClose =iTEMA(_Symbol,PERIOD_H4,8,0,PRICE_CLOSE);

 

iTEMA = Triple EMA.

 

In cAlgo I  have taken the cAlgo example:

[Parameter()]

public DataSeries Source {get;set;}

[Parameter(DefaultValue =14)]

public int periodfast {get;set;}

[Parameter(DefaultValue =24)]

public int periodslow {get;set;}

private TimeSeriesMovingAverage tsmfast;

private TimeSeriesMovingAverage tsmslow;

protectedoverridevoid OnStart()

{

            tsmfast = Indicators.TimeSeriesMovingAverage(Source, periodfast);

            tsmslow = Indicators.TimeSeriesMovingAverage(Source, periodslow);

}

protectedoverridevoid OnTick()

{

//If TSMA with period 14 moves above TSMA with period 24

if(tsmfast.Result.LastValue > tsmslow.Result.LastValue)

{

//Do something

}

}

How can I define the timeframe and the type of MA (HullMA, EMA etc.)? An answer in the form of example code is sufficient.

Thanks

Hans


@jmmslagter
Replies

PanagiotisCharalampous
14 Mar 2022, 08:26

Hi jmmslagter,

Here is an example on how you can feed an indicator with data from another timeframe.

var tsmfast = Indicators.TimeSeriesMovingAverage(MarketData.GetBars(TimeFrame.Hour).ClosePrices, 14);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

jmmslagter
14 Mar 2022, 11:30

RE:

PanagiotisCharalampous said:

Hi jmmslagter,

Here is an example on how you can feed an indicator with data from another timeframe.

var tsmfast = Indicators.TimeSeriesMovingAverage(MarketData.GetBars(TimeFrame.Hour).ClosePrices, 14);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Thank you very much, I was thinking to much MQL5.


@jmmslagter