Page 1 of 1

Could use some help with a coding issue

Posted: Mon Feb 01, 2021 10:25 am
by bsegura
Hello:

I was hoping someone could help me with a coding issue I am having:

When a trigger occurs, I am trying to draw a continuous horizontal line from that close until the next trigger occurs - then it will again draw a horizontal line from that close until the next trigger.


I thought it would be like:

trigger := if (cross(close,ma(close,30),1,0);.....................................(produce the trigger and get a 1 or 0 result)

b := barssince(trigger);.................................................................... (find out the amount of bars since the trigger happened)

horizontal_line : ref(close,b);........................................................ (have it draw a continuous horizontal line at the close where the trigger happened until the next trigger


This is easily done in the Think or Swim platform - but I am having trouble trying to code it in this Formula Script

Thanks,
Brian

Re: Could use some help with a coding issue

Posted: Thu Feb 04, 2021 10:08 pm
by Chris White
Hi Brian,

You can use VALUEWHEN(CLOSE, Trigger) to get the value of Close when the trigger is true.
Here's the full script:

Code: Select all

trigger:= IF(CROSS(CLOSE, MA(CLOSE,30)),1,0);
B: VALUEWHEN(CLOSE,trigger),colorblue,width2,pointdot;
This produces the following plot:
BSeg_Line.png
BSeg_Line.png (32.81 KiB) Viewed 11903 times

Re: Could use some help with a coding issue

Posted: Sun Feb 07, 2021 12:07 pm
by bsegura
What a Simple - Brilliant & Elegant Solution

Many Thanks!
-Brian