In order to use price data for any instrument in plotting any indictore on the current chart I appended
extern string Security_Name = "EURUSD"
under indicator parameters and changed NULL to Security_Name. This works fine as long as the price I am calling in is within the group my price chart belongs to and not with anything outside that group. In reading here, I understand the MT4 looks within its "Sand Box" in searching for other prices. My setup have 12 different Sand Boxes (or groups listed when I open history center), but windows file explorer shows them all in one location (C:\MBT\History\MBT\**.*). How can I call prices of an instrument from other sand boxes?
If you want prices of other instruments use MarketInfo() with the symbol name and MODE_BID
If you want to calculate an Indicator for a different symbol compared to the chart symbol you have to make sure you have the data to use . . . do you have the data ?
So where should I append this in this code, for example. Under Indicator buffers?
Thanks
//---- indicator settings #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Lime #property indicator_color2 Green #property indicator_color3 Maroon #property indicator_color4 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 #property indicator_level1 0 #property indicator_levelcolor Silver #property indicator_levelstyle 2 //---- indicator parameters extern string Security_Name = "AUDUSD"; extern int FastMA=34; extern int SlowMA=89; extern string strType = "Moving Average Types:"; extern string strm0 = "0 = SMA, 1 = EMA"; extern string strm1 = "2 = SMMA, 3 = LWMA"; extern int MAType = 1; //---- indicator buffers double green_buffer[]; double DarkGreen_buffer[]; double red_buffer[]; double Maroon_buffer[]; string strMAType; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(0,green_buffer); //---- SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(1,DarkGreen_buffer); //---- SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(2,red_buffer); //---- SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID); SetIndexBuffer(3,Maroon_buffer); //---- switch(MAType) { case 1: strMAType="EMA"; break; case 2: strMAType="SMMA"; break; case 3: strMAType="LWMA"; break; default: strMAType="SMA"; break; } IndicatorDigits(Digits+1); //---- name for DataWindow and indicator subwindow label string short_name=""+Security_Name+", MACD (" +FastMA+ ", " +SlowMA+ ", " + strMAType+ ")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); SetIndexLabel(1,short_name); SetIndexLabel(2,short_name); SetIndexLabel(3,short_name); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { double MACD; int counted_bars=IndicatorCounted(); int i; //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted for (i = Bars - Max (counted_bars-1, 1); i>=0; i--) { MACD=iMA(Security_Name,0,FastMA,0,MAType,PRICE_MEDIAN,i)- iMA(Security_Name,0,SlowMA,0,MAType,PRICE_MEDIAN,i); if(MACD>0) { if ( ( (green_buffer[i+1] != 0) && (MACD >= green_buffer[i+1]) ) || ( (DarkGreen_buffer[i+1] != 0) && (MACD > DarkGreen_buffer[i+1]) ) ) { green_buffer[i] = MACD; DarkGreen_buffer[i] = 0; } else { green_buffer[i] = 0; DarkGreen_buffer[i] = MACD;} } else { if ( ( (red_buffer[i+1] != 0) && (MACD >= red_buffer[i+1]) ) || ( (Maroon_buffer[i+1] != 0) && (MACD > Maroon_buffer[i+1]) ) ) { red_buffer[i] = MACD; Maroon_buffer[i] = 0; } else { red_buffer[i] = 0; Maroon_buffer[i] = MACD; } } } //---- done return(0); } //+------------------------------------------------------------------+ int Max (int val1, int val2) { if (val1 > val2) return(val1); return(val2); }
this in this code for example. Thanks for you help.
----------------
As was mentioned... you should be able to call the data from other currency pairs as long as you have that data stored in your history folders... the currency pairs you are able to use are the ones that are supplied by the server you are connecting to at your broker... for instance you will not be able to call for info on the CADJPY if your broker does not offer that pair.. But even if they do offer that pair and yet you have never opened a chart on your platform and caused the platform to download the data for that pair... you will not have it in your History ..YET... so you may want to go to those pairs and load history for them...
.....The second thing I wanted to mention is that many brokers attach a suffix to their currency pairs... such as EURUSDpro or EURUSDm something like that.. so when you put the Security_Name in .. make sure you remember to use that proper suffix.
.....Of course you can put an extern setting in for suffix and then in the init() function have it append the Securuty_Name string with the suffix string.. so that by the time it gets used in the MACD the EURUSD has had the pro added to it and has become EURUSDpro. But you've go the right idea. If you want the data for the USDCHF pair while you are on a eurusd chart .. you put that USDCHF in place of the NULL.... Hope this helps a little... JimDandy.
p.s. you will want to go into market watch and make sure that the pair you are calling is listed in your market watch so that the server is sending you the data for that pair all the time..
So where should I append this in this code, for example. Under Indicator buffers?
As was mentioned... you should be able to call the data from other currency pairs as long as you have that data stored in your history folders... the currency pairs you are able to use are the ones that are supplied by the server you are connecting to at your broker... for instance you will not be able to call for info on the CADJPY if your broker does not offer that pair.. But even if they do offer that pair and yet you have never opened a chart on your platform and caused the platform to download the data for that pair... you will not have it in your History ..YET... so you may want to go to those pairs and load history for them...
.....The second thing I wanted to mention is that many brokers attach a suffix to their currency pairs... such as EURUSDpro or EURUSDm something like that.. so when you put the Security_Name in .. make sure you remember to use that proper suffix.
.....Of course you can put an extern setting in for suffix and then in the init() function have it append the Securuty_Name string with the suffix string.. so that by the time it gets used in the MACD the EURUSD has had the pro added to it and has become EURUSDpro. But you've go the right idea. If you want the data for the USDCHF pair while you are on a eurusd chart .. you put that USDCHF in place of the NULL.... Hope this helps a little... JimDandy.
p.s. you will want to go into market watch and make sure that the pair you are calling is listed in your market watch so that the server is sending you the data for that pair all the time..
Thanks for your input. Just to clarify that I don't have any problem calling a security that sits in the same group (as it appears in history center) as shown below.
Actually, I use a non-broker/not connected version of MT4 terminal and this functionality works for all files in history folder. Also not to confuse the issue, this functionality also works in the same way on a broker connected version but only if the security I am calling is in the same group (as provided by the broker).
Thanks for your input. Just to clarify that I don't have any problem calling a security that sits in the same group (as it appears in history center) as shown below.
Actually, I use a non-broker/not connected version of MT4 terminal and this functionality works for all files in history folder. Also not to confuse the issue, this functionality also works in the same way on a broker connected version but only if the security I am calling is in the same group (as provided by the broker).
It would help you if you actually read what I had written . . .
Just set Security_Name to the instrument you are interested in . . >>>>>>>>> but you must have history data for that instrument. <<<<<<<<<
It would help you if you actually read what I had written . . .
. . . do you have data for the instrument that doesn't work ? have you tried opening a chart for that instrument ?
I sure have read each word you and other wrote. I do have data for that instrument and not only it plots in chart window, I can use it with this indicator along with any other instrument within its group. I think I am done with this issue. I just copied the history in the same group and it works.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In order to use price data for any instrument in plotting any indictore on the current chart I appended
extern string Security_Name = "EURUSD"
under indicator parameters and changed NULL to Security_Name. This works fine as long as the price I am calling in is within the group my price chart belongs to and not with anything outside that group. In reading here, I understand the MT4 looks within its "Sand Box" in searching for other prices. My setup have 12 different Sand Boxes (or groups listed when I open history center), but windows file explorer shows them all in one location (C:\MBT\History\MBT\**.*). How can I call prices of an instrument from other sand boxes?
Thanks for your help