Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.63 KB | None | 0 0
  1. Arizona times = CDT - 2 (Arizona does not have Daylight Savings Time)
  2.  
  3. ------- Monday, March 19, 2018 -------
  4. 03:38 slow_ed: gm
  5. 04:02 stevie_s: gm
  6. 05:36 stevie_s: .
  7. 05:36 MTS1: JM: Below is what we were thinking adding logic wise for you to add to your script as an alternative to using FOLD. It works for the AvgDown, but if you uncomment the PlotAvgUp lines and scroll the chart back to the first bar you'll see there is an issue with the first Up / Chg calculation on the second bar which is the first bar where it starts plotting: It seems to retain or start with a value from the bar prior to the first one plotted. I tried to mess with it a bit but could not work around it; maybe someone else here has a suggestion:
  8.  
  9. I do have to say I don't understand the zzSave def line; where the zzSave value comes from (itself?) if "ZZ$" is not a number, or what GetValue does, but I think that this may be the root of the isue:
  10. def zzSave = if !IsNaN("ZZ$") then price else GetValue(zzSave, 1);)
  11.  
  12. Updated Script:
  13.  
  14. def price = close;
  15. def reversalAmount = 0.1;
  16. def "ZZ$" = reference ZigZagHighLow(price, price, 0, reversalAmount, 1, 0);
  17. def zzSave = if !IsNaN("ZZ$") then price else GetValue(zzSave, 1);
  18. def chg = price - GetValue(zzSave, 1);
  19.  
  20. plot Up = if !IsNaN("ZZ$") and chg > 0 then chg else 0;
  21. plot Down = if !IsNaN("ZZ$") and chg < 0 then chg else 0;
  22.  
  23. def SumUp = if Up > 0
  24. then SumUp[1] + Up
  25. else SumUp[1] ;
  26. def CountUp = if Up > 0
  27. then CountUp[1] + 1
  28. else CountUp[1] ;
  29. # Plot AvgUp = if IsNaN(SumUp)
  30. # then 0
  31. # else SumUp / CountUp;
  32.  
  33. def SumDown = if Down < 0
  34. then SumDown[1] + Down
  35. else SumDown[1] ;
  36. def CountDown = if Down < 0
  37. then CountDown[1] + 1
  38. else CountDown[1] ;
  39. Plot AvgDown = if CountDown == 0
  40. then 0
  41. else SumDown / CountDown;
  42. 06:05 DMonkey: http://tos.mx/HmaZwG ....that does both....
  43. 06:16 DMonkey: but that like all the zigzzag studies repaints so the signals look great in hindsight...
  44. 06:22 JohnnyQuotronKidderPeabodyAlum: DMonkey.. if you would please share with us/me how you use the study you kindly posted. I want to be certain I am seeing what you are seeing.
  45. 06:24 JohnnyQuotronKidderPeabodyAlum: Do you find it most helpful as an upper or lower study? Do you use it as a leading or conforming indicator? Do you find it particularly helpful with a particular type of investment vehicle?
  46. 06:24 DMonkey: johny its not mine, just corrected the logic to do what was requested... I would never use that for trading......
  47. 06:25 JohnnyQuotronKidderPeabodyAlum: undestood. Thank you.
  48. 06:26 JohnnyQuotronKidderPeabodyAlum: If I may, and I am always curious about this, what are your favs when it comes to indicators?
  49. 06:29 Paris: I looked up my notes on ZigZag, here's what Mobius posted several months ago, exactly what DMonkey mentioned above:
  50.  
  51. Mobius: ZigZag is never wrong and always looks great because it uses future bars to set past conditions and replots when it's wrong. Get over it and move on. Zig Zag is a criminal waste of time
  52. 06:29 MTS1: So what does GetValue do; is GetValue(zzSave, 1) the same as zzSave[1]? I'm missing something; the reference / manual does not help, and I've looked at multple script samples using GetValue and still not getting it. .
  53. 06:30 DMonkey: johnny....everyone has a different style and goal.....so the character of of the goal tends to define method.......
  54. 06:31 MTS1: It's not mine either; was just looking at it as a scripting exersize. I do suspect JM was not neccessarilly using it as a plain zig-zag, maybe more tracking the changes in the pivots and determining a trend?
  55. 06:32 JohnnyQuotronKidderPeabodyAlum: DMonkey...I absolutely agree, but I am always curious. Not just about individual indicators but how people choose to group them.
  56. 06:33 MTS1: +1 Johnny; same here
  57. 06:37 DMonkey: to me thats just a broad spectrum random question... I could give you ten answers on trading futures and you could say, yeah, but I trade options, or I trade pairs, or whatever.....different goals have different needs.....
  58. 06:37 Nube: MTS1, that's more or less what it will do here. For a better idea of what it does, plot getvalue(low, 100) or something like that.
  59. 06:38 MTS1: thanks Nube; will do
  60. 06:40 Paris: There was some discussion on GetValue() a year or so ago. getValue() is the function used to index a value from the past. My understanding is that a positive number fetches data from forward. I'm used to bar indexing the other way around - where positive numbers looks backwards.
  61. 06:40 JohnnyQuotronKidderPeabodyAlum: DMonkey...understood and as I am more equity than futures and more swing and position than intraday I see your point.
  62. 06:42 Paris: AlphaInvestor, thb posted Pinto's sector rotation prior to the close on Friday. Just wanted to follow up with your request.
  63. 06:43 AlphaInvestor: Paris - Yes I got it, also found your mods to that study. Nice work
  64. 06:45 Paris: yw
  65. 06:45 AlphaInvestor: Johnny last week I posted my list of favorite indicators. Since you have been saving the chat, you probably have it
  66. 06:46 MTS1: OK; did that Nube, but still not clear when you use GetValue instead of just [x] as they seem to function the same if you just use the Dynamic Offset variable. I've seen several scripts posted here that use GetValue which just seems more complex if it functions the same?
  67. 06:47 MTS1: Or is it when the offset needs to be calculated, and can we not use a calculation in [x]?
  68. 06:48 JohnnyQuotronKidderPeabodyAlum: Alpha...I do indeed. But I remain curious about how you modifyed your breakout study . IF my memory serves me correctly.
  69. 06:51 Paris: Here is a study from Mobius that uses GetValue().
  70.  
  71.  
  72. # Comparison of Today's Volume at bar and Volume at time.
  73. # Mobius
  74. # V01.11.02.2017
  75.  
  76. # There's been a number of requests for a volume comparison study
  77. # for previous day's volume at the relative bar and current time.
  78.  
  79. def v = volume;
  80. def bar = barNumber();
  81. def xBar = if SecondsTillTime(0930) == 0
  82. then bar
  83. else xBar[1];
  84. def pxBar = if xBar != xBar[1]
  85. then xBar[1]
  86. else pxBar[1];
  87. def zxBar = if SecondsFromTime(0930) >= 0 and
  88. SecondsTillTime(1600) > 1
  89. then 0
  90. else if SecondsTillTime(1600) == 0
  91. then bar
  92. else zxBar[1];
  93. def pzxBar = if zxBar != zxBar[1]
  94. then zxBar[1]
  95. else pzxBar[1];
  96. def pxBars = if bar == xBar
  97. then pxBar
  98. else if bar >= xBar
  99. then pxBars[1] + 1
  100. else pxBars[1];
  101. def length = bar - (pxBars-1);
  102. def RelVol = if bar >= xBar
  103. then getValue(v, length)
  104. else 0;
  105. def pVol = if bar == xBar
  106. then 0
  107. else if bar > xBar
  108. then pVol[1] + RelVol
  109. else pVol[1];
  110. def tVol = if SecondsTillTime(0930) == 0
  111. then v
  112. else if SecondsFromTime(0930) > 0 and SecondsTillTime(1600) >= 0
  113. then compoundValue(1, tVol[1] + v, v)
  114. else tVol[1];
  115. addlabel(1, "yesterdays volume at bar = " + RelVol +
  116. " yesterdays volume = " + pVol +
  117. " todays volume = " + tVol,
  118. if tVol > pVol
  119. then color.green
  120. else color.red);
  121. # End Code Previous Days Volume Comparison
  122. 06:54 JFG78: is there a way to force the FloatingPL subgraph to use the correct multiplier for various products? I keep having this issue where it will work for one contract or stock but then 'sticks' w/ that multiplier even though I've moved on to another commodity or stock?
  123. 06:57 Nube: re: getvalue() positive brings it forward, negative brings it backwards.
  124. 06:58 MTS1: OK; get it now; in theory "then getValue(v, length)" could just be "then v[length]"; but TS does not seem to like a variable there, needs to be a number. Thanks!
  125. 07:03 Mobius: getValue() alows the use of a variable for indexing
  126. 07:04 Nube: Probably, MTS1. I banged my head flat over the inability to index with a variable until Mob explained to us that's what GetValue is for.
  127. 07:07 MTS1: Got it, thanks.
  128. On a separate note; Internals trending up, while markets still trending down. .
  129. 07:10 JohnnyQuotronKidderPeabodyAlum: Sold my AMZN position. Aloha old friend.
  130. 07:33 Joebone87: paris.. did you share the sector rotaion stuff we talked about a few days ago? I havent been at computer 100% of the time..
  131. 07:33 Joebone87: the one AI asked for^^?
  132. 07:33 Joebone87: the one AI asked for^^?
  133. 07:52 AlphaInvestor: Joe - THB shared it, and I found Paris' updated version in my archive
  134. 07:54 AlphaInvestor: Mobius or any other Guru - one of the studies I am working on requires me to know whether it is a Saturday or Sunday. Since bars don't exist on those days the function:
  135. def CurrentDOW = GetDayOfWeek(GetYYYYMMDD());
  136. returns Friday if it is a weekend.
  137. Any idea how to determine if we are in a weekend day?
  138. 07:55 MTS1: Combine with secondsfromtime or secondstilltime when Friday is returned?
  139. 07:56 MTS1: Or RegularTradingEnd/Start
  140. 07:58 AlphaInvestor: Good thoughts - implementatino details fuzzy in my head
  141. 08:00 MTS1: Or maybe something like
  142. def CurrentDate = GetYYYYMMDD();
  143. def CurrentDOW = GetDayOfWeek(GetYYYYMMDD());
  144. If currentDate > CurrentDate[1] and CurrentDOW >CurrentDOW[1] then CurrentDOW+1 or somethign like that;)
  145. Willl have to test on weekend though or on demand. .
  146. 08:00 MTS1: Sorry; CurrentDOW = CurrentDOW[1]
  147. 08:01 Joebone87: would you mind sharing AI? working on this sector rotaion stuff and was curious about it?
  148. 08:01 MTS1: Not sure if you can subptract dates to calculate days between
  149. 08:03 Paris: Joe, this one's for you
  150.  
  151.  
  152. # PINTO_SectorsOverlay
  153. # S&P Sector ETFs
  154. # jaimepinto
  155. #
  156. # Modified by Paris to specify S&P Sector Indices
  157. # 10.21.2016
  158.  
  159. declare upper;
  160.  
  161. input ShowOverlay = yes;
  162. input pivot = 180; ### bars
  163. input length = 4;
  164. input displace = 3;
  165. input SnP500 = "SPY";
  166. input Cyclicals = "$SP500#25"; # Consumer Discretionary
  167. input Technology = "$SP500#45";
  168. input Industrials = "$SP500#20";
  169. input Materials = "$SP500#15";
  170. input Energy = "$SP500#10";
  171. input Staples = "$SP500#30";
  172. input HealthCare = "$SP500#35";
  173. input Utilities = "$SP500#55";
  174. input Financials = "$SP500#40";
  175. input Telecom = "$SP500#50";
  176.  
  177. def BasePrice = WildersAverage(open , length)[-length + displace];
  178. def SnP500Price = WildersAverage(open(SnP500) , length)[-length + displace];
  179. def CyclicalsPrice = WildersAverage(open(Cyclicals) , length)[-length + displace];
  180. def TechnologyPrice = WildersAverage(open(Technology) , length)[-length + displace];
  181. def IndustrialsPrice = WildersAverage(open(Industrials), length)[-length + displace];
  182. def MaterialsPrice = WildersAverage(open(Materials) , length)[-length + displace];
  183. def EnergyPrice = WildersAverage(open(Energy) , length)[-length + displace];
  184. def StaplesPrice = WildersAverage(open(Staples) , length)[-length + displace];
  185. def HealthCarePrice = WildersAverage(open(HealthCare) , length)[-length + displace];
  186. def UtilitiesPrice = WildersAverage(open(Utilities) , length)[-length + displace];
  187. def FinancialsPrice = WildersAverage(open(Financials) , length)[-length + displace];
  188.  
  189. def barNumber = if barNumber() > pivot then barNumber() else 1;
  190. def BaseOpen = if barNumber == 1 then basePrice else BaseOpen[1];
  191. def SnP500Open = if barNumber == 1 then SnP500Price else SnP500Open[1];
  192. def CyclicalsOpen = if barNumber == 1 then CyclicalsPrice else CyclicalsOpen[1];
  193. def TechnologyOpen = if barNumber == 1 then TechnologyPrice else TechnologyOpen[1];
  194. def IndustrialsOpen = if barNumber == 1 then IndustrialsPrice else IndustrialsOpen[1];
  195. def MaterialsOpen = if barNumber == 1 then MaterialsPrice else MaterialsOpen[1];
  196. def EnergyOpen = if barNumber == 1 then EnergyPrice else EnergyOpen[1];
  197. def StaplesOpen = if barNumber == 1 then StaplesPrice else StaplesOpen[1];
  198. def HealthCareOpen = if barNumber == 1 then HealthCarePrice else HealthCareOpen[1];
  199. def UtilitiesOpen = if barNumber == 1 then UtilitiesPrice else UtilitiesOpen[1];
  200. def FinancialsOpen = if barNumber == 1 then FinancialsPrice else FinancialsOpen[1];
  201.  
  202. def Multiplier = BaseOpen;
  203.  
  204. plot dot = if barNumber() == pivot then BaseOpen else Double.NaN;
  205. dot.SetDefaultColor(Color.WHITE);
  206. dot.SetStyle(Curve.POINTS);
  207. dot.SetLineWeight(5);
  208.  
  209. plot basePriceToPlot = if ShowOverlay then BasePrice - (BasePrice - BaseOpen) + Multiplier * (BasePrice - BaseOpen) / BaseOpen else Double.NaN;
  210. basePriceToPlot.SetDefaultColor(Color.WHITE);
  211. AddLabel(ShowOverlay, " " + GetUnderlyingSymbol() + " ", Color.WHITE);
  212. basePriceToPlot.SetLineWeight(2);
  213.  
  214. plot SnP500PriceToPlot = if ShowOverlay then SnP500Price - (SnP500Open - BaseOpen) + Multiplier * (SnP500Price - SnP500Open) / SnP500Open else Double.NaN;
  215. SnP500PriceToPlot.SetDefaultColor(Color.RED);
  216. AddLabel(ShowOverlay, " SnP500 ", Color.RED);
  217.  
  218. plot CyclicalsPriceToPlot = if ShowOverlay then CyclicalsPrice - (CyclicalsOpen - BaseOpen) + Multiplier * (CyclicalsPrice - CyclicalsOpen) / CyclicalsOpen else Double.NaN;
  219. CyclicalsPriceToPlot.SetDefaultColor(Color.VIOLET);
  220. AddLabel(ShowOverlay, " Cyclicals ", Color.VIOLET);
  221.  
  222. plot TechologyPriceToPlot = if ShowOverlay then TechnologyPrice - (TechnologyOpen - BaseOpen) + Multiplier * (TechnologyPrice - TechnologyOpen) / TechnologyOpen else Double.NaN;
  223. TechologyPriceToPlot.SetDefaultColor(Color.GREEN);
  224. TechologyPriceToPlot.SetLineWeight(3);
  225. AddLabel(ShowOverlay, " Techology ", Color.GREEN);
  226.  
  227. plot IndustrialsPriceToPlot = if ShowOverlay then IndustrialsPrice - (IndustrialsOpen - BaseOpen) + Multiplier * (IndustrialsPrice - IndustrialsOpen) / IndustrialsOpen else Double.NaN;
  228. IndustrialsPriceToPlot.SetDefaultColor(Color.MAGENTA);
  229. AddLabel(ShowOverlay, " Industrials ", Color.MAGENTA);
  230.  
  231. plot MaterialsPriceToPlot = if ShowOverlay then MaterialsPrice - (MaterialsOpen - BaseOpen) + Multiplier * (MaterialsPrice - MaterialsOpen) / MaterialsOpen else Double.NaN;
  232. MaterialsPriceToPlot.SetDefaultColor(Color.CYAN);
  233. AddLabel(ShowOverlay, " Materials ", Color.CYAN);
  234.  
  235. plot EnergyPriceToPlot = if ShowOverlay then EnergyPrice - (EnergyOpen - BaseOpen) + Multiplier * (EnergyPrice - EnergyOpen) / EnergyOpen else Double.NaN;
  236. EnergyPriceToPlot.SetDefaultColor(Color.YELLOW);
  237. AddLabel(ShowOverlay, " Energy ", Color.YELLOW);
  238.  
  239. plot StaplesPriceToPlot = if ShowOverlay then StaplesPrice - (StaplesOpen - BaseOpen) + Multiplier * (StaplesPrice - StaplesOpen) / StaplesOpen else Double.NaN;
  240. StaplesPriceToPlot.SetDefaultColor(Color.DARK_GREEN);
  241. AddLabel(ShowOverlay, " Staples ", Color.DARK_GREEN);
  242.  
  243. plot HealthCarePriceToPlot = if ShowOverlay then HealthCarePrice - (HealthCareOpen - BaseOpen) + Multiplier * (HealthCarePrice - HealthCareOpen) / HealthCareOpen else Double.NaN;
  244. HealthCarePriceToPlot.SetDefaultColor(Color.PLUM);
  245. AddLabel(ShowOverlay, " HealthCare ", Color.PLUM);
  246.  
  247. plot UtilitiesPriceToPlot = if ShowOverlay then UtilitiesPrice - (UtilitiesOpen - BaseOpen) + Multiplier * (UtilitiesPrice - UtilitiesOpen) / UtilitiesOpen else Double.NaN;
  248. UtilitiesPriceToPlot.SetDefaultColor(Color.ORANGE);
  249. AddLabel(ShowOverlay, " Utilities ", Color.ORANGE);
  250.  
  251. plot FinancialsPriceToPlot = if ShowOverlay then FinancialsPrice - (FinancialsOpen - BaseOpen) + Multiplier * (FinancialsPrice - FinancialsOpen) / FinancialsOpen else Double.NaN;
  252. FinancialsPriceToPlot.SetDefaultColor(Color.PINK);
  253. AddLabel(ShowOverlay, " Financials ", Color.PINK);
  254.  
  255. # End Study
  256. 08:03 AlphaInvestor: If it is Saturday - CurrentDate will return Friday, Same with Sunday. And CurrentDate[1] will return Thursday for both
  257. 08:03 DMonkey: Alpha...i never really tought about it, but I can assume, since there is no data, there is no real way to differentiate....
  258. 08:03 Nube: AI, I thought getdayofweek will return 1 - 7?
  259. 08:05 AlphaInvestor: Apparently it only returns 1-5 for equities when you feed it using GetYYYYMMDD() because there are no bars to populate day 6 or 7 in GetYYYYMMDD()
  260. 08:06 Joebone87: thanks Paris!
  261. 08:06 Mobius: Alpha.. Weekends are a dead zone for TOS. Nothing is recognized by the platform till trading begins again on Sunday.
  262. 08:06 Mobius: It is a flaw in the platform.
  263. 08:07 AlphaInvestor: If I step back one more level of abstraction - I am trying to automagically calculate the days to expiration for each weekly series returned from GetSeriesVolatility()
  264. 08:07 MTS1: Oh; that stinks. Can you add one day to GetYYYMMMDDD()? Wonder how RegularTradingStart(GetYYYYMMDD() +1 Day) would work (in propper Syntax)
  265. 08:07 AlphaInvestor: Mobius - I tried many things, couldn't figure out how to do it - apparently I am not the only one with the issue
  266. 08:07 MTS1: Since that returns secons; would that return a larger number for Monday's start when it's Sat vs Sun?
  267. 08:07 Joebone87: use next third friday AI
  268. 08:08 AlphaInvestor: MTS - sure yoiu could add one day to that ... but how would you know when you need to? Since you don't know if it is really Friday, Saturday, or Sunday.
  269. 08:08 Mobius: There's no work-around. Options are calculated by the numeric variance from option start date to maturity date
  270. 08:08 MTS1: You know it returns Friday for any of those; the seconds should be higher on Friday, next Sat, next Syn]
  271. 08:08 MTS1: Sun
  272. 08:08 AlphaInvestor: Joe - I use that for Regular monthly options, but trying to do it for Weekly's too
  273. 08:09 Joebone87: your going to have to do that weird calendar programming stuff
  274. 08:09 Joebone87: here is how i got days till VX expiration
  275.  
  276. ############# 30day average premium #############
  277.  
  278. ###### days till CCE
  279. script
  280. VX_days {
  281.  
  282. input series = 1;
  283. input show_label = yes;
  284.  
  285. Assert(series > 0, "'series' must be positive: " + series);
  286.  
  287. def CurrentYear = GetYear();
  288. def CurrentMonth = GetMonth();
  289. def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
  290.  
  291. def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
  292. def FirstFridayDOM1 = if Day1DOW1 < 6
  293. then 6 - Day1DOW1
  294. else if Day1DOW1 == 6
  295. then 7
  296. else 6;
  297. def RollDOM = FirstFridayDOM1 + 14;
  298. def ExpMonth1 = if RollDOM > CurrentDOM
  299. then CurrentMonth + series - 1
  300. else CurrentMonth + series;
  301. def ExpMonth2 = if ExpMonth1 > 12
  302. then ExpMonth1 - 12
  303. else ExpMonth1;
  304. def ExpYear = if ExpMonth1 > 12
  305. then CurrentYear + 1
  306. else CurrentYear;
  307. def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
  308. def FirstFridayDOM = if Day1DOW < 6
  309. then 6 - Day1DOW
  310. else if Day1DOW == 6
  311. then 7
  312. else 6;
  313. def ExpDOM = FirstFridayDOM + 14;
  314.  
  315. plot N3rdF = if IsNaN(close) then Double.NaN else (DaysTillDate(ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM)) - 30;
  316.  
  317. }
  318.  
  319. ###################### EVERYTHING ELSE #################
  320.  
  321.  
  322. ############ distance to CCE 1 2 and 3
  323. def CCE1 = VX_days(1, no);
  324. def CCE2 = VX_days(2, no);
  325. def CCE3 = VX_days(3, no);
  326.  
  327. ########### Distance to closest future CCE
  328. def days_till_CCE = if VX_days(1, no) > 0 then VX_days(1, no) else if VX_days(2, no) > 0 then VX_days(2, no) else VX_days(3, no);
  329. #days_till_CCE.setpaintingStrategy(paintingStrategy.LINE_VS_POINTS);
  330.  
  331. 08:09 DMonkey: alpha....
  332. declare lower;
  333. input series = 1;
  334. def year = (Round(GetYYYYMMDD() / 10000, 0));
  335. def Month = GetMonth();
  336. def Day = GetDayOfMonth(GetYYYYMMDD());
  337. def CurrentYear = GetYear();
  338. def CurrentMonth = GetMonth();
  339. def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
  340. def CurrentDOW = GetDayOfWeek(GetYYYYMMDD());
  341. def Day1DOW = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1);
  342. def ThisFriday = if CurrentDOW < 6
  343. then 6 - CurrentDOW - 1
  344. else if CurrentDOW == 6
  345. then 0
  346. else 6;
  347. def FirstFridayDOM = if Day1DOW < 6
  348. then 6 - Day1DOW
  349. else if Day1DOW == 6
  350. then 7
  351. else 6;
  352. def RollDOM = FirstFridayDOM + 27;
  353. def ExpMonth = if RollDOM > CurrentDOM
  354. then CurrentMonth + series - 1
  355. else CurrentMonth + series;
  356. def ExpYear = if ExpMonth > 12
  357. then CurrentYear + 1
  358. else CurrentYear;
  359. def ExpDOW1 = FirstFridayDOM;
  360. def EXPDOW2 = FirstFridayDOM + 7;
  361. def ExpDOW3 = FirstFridayDOM + 14;
  362. def N3rdF = if IsNaN(close)
  363. then Double.NaN
  364. else DaysTillDate(ExpYear * 10000 + ExpMonth * 100 + ExpDOW3);
  365. AddLabel(1, "Days till 3rd Friday = " + " Series : " + series + " : " + (N3rdF) + " Days");
  366.  
  367.  
  368. input your series.....
  369. 08:09 AlphaInvestor: I might have to use NextThirdFriday ... then index forward or backward one or more weeks - could get very complicated
  370. 08:10 MTS1: You can devide by AggregationPeriod.HOUR like the sample in reference
  371. 08:10 Joebone87: thats exactly what i did AI
  372. 08:12 AlphaInvestor: Thanks ALL! Especially, Joe, Dmonkey, MTS. I think I will be able to find a solution in there.
  373. 08:13 help: hello can you help
  374. 08:13 MTS1: (Or AggregationPeriod.Day I assume). Not sure what it'd return when you run RegularTradingStart() for a Sat or Sun date though.
  375. 08:14 MTS1: Help; depends. .
  376. 08:14 help: is there a way to say the current price is greater or less than pre market price
  377. 08:15 MTS1: Yes
  378. 08:15 MTS1: what pre-market price?
  379. 08:16 help: well say in premarket a stock had a great amount of change from 1.1 to 1.5 and i do not want any great pre market movement to affect my scanner
  380. 08:17 trader2040: How do I get started with scripting here?
  381. 08:17 help: is there a way to say current price is greater than premarket prices between 1559 and 0930.
  382. 08:17 help: yes how do i get started on scripting
  383. 08:19 DMonkey: http://tlc.thinkorswim.com/center/howToTos.html
  384. 08:19 MTS1: Start with the manual and howtos, then view some of the built-in or custom scripts you already have to understand them.
  385. Room FAQ: http://tos.mx/ZQmLy9 A good starting place is having questions and taking a free platform tour. Contact support@thinkorswim.com
  386. This is a lounge of volunteers who do not work for TOS. We are not TOS support, just experienced users interested in coding.
  387.  
  388. When you're setting up your platform tour, request the chat room scripts created by TOS support.
  389. When looking for scripts ask a search engine: Thinkscripts, TOS scripts or check out MyTrade/Mobius
  390. 08:21 MTS1: When you have requests; be specific in your inquiry and logic you're looking to build into a script. Help; I thought you were looking at a chart not a scan, and you still need to clarify what pre-market price. (something like highest or lowest between certain time, close, etc). If you can explain the logic that's how it can be coded.
  391. 08:22 trader2040: thanks
  392. 08:22 crimsontide: I have price lines drawn at support and resistance. Can someone please tell me how to get the percent to change between these lines as you move up or down? Thanks.
  393. 08:25 Nube: close minus support divided by support
  394. 08:25 MTS1: Crimson; ThinkScript does not have access to drawings; so no math can be done on drawings.
  395. 08:25 Nube: keep order of operations in mind better than I did.
  396. 08:28 monkeyswing: Hi guys, i have the following code AddLabel (1, "PRV" + volume / volume[1], Color.MAGENTA);, to display volume today compared to preeious day however, when i switch the chart to say the 30 min it compares it to the prior 30 minute bar and i would like it to contiue to show me the amount ont he daily aggregation. Could someone please help me make it so it stays on daily . thanks
  397. 08:29 MTS1: Help; here is a snippet from Mobius that may help get started: "here is the code for the premarket part
  398. def MarketClosePrice = if getTime()[1] > RegularTradingEnd(getYYYYMMDD()) and
  399. getTime() < RegularTradingEnd(getYYYYMMDD())
  400. then close[1]
  401. else MarketClosePrice[1];
  402. plot PreMarketScan = getTime() < RegularTradingStart(getYYYYMMDD()) and
  403. close(priceType = "LAST") < MarketClosePrice;
  404.  
  405. #Mobius: that part of the scan must be run on a 3min or less aggregation the other filters will be daily aggregation"
  406. 08:31 Nube: monkey, see aggregation period in the manual. It's a good starter project.
  407. 08:31 MTS1: Monkey; check this out in the manual: http://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod/AggregationPeriod-DAY.html
  408. 08:36 monkeyswing: MTS1 so would this be it
  409. 08:36 monkeyswing: def agg = AggregationPeriod.DAY;
  410. plot data = volume(period = agg);
  411.  
  412. AddLabel (1, "PRV" + agg / agg[1], Color.MAGENTA);
  413.  
  414.  
  415. 08:37 MTS1: Did you try that?
  416. 08:40 monkeyswing: not yet
  417. 08:40 monkeyswing: i will rn
  418. 08:41 monkeyswing: Hmm it doesnt display a value
  419. 08:42 monkeyswing: jus the label title
  420. 08:43 Paris: monkeyswing - here is a Volume Pct Change Label study that you can play with
  421.  
  422. input aggregationPeriod = AggregationPeriod.DAY;
  423. def percentChg = (volume(period = AggregationPeriod) / volume(period = AggregationPeriod)[1]-1) * 100;
  424. AddLabel(yes, " %V curr " + (Round(percentChg) + "%"), if percentChg > 0 then Color.GREEN else Color.RED);
  425. 08:46 MTS1: Monkey; you're trying to print AGG instead of Vol which you called Data; try def data instead of plot, and use data/data[1] in your math
  426. 08:54 Mobius: /ES big picture stuff - $2728 was support. Stronger support 2687 weak support 2700.
  427. 08:56 trader2040: any one has sample on how to setup a trade using scripting?
  428. 08:57 AlphaInvestor: if you mean Auto-Trading - TOS does not do that
  429. 08:58 abts: any ideas on why my 30min aggregation script is not working in the following plus will the plot data soap work?#AB_IchMACDFWSOAP Strategy LE
  430.  
  431. #Buy Signal is:
  432. #FWSOAP s8x5 line has positive slope on daily aggregate
  433. #MACD Value line has positive slope on daily aggegate
  434. #Price Close crosses above Ichimoku Span B on a 30 min aggregate
  435.  
  436. input tradeSize = 100;
  437.  
  438. def Soap = FW_SOAP().s8x5;
  439. plot data = Soap > Soap[1]; # not sure using plot data is correct in stragegy
  440. def macd = Sum("data" = MACD() > MACD()[1], "length" = 2);
  441.  
  442. #Ichimoku Span B Need to be 30min Aggregate;
  443. input Period = 30 min; #input error, 30 min??
  444. def agg = AggregationPeriod.Period;
  445. plot data = close(period = agg);
  446.  
  447. def IchSpanB = close crosses above Ichimoku()."Span B" within 2 bars;
  448.  
  449. def signal = Soap and macd and IchSpanB;
  450.  
  451. AddOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
  452.  
  453. #Exit Signal is:
  454. #Price close crosses below Ichimoku Span A on daily Aggregate
  455. #Changing Aggregation Period, DAY again, not sure this will work
  456.  
  457. input Period = DAY;
  458. def agg = AggregationPeriod.Period;
  459. plot data = close(period = agg);
  460.  
  461. def exit = close crosses below Ichimoku()."Span A";
  462. AddOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
  463. 08:58 Paris: This sure looks/feels like an impulsive move ala EWI terminology
  464. 08:59 Mobius: VooDoo
  465. 08:59 monkeyswing: ok let me try, thanks guys
  466. 09:01 Mobius: abts - it helps to use actual ThinkScript language.
  467.  
  468. 30 min = Aggregationperiod.Thirty_Min
  469. 09:01 MTS1: Trader2040 check out conditional orders http://tlc.thinkorswim.com/center/howToTos/thinkManual/Trade/Order-Entry-Tools/conditionalorders.html
  470. 09:03 AlphaInvestor: Mobius - what? What? we cannot use English yet?
  471. 09:03 abts: thx Mobius, i'll try that
  472. 09:04 Mobius: The manual is your friend
  473. 09:08 MTS1: Do or Do Not; there is no Try ;)
  474. 09:14 abts: doesn't work for me
  475. 09:22 MTS1: Use propper syntax; can't make up your own. RTM for propper syntax.
  476. 09:24 MTS1: Example: close(period = agg) is not TS Syntax, nor was AggregationPeriod. Consolidate this:
  477.  
  478. input Period = 30 min; #input error, 30 min??
  479. def agg = AggregationPeriod.Period;
  480. plot data = close(period = agg);
  481.  
  482. To:
  483.  
  484. Input agg = Aggregationperiod.Thirty_Min;
  485. plot data = close(getSymbol(), agg);
  486.  
  487. Did not test; writing in chat.
  488. 09:24 Nube: First maybe buyable moment all day.
  489. 09:24 Wongyc72: Good day
  490. 09:25 Wongyc72: Is there anyway, that I can exclude certain futures by using thinkscript. For example, I want my scan alert to exclude /ZC. Is it possible?
  491. 09:26 Mobius: Wong - Make your own scan list
  492. 09:31 rafael0021: hi eveyone is there a way to just have a drawing on 1 chart instead it being duplicated on evey chart TIA
  493. 09:37 Mobius: http://tlc.thinkorswim.com/center/howToTos/thinkManual/charts/Using-Drawings.html
  494. 09:38 AlphaInvestor: Raf - the answer is yes, the method is in the manual
  495. 09:38 rafael0021: thanks
  496. 09:42 abts: MTS1 fixed one error caused an other, thx for helping
  497. 09:42 Wongyc72: @Mobius : Can I code If (futures <> / zc) then ?
  498. 09:45 AlphaInvestor: Wong - you will be well served by reading the manual, and doing the online tutorials
  499. 09:46 harndog: rafael: Get a platform tour. Long version: Good morning. Room FAQ: http://tos.mx/ZQmLy9 A good starting place is having questions and taking a free platform tour. Contact support@thinkorswim.com
  500. This is a lounge of volunteers who do not work for TOS.
  501. We are not TOS support, just experienced users interested in coding.
  502.  
  503. When you're setting up your platform tour, request the chat room scripts created by TOS support.
  504. When looking for scripts ask a search engine: Thinkscripts, TOS scripts or check out MyTrade/Mobius
  505. 09:52 JohnnyQuotronKidderPeabodyAlum: If anyone needs a copy of Friday's or Saturday's Lounge banter I have it and am happy to post it whereever.
  506. 09:54 Wongyc72: @Alphainvestor : Can give me the link for the tutorial?
  507. 09:56 AlphaInvestor: Wong - http://tlc.thinkorswim.com/center/howToTos.html
  508. 10:02 Mobius: Close all watertight doors and take her down Virgil
  509. 10:13 FrankB3: too late,,,, unless your boat already has holes in it
  510. 10:13 fasza: Mobius hi, ... do u have a good script or indicator for scalping,, i clicking always in very bad time on it... pls.
  511. 10:15 amalia: Not the place to learn scalping imo
  512. 10:23 Mobius: fasza - there are no good scripts for scalping. That's not even a real type of trading. If you want to learn intraday trading find a mentor or a group that is successful at it. And practice on paper till your so comfortable with it that it's natural to you. 10,000 trades is about normal for someone to learn it well
  513. 10:25 fasza: :(
  514. 10:27 FrankB3: First time ever ::: hear anyone mention a mentor::: wish I found one 20 years ago
  515. 10:28 Mobius: As one old book put it "How can I learn without someone to teach me?"
  516. 10:33 FrankB3: Out of the 100 or so books, DVD, courses:: their is only a few traders that have a complete trading plan,,, that did not change over the years
  517. 10:41 jack6966: Hello, would anyone have a study to share on whether futures in Contango vs. Backwardation? and possibly plotted over days?
  518. 10:41 jack6966: Must be quite tall skills to write something like that
  519. 10:43 tom: hello
  520. 10:44 Mobius: jack...
  521.  
  522. # Futures Contango / Normal Backwardation Labels
  523. # Mobius
  524. # Chat Room Request 12.29.2015
  525.  
  526. #declare lower;
  527.  
  528. def Month = GetMonth();
  529. def Year = GetYear();
  530. def Year_Ext = Year - 2010;
  531. def agg = AggregationPeriod.DAY;
  532. def NextContract = if Month == 1
  533. then Close(symbol = getSymbol() + "G" + Year_Ext, period = agg)
  534. else if Month == 2
  535. then Close(symbol = getSymbol() + "H" + Year_Ext, period = agg)
  536. else if Month == 3
  537. then Close(symbol = getSymbol() + "J" + Year_Ext, period = agg)
  538. else if Month == 4
  539. then Close(symbol = getSymbol() + "K" + Year_Ext, period = agg)
  540. else if Month == 5
  541. then Close(symbol = getSymbol() + "M" + Year_Ext, period = agg)
  542. else if Month == 6
  543. then Close(symbol = getSymbol() + "N" + Year_Ext, period = agg)
  544. else if Month == 7
  545. then Close(symbol = getSymbol() + "Q" + Year_Ext, period = agg)
  546. else if Month == 8
  547. then Close(symbol = getSymbol() + "U" + Year_Ext, period = agg)
  548. else if Month == 9
  549. then Close(symbol = getSymbol() + "V" + Year_Ext, period = agg)
  550. else if Month == 10
  551. then Close(symbol = getSymbol() + "X" + Year_Ext, period = agg)
  552. else if Month == 11
  553. then Close(symbol = getSymbol() + "Z" + Year_Ext, period = agg)
  554. else if Month == 12
  555. then Close(symbol = getSymbol() + "F" + (Year_Ext + 1), period = agg)
  556. else double.nan;
  557.  
  558.  
  559. def NextContract4 = if Month == 1
  560. then close(symbol = getSymbol() + "J" + Year_Ext, period = agg)
  561. else if Month == 2
  562. then close(symbol = getSymbol() + "K" + Year_Ext, period = agg)
  563. else if Month == 3
  564. then close(symbol = getSymbol() + "M" + Year_Ext, period = agg)
  565. else if Month == 4
  566. then close(symbol = getSymbol() + "N" + Year_Ext, period = agg)
  567. else if Month == 5
  568. then close(symbol = getSymbol() + "Q" + Year_Ext, period = agg)
  569. else if Month == 6
  570. then close(symbol = getSymbol() + "U" + Year_Ext, period = agg)
  571. else if Month == 7
  572. then close(symbol = getSymbol() + "V" + Year_Ext, period = agg)
  573. else if Month == 8
  574. then close(symbol = getSymbol() + "X" + Year_Ext, period = agg)
  575. else if Month == 9
  576. then close(symbol = getSymbol() + "Z" + Year_Ext, period = agg)
  577. else if Month == 10
  578. then close(symbol = getSymbol() + "F" + (Year_Ext + 1), period = agg)
  579. else if Month == 11
  580. then close(symbol = getSymbol() + "G" + (Year_Ext + 1), period = agg)
  581. else if Month == 12
  582. then close(symbol = getSymbol() + "H" + (Year_Ext + 1), period = agg)
  583. else Double.NaN;
  584. def Month6Contract = if Month == 1
  585. then close(symbol = getSymbol() + "Q" + Year_Ext, period = agg)
  586. else if Month == 2
  587. then close(symbol = getSymbol() + "U" + Year_Ext, period = agg)
  588. else if Month == 3
  589. then close(symbol = getSymbol() + "V" + Year_Ext, period = agg)
  590. else if Month == 4
  591. then close(symbol = getSymbol() + "X" + Year_Ext, period = agg)
  592. else if Month == 5
  593. then close(symbol = getSymbol() + "Z" + Year_Ext, period = agg)
  594. else if Month == 6
  595. then close(symbol = getSymbol() + "F" + (Year_Ext + 1), period = agg)
  596. else if Month == 7
  597. then close(symbol = getSymbol() + "G" + (Year_Ext + 1), period = agg)
  598. else if Month == 8
  599. then close(symbol = getSymbol() + "H" + (Year_Ext + 1), period = agg)
  600. else if Month == 9
  601. then close(symbol = getSymbol() + "J" + (Year_Ext + 1), period = agg)
  602. else if Month == 10
  603. then close(symbol = getSymbol() + "K" + (Year_Ext + 1), period = agg)
  604. else if Month == 11
  605. then close(symbol = getSymbol() + "M" + (Year_Ext + 1), period = agg)
  606. else if Month == 12
  607. then close(symbol = getSymbol() + "N" + (Year_Ext + 1), period = agg)
  608. else Double.NaN;
  609. def YearOutContract = if Month == 1
  610. then close(symbol = getSymbol() + "F" + (Year_Ext + 1), period = agg)
  611. else if Month == 2
  612. then close(symbol = getSymbol() + "G" + (Year_Ext + 1), period = agg)
  613. else if Month == 3
  614. then close(symbol = getSymbol() + "H" + (Year_Ext + 1), period = agg)
  615. else if Month == 4
  616. then close(symbol = getSymbol() + "J" + (Year_Ext + 1), period = agg)
  617. else if Month == 5
  618. then close(symbol = getSymbol() + "K" + (Year_Ext + 1), period = agg)
  619. else if Month == 6
  620. then close(symbol = getSymbol() + "M" + (Year_Ext + 1), period = agg)
  621. else if Month == 7
  622. then close(symbol = getSymbol() + "N" + (Year_Ext + 1), period = agg)
  623. else if Month == 8
  624. then close(symbol = getSymbol() + "Q" + (Year_Ext + 1), period = agg)
  625. else if Month == 9
  626. then close(symbol = getSymbol() + "U" + (Year_Ext + 1), period = agg)
  627. else if Month == 10
  628. then close(symbol = getSymbol() + "V" + (Year_Ext + 1), period = agg)
  629. else if Month == 11
  630. then close(symbol = getSymbol() + "X" + (Year_Ext + 1), period = agg)
  631. else if Month == 12
  632. then close(symbol = getSymbol() + "Z" + (Year_Ext + 1), period = agg)
  633. else Double.NaN;
  634. AddLabel(1, "Date: " + Month +
  635. "/" +
  636. AsPrice(Year) +
  637. " Current Contract: " +
  638. getSymbol() +
  639. " Curr Cont Price = " +
  640. AsDollars(close(symbol = GetSymbol())) +
  641. " Next Month Contract Price = " +
  642. AsDollars(NextContract) +
  643. " 6 Months Out = " +
  644. AsDollars(Month6Contract) +
  645. " One Year Out = " +
  646. AsDollars(YearOutContract), Color.WHITE);
  647. plot contango = close(symbol = getSymbol()) < NextContract;
  648. AddLabel(close(symbol = getSymbol()) <= NextContract, "Contango", Color.GREEN);
  649. AddLabel(close(symbol = getSymbol()) > NextContract, "Backwardation", Color.RED);
  650. # End Code VIX Contango/Normal Backwardation
  651.  
  652. 10:45 Mobius: Actually trivial to write.
  653. 10:45 jack6966: Wow ! Very impressive and much appreciated Mobius !
  654. 10:54 JohnnyQuotronKidderPeabodyAlum: Alpha...from 12:45 online tutorials? Have I missed an education tool?
  655. 10:55 MTS1: Johnny; 11:56 AlphaInvestor: Wong - http://tlc.thinkorswim.com/center/howToTos.html
  656. 10:56 AlphaInvestor: Johnny - possbily
  657. 10:58 JohnnyQuotronKidderPeabodyAlum: Nope. I have been working through those. Gotta remember the first language I learned was APL. Oh and did I mention I dropped the class.
  658. 10:59 AlphaInvestor: I was one of the geeks who helped out in the computer lab in university - I learned some APL, PL/1, COBOL, etc ... while helping the idjits in there
  659. 11:00 AlphaInvestor: APL terminals were green text on a black background - shows you how old I am
  660. 11:00 JohnnyQuotronKidderPeabodyAlum: Alpha...If you were at Wharton UG in 1979 I was one of those idjits.
  661. 11:01 AlphaInvestor: Not Wharton - but that is about the right timeframe
  662. 11:02 JohnnyQuotronKidderPeabodyAlum: and every line was in reverse polish notation as i recall
  663. 11:02 JohnnyQuotronKidderPeabodyAlum: oh what a headache.
  664. 11:02 Wongyc72: @Mobius : I've written a code to scan those I wanted only .
  665. 11:02 AlphaInvestor: twas an odd language
  666. 11:02 Wongyc72: def df = if (GetSymbol() == /ES) or (GetSymbol() == /CL) or (GetSymbol() == /GC) or (GetSymbol() == /SI) or (GetSymbol() == /ZN) or (Getsymbol() == /ZW) or (Getsymbol() == /ZB) or (Getsymbol() == /ZC) or (Getsymbol() == /ZS) or (Getsymbol() == /KC) or (Getsymbol() == /NG) then 1 else 0; plot scan = if df;
  667. 11:03 Mobius: What a waste -- you could have just taken 2 min and made that your list to scan in
  668. 11:04 AlphaInvestor: it was a learning exercise
  669. 11:05 JohnnyQuotronKidderPeabodyAlum: 
  670. 11:05 Mobius: never suggest someone waste time learning something useless or just plain wrong
  671. 11:05 JohnnyQuotronKidderPeabodyAlum: it was a nughtmare
  672. 11:07 AlphaInvestor: It was impressive how much "stuff" your could get doen with a tiny amount of code
  673. 11:08 Mobius: I had a nughtmare once. Stopped drinking tequila before bedtime and never had another
  674. 11:19 amalia: Johnny, what I usually do is post a pastebin of the whole day’s chat right before admins close the room. I never asked if it was wanted. lol Just an idea.
  675. 11:20 amalia: * did
  676. 11:20 JohnnyQuotronKidderPeabodyAlum: Understood
  677. 11:36 JohnnyQuotronKidderPeabodyAlum: I have been unable to find a script (google: thinkscript has weekly options) that creates a label when an underlyine has weekly options. Anyone seen anything of the sort?
  678. 11:41 Mobius: the scanner has weekly as an option - scan and save list
  679. 11:42 Mobius: past weak wupport
  680. 11:42 Mobius: support too
  681. 11:43 JohnnyQuotronKidderPeabodyAlum: I have the list. I just wanted to create a little label that would draw when the uderlying of my primay chart has weeklies. Kind of like an idiot light on my car's dashboard.
  682. 11:45 AlphaInvestor: it could be done, but not worth the effort IMO - you could use a fully qualified GetSeriesVolatiltiy() that specified weekly's and look to see if you got a valid IV back
  683. 11:51 R2S2: why use a simple solution when a complicated one will do.... :)
  684. 11:51 JohnnyQuotronKidderPeabodyAlum: fully qualified?
  685. 11:51 AlphaInvestor: specifying all the parameters including whether you want REGULAR or WEEKLYS
  686. 11:59 Mobius: here's a start for you
  687.  
  688. # Weekly Options Implied Volatility Plotted intraday
  689. # Mobius
  690. # Chat Room Request
  691. # 02.27.2016
  692.  
  693. declare lower;
  694. declare Once_Per_Bar;
  695.  
  696. input series = 1;
  697. input show_label = yes;
  698. input Days_In_Contract = 0;
  699. Assert(series > 0, "'series' must be positive: " + series);
  700.  
  701. def CurrentYear = GetYear();
  702. def CurrentMonth = GetMonth();
  703. def CurrentDOM = GetDayOfMonth(GetYYYYMMDD());
  704. def Day1DOW1 = GetDayOfWeek(CurrentYear * 10000 + CurrentMonth * 100 + 1); # First DOM is this DOW
  705. def FirstFridayDOM1 = if Day1DOW1 < 6
  706. then 6 - Day1DOW1
  707. else if Day1DOW1 == 6
  708. then 7
  709. else 6;
  710. def SecondFridayDOM = FirstFridayDOM1 + 7;
  711. def ThirdFridayDOM = FirstFridayDOM1 + 14;
  712. def FourthFridayDOM = FirstFridayDOM1 + 21;
  713. def RollDOM = FirstFridayDOM1 + 21; #14; changed to 21 to pick up all Fridays of the current month for weekly options
  714. def ExpMonth1 = if RollDOM > CurrentDOM
  715. then CurrentMonth + series - 1
  716. else CurrentMonth + series;
  717. def ExpMonth2 = if ExpMonth1 > 12
  718. then ExpMonth1 - 12
  719. else ExpMonth1;
  720. def ExpYear = if ExpMonth1 > 12
  721. then CurrentYear + 1
  722. else CurrentYear;
  723. def Day1DOW = GetDayOfWeek(ExpYear * 10000 + ExpMonth2 * 100 + 1);
  724. def FirstFridayDOM = if Day1DOW < 6
  725. then 6 - Day1DOW
  726. else if Day1DOW == 6
  727. then 7
  728. else 6;
  729. def ExpDOM = if currentDOM < FirstFridayDOM -1
  730. then FirstFridayDOM1
  731. else if between(currentDOM, FirstFridayDOM, SecondFridayDOM-1)
  732. then SecondFridayDOM
  733. else if between(currentDOM, SecondFridayDOM, ThirdFridayDOM-1)
  734. then ThirdFridayDOM
  735. else if between(currentDOM, ThirdFridayDOM, FourthFridayDOM-1)
  736. then FourthFridayDOM
  737. else FirstFridayDOM;
  738. def NextFriday = DaysTillDate(ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM);
  739. def ExpirationDate = GetYYYYMMDD() + NextFriday;
  740. def ExpData = (ExpirationDate / 1) + 1;
  741. def yr = Round(GetYear() / 100, 0);
  742. def yr2 = GetYear() - 2000;
  743. def OptionDateString = ExpYear * 10000 + ExpMonth2 * 100 + ExpDOM + 1;
  744. def ATMCprice = if isNaN(close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL)))
  745. then ATMCprice[1]
  746. else close(symbol = GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL));
  747. def HPD = if Days_In_Contract == 0 #HPD = Holding Period Days
  748. then NextFriday
  749. else Days_In_Contract;
  750. def t = HPD / 365;
  751. def ClosedForm_IV_est = if isNaN(((ATMCprice[1] * Sqrt(2 * Double.Pi)) / (close * Sqrt(t))))
  752. then ClosedForm_IV_est[1]
  753. else ((ATMCprice * Sqrt(2 * Double.Pi)) / (close * Sqrt(t)));
  754. plot Intraday_IV = if ClosedForm_IV_est > 0 then ClosedForm_IV_est else double.nan;
  755. Intraday_IV.SetStyle(Curve.Firm);
  756. Intraday_IV.SetDefaultColor(Color.Cyan);
  757.  
  758. def ImpMove = Round(((close * Intraday_IV * Sqrt(HPD)) / Sqrt(365)) / tickSize(), 0) * tickSize();
  759. AddLabel(show_label and IsOptionable(), "ATM Call option is " + GetATMOption(GetUnderlyingSymbol(), OptionDateString, OptionClass.CALL) + " Price = $" + ATMCprice + " Intraday IV = " + AsPercent(ClosedForm_IV_est) + " Implied Move By Friday = " + AsDollars(ImpMove), color.green);
  760.  
  761. # End Code Weekly Options with Closed Form IV estimate
  762.  
  763.  
  764. 12:02 anthony1999: Sorry to bother any help appreciated. How do I add a stationary line to a study ?
  765. 12:03 anthony1999: Example would be the ADX study, I would like to add a line at 25. thank you.
  766. 12:03 AlphaInvestor: Plot twentyfive = 25;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement