390

Hi experts.

I am trying to create trend line that must not run across the graph.

I have some question.How to get value price between the coordinates that can be used in the mql4 rule (Ask>Trend value)?

plz give me some advice. thank very much.

16563

moonsky: .How to get value price between the coordinates that can be used in the mql4 rule (Ask>Trend value)?

Perhaps you should read the manual. ObjectGetValueByShift - Object Functions - MQL4 Reference

390

whroeder1:

Perhaps you should read the manual. ObjectGetValueByShift - Object Functions - MQL4 Reference

Thank you

1090

whroeder1:

Perhaps you should read the manual. ObjectGetValueByShift - Object Functions - MQL4 Reference

I'm not sure that will help OP. OP is looking to not exceed the minimum-slope when slope is positive or the maximum slope when slope is negative. OP, you will need to calculate the slope of each point from your time1 anchor point to your time2 end-point and then draw from the time1 anchor to the (min/max) slope point.

1090

moonsky, here, I hacked together a script to demonstrate the slope concept.

```#property strict

#include <ChartObjects\ChartObjectsLines.mqh>

struct ZZ{datetime time;double price;int shift;};

void OnStart()
{
ObjectDelete(0,"T-Line");
MqlRates r[];
ArraySetAsSeries(r,true);
CopyRates(Symbol(),Period(),0,Bars(Symbol(),Period()),r);
ZZ zz[2];
DrawTrend(zz,r);
}
//+------------------------------------------------------------------+
void DrawTrend(ZZ &zz[],MqlRates &r[])
{
GetZZ(zz,r);
bool slope_pos = zz[0].price < zz[1].price ? true : false;
int j=zz[0].shift;
double min_slope = DBL_MAX;
double max_slope = DBL_MIN_10_EXP;
int min_index = 0, max_index = 0;
for(int i=j-5;i>=zz[1].shift;i--) //start 5 bars from anchor
{
double   run   = double(j - i);
double   rise  = slope_pos ? r[i].low - zz[0].price : r[i].high - zz[0].price;
double   slope = rise / run;
if(slope > max_slope)
{
max_slope = slope;
max_index = i;
}
if(slope < min_slope)
{
min_slope = slope;
min_index = i;
}
}
datetime t1 = zz[0].time;
double   p1 = zz[0].price;
datetime t2 = slope_pos ? r[min_index].time : r[max_index].time;
double   p2 = slope_pos ? r[min_index].low : r[max_index].high;
CChartObjectTrend trend;
trend.Create(0,"T-Line",0,t1,p1,t2,p2);
trend.Detach();
}
//+------------------------------------------------------------------+
void GetZZ(ZZ &zz[],MqlRates &r[])
{
int cnt=ArraySize(zz)-1;

for(int i=0;cnt>=0;i++)
{
double val = iCustom(Symbol(),Period(),"ZigZag",200,5,3,0,i);
if(val > 0 && val != EMPTY_VALUE)
{
zz[cnt].time = r[i].time;
zz[cnt].shift = i;
if(r[i].close < val || r[i].high == val)
zz[cnt].price = r[i].high;
else
zz[cnt].price = r[i].low;
cnt--;
}
}
}
//+------------------------------------------------------------------+```
16563

nicholishen: I'm not sure that will help OP. OP is looking to not exceed the minimum-slope when slope is positive or the maximum slope when slope is negative. OP, you will need to calculate the slope of each point from your time1 anchor point to your time2 end-point and then draw from the time1 anchor to the (min/max) slope point.
1. That's not what he said. "How to get value price between the coordinates that can be used in the mql4 rule (Ask>Trend value)"
2. The slope is constant. He needs to get the line's value at each bar to see if it has been exceeded and change that end point.
390

nicholishen:

I'm not sure that will help OP. OP is looking to not exceed the minimum-slope when slope is positive or the maximum slope when slope is negative. OP, you will need to calculate the slope of each point from your time1 anchor point to your time2 end-point and then draw from the time1 anchor to the (min/max) slope point.

Thank you very much for helping me.

1090

whroeder1:
1. That's not what he said. "How to get value price between the coordinates that can be used in the mql4 rule (Ask>Trend value)"
2. The slope is constant. He needs to get the line's value at each bar to see if it has been exceeded and change that end point.
1. Just because he's asking for a thing doesn't mean that thing will solve his problem.

2. Slope is not constant. Slope is different at every bar when calculating the slope from that bar to an anchor point. Like I said in post #3, OP is looking to connect the anchor to the bar with the minimum-slope (in range) when slope is positive or the maximum slope (in range) when slope is negative.

Run my script and tell me I'm wrong.

390

whroeder1:

The slope is constant. He needs to get the line's value at each bar to see if it has been exceeded and change that end point.

Hi  whroeder1

yeah, I think If we have line's value , we can use it to create condition not to be passed by line.

1090

moonsky:

Hi  whroeder1

yeah, I think If we have line's value , we can use it to create condition not to be passed by line.

It's going to cost you, computationally speaking. Assuming you already have a collection of swing-points to 'test', you're going to have to create a chart-object (trend-line) and then iterate over the range of bars to check to see if it crossed or not, and when it does you have to destroy the chart object then create it again to the next testing-point...and on and on... until you find a testing point that doesn't cross.

All this does is circumvent math, and it will be MUCH slower. You'll also need to make sure your swing-points are correct and you didn't miss any.

...it's so much more work for both the pc and the developer, but to each his own. :)