Qscript Vertical trendlines

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
Mark
Posts: 18
Joined: Wed Mar 18, 2020 7:37 pm
Contact:

Qscript Vertical trendlines

Post by Mark » Mon Nov 22, 2021 8:16 pm

I'm trying to write a my first Qscript.
This should be easier then I making it out to be.
Tried to find a script I could alter, could not find.
I want multiple vertical trend lines
One at the beginning and one at the end on of two hot spots with equal  divisions of vertical tend lines between the outside two.
inputs would be styles,  # of divisions, color, thickness, etc.
This way I can alter the time by the hot spots, 30 min, 30 hours, or 30 years. this way time does not need to be put in Qscript to make it easier.
I really would like to do this myself but need some direction.

Mark

sbank
Posts: 174
Joined: Tue Jul 21, 2015 9:35 pm
Contact:

Re: Qscript Vertical trendlines

Post by sbank » Tue Nov 23, 2021 2:51 pm

Check out this sample code. Seems to work on a basic 10 minute chart. It should get you started. I did not add any arguments, or colors or styles, but that should be easy.

Also not sure about my syntax for the trendlines, as I rarely use them. But it looked good on my screen... :)

Code: Select all

# Grab the two hotspots   
bar1 = hotspot_to_bar(1);   
bar2 = hotspot_to_bar(2);  
if (bar1 < bar2) {
  leftbar = bar1;
  rightbar = bar2;
} else {      
  leftbar = bar2;
  rightbar = bar1;
}

# Calculate the difference     
bardiff = abs(bar1-bar2);

# Draw the two hotspots on the chart
pad=(h-l)*0.5; 
additionalTrendlines=3; 

for (i=0 to additionalTrendlines by 1) {
  tl1=trendline(leftbar-(bardiff*i), low-pad, leftbar-(bardiff*i), low-pad*2, silver);
  tl_extend_left(tl1,true);
  set_tl_style(tl1, ps_dot);
  
  tl2=trendline(rightbar+(bardiff*i), low-pad, rightbar+(bardiff*i), low-pad*2, silver);
  tl_extend_left(tl2,true);
  set_tl_style(tl2, ps_dot);
}   
EDIT: I just re-read your request. I added the additional trendlines on the *outside* of the two initial hotspots. Looks like you wanted to perhaps subdivide instead? If you need help with that part, let me know and I can try another crack at it if the above sample code doesn't help you.

Mark
Posts: 18
Joined: Wed Mar 18, 2020 7:37 pm
Contact:

Re: Qscript Vertical trendlines

Post by Mark » Wed Nov 24, 2021 12:46 am

Thank You
I will install and see how it works.
Mark

abacaba
Posts: 143
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

Re: Qscript Vertical trendlines

Post by abacaba » Wed Nov 24, 2021 4:26 pm

This does what you want. You can add extra subdivisions, etc. as variables.

Todd

Code: Select all

 input: ratio1(0.5);

#get bar values and time difference
if (barnum==barsback)
{
    bar1=hotspot_to_bar(1);
    price1=hotspot_to_price(1);
    bar2=hotspot_to_bar(2);
    price2=hotspot_to_price(2);

    #make sure bar1 happens before bar2
    if (bar2 < bar1)
    {
        temp=bar1;
        bar1=bar2;
        bar2=temp;

        temp=price1;
        price1=price2;
        price2=temp;
    }

    time_diff=bar2-bar1;
   
    #draw vertical target at bar1
    targetbar=bar1;
    ref=trendline(targetbar,0,targetbar,999999,silver);
    set_tl_style(ref,ps_dot);

    #draw vertical target at bar2         
    targetbar=bar2;
    ref=trendline(targetbar,0,targetbar,999999,silver);
    set_tl_style(ref,ps_dot);

    #draw vertical target at subdivision
    targetbar=bar1+time_diff*ratio1;
    ref=trendline(targetbar,0,targetbar,999999,fuchsia);
    set_tl_style(ref,ps_dash);
}                                                                                       
# END          

Mark
Posts: 18
Joined: Wed Mar 18, 2020 7:37 pm
Contact:

Re: Qscript Vertical trendlines

Post by Mark » Sat Dec 04, 2021 8:27 am

Thank You Todd works good.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests