e-Invester Posted June 18, 2012 Report Share Posted June 18, 2012 (edited) Hi there, I just started learning MQL4, and need this indicator for my system to work, but tried coding it from my old platform (in another language), but cant get it to show in the chart window in Meta Trader. Here the mgl code that I have. Help will be greatly appreciated!!=D>=D>=D>=D>=D>=D>=D>=D>=D> P.S> I know this calculation looks different than those used in the ACI indicators, but this was the calculation my old platform used and need to duplicate it for my system to run. #property copyright "" #property link "" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Blue extern double T = 300.0; double ExtMapBuffer1[]; double SIBuffer[]; int init() { IndicatorBuffers(2); SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, ExtMapBuffer1); SetIndexLabel(0, "Swing Index"); SetIndexBuffer(1, SIBuffer); SetIndexEmptyValue(0, 0.0); SetIndexEmptyValue(1, 0.0); return(0); } int deinit() { return(0); } int start() { int counted_bars = IndicatorCounted(); int i, limit; double R, TR, AA, BB, CC, DD, Tpoints, X,K,ER,SH1,SH2,SI; if(counted_bars == 0) limit = Bars - 1; if(counted_bars > 0) limit = Bars - counted_bars; Tpoints = T*MarketInfo(Symbol(), MODE_POINT); for(i = limit; i >= 0; i--) { AA = MathAbs(High - Close[i-1]); BB = MathAbs(Low - Close[i-1]); CC = MathAbs(High - Low[i-1]); DD = MathAbs(Close[i+1] - Open[i-1]); if(AA>BB && AA>CC) { R = (AA+BB)/2 + DD/4; } if (BB>CC && BB>AA) { R = (BB+AA)/2 + DD/4; } else { R = (CC+DD)/4; } X =(Close-Close[i+1]+(Close-Open)/2 + Close[i+1] - Open[i+1] ); SIBuffer =16 * X/R * MathMax (AA,BB); } return(0); } //+------------------------------------------------------------------+ Edited June 18, 2012 by e-Invester Quote Link to comment Share on other sites More sharing options...
⭐ luxinterior Posted June 18, 2012 Report Share Posted June 18, 2012 First thing that jumps out is you've specifically specified to NOT show it in the chart window... #property indicator_separate_window It should be... #property indicator_chart_window Hope that helps. Good luck Lux Quote Link to comment Share on other sites More sharing options...
⭐ luxinterior Posted June 18, 2012 Report Share Posted June 18, 2012 First thing that jumps out is you've specifically specified to NOT show it in the chart window... #property indicator_separate_window It should be... #property indicator_chart_window Hope that helps. Good luck Lux Quote Link to comment Share on other sites More sharing options...
iwjw Posted June 18, 2012 Report Share Posted June 18, 2012 you have defined 1 indicator_buffer, but 2 Indexbuffer the indicator will only plot values that are in the buffer with index=0 in this case it's ExtMapBuffer1 that you aren't filling at all either set SIBuffer to index= 0 and delete ExtMapBuffer1 or fill the latter one e-Invester 1 Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 18, 2012 Author Report Share Posted June 18, 2012 Thanx for the reply, but that only means that it will be plotted on a separate window and not on the main price chart window. First thing that jumps out is you've specifically specified to NOT show it in the chart window... #property indicator_separate_window It should be... #property indicator_chart_window Hope that helps. Good luck Lux Quote Link to comment Share on other sites More sharing options...
e-Invester Posted June 18, 2012 Author Report Share Posted June 18, 2012 Thanx a million for the help!! Now I just need to figure out how to convert this indicator into an function that I can call in my main system. you have defined 1 indicator_buffer, but 2 Indexbuffer the indicator will only plot values that are in the buffer with index=0 in this case it's ExtMapBuffer1 that you aren't filling at all either set SIBuffer to index= 0 and delete ExtMapBuffer1 or fill the latter one Quote Link to comment Share on other sites More sharing options...
iwjw Posted June 18, 2012 Report Share Posted June 18, 2012 Thanx a million for the help!! Now I just need to figure out how to convert this indicator into an function that I can call in my main system. you can call an indicator with the iCustom() function just look into the help for the parameters that are to be passed with iCustom Quote Link to comment Share on other sites More sharing options...
⭐ luxinterior Posted June 18, 2012 Report Share Posted June 18, 2012 Thanx for the reply, but that only means that it will be plotted on a separate window and not on the main price chart window. You said you wanted it in the main chart and that's what '#property indicator_chart_window' does. I played with it for a bit and fixed the code. It doesn't actually make sense to put it in the main chart as the values don't relate to price. Sounds like you've got it sorted out know so I guess you're set. Lux Quote Link to comment Share on other sites More sharing options...
atilabr Posted June 18, 2012 Report Share Posted June 18, 2012 #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Blue #property indicator_width1 1 extern double T = 300.0; double SIBuffer[]; int init() { SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, SIBuffer); SetIndexLabel(0, "Swing Index"); SetIndexEmptyValue(0, 0.0); return(0); } int deinit() { return(0); } int start() { int counted_bars = IndicatorCounted(); int i, limit; double R, TR, AA, BB, CC, DD, Tpoints, X,K,ER,SH1,SH2,SI; if(counted_bars == 0) limit = Bars - 1; if(counted_bars > 0) limit = Bars - counted_bars; Tpoints = T*MarketInfo(Symbol(), MODE_POINT); for(i = limit; i >= 0; i--) { AA = MathAbs(High - Close[i-1]); BB = MathAbs(Low - Close[i-1]); CC = MathAbs(High - Low[i-1]); DD = MathAbs(Close[i+1] - Open[i-1]); if(AA>BB && AA>CC) { R = (AA+BB)/2 + DD/4; } if (BB>CC && BB>AA) { R = (BB+AA)/2 + DD/4; } else { R = (CC+DD)/4; } X =(Close-Close[i+1]+(Close-Open)/2 + Close[i+1] - Open[i+1] ); SIBuffer =16 * X/R * MathMax (AA,BB); } return(0); } //+------------------------------------------------------------------+ Quote Link to comment Share on other sites More sharing options...
bgrtz Posted June 20, 2012 Report Share Posted June 20, 2012 (edited) e-Invester, Can you elaborate this indicator more? from this line: double R, TR, AA, BB, CC, DD, Tpoints, X, K, ER, SH1, SH2, SI; variable TR, K, ER, SH1, SH2 and SI is defined but not used. from this line: if (AA > BB && AA > CC) { R = (AA+BB)/2 + DD/4; } if (BB > CC && BB > AA) { R = (BB+AA)/2 + DD/4; } why variable R calculated with exact same formula, although it has 2 different condition and most vital question: extern double T = 300.0; .. .. Tpoints = T * MarketInfo(Symbol(), MODE_POINT); the Tpoints value did not affect anything, because Tpoints is calculated outside, and never used inside the loop function. Since T is external variable, so changing T variable will not change anything Edited June 20, 2012 by bgrtz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.