Script Assist: Define Static Plot Values to Specified Date

paramay

paramay

New member
Greetings,

Has anyone had any success plotting a numeric value to a defined/specified date?

Each Friday, I generate a report and I would like that value (0 to 100) to be displayed on the plot. I suppose the value could be assigned to the open of that date. I have been informed by the kind folks here that I cannot tie to an external data set, so I am comfortable inputting a new value each week.

I do not have the foggiest just yet how to make that work. Has anyone on the forum had any success with this strange request?
 
BenTen

BenTen

Administrative
Staff
VIP
As far as inputting manual values, it will only be displayed on the current day or the last trading day. I don’t think you can tie it to a specific day.
 
T

tomsk

Well-known member
VIP
@paramay @BenTen Sure you can plot whatever value you wish so long as you can identify a bar number to do so against. Here is a simple example. Let's say you want to plot the value 280 on January 3, 2020 forward in time. This snippet does it. Load this on a daily aggregation of AAPL

Code:
# Plot Specific Date
# tomsk
# 1.21.2020

declare hide_on_intraday;

input date = 20200103;
input myLevel = 280;

def bar = if getYYYYMMDD() == date then barNumber() else Double.NaN;
plot data = if barNumber() >= HighestAll(bar) then myLevel else Double.NaN;
# End Plot Specific Date
 
paramay

paramay

New member
@tomsk This is fantastic! How can I input 6 months to a 1 Year of 'myLevels' and 'Input dates' history so that it plots it in a continual line?

Would I have to do something like:

Code:
input date1 = 20200114;
input date2 = 20200107;
input date3 = 20191231;

input mylevel2 = 50;
input mylevel3 = 67;

Or is there a much simpler way to code that into a single plot line?

Thanks so much!
 
T

tomsk

Well-known member
VIP
Every price level would require a separate plot statement
 
paramay

paramay

New member
How would I accomplish that so the output does something like this?

Each level is good for the next 7 days until the report produces the next result.

 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@tomsk Thank you for the example. That’s new to me.
 
T

tomsk

Well-known member
VIP
@BenTen ThinkScript is like a painting program. Important thing is to identify bars, then pretty much you can do whatever you want.

@paramay Over time all those levels are going to be a real challenge to manage. You might be better served to use a spreadsheet of some kind. That said if you really want to achieve this sort of thing by Thinkscript, you literally have to manage dates, barNumbers as well as input levels. Suggest you rethink about this a bit and maybe have a different approach
 
paramay

paramay

New member
@tomsk Thank you for the assistance with this. It does appear to be a lot of work. Generating the code and managing the dates I have a handle on (My report only maintains 1 year, and 6 months of visible data, anything more is shaved off). I'm certain I could generate a template from my data-set/spreadsheet, filling in the dynamic variables.

Thinking about the 40+ /futures contracts of data that I generate a report for, I can foresee, with this approach, could be a lengthy Study (or more like 40!).

I do have a wonderful report that I look at and have cultivated over the last several months, and I thought, "Man, this would be nice to have these levels right on the charts since it is a part of my strategy.

I'm not yet ready to give up on it. I am open to different approaches. Even if I was managing less data (dates, barNumbers, input levels), say 2 months worth - it would be beneficial to have that on a chart. I do like the idea of having this juxtaposed to candles and other indicators (minimal I mind you - I run a clean ship), as I find myself manually drawing things on the many charts everyday for reference. This could potentially save me 10's of hours a week of fiddling and managing my charts.

The data I am looking for, from what I can tell, is available on other platforms, just not TS yet - I wish it was.

"Nothing ventured, nothing gained" - Thanks for the help thus far, as I yet do not know much about the limitations/capabilities of thinkScript.

I was able to get some assistance with some simple code that does what I need it to do.



My report takes about 30 seconds to update, and the indicator another 30 seconds. I use a spreadsheet based off my report spreadsheet to generate the code. The code itself is a bit lengthy, nothing epic, but it delivers what I need while only adding a second or two to the load. I can absolutely live with this.

The folks at thinkScript lounge assisted and in it's simplest form looks like this:

Code:
plot line6MonthRTY = if GetSymbol() == "/RTY:XCME" OR  GetSymbol() == "/M2K:XCME" then                                 
if GetYYYYMMDD() >     20200121    then    0.00    else                 
if GetYYYYMMDD() >     20200114    then    2.81    else                 
if GetYYYYMMDD() >     20200107    then    5.72    else                 
if GetYYYYMMDD() >     20191231    then    0.28    else
if GetYYYYMMDD() >     20190730    then    94.92    else    94.92
else double.nan;

Thanks for all the assistance. If anyone wants to know more, please ask.
 
MrBruceKA

MrBruceKA

New member
I registered with useThinkScript this morning. I almost got an answer to my first question in a very short time. This site a great time saver

I would like someone to modify this script so there is an end date. So plot a line at a level between two date, eg: plot at level 280 between 20200101 and 20200131, the month of January

How about adding code to end the line, at say 20200131 end of January?

Thanks for the help
 
Last edited:
R

redart1021

New member
Hi, I'd like a drawing on every previous Friday regardless of the day of week. I can't grasp how GetDayofWeek works though. Is this possible?
 
rad14733

rad14733

Well-known member
VIP
@redart1021 Please explain further your "I'd like a drawing on every previous Friday regardless of the day of week" statement... As of now it's somewhat ambiguous...
 
R

redart1021

New member
@rad14733 Of course. Every Friday I have fib extensions drawn based off the range of that day. I'd like them on the chart to use for future support/resistance levels.

ps. thanks mods for moving my question here!
 
R

redart1021

New member
In ninjascript there's a command called DayOfWeek.Friday. With it, it'll identify and draw on only Fridays. Is there anything similar in thinkscript? Otherwise I have to update the thinkscript code everyday to look back x number of days. There must be a better way
 

Similar threads

Top