Jump to content

[ASK] Need help with SI indicator coding


Recommended Posts

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 by e-Invester
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

#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);

}

//+------------------------------------------------------------------+

Link to comment
Share on other sites

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 by bgrtz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...