NexusFi: Find Your Edge


Home Menu

 





Close Price based on X Date


Discussion in ThinkOrSwim

Updated
    1. trending_up 1,573 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Close Price based on X Date

  #1 (permalink)
jimderbehr
Rowland Heights, CA USA
 
Posts: 3 since Jul 2019
Thanks Given: 1
Thanks Received: 0

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 NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
Quantum physics & Trading dynamics
The Elite Circle
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
Strategy stop orders partially filled
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
22 thanks
What is Markets Chat (markets.chat) real-time trading ro …
19 thanks
ApexTraderFunding.com experience and review
15 thanks
GFIs1 1 DAX trade per day journal
15 thanks
EG Indicators
11 thanks
  #2 (permalink)
Nube
Minneapolis Minnesota
 
Posts: 24 since Jul 2019
Thanks Given: 0
Thanks Received: 13

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
  #3 (permalink)
jimderbehr
Rowland Heights, CA USA
 
Posts: 3 since Jul 2019
Thanks Given: 1
Thanks Received: 0


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
  #4 (permalink)
Nube
Minneapolis Minnesota
 
Posts: 24 since Jul 2019
Thanks Given: 0
Thanks Received: 13


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
Thanked by:
  #5 (permalink)
jimderbehr
Rowland Heights, CA USA
 
Posts: 3 since Jul 2019
Thanks Given: 1
Thanks Received: 0

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
  #6 (permalink)
Nube
Minneapolis Minnesota
 
Posts: 24 since Jul 2019
Thanks Given: 0
Thanks Received: 13


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




Last Updated on July 7, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts