Price Data Components
Miscellaneous
0
Views
0
Downloads
0
Favorites
aLines
//+------------------------------------------------------------------+
//| Hi-Lo.mq4 |
//| |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
//---- input parameters
extern int Per=3;
extern int CountBars=300;
extern string period="";
extern int symbol=255;
//---- buffers
double Up[];
double Down[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
string iname = "";
string isymbol = "";
int iperiod = 0;
int window = -1;
int init(){
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_SECTION,0,3);
SetIndexEmptyValue(0,0.0);
SetIndexBuffer(0,Up);
SetIndexStyle(1,DRAW_ARROW);
SetIndexEmptyValue(1,0.0);
SetIndexBuffer(1,Down);
//----
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----
switch(symbol){
case 0: isymbol = "EURUSD";break;
case 1: isymbol = "USDJPY";break;
case 2: isymbol = "USDCHF";break;
case 3: isymbol = "GBPUSD";break;
case 4: isymbol = "USDCAD";break;
case 5: isymbol = "AUDUSD";break;
case 6: isymbol = "EURJPY";break;
case 7: isymbol = "EURGBP";break;
case 8: isymbol = "EURCHF";break;
case 9: isymbol = "GBPCHF";break;
case 10: isymbol = "GBPJPY";break;
case 11: isymbol = "CHFJPY";break;
case 12: isymbol = "AUDJPY";break;
case 13: isymbol = "EURCAD";break;
default: isymbol = Symbol();break;
}
iperiod = Period();
if(period=="M1") iperiod = PERIOD_M1;
else if(period=="M5") iperiod = PERIOD_M5;
else if(period=="M15") iperiod = PERIOD_M15;
else if(period=="M30") iperiod = PERIOD_M30;
else if(period=="H1") iperiod = PERIOD_H1;
else if(period=="H4") iperiod = PERIOD_H4;
else if(period=="D1") iperiod = PERIOD_D1;
else if(period=="W1") iperiod = PERIOD_W1;
else if(period=="MN1") iperiod = PERIOD_MN1;
else period = Period();
iname = "aLines_"+isymbol+"_"+period;
IndicatorShortName(iname);
ArrayInitialize(Up,0);
return(0);
}
void delete_lines(int len){
string buff_str = "";
for(int i=0;i<len;i++){
buff_str = "Line_"+i;
ObjectDelete(buff_str);
}
buff_str = "Mark_Cross";
ObjectDelete(buff_str);
}
void place_mark(int x,double price){
string buff_str = "Mark_Cross";
if(ObjectFind(buff_str)==-1){
if(!ObjectCreate(buff_str, OBJ_ARROW, window, Time[x], price)) Print("Error");
ObjectSet(buff_str,OBJPROP_COLOR,Red);
}
else{
ObjectSet(buff_str,OBJPROP_TIME1,Time[x]);
ObjectSet(buff_str,OBJPROP_PRICE1,price);
}
}
void create_line(int line,int from,int to,color c,bool down,double p0,double p1,int long){
string buff_str = "Line_"+line;
if(down){
if(!ObjectCreate(buff_str, OBJ_TREND, window, Time[from], p0, Time[to], p1)) Print("Error");
}
else{
if(!ObjectCreate(buff_str, OBJ_TREND, window, Time[from], p0, Time[to], p1)) Print("Error");
}
ObjectSet(buff_str,OBJPROP_RAY,long);
ObjectSet(buff_str,OBJPROP_COLOR,c);
ObjectSet(buff_str,OBJPROP_XDISTANCE,100);
ObjectSet(buff_str,OBJPROP_YDISTANCE,100);
ObjectSet(buff_str,OBJPROP_STYLE,STYLE_SOLID);
}
int deinit(){
delete_lines(7);
return (0);
}
int last_bar = 0;
/*
y4*(x3-x1) - x4*(y3-y1)
u = ---------------------------------
y4*x2 - x4*y2
y2*(x3-x1) - x2*(y3-y1)
v = ---------------------------------
y4*x2 - x4*y2
y = m*x + b
b = y - m*x
m = (y-b) / x
y1 - m*x1 = y2 - m*x2
y1-y2 = m*x1 - m*x2 = m*(x1 - x2)
m = (y1-y2) / (x1 - x2)
---------------------
m = (y2-y1) / (x2-x1)
b = y1 - m*x1
*/
bool get_line_collusion2(double &p[][],int a,int b,int c,int d,int v){
double m1,b1,m2,b2;
m1 = (p[a][1] - p[b][1]) / (p[a][0]-p[b][0]);
//m1 = (p[b][1] - p[a][1]) / (p[b][0]-p[a][0]);
b1 = p[a][1] - m1*p[a][0];
m1 = (p[c][1] - p[d][1]) / (p[c][0]-p[d][0]);
//m2 = (p[d][1]-p[c][1]) / (p[d][0]-p[c][0]);
b2 = p[c][1] - m1*p[c][0];
double d_ = (m1-m2);
if(d_!=0.0){
p[v][0] = (b2-b1) / d_;
p[v][1] = m1*p[v][0] + b1;
return (true);
}
return (false);
}
void get_line_collusion(double &p[][],int a,int b,int c,int d,int v){
double ta,d_;
d_ = ((p[d][1] - p[c][1])*(p[b][0] * p[a][0]) - (p[d][0] - p[c][0])*(p[b][1] * p[a][1]));
if(d_!=0.0){
ta = ((p[d][0]-p[c][0])*(p[a][1]-p[c][1]) - (p[d][1]-p[c][1])*(p[a][0]-p[c][0])) / d_;
p[v][0] = p[a][0]+(p[b][0]-p[a][0])*ta;
p[v][1] = p[a][1]+(p[b][1]-p[a][1])*ta;
}
}
//+------------------------------------------------------------------+
//| Hi-Lo |
//+------------------------------------------------------------------+
void get_point_on_line(double &p[][],int a,int b,int v){
double m1,b1,m2,b2;
m1 = (p[a][1] - p[b][1]) / (p[a][0]-p[b][0]);
b1 = p[a][1] - m1*p[a][0];
p[v][1] = m1 * p[v][0] + b1;
}
double last_time = 0;
int start(){
if(window==-1){
window = WindowFind(iname);
}
SetIndexDrawBegin(0,Bars-CountBars+Per);
SetIndexDrawBegin(1,Bars-CountBars+Per);
last_bar = Bars;
delete_lines(7);
int point_arr[5];
double val_arr[5];
int i,counted_bars=IndicatorCounted();
int pi = 4,j = 0;
while(j<last_bar && pi>=0){
Up[j] = 0;
double gann = iCustom(isymbol,iperiod,"a_ZZ",last_bar,0,10,2,j);
if(gann!=0.0){
point_arr[pi] = j;
val_arr[pi] = gann;
Up[j] = gann;
pi--;
}
j++;
}
Up[0] = iClose(isymbol,PERIOD_M1,0);
create_line(4,point_arr[0],point_arr[2],Green,false,val_arr[0],val_arr[2],100);
create_line(5,point_arr[0],point_arr[3],Green,false,val_arr[0],val_arr[3],100);
create_line(6,point_arr[1],point_arr[3],Green,false,val_arr[1],val_arr[3],100);
/*
double p[6][2];
for(i=0;i<5;i++){
p[i][0] = point_arr[i]; // x - time
p[i][1] = val_arr[i]; // y - price
}
bool WW =
(
p[1][1]>p[0][1] && p[2][1]<p[0][1] &&
p[3][1]>p[0][1] && p[3][1]<p[1][1] &&
p[4][1]<p[2][1]
) ||
(
p[1][1]<p[0][1] && p[2][1]>p[0][1] &&
p[3][1]<p[0][1] && p[3][1]>p[1][1] &&
p[4][1]>p[2][1]
);
if(WW && get_line_collusion2(p,0,2,1,3,5)){
p[5][0] = p[4][0] - p[5][0];
get_point_on_line(p,0,2,5);
int ct = p[4][0];
if(last_time==Time[ct]) return (0);
place_mark(p[4][0],p[5][1]);
last_time = Time[ct];
}
*/
ObjectsRedraw();
return(0);
}
//+------------------------------------------------------------------+
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
---