Could use some help with a coding issue

This is the place to discuss EdgeRater Chart Script

Moderator: Chris White

Post Reply
bsegura
Posts: 32
Joined: Tue Jan 12, 2021 11:56 am

Could use some help with a coding issue

Post 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
Chris White
Posts: 200
Joined: Mon Nov 29, 2010 9:21 pm

Re: Could use some help with a coding issue

Post 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 11247 times
bsegura
Posts: 32
Joined: Tue Jan 12, 2021 11:56 am

Re: Could use some help with a coding issue

Post by bsegura »

What a Simple - Brilliant & Elegant Solution

Many Thanks!
-Brian
Post Reply