How can I code a line (x1,y1,x2,y2)?

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #85857 quote
    ligand
    Participant
    Average

    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))).

    #85858 quote
    ligand
    Participant
    Average

    Vronasi suggested that perhaps Nicolas or juanj know the answer.

    #85860 quote
    Vonasi
    Moderator
    Master

    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.

    #85861 quote
    GraHal
    Participant
    Master

    @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?

    #85863 quote
    GraHal
    Participant
    Master

    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! 🙂

    #85869 quote
    robertogozzi
    Moderator
    Master

    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.

    GraHal thanked this post
    #85896 quote
    Nicolas
    Keymaster
    Master

    If you can define the distance in price (Y) between 2 bar coordinates (X), then you can calculate the factor.

    #86165 quote
    ligand
    Participant
    Average

    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?

    qI3sY6df.png qI3sY6df.png
    #86167 quote
    ligand
    Participant
    Average

    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)

    qI3sY6df-1.png qI3sY6df-1.png
    #87360 quote
    ligand
    Participant
    Average

    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
    #87361 quote
    ligand
    Participant
    Average

    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?

    #87365 quote
    Nicolas
    Keymaster
    Master

    disregarding the last 2 lowest low? so you want to pick the third one backward?

    #87386 quote
    ligand
    Participant
    Average

    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. 🙁

    #87390 quote
    Vonasi
    Moderator
    Master
    ll = close[2]
    for a = 2 to 9
    ll = min(low[a],ll)
    next
    Nicolas thanked this post
    #87400 quote
    ligand
    Participant
    Average

    Thanks a lot!

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.

How can I code a line (x1,y1,x2,y2)?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ligand @ligand Participant
Summary

This topic contains 14 replies,
has 5 voices, and was last updated by ligand
7 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/27/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...