Close Price based on X Date - futures io
futures io futures trading



Close Price based on X Date


Discussion in ThinkOrSwim

Updated by Nube
    1. trending_up 538 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Close Price based on X Date

(login for full post details)
  #1 (permalink)
Rowland Heights, CA USA
 
 
Posts: 3 since Jul 2019
Thanks: 1 given, 0 received

I am trying to get a close price based on certain previous date, right now is based on EX-Dividend date, however TOS doesnt allow me to use that date. Below code for reference


#I can declare the X amount of days since last Ex Div Date
def LastXDiv= (GetEventOffset(Events.DIVIDEND, -1));

#But unable to put it under close parameters as below, it does not accept the Def variable LastXDiv or if I type out it all out.
#def LastXDivClose = close[GetEventOffset(Events.DIVIDEND, -1)];
#However I can get TOS to accept as below, but this would the result would be the next amount dividend days, not for previous.

def LastXDivClose = close[Events.DIVIDEND];



#right now I can only way I can get it to semi-working is to put label and find out X amount of days then change the input manually each time, but too tedious and wondering any work around for it.

input DaySinceLastXDiv = 2;
input CloseDay= 1;

def LastXDiv= (GetEventOffset(Events.DIVIDEND, -1));
def PrevDivClose = close(period = dayagg)[DaySinceLastXDiv];
def CurrentDayClose = close(period = dayagg)[CloseDay];
def PercentGain = (PrevdivClose - CurrentDayClose)/CurrentDayClose;

AddLabel(yes, LastXDiv + ": " + round(Percentgain,2) + "%" );

Reply With Quote

Can you help answer these questions
from other members on futures io?
QDEL
Stocks and ETFs
Thinkscript for scanning in Option Hacker
ThinkOrSwim
3x Fangdango
Traders Hideout
Degiro Negative Balance Advice
Traders Hideout
Trade Summary Error
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on futures io
VWAP for stock index futures trading?
48 thanks
Coronavirus COVID-19
18 thanks
VWAP oscillator for NT8
15 thanks
Battlestations: Show us your trading desks!
12 thanks
Opinion on iron condor strategy
8 thanks
 
(login for full post details)
  #2 (permalink)
Minneapolis Minnesota
 
 
Posts: 23 since Jul 2019
Thanks: 0 given, 11 received

Try this

 
Code
def dayClose = close(period = AggregationPeriod.DAY);
def divvieClose = if !IsNaN(GetDividend()) then dayClose else divvieclose[1];
def dow = GetDayOfWeek(GetYYYYMMDD());
def daysSinceDivvie = if !IsNaN(GetDividend()) then 
                        0 else if dow != dow[1] then
                                 daysSinceDivvie[1] + 1 else
                                 daysSinceDivvie[1];

plot ClosePriceOnDivviDate = divvieClose; 
AddLabel(1, "Days Since Last Dividend: "+daysSinceDivvie, Color.Gray);

Reply With Quote
 
(login for full post details)
  #3 (permalink)
Rowland Heights, CA USA
 
 
Posts: 3 since Jul 2019
Thanks: 1 given, 0 received


Thanks, but I tried that and seems doesn't work, as I want to get the DayClose of the Last Previous Div date, but when I use your code and just add one extra line, and use the "daysSinceDivvie" as the length number for Close it doesn't accept it as says it only accepts constant. Which is the same error I got when I did it my way.

def prevdivclose = close(period = AggregationPeriod.DAY)[daysSinceDivvie];

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Minneapolis Minnesota
 
 
Posts: 23 since Jul 2019
Thanks: 0 given, 11 received


jimderbehr View Post
Thanks, but I tried that and seems doesn't work, as I want to get the DayClose of the Last Previous Div date, but when I use your code and just add one extra line, and use the "daysSinceDivvie" as the length number for Close it doesn't accept it as says it only accepts constant. Which is the same error I got when I did it my way.

def prevdivclose = close(period = AggregationPeriod.DAY)[daysSinceDivvie];

Don't add anything. It's already plotting the close price for the day of the last dividend.

Reply With Quote
The following user says Thank You to Nube for this post:
 
(login for full post details)
  #5 (permalink)
Rowland Heights, CA USA
 
 
Posts: 3 since Jul 2019
Thanks: 1 given, 0 received

Sorry I was being dumb, I was fixated on just what the label was showing didnt actually saw the plot itself. It works now thanks for your help.

Reply With Quote
 
(login for full post details)
  #6 (permalink)
Minneapolis Minnesota
 
 
Posts: 23 since Jul 2019
Thanks: 0 given, 11 received


jimderbehr View Post
Sorry I was being dumb, I was fixated on just what the label was showing didnt actually saw the plot itself. It works now thanks for your help.

No problem. It isn't obvious when skimming the code. The value not being [indexed] makes it a little confusing.

Reply With Quote


futures io Trading Community Platforms and Indicators ThinkOrSwim > Close Price based on X Date


July 7, 2019


Upcoming Webinars and Events
 

An Afternoon With futures io member TropicalTrader

Elite only
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts