Vaibhav Vishwakarma:
I have this indicator on trading view that I'm trying to replicate on MT5 but it's like a dead end.
The trading view indicator works by plotting ALMA on the current timeframe and then going 8x the current timeframe to get the ALT ALMA values on the new obtained timeframe.
I'm super close (I think) on the MT5 side but they are not matching no matter what I do, here's the code for both platforms.
SO for M5 timeframe, the TradingView code goes to 8x5 = 40.
TradingView:
I have this indicator on trading view that I'm trying to replicate on MT5 but it's like a dead end.
The trading view indicator works by plotting ALMA on the current timeframe and then going 8x the current timeframe to get the ALT ALMA values on the new obtained timeframe.
I'm super close (I think) on the MT5 side but they are not matching no matter what I do, here's the code for both platforms.
SO for M5 timeframe, the TradingView code goes to 8x5 = 40.
TradingView:
MT5:
Generate the Custom Symbol/chart:
Aleksandr Slavskii, 2025.07.13 12:13
An analogue of Period Converter in MT4And then apply the indicator to the Custom Symbol/chart:
Forum on trading, automated trading systems and testing trading strategies
Indicators: ALMA(Arnaud Legoux Moving Average)
xtemer, 2021.04.03 04:58
The indicator doesn't work, there is compile error: 'iTime' - override system function alma_v2.mq5 209 10
I think this function should be removed as current version of MQL5 already has built-in iTime function.
datetime iTime(string symbol,ENUM_TIMEFRAMES TF,int index) { if(index < 0) return(-1); static datetime timearray[]; if(CopyTime(symbol,TF,index,1,timearray) > 0) return(timearray[0]); else return(-1); }
Attached the fixed mq5 file (note: you have to click "Go to discussion" link to see the attachment)
Ryan L Johnson #:
ALMA works perfectly but I still can't get the custom timeframe part going, Generate the Custom Symbol/chart:
And then apply the indicator to the Custom Symbol/chart:
I got very close but still not matching tradingview.
here is the latest code:
#property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 4 #property indicator_label1 "ALMA Close (LTF)" #property indicator_type1 DRAW_LINE #property indicator_color1 clrOrange #property indicator_width1 2 #property indicator_label2 "ALMA Open (LTF)" #property indicator_type2 DRAW_LINE #property indicator_color2 clrDodgerBlue #property indicator_width2 2 #property indicator_label3 "closeAlt (HTF ALMA)" #property indicator_type3 DRAW_LINE #property indicator_color3 clrLime #property indicator_width3 3 #property indicator_label4 "openAlt (HTF ALMA)" #property indicator_type4 DRAW_LINE #property indicator_color4 clrRed #property indicator_width4 3 input int Length = 2; input double Offset = 0.85; input double Sigma = 5; input int TF_Multiplier = 8; double AlmaClose[]; double AlmaOpen[]; double closeAltBuf[]; double openAltBuf[]; double Weights[]; void ComputeWeights() { ArrayResize(Weights, Length); double m = Offset * (Length - 1); double s = (double)Length / Sigma; double wsum = 0; for(int i = 0; i < Length; i++) { Weights[i] = MathExp(-((i - m)*(i - m)) / (2*s*s)); wsum += Weights[i]; } for(int i = 0; i < Length; i++) Weights[i] /= wsum; } double ALMAonArray(const double &arr[], int newestIdx) { if(newestIdx < Length - 1) return EMPTY_VALUE; double sum = 0; for(int i = 0; i < Length; i++) sum += arr[newestIdx - i] * Weights[Length - 1 - i]; return sum; } int OnInit() { SetIndexBuffer(0, AlmaClose); SetIndexBuffer(1, AlmaOpen); SetIndexBuffer(2, closeAltBuf); SetIndexBuffer(3, openAltBuf); ArrayInitialize(closeAltBuf, EMPTY_VALUE); ArrayInitialize(openAltBuf, EMPTY_VALUE); ComputeWeights(); return INIT_SUCCEEDED; } 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[]) { if(rates_total < Length) return 0; int start = (prev_calculated < Length) ? Length - 1 : prev_calculated; // Calculate LTF ALMA for(int bar = start; bar < rates_total; bar++) { AlmaClose[bar] = ALMAonArray(close, bar); AlmaOpen[bar] = ALMAonArray(open, bar); } // Build synthetic 8x blocks int blockId[]; ArrayResize(blockId, rates_total); int block = 0; int pos = 0; for(int bar = 0; bar < rates_total; bar++) { blockId[bar] = block; pos++; if(pos == TF_Multiplier) { block++; pos = 0; } } int maxBlock = blockId[rates_total - 1]; int blockFirst[]; int blockLast[]; ArrayResize(blockFirst, maxBlock + 1); ArrayResize(blockLast, maxBlock + 1); ArrayInitialize(blockFirst, -1); ArrayInitialize(blockLast, -1); for(int bar = 0; bar < rates_total; bar++) { int b = blockId[bar]; if(blockFirst[b] == -1) blockFirst[b] = bar; blockLast[b] = bar; } // Sample HTF values directly from LTF ALMA double htfCloseAlt[]; double htfOpenAlt[]; ArrayResize(htfCloseAlt, maxBlock + 1); ArrayResize(htfOpenAlt, maxBlock + 1); for(int b = 0; b <= maxBlock; b++) { if(blockLast[b] >= Length - 1) htfCloseAlt[b] = AlmaClose[blockLast[b]]; else htfCloseAlt[b] = EMPTY_VALUE; if(blockFirst[b] >= Length - 1) htfOpenAlt[b] = AlmaOpen[blockFirst[b]]; else htfOpenAlt[b] = EMPTY_VALUE; } // Project HTF values back to LTF bars for(int bar = 0; bar < rates_total; bar++) { int b = blockId[bar]; if(b >= 0 && b <= maxBlock) { closeAltBuf[bar] = htfCloseAlt[b]; openAltBuf[bar] = htfOpenAlt[b]; } else { closeAltBuf[bar] = EMPTY_VALUE; openAltBuf[bar] = EMPTY_VALUE; } } return rates_total; }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The trading view indicator works by plotting ALMA on the current timeframe and then going 8x the current timeframe to get the ALT ALMA values on the new obtained timeframe.
I'm super close (I think) on the MT5 side but they are not matching no matter what I do, here's the code for both platforms.
SO for M5 timeframe, the TradingView code goes to 8x5 = 40.
TradingView:
MT5: