Sorry if this is redundant. I don’t succeed to code a line y=mx+n, defined by 4 known parameters x1,y1,x2,y2. My aim ist to code for example a buy order if close crosses under a certain line (which can be described mathematically with y=((y2-y1)/(x2-x1))x + y1-((y2-y1)x1/(x2-x1))).
Vronasi suggested that perhaps Nicolas or juanj know the answer.
Please don’t double post.
If you have not received an answer then patience is better than having two topics on the same subject. If you have waited a long time for an answer then maybe it is because no one knows the answer! Sometimes a little polite reminder on the original thread can bump it back to the top and maybe get your answer. Double posting leads to confusion and wasted time for those trying to help.
@ligand … you know you can draw a line on a Chart and set an alert and / or trade if price crosses under / over this line?
I know this is not what you mean, but thought I’d mention it in case you may be able to use the above easy method re prices crossing lines to prove whether your y=mx+c coded strategy is worth pursuing?
Anyway can’t you do something similar (to y=mx+c) by considering …
Price increase > a and < b over c bars represents gradient d Price Line?
Price increase > e and < f over c bars represents gradient g Price Line?
Just an idea going round in my head! 🙂
ProOrder only deals with prices, so you must refence a line (S/R) only by the price it sits on. Line coordinates are used only to draw lines on charts, but cannot be refenced from code.
If you can define the distance in price (Y) between 2 bar coordinates (X), then you can calculate the factor.
Thanks for the answers and sorry vronasi – I didn’t know wether I should start an extra question. I won’t do this again.
If you look at the countertrendlines in the chart below you can see the general idea of the system (for example for a bull market):
1. Momentum(EMA20-EMA50)>0 on a higher time frame, so the bull is still developing
2. Define the line between highest(5) and highest(10)
3. Buy if close crosses over this line
4. trailing stop 1.5 x length of the crossing bar.
But if I understand you ok, it is not possible to code for such countertrendlines?
I forgot one criterium:
5. the countertrendline is not to cross the price ranges of any of the bars involved, just the highest points of for example 5 and 10 bars (optimal values have to be defined by backtesting, which is of course also true for the length of the trailing stop)
If someone is interested, I did it with a little trigonometry and this seems to work, at least as a screener:
y1=lowest[25](low)
y2=lowest[10](low)
For i=25 downto 0 do
IF low[i]=y1 then
x1=barindex[i]
break
endif
next
For i=10 downto 0 do
IF low[i]=y2 then
x2=barindex[i]
break
endif
next
//Der Punkt auf der Aufwärtslinie wird bestimmt, der vom letzten barclose unterkreuzt werden muss, damit ein Verkaufssignal entsteht
x3=barindex[1]
y3=y2+((x3-x1)*(y2-y1)/(x2-x1))
//Falls close[1] den Punkt y3 auf der Gegentrend-Aufwärtslinie unterkreuzt, gibt es das Verkaufssignal
indicator4=close[1] crosses under y3
I’ve got just one short question:
How can I find/code the lowest low of the last 10 bars, disregarding the last 2 ones?
disregarding the last 2 lowest low? so you want to pick the third one backward?
Exactly, I’m looking for the lowest value of the seven bars, which precede the third last bar (or in other words: the low of the tenth to third last bar). Itl’s obviously not possible to call it something like lowest[10-3](low). I tried to construct a loop but was unable to do so. 🙁
ll = close[2]
for a = 2 to 9
ll = min(low[a],ll)
next