-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
There is no such function as “iParabolicSAR”. Perhaps you should read the manual. List of MQL4 Functions - MQL4 Reference
- Read the call for iBands.
- Read the call for iStochastic.
- Read the call for iADX.
-
double bb_upper = iBands(NULL, 0, bb_period, bb_dev, PRICE_CLOSE, MODE_UPPER, counted_bars);
After the first call counted_bars will be equal to Bars and you are reading/writing after the oldest bar.
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)
have some error which is
The lines for sell and buy are identical .
- The stochastic was missing the mode (main or signal) and the stochastic price is STO_CLOSECLOSE or STO_HIGHLOW .
- The ParabolicSar is the iSAR in mt4
- The adx also needed MODE_MAIN or PLUS_DI MINUS_DI
- There was no loop for the iteration through bars
- You must also deflect the amount of bars equivalent to the number of required bars to exist for the calculation to be viable (although i think this is handled automatically now)
- The parameters for the indicators could be inputs so i placed them on top
- You needed more buffers for the calculation of all indicators , and 3 plots per the display
Now i'm curious if you feed this back to chatGPT and instruct it that this would be the correct form , (after you plug in the calculation for the sell[]) , will it learn ? (if this is the case can you actually send it to chatgpt and report on its response here ? thanks)
All this assumes you wanted it for mt4 . 😇
#property indicator_chart_window #property indicator_plots 3 #property indicator_buffers 10 #property indicator_color1 clrRed #property indicator_color2 clrBlue #property indicator_color3 clrGreen #property strict input int ikh_tenkan = 9; input int ikh_kijun = 26; input int ikh_senkou = 52; input int bb_period = 20; input double bb_dev = 2.0; input int rsi_period = 14; input int macd_fast = 12; input int macd_slow = 26; input int macd_signal = 9; input int sto_k_period = 14; input int sto_d_period = 3; input int sto_slowing = 3; input int sto_method = MODE_SMA; input int adx_period = 14; input int cci_period = 20; double PSAR[]; double IKH[]; double BB[]; double RSI[]; double MACD[]; double STO[]; double ADX[]; double CCI[]; double Buy[]; double Sell[]; int deflect=0; int OnInit() { SetIndexBuffer(0, Buy); SetIndexBuffer(1, Sell); SetIndexBuffer(2, PSAR); int co=3; SetIndexBuffer(co,IKH);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,BB);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,RSI);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,MACD);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,STO);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,ADX);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; SetIndexBuffer(co,CCI);SetIndexStyle(co,DRAW_NONE,EMPTY,EMPTY,clrNONE);co++; deflect=MathMax(MathMax(ikh_tenkan,ikh_kijun),ikh_senkou); deflect=MathMax(deflect,bb_period); deflect=MathMax(deflect,rsi_period); deflect=MathMax(deflect,macd_slow); deflect=MathMax(deflect,macd_signal); deflect=MathMax(deflect,sto_k_period*sto_d_period); deflect=MathMax(deflect,adx_period); deflect=MathMax(deflect,cci_period); 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[]) { int new_bars=rates_total-prev_calculated; int from=new_bars-deflect-2; if(new_bars>=1&&new_bars<deflect){ from=new_bars; } for(int i=from;i>=1;i--) { // Calculate Parabolic SAR double sar = iSAR(NULL, 0, 0.02, 0.2, i); PSAR[i] = sar; // Calculate Ichimoku Kinko Hyo double tenkan = iIchimoku(NULL, 0, ikh_tenkan, ikh_kijun, ikh_senkou, MODE_TENKANSEN, i); double kijun = iIchimoku(NULL, 0, ikh_tenkan, ikh_kijun, ikh_senkou, MODE_KIJUNSEN, i); double senkou = iIchimoku(NULL, 0, ikh_tenkan, ikh_kijun, ikh_senkou, MODE_SENKOUSPANA, i); IKH[i] = (tenkan + kijun + senkou) / 3; // Calculate Bollinger Bands double bb_upper = iBands(NULL, 0, bb_period, bb_dev,0, PRICE_CLOSE, MODE_UPPER, i); double bb_lower = iBands(NULL, 0, bb_period, bb_dev,0, PRICE_CLOSE, MODE_LOWER, i); BB[i] = (bb_upper + bb_lower) / 2; // Calculate Relative Strength Index double rsi = iRSI(NULL, 0, rsi_period, PRICE_CLOSE, i); RSI[i] = rsi; // Calculate Moving Average Convergence Divergence double macd = iMACD(NULL, 0, macd_fast, macd_slow, macd_signal, PRICE_CLOSE, MODE_MAIN, i); MACD[i] = macd; // Calculate Stochastic Oscillator double sto_k = iStochastic(NULL, 0, sto_k_period, sto_d_period, sto_slowing, sto_method,STO_CLOSECLOSE,MODE_MAIN,i); STO[i] = sto_k; // Calculate Average Directional Movement Index double adx = iADX(NULL, 0, adx_period, PRICE_CLOSE,MODE_MAIN,i); ADX[i] = adx; // Calculate Commodity Channel Index double cci = iCCI(NULL, 0, cci_period, PRICE_TYPICAL, i); CCI[i] = cci; // Calculate Buying Point Buy[i] = (PSAR[i] + IKH[i] + BB[i] + RSI[i] + MACD[i] + STO[i] + ADX[i] + CCI[i]) / 8; // Calculate Selling Point Sell[i] = (PSAR[i] + IKH[i] + BB[i] + RSI[i] + MACD[i] + STO[i] + ADX[i] + CCI[i]) / 8; } return(rates_total); }
The lines for sell and buy are identical .
- The stochastic was missing the mode (main or signal) and the stochastic price is STO_CLOSECLOSE or STO_HIGHLOW .
- The ParabolicSar is the iSAR in mt4
- The adx also needed MODE_MAIN or PLUS_DI MINUS_DI
- There was no loop for the iteration through bars
- You must also deflect the amount of bars equivalent to the number of required bars to exist for the calculation to be viable (although i think this is handled automatically now)
- The parameters for the indicators could be inputs so i placed them on top
- You needed more buffers for the calculation of all indicators , and 3 plots per the display
Now i'm curious if you feed this back to chatGPT and instruct it that this would be the correct form , (after you plug in the calculation for the sell[]) , will it learn ? (if this is the case can you actually send it to chatgpt and report on its response here ? thanks)
All this assumes you wanted it for mt4 . 😇
STO[i] = sto_k;
if i put like this, it will have
possible use of uninitialized variable 'i'
how to solve it??
actually, if coding like this it is ok???
- mt4 money #: how to solve it??
Don't use the uninitialized variable “i”, initialize it first.
-
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)
STO[i] = sto_k;
if i put like this, it will have
possible use of uninitialized variable 'i'
how to solve it??
actually, if coding like this it is ok???
Imagine the file you have opened is the "global scope" , and inside each function you have "the function scope".
If you -for example- remove the input words from the indicator parameters in the example i shared , then you will have your indicator parameters available for the calculations but the user wont be able to adjust them (you wont need to declare them in the oncalculate function that is)
Then when it comes to i , where is it running ? Where are you placing that code ?
If you changed the stochastic in your code to have STO_CLOSECLOSE,MODE_MAIN and i , then no it wont work .
The OnCalculate is telling you 2 things when it runs .
How many candles exist on the chart (rates_total)
And how many of them OnCalculate (the indicator) has processed so far.
So the first time it runs it will tell you "i have 100 candles and have processed 0 of them"
So you will have to loop inside those 100 candles and perform your operations . That is what "i" could be .
So unlike trading view , you have to iterate , it does not apply your calculations to all past candles
-
Don't use the uninitialized variable “i”, initialize it first.
-
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)
how initialize
Imagine the file you have opened is the "global scope" , and inside each function you have "the function scope".
If you -for example- remove the input words from the indicator parameters in the example i shared , then you will have your indicator parameters available for the calculations but the user wont be able to adjust them (you wont need to declare them in the oncalculate function that is)
Then when it comes to i , where is it running ? Where are you placing that code ?
If you changed the stochastic in your code to have STO_CLOSECLOSE,MODE_MAIN and i , then no it wont work .
The OnCalculate is telling you 2 things when it runs .
How many candles exist on the chart (rates_total)
And how many of them OnCalculate (the indicator) has processed so far.
So the first time it runs it will tell you "i have 100 candles and have processed 0 of them"
So you will have to loop inside those 100 candles and perform your operations . That is what "i" could be .
So unlike trading view , you have to iterate , it does not apply your calculations to all past candles
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
have some error which is
'iParabolicSAR' - function not defined,
'iBands' - wrong parameters count,
'iBands' - wrong parameters count,
'iStochastic' - wrong parameters count,
improper enumerator cannot be used,
'iADX' - wrong parameters count,
variable 'i' not used