but I'm a bit stuck because I don't have enough knowledge yet, could you help me? it's a relatively simple code.
Multi-timeframe indicators are not where to start getting acquainted with MQL. The implementation of a multi-timeframe indicator cannot be simple in MQL.
But if you want to try bench pressing 150 kilograms during your first visit to the gym, you can search for information about multitimeframe on this site (articles, book).
If there is no description provided for what the indicator is supposed to do or how it's supposed to work, we can only guess by looking at the given code. That nz() function in pine is likely to be the least of your worries. It's just an error handling function if I'm not mistaken. It appears like some bull/bear power indicator.
not that simple, Pine makes it look simple
#property copyright "Copyright 2024, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 3 #property indicator_color1 clrGreen #property indicator_type1 DRAW_LINE #property indicator_color2 clrRed #property indicator_type2 DRAW_LINE #property indicator_color3 clrGray #property indicator_type3 DRAW_LINE #property indicator_minimum -1.08 #property indicator_maximum 1.08 input ENUM_TIMEFRAMES per = PERIOD_CURRENT; // Period //--- indicator buffers double LongBuffer[]; double ShortBuffer[]; double Zeromark[]; //--- variables for calculations datetime lastLongTime = 0; datetime lastShortTime = 0; MqlRates ch1[], ch2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0, LongBuffer); SetIndexBuffer(1, ShortBuffer); SetIndexBuffer(2, Zeromark); ArrayInitialize(LongBuffer, -1.0); ArrayInitialize(ShortBuffer, 1.0); ArrayInitialize(Zeromark, 0.0); return(INIT_SUCCEEDED); } double crossover(MqlRates &_ch1[], MqlRates &_ch2[], int i){ return _ch2[i].close > _ch1[i].open && _ch2[i-1].close < _ch1[i-1].open; } double crossunder(MqlRates &_ch1[], MqlRates &_ch2[], int i){ return _ch2[i].close < _ch1[i].open && _ch2[i-1].close > _ch1[i-1].open; } //+------------------------------------------------------------------+ //| Custom indicator iteration 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[]) { int prev = prev_calculated; int copied = CopyRates(_Symbol, per, 0, rates_total, ch1); if (copied < rates_total) { Print("Error copying open prices: ", GetLastError()); return prev; } copied = CopyRates(_Symbol, per, 0, rates_total, ch2); if (copied < rates_total) { Print("Error copying close prices: ", GetLastError()); return prev; } int start = rates_total-prev_calculated + (rates_total == prev_calculated); for (int i = MathMax(2, start); i < rates_total; i++){ Zeromark[i] = 0.0; LongBuffer[i] = -1; ShortBuffer[i] = 1; bool longSignal = crossover(ch1, ch2, i); bool shortSignal = crossunder(ch1, ch2, i); if (longSignal){ lastLongTime = time[i]; } if (shortSignal){ lastShortTime = time[i]; } bool crossoverLong = (lastLongTime > lastShortTime); bool crossoverShort = (lastShortTime > lastLongTime); crossoverLong ? LongBuffer[i-1] = 1.0 : LongBuffer[i-2] = -1.0; crossoverShort ? ShortBuffer[i-1] = -1.0 : ShortBuffer[i-2] = 1.0; } return (rates_total); } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi coders, I'm trying to convert a Pinescript indicator to MQL4/5, but I've been having troubles, I know there's no such thing as the "nz()" function in MQL, but I also know there are ways to replace it:
(https://www.mql5.com/en/forum/439178)
but I'm a bit stuck because I don't have enough knowledge yet, could you help me? it's a relatively simple code.
short = crossunder(ch2,ch1)
plot(0, title="Trigger", color=white)
This indicator should be displayed in a separate window.
Thanks in advance :)