Define the type of MA in combination with several Timeframes.
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
Replies
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
Thank you very much, I was thinking to much MQL5.
@jmmslagter
PanagiotisCharalampous
14 Mar 2022, 08:26
Hi jmmslagter,
Here is an example on how you can feed an indicator with data from another timeframe.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous