Price Data Components
Miscellaneous
0
Views
0
Downloads
0
Favorites
Gold_Silver_Ratio
//+------------------------------------------------------------------+
//| Gold_Silver_Ratio.mq4 |
//| Copyright © 2010, Forex-Experts. |
//| http://www.forex-experts.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Forex-Experts"
#property link "http://www.forex-experts.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
extern string Symbol1="XAUUSD";
extern string Symbol2="XAGUSD";
extern color BarColor = Red;
extern color BarWidth = 3;
extern int NumBars = 1000;
//---- buffers
double HighBuffer[];
double LowBuffer[];
int k=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_NONE,EMPTY,0);
SetIndexBuffer(0, HighBuffer);
SetIndexStyle(1,DRAW_NONE,EMPTY,0);
SetIndexBuffer(1, LowBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
string ea=WindowExpertName();
int window=WindowFind(ea);
ObjectsDeleteAll(window,OBJ_TREND);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return (-1);
if (counted_bars>0) counted_bars--;
limit=(Bars-counted_bars)-1;
limit=NumBars;
for(k=limit; k>=0; k--) {
double high2=iHigh(Symbol2,0,k);
double low2=iLow(Symbol2,0,k);
if (high2==0 || low2==0) continue;
double high_ratio=iHigh(Symbol1,0,k)/high2;
double low_ratio=iLow(Symbol1,0,k)/low2;
HighBuffer[k]=high_ratio;
LowBuffer[k]=low_ratio;
DrawLine("bar_"+Time[k], k, high_ratio, k , low_ratio, BarColor, 0, BarWidth, false);
}
//----
return(0);
}
void DrawLine(string _name, int _startbar, double _start_y, int _endbar, double _end_y, int _color, int _style=0, int _width=5, bool _ray=false) {
string ea=WindowExpertName();
int window=WindowFind(ea);
int _x1=Time[_startbar];
int _x2=Time[_endbar];
double _y1=_start_y;
double _y2=_end_y;
if(ObjectFind(_name) != 0) {
ObjectCreate(_name,OBJ_TREND,window,_x1,_y1,_x2,_y2);
ObjectSet(_name,OBJPROP_RAY,_ray);
ObjectSet(_name,OBJPROP_COLOR,_color);
ObjectSet(_name,OBJPROP_WIDTH,_width);
ObjectSet(_name,OBJPROP_STYLE,_style);
}
else
{
ObjectSet(_name,OBJPROP_RAY,_ray);
ObjectMove(_name,0,_x1,_y1);
ObjectMove(_name,1,_x2,_y2);
ObjectSet(_name,OBJPROP_COLOR,_color);
ObjectSet(_name,OBJPROP_WIDTH,_width);
ObjectSet(_name,OBJPROP_STYLE,_style);
}
return;
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---