Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.84 KB | None | 0 0
  1. 10:35 optntradrsuntd: It signals green/red based on the breakout/breakdown which is good, but it's just fine tuning the areas where you shouldn't be in the trade
  2. 10:42 Nube: Rewrite the assignpricecolor statement to have the 3 conditions you want. It won't change to users preference.
  3. 10:43 Nube: As is there is no condition that would make it apply the "neutral" color
  4. 10:44 Nube: harumph, wrong I am. Should have looked closer.
  5. 10:45 Nube: You will still need to rewrite the the statement to make it do what you want instead of what it's scripted to do currently.
  6. 10:46 optntradrsuntd: Oh man
  7. 10:46 Nube: Not nearly as tough as it may seem.
  8. 10:48 optntradrsuntd: It's all the same, except it's giving signals off the EMA's disregarding price action
  9. 10:48 optntradrsuntd: And that's out of my realm, I just spotted the weakness in it, I don't know how to change it
  10. 10:51 Nube: start with definitely the price action
  11. 10:53 Paris: optntradrsuntd - Here is a real simple snippet to do what you wish. It colors candles YELLOW if between MA8-13, WHITE if between MA13-21, and PINK otherwise). Note this is a standalone study, so you'll need to do some work to fit this back into Slim's study
  12.  
  13. plot MA8 = ExpAverage(close, 8);
  14. plot MA13 = ExpAverage(close, 13);
  15. plot MA21 = ExpAverage(close, 21);
  16.  
  17. AssignPriceColor(if between(close, MA8, MA13) then Color.YELLOW
  18. else if between(close, MA13, MA21) then Color.WHITE
  19. else Color.PINK);
  20. 10:54 optntradrsuntd: Awesome, thank you very much
  21. 10:56 optntradrsuntd: Curious about the pink
  22. 11:00 AlphaInvestor: I am curious about a lot of things but not color names
  23. 11:03 optntradrsuntd: I'm a newbie, I'm curious about all of it lol
  24. 11:04 optntradrsuntd: Like I know what I'mn looking for in the code, but I don't know how to modify it enough or start with what I'm trying to do. Slims study has a simliar concept, it just relies on the EMA's positioning over each other
  25. 11:13 linas: random message from me here....
  26. 11:14 MTS1: Optn; to understand the code make sure to use the reference as you're reviewing or writing code. Also read the thinkscript tutorials as a great place to get started. Both are at http://tlc.thinkorswim.com/. Reviewing existing scripts, built-in or custom, like you're doing now is a great way to learn also, but helps to have read the tutorials and they are not long.
  27. 11:14 linas: you can do a lot more logistically, and set auto trades rather easy
  28. 11:14 Vimes: linas, bad form to discuss other platforms
  29. 11:15 linas: sorry
  30. 11:15 linas: i do LOVE Tda
  31. 11:15 linas: to be fair
  32. 11:15 linas: i just see this "I'm looking to do this, how I do it" questions a lot
  33. 11:15 harndog: To be fair, your posting in TDA forum, run by TDA, and your acknowledge TDA rules.
  34. 11:16 linas: and Mobius and the rest of the crew are awesome to help
  35. 11:16 linas: just saying.. wish it used C# or C++, to go to next level
  36. 11:16 linas: but fair enough, it has amazing library of built in code, and noone can match that
  37. 11:17 linas: have a good day everyone !
  38. 11:17 MTS1: Hope they have a useful lounge also;)
  39. 11:17 harndog: +1
  40. 11:32 optntradrsuntd: Paris - I have the script in, everything is good up until the 8 EMA.
  41.  
  42. So if price is above the 8 EMA = green
  43. if price is below 8 EMA = red
  44.  
  45. But to still hold the corresponding colors when price action is between certain EMA's
  46. 11:53 MTS1: believe that is color.current
  47. 11:56 Blue_Oyster_Cult-: optntradrsuntd: #start
  48.  
  49. #hint: b>Ask SLM Ribbon
  50. thank you for the post ...........
  51. 12:01 Nube: re languages other than ThinkScript, I'm extremely thankful this is in ThinkScript. I'd have never learned nor been involved here at all for that matter if it was a different language
  52. 12:04 optntradrsuntd: No problem Blue, trying to get some fine tuning done to it
  53. 12:08 RKX1: Grid_20180828_2
  54. 12:11 RKX1: http://tos.mx/rcbmch
  55. 12:12 optntradrsuntd: ?
  56. 12:20 optntradrsuntd: So thinkscript is it's own language in a sense? Or is it variations of all the coding languages?
  57. 12:20 optntradrsuntd: Or varations of some*
  58. 12:21 AlphaInvestor: thinkScript is it own language
  59. 12:21 MTS1: variation of JavaScript
  60. 12:22 MTS1: Or Java (not a programmer) TOS is written in Java and TS was a derivative written by it's programmers.
  61. 12:22 MTS1: or using the same structure anyways. .
  62. 12:30 Geeha: I would like to install two filters into my chart. The first is to scan the S&P500 for all stocks after market close that have two bars above a ten period moving average High and those two bars highlighted in light green. The second is to scan the S&P500 for all stocks after market close that have two bars below an eight period moving average Low and those two bars highlighted in light red. If you can take me through the steps to do this I would greatly appreciate it! Thank You
  63. 12:36 AlphaInvestor: you are asking for 2 things - a Scan and a companion Chart
  64. 12:38 Vimes: the scan part is going to return too many hits to be useful imo
  65. 12:38 AlphaInvestor: Vimes - agreed
  66. 12:41 Vimes: Geeha, you can try something like this to get you started - but you will need to add some additional criteria: put this in a custom scan of the S&P500 watchlist
  67. def cond1 = close>simpleMovingAvg(high,8)[1];
  68. plot scan = sum(cond1,2)==2;
  69.  
  70.  
  71. 12:52 AlphaInvestor: Amalia - CAHOLD column
  72.  
  73. # CAHOLD Bull Flag Watchlist Column
  74. # 7.17.2018
  75.  
  76. # [email protected] CAHOLD Search
  77. # To use for scan place # signs before Addlabel statement and change "def" before trigger statement to "plot"
  78.  
  79. #14:10 Mobius: The Mr. Script Replacement or Mr. Script Redux didn't explain that the reason MACD is used in his study to identify flags is that MACD shows divergence, squeeze, price compression fairly well. If price is rising and MACD is not that is the reason.
  80.  
  81. input PriceOfStock = 10;#Default 10
  82. input BullFlagWithinHowManyDays = 1; #Default 1
  83. input SensitivityMALength = 30; #Default 30
  84. input SMAlookback = 5;#Defaqult 5
  85. def StockPrice = close >=PriceOfStock;
  86. def trend = simpleMovingAvg("length"=SensitivityMALength)> simpleMovingAvg("length"=SensitivityMALength)[SMAlookback];
  87. def MacdLow = macdHistogram(8,17,9)[1]< macdHistogram(8,17,9)[2]and close[1]<close[2] and close>high[1];
  88. #def Momentum = macdHistogram(8,17,9) > macdHistogram(8,17,9)[1];
  89.  
  90. #def trigger = trend and momentum and MacdLow;
  91. def trigger = trend and MacdLow;
  92. AddLabel(yes, if trigger within BullFlagWithinHowManyDays bar then "Bull Flag" else " ",Color.PLUM);
  93.  
  94. AssignBackgroundColor(if trigger then color.YELLOW else color.WHITE);
  95.  
  96.  
  97. 12:56 optntradrsuntd: Is that the whole code Mobius? I use MACD a lot, would like to test it out
  98. 12:56 amalia: Thanks, Ai.
  99. 12:57 fifotrader: Mobius Can you help me with how to determine the following:
  100. Let’s say there are condition that causes a stock go up by 60 percent and another condition to make it go up 30 per cent.
  101. What is the per cent if both happen? Should it be more than 60 per cent? Or is it impossible since all possible conditions are not known?
  102. 12:57 amalia: eh
  103. 12:58 Farmin: go look up a compound interest equation
  104. 12:59 AlphaInvestor: yeah, it depends on whether they are subsequent moves, and which came first
  105. 13:01 Vimes: 1.6*1.3?
  106. 13:01 fifotrader: Let.s say they both happen at the same time.
  107. 13:02 Farmin: 1.6 * 1.3 = 1.3 * 1.6 assuming they are subsequent moves
  108. 13:03 Farmin: fifo, make it real start with a dollar. figure out what your question reeally is
  109. 13:04 AlphaInvestor: farmin - dats that new math isn't it
  110. 13:04 Farmin: yup it is
  111. 13:05 Vimes: well its one of the basic properties of multiplication so not relaly new math
  112. 13:05 Farmin: sure wish someone could splain it to me. and then probablilty density functions
  113. 13:06 Farmin: well, new math is kinda old now
  114. 13:06 AlphaInvestor: Vimss -1 ... your makin' me look bad
  115. 13:06 Vimes: lol
  116. 13:06 Vimes: sorry - ;)
  117. 13:12 mthfr_vaxxed: per cent or percent? this a trick question?
  118. 13:14 Vimes: not sure; i also wasn't sure if there was more to the question - if you are saying the outcome is random you would need to provide a probability of the events occurring
  119. 13:15 amalia: lol mth
  120. 13:19 Anonymous so far: What u think about AMD
  121. 13:20 AlphaInvestor: Wrong chat room
  122. 13:25 fifotrader: I have been trying to figure this out for some time.
  123. To determine a probability occurrence you record all occurrences of a condition and divide it by all possible occurrences.
  124. So I guess this can’t be solved?`
  125. 13:26 optntradrsuntd: a bell curve
  126. 13:27 AlphaInvestor: fifo - what you describe can be solved
  127. 13:27 fifotrader: how
  128. 13:27 AlphaInvestor: count all the times it occurred on the chart, divide by the number of bars on the chart - easy peasy
  129. 13:28 optntradrsuntd: That's the best way tbh, don't need a code for that
  130. 13:31 fifotrader: Alpha- you are right- but I do not have that data I just have the percent's
  131. 13:32 optntradrsuntd: If you have the percentages already what are you looking for?
  132. 13:33 fifotrader: What happen when they both occur
  133. 13:33 AlphaInvestor: Fifo - you can calculate that data from the chart
  134. 13:34 Vimes: fifo can you describe exactly what you are struggling to do - seems very vague atm
  135. 13:35 AlphaInvestor: are you looking for the number of times that a 60% move on day 1 ... is followed by a 30% move on day 2?
  136. 13:35 AlphaInvestor: or are you looking for the number of times that there is a total move of 90% over a 2 day period?
  137. 13:35 AlphaInvestor: we have no idea what your question is
  138. 13:35 Vimes: ^
  139. 13:38 fifotrader: I have info that a pattern
  140. 13:38 fifotrader: sorry not do i
  141. 13:41 optntradrsuntd: Take a minute, recollect and explain what you are trying to do
  142. 13:50 fifotrader: I have data that a stock goes up let’s say 60% with a candle pattern.
  143. I also know that the stock go up let’s 40% during the first week September.
  144. What is the probability of the stock going up?
  145. 13:51 optntradrsuntd: There are countless variables to why the stock would be going up
  146. 13:51 Nube: Does that percent with a pattern include that period of September?
  147. 13:51 optntradrsuntd: earnings/good news etc
  148. 13:52 fifotrader: give up
  149. 13:52 optntradrsuntd: Bullflag patterns have hige probabilities of breaking out etc
  150. 13:52 optntradrsuntd: high*
  151. 13:52 AlphaInvestor: Fifo - 50%
  152. 13:52 Vimes: fifo - what you are asking is possible but you have to define the problem for us to help you
  153. 13:53 Vimes: otherwise 50% is the best estimate which would put you around 45% return
  154. 13:53 cattle_trader: how would i code to have a moving average + so many tiks = sell and vise versa?
  155. 13:53 fifotrader: Alpha that is what I keep coming up with but I am not sure?
  156. 13:54 AlphaInvestor: without more information you have a 50% chance of going up, a 50% chance of going down - prices are RANDOM
  157. 13:54 optntradrsuntd: ^
  158. 13:54 Vimes: if both are independent - define the candle pattern and observe the number of roc occurencesn in your defined timeframe. this is probablity 1
  159. 13:54 Farmin: past performance is not indicative of future results
  160. 13:55 optntradrsuntd: performance, not of patterns
  161. 13:55 AlphaInvestor: The chances of a 60% move up, followed by a 30% move up the next day are so infintessimally small that I would ignore that chance
  162. 13:56 Vimes: if you are looking for back data on candlestick patterns check bulkowski site
  163. 13:56 optntradrsuntd: H&S formations are high probability trades too
  164. 13:56 optntradrsuntd: like 55-60% I believe, may be slightly higher
  165. 13:58 AlphaInvestor: Bull market resutls for H&S tops
  166. "Percentage meeting price target: 55%"
  167. 13:59 Vimes: and if anything was so obvious as buying in september would give you a 40% return everyone would be filfthy rich
  168. 13:59 RayK: Today is Mr Script day. Every Tuesday at 5:30 EDT, Ken Rose does the Mr Script Thinkscript tutorial Webcast. This week, Ken will finish a multisession discussion and demonstration of TOS Strategies. TOS Strategies are a simple but effective backtesting system. These tutorials and demonstrations are not to be missed! The Mr Script Webcast is at 5:30 EDT Tuesdays and can be found either in the Thinkscript Lounge (click Watch) - close the room and reopen it no more than 10 minutes before 5:30 EDT. Or, on the Web at https://events.thinkorswim.com/#/webcast - Login no more than 10 minutes in advance of the session.
  169. 14:00 mthfr_vaxxed: thanks RayK
  170. 14:02 cattle_trader: nobody?
  171. 14:02 fifotrader: Vimes not 40% return 40% probability
  172. 14:03 fifotrader: big difference
  173. 14:03 Vimes: 0.5*0.6+0.5*0.3=0.45
  174. 14:03 Vimes: you have to define the probability - withou more information they are 50%
  175. 14:03 optntradrsuntd: There is a higher probability that if a stock makes an extreme move that the following day it will revert back to the mean
  176. 14:04 fifotrader: you would have 60% chance of losing
  177. 14:04 AlphaInvestor: This converstaion is going in circles - it needs to stop, I am getting dizzy
  178. 14:04 optntradrsuntd: See why not really following why you want to figure this out, it's very small chance that you'd be right
  179. 14:06 Vimes: agree with alpha you orig said a 60% return and 30% return for two separate occurences without mention of probability - unless you are going to define the probelm further as a thinkscript questino suggest we drop it
  180. 14:06 mthfr_vaxxed: "Fooled by Randomness" is a good read
  181. 14:07 mthfr_vaxxed: kinda.... could have rambled less. but still good info.
  182. 14:09 AlphaInvestor: I haven't read that one, but this one is an excellent book
  183. "A Random Walk Down Wall Street"
  184. 14:09 Vimes: i don't agree with pure random price - if that was the case and there wasn't a p[ositive expectancy we wouldn't have a market
  185. 14:09 FrankB3: I have that book
  186. 14:10 mthfr_vaxxed: false positives probablity question : if test for disease is 90% accurate and disease effects 1 in 10,000 people... if you test positive what is the chance you have disease? hint: its not 90%
  187. 14:10 mthfr_vaxxed: i have that one Alpha. next on my reading list. need to get that started after i finishing sending resumes everywhere and doing stupid coding challenges.... ugh
  188. 14:12 Nube: .9/10,000 seems like a small number
  189. 14:12 mthfr_vaxxed: and no one agrees with a completely random price... the point is if you can account for that you can acocunt for anythihng
  190. 14:12 mthfr_vaxxed: ie. Monte Carlo simulation
  191. 14:13 mthfr_vaxxed: just like no one should agree with a completely rational market either... (**cough** Long Term Capital Management **cough** )
  192. 14:14 mthfr_vaxxed: "When Genius Failed" for that blunder
  193. 14:15 mthfr_vaxxed: because..... people are not rational or random. a drunk sailor is headed somewhere.. we can all guess
  194. 14:16 mthfr_vaxxed: class dismissed.
  195. 14:16 optntradrsuntd: *bell rings* lol
  196. 14:17 optntradrsuntd: There was a code shared from here a while back that shows trends based off a ATR, with targets on each side. That has been the best study I've used. Whoever made it, if you are here, thank you
  197. 14:19 optntradrsuntd: #ATRTrailingStop_ATR_Method_Only_MTF Script (referred to as ATR hereafter)
  198. #Volume Profile option will display a new volume profile at each change of state in the ATRTrailingStop indicator
  199. input showvolumeprofile = yes;
  200. input stopmethod = {default atr, custom};
  201. input usehigheraggperiod = {default "Current", "Higher"};
  202. input agg = AggregationPeriod.TWO_MIN;
  203. input atraveragetype = averageType.WILDERS;
  204. input outputformat = {default Rounded, "Not Rounded"};#Hint outputformat: 'Not Rounded' is used for notes, bonds (eg: 109'110), forex, etc type format.
  205. input usealerts = no;
  206. input target1 = 1.5;#Hint target1: number times entry - stop
  207. input target2 = 3.0;#Hint target2: number times entry - stop
  208. input trailType = {default modified, unmodified};
  209. input ATRPeriod = 5;
  210. input ATRFactor = 1.618;
  211. input firstTrade = {default long, short};
  212. def c;
  213. def l;
  214. def h;
  215. def o;
  216.  
  217. def error = usehigheraggperiod == usehigheraggperiod."Higher" and GetAggregationPeriod() > agg;
  218. switch (usehigheraggperiod) {
  219. case Current:
  220. c = close;
  221. l = low;
  222. h = high;
  223. o = open;
  224.  
  225. case Higher:
  226. if error {
  227. o = Double.NaN;
  228. h = Double.NaN;
  229. l = Double.NaN;
  230. c = Double.NaN;
  231.  
  232. } else {
  233. c = close(period = agg);
  234. l = low(period = agg);
  235. h = high(period = agg);
  236. o = open(period = agg);
  237.  
  238. }
  239. }
  240.  
  241. def HiLo = Min(h - l, 1.5 * Average(h - l, ATRPeriod));
  242. def HRef = if l <= h[1]
  243. then h - c[1]
  244. else (h - c[1]) - 0.5 * (l - h[1]);
  245. def LRef = if h >= l[1]
  246. then c[1] - l
  247. else (c[1] - l) - 0.5 * (l[1] - h);
  248. def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);
  249.  
  250. def trueRange;
  251. switch (trailType) {
  252. case modified:
  253. trueRange = Max(HiLo, Max(HRef, LRef));
  254. case unmodified:
  255. trueRange = TrueRange(h, c, l);
  256. }
  257. def loss = ATRFactor * MovingAverage(atraverageType, trueRange, ATRPeriod);
  258.  
  259. def state = {default init, long, short};
  260. def trail;
  261. switch (state[1]) {
  262. case init:
  263. if (!IsNaN(loss)) {
  264. switch (firstTrade) {
  265. case long:
  266. state = state.long;
  267. trail = c - loss;
  268. case short:
  269. state = state.short;
  270. trail = c + loss;
  271. }
  272. } else {
  273. state = state.init;
  274. trail = Double.NaN;
  275. }
  276. case long:
  277. if (c > trail[1]) {
  278. state = state.long;
  279. trail = Max(trail[1], c - loss);
  280. } else {
  281. state = state.short;
  282. trail = c + loss;
  283. }
  284. case short:
  285. if (c < trail[1]) {
  286. state = state.short;
  287. trail = Min(trail[1], c + loss);
  288. } else {
  289. state = state.long;
  290. trail = c - loss;
  291. }
  292. }
  293.  
  294.  
  295. plot TrailingStop = trail;
  296. TrailingStop.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
  297. TrailingStop.DefineColor("Buy", GetColor(0));
  298. TrailingStop.DefineColor("Sell", GetColor(1));
  299. TrailingStop.AssignValueColor(if state == state.long
  300. then TrailingStop.Color("Sell")
  301. else TrailingStop.Color("Buy"));
  302. TrailingStop.HideBubble();
  303.  
  304. #Horizontals are used to determine color of price bars
  305. input showhorizontals = no;
  306. def HAclose = (o + h + l + c) /4;
  307. def HAopen = CompoundValue( 1, ( HAopen[1] + HAclose[1] ) / 2, HAclose );
  308. def HAhigh = Max( h, Max( HAopen, HAclose ) );
  309. def HAlow = Min( l, Min( HAopen, HAclose ) );
  310. def hamid = (haHigh + haLow) / 2;
  311. def horizontall = if state != state[1] and state == state.long
  312. then hamid
  313. else horizontall[1];
  314. plot horizontallow = horizontall;
  315. horizontallow.SetPaintingStrategy(PaintingStrategy.DASHES);
  316. horizontallow.SetDefaultColor(Color.GREEN);
  317. horizontallow.SetHiding(!showhorizontals);
  318. def horizontalh = if state != state[1] and state == state.short
  319. then hamid
  320. else horizontalh[1];
  321. plot horizontalhigh = horizontalh;
  322. horizontalhigh.SetPaintingStrategy(PaintingStrategy.DASHES);
  323. horizontalhigh.SetDefaultColor(Color.RED);
  324. horizontalhigh.SetHiding(!showhorizontals);
  325.  
  326. #Price Bar Coloring - Green=Up; Red=Down; White=Warning, no direction determined by horizontals. Look for green/red bars above/below entry for better signal. White bars pulling back to trailing stop followed by a colored bar(s) in direction of ATR may be a good entry
  327. input pricecolor = yes;
  328. AssignPriceColor(if pricecolor
  329. then if state == state.long and c > horizontall and l > trail
  330. then Color.GREEN
  331. else if state == state.short and c < horizontalh and h < trail
  332. then Color.RED
  333. else Color.WHITE
  334. else Color.CURRENT);
  335.  
  336. #Counter - Displays a bubble at last bar printed of the number of bars at a particular color
  337. def greencount = if state == state.long and c > horizontall
  338. then (greencount[1] + 1)
  339. else 0;
  340. def redcount = if state == state.short and c < horizontalh
  341. then (redcount[1] + 1)
  342. else 0;
  343. def whitecount = if greencount == 0 and redcount == 0
  344. then (whitecount[1] + 1)
  345. else 0;
  346. input showcolor_counting_bubble = yes;
  347. AddChartBubble(showcolor_counting_bubble and IsNaN(close[-1]) and !IsNaN(close) and greencount > 0,
  348. low, greencount, Color.GREEN , no);
  349. AddChartBubble(showcolor_counting_bubble and IsNaN(close[-1]) and !IsNaN(close) and redcount > 0,
  350. low, redcount , Color.RED , no);
  351. AddChartBubble(showcolor_counting_bubble and IsNaN(close[-1]) and !IsNaN(close) and greencount == 0 and redcount == 0,
  352. low, whitecount, Color.WHITE, no);
  353.  
  354. def BuySignal = if Crosses(state == state.long, 0, CrossingDirection.ABOVE)
  355. then 1
  356. else Double.NaN;
  357. def SellSignal = if Crosses(state == state.short, 0, CrossingDirection.ABOVE)
  358. then 1
  359. else Double.NaN;
  360.  
  361. def condup = !IsNaN(BuySignal);
  362. def conddn = !IsNaN(SellSignal);
  363.  
  364. def condu = if !IsNaN(c) and condup == 1
  365. then BarNumber()
  366. else condu[1];
  367. def condd = if !IsNaN(c) and conddn == 1
  368. then BarNumber()
  369. else condd[1];
  370. #Entry plot is based upon the high/low of the signal bar or the prior bar (use input entrybars as "0" for just the signal bar or "1" for high/low of the signal or next bar)after the buysignal or sellsignal was met. The entry bubble will change from white to green/red when the high/low breaks the entry value. You will need to change the code if you want to use another basis.
  371. plot entry = if BarNumber() >= Max(HighestAll(condu), HighestAll(condd))
  372. then if condu > condd
  373. then HighestAll(if BarNumber() == HighestAll(condu)
  374. then Max(h, h[1])
  375. else Double.NaN)
  376. else HighestAll(if BarNumber() == HighestAll(condd)
  377. then Min(l, l[1])
  378. else Double.NaN)
  379. else Double.NaN;
  380. #Initial Stop
  381. #Choose the initial stop method, either the change of the ATR or a custom method of your choosing. The custom initial stop is based upon a lookback from when the buysignal or sellsignal is met. Since these buysignals or sellsignals can change based on the 2nd condition while the atrtrailingStop method does not, then custom initial stop may provide better targets. The lookback length can be changed at the input screen.
  382. input stoplookback = 3;
  383. def atrinitialstop = if state != state[1]
  384. then trail
  385. else atrinitialstop[1];
  386. def atrintstopext = if IsNaN(c) then atrintstopext[1] else atrinitialstop;
  387.  
  388. plot stop = if IsNaN(entry)
  389. then Double.NaN
  390. else if stopmethod == stopmethod.atr
  391. then if BarNumber() >= Max(HighestAll(condu), HighestAll(condd))
  392. then atrintstopext
  393. else Double.NaN
  394. else if BarNumber() >= Max(HighestAll(condu), HighestAll(condd))
  395. then if condu > condd
  396. then HighestAll(if BarNumber() == HighestAll(condu)
  397. then Lowest(l, stoplookback)
  398. else Double.NaN)
  399. else HighestAll(if BarNumber() == HighestAll(condd)
  400. then Highest(h, stoplookback)
  401. else Double.NaN)
  402. else Double.NaN;
  403.  
  404. #Trailing Stop uses the current position of the ATR's "trail" variable
  405. plot atrstop = if IsNaN(entry)
  406. then Double.NaN
  407. else if BarNumber() < Max(HighestAll(condu), HighestAll(condd))
  408. then Double.NaN
  409. else HighestAll(if IsNaN(c[-1]) and !IsNaN(c)
  410. then trail
  411. else Double.NaN);
  412.  
  413. #Alerts - The alerts can be turned on/off at the input screen.
  414. Alert(usealerts and c crosses entry, "Entry " + c, Alert.BAR, Sound.Chimes);
  415.  
  416.  
  417. #Targets - These are based upon the difference between the entry price and the initial stop of your choice, multiplied by then variables that you input below. The targets will be displayed in lines and bubbles, which will change from a light color to green when the target is met.
  418. plot t1 = if IsNaN(entry) then Double.NaN
  419. else if condu > condd
  420. then (entry + (entry - stop) * target1)
  421. else (entry - (stop - entry) * target1);
  422. plot t2 = if IsNaN(entry) then Double.NaN
  423. else if condu > condd
  424. then (entry + (entry - stop) * target2)
  425. else (entry - (stop - entry) * target2);
  426.  
  427. #Plot Look and Feel
  428.  
  429. entry.SetDefaultColor(Color.WHITE);
  430. stop.SetDefaultColor(Color.RED);
  431. t1.SetDefaultColor(Color.WHITE);
  432. t2.SetDefaultColor(Color.WHITE);
  433. entry.HideBubble();
  434. stop.HideBubble();
  435. t1.HideBubble();
  436. t2.HideBubble();
  437. atrstop.HideBubble();
  438. atrstop.SetLineWeight(1);
  439. atrstop.AssignValueColor(if HighestAll(if IsNaN(c[-1]) and !IsNaN(c) and c > atrstop
  440. then 1
  441. else 0) == 1
  442. then Color.GREEN
  443. else Color.RED);
  444.  
  445. #ATR Trailing Stop Long/Short (shown as Green/Red) Bubble in expansion denotes current status of ATRTrailingStop indicator
  446. input showbubble_indicator = no;
  447. input bubblemover_indicator = 20;#Hint bubblemover_indicator: = number of spaces to move atrtrailingstop indicator bubble sideways
  448. def z = bubblemover_indicator;
  449. def z1 = z + 1;
  450. input bubblealign = .00;
  451. AddChartBubble(showbubble_indicator and IsNaN(c[z]) and !IsNaN(c[z1]),
  452. c[z1] - bubblealign,
  453. "A",
  454. if state[z1] == state.long
  455. then Color.GREEN
  456. else Color.RED);
  457.  
  458. #Trailing Stop Bubble
  459. input bubblemover_trailingstop = 2;#Hint bubblemover_trailingstop: = number of spaces to move trail stop bubble sideways
  460. def s = bubblemover_trailingstop;
  461. def s1 = s + 1;
  462. AddChartBubble(IsNaN(c[s]) and !IsNaN(c[s1]),
  463. atrstop[s1],
  464. "Trail \n" + (if outputformat == outputformat."Not Rounded"
  465. then AsPrice(trail[s1])
  466. else AsText(Round(trail[s1], 2))),
  467. if HighestAll(if IsNaN(c[s]) and !IsNaN(c[s1]) and c[s1] > atrstop[s1]
  468. then 1
  469. else 0) == 1
  470. then Color.GREEN
  471. else Color.RED,
  472. if condu[s1] > condd[s1]
  473. then no
  474. else yes);
  475.  
  476. #Entry Bubble - Will turn green or red if entry is exceeded
  477. input bubblemover_entry_stop_targets = 8;#Hint bubblemover_entry_stop_targets: = number of spaces to move entry, initial stop and target bubbles sideways
  478. def n = bubblemover_entry_stop_targets;
  479. def n1 = n + 1;
  480. def eup = if condu > condd and h > entry
  481. then 1
  482. else if eup[1] == 1 and condu > condd
  483. then 1
  484. else 0;
  485. def edn = if condu < condd and l < entry
  486. then 1
  487. else if edn[1] == 1 and condu < condd
  488. then 1
  489. else 0;
  490. AddChartBubble(IsNaN(c[n]) and !IsNaN(c[n1]),
  491. entry[n1],
  492. "Entry: " + (if outputformat == outputformat."Not Rounded"
  493. then AsPrice(entry[n1])
  494. else AsText(Round(entry[n1], 2))),
  495. if !IsNaN(eup[n1]) == 1
  496. then Color.GREEN
  497. else if !IsNaN(edn[n1]) == 1
  498. then Color.RED
  499. else Color.WHITE);
  500.  
  501. #Stop Bubble
  502. AddChartBubble(IsNaN(c[n]) and !IsNaN(c[n1]),
  503. stop[n1],
  504. "Stop: " + (if outputformat == outputformat."Not Rounded"
  505. then AsPrice(stop[n1])
  506. else AsText(Round(stop[n1], 2))),
  507. Color.RED);
  508.  
  509. #Targets
  510. #Defining when targets are met
  511. def t1ru = if condu > condd and
  512. h > t1
  513. then 1
  514. else if t1ru[1] == 1 and condu > condd
  515. then 1
  516. else 0;
  517. def t2ru = if condu > condd and
  518. h > t2
  519. then 1
  520. else if t2ru[1] == 1 and condu > condd
  521. then 1
  522. else 0;
  523. def t1rd = if condu < condd and
  524. l < t1
  525. then 1
  526. else if t1rd[1] == 1 and condu < condd
  527. then 1
  528. else 0;
  529. def t2rd = if condu < condd and
  530. l < t2
  531. then 1
  532. else if t2rd[1] == 1 and condu < condd
  533. then 1
  534. else 0;
  535.  
  536. #Target Bubbles - Green if Target Hit, Light_Gray otherwise
  537. AddChartBubble(IsNaN(c[n]) and !IsNaN(c[n1]),
  538. t1[n1],
  539. "T1 " +
  540. ": " + (if outputformat == outputformat."Not Rounded"
  541. then AsPrice(t1[n1])
  542. else AsText(Round(t1[n1], 2))) +
  543. " " + (if outputformat == outputformat."Not Rounded"
  544. then AsPrice(AbsValue(t1[n1] - entry[n1]))
  545. else AsText(AbsValue(Round(t1[n1], 2) - Round(entry[n1], 2)))),
  546. if !IsNaN(t1ru[n1]) == 1 or !IsNaN(t1rd[n1]) == 1
  547. then Color.GREEN
  548. else Color.LIGHT_GRAY);
  549. AddChartBubble(IsNaN(c[n]) and !IsNaN(c[n1]),
  550. t2[n1],
  551. "T2 " +
  552. ": " + (if outputformat == outputformat."Not Rounded"
  553. then AsPrice(t1[n1])
  554. else AsText(Round(t2[n1], 2))) +
  555. " " + (if outputformat == outputformat."Not Rounded"
  556. then AsPrice(AbsValue(t2[n1] - entry[n1]))
  557. else AsText(AbsValue(Round(t2[n1], 2) - Round(entry[n1], 2)))),
  558. if !IsNaN(t2ru[n1]) == 1 or !IsNaN(t2rd[n1]) == 1
  559. then Color.GREEN
  560. else Color.LIGHT_GRAY);
  561.  
  562.  
  563. #
  564. # TD Ameritrade IP Company, Inc. (c) 2010-2016
  565. #
  566.  
  567. input pricePerRowHeightMode = {AUTOMATIC, default TICKSIZE, CUSTOM};
  568. input customRowHeight = 1.0;
  569. input onExpansion = no;
  570. input profiles = 1000;
  571. input showPointOfControl = yes;
  572. input showValueArea = yes;
  573. input valueAreaPercent = 70;
  574. input opacity = 50;
  575.  
  576. def cond = state[1]!= state;
  577. def height;
  578. switch (pricePerRowHeightMode) {
  579. case AUTOMATIC:
  580. height = PricePerRow.AUTOMATIC;
  581. case TICKSIZE:
  582. height = PricePerRow.TICKSIZE;
  583. case CUSTOM:
  584. height = customRowHeight;
  585. }
  586.  
  587. profile vol = volumeProfile("startNewProfile" = if showvolumeprofile then cond else double.nan, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = if showvolumeprofile then valueAreaPercent else double.nan);
  588. def con = compoundValue(1, onExpansion, no);
  589. def pc = if IsNaN(vol.getPointOfControl()) and con then pc[1] else vol.getPointOfControl();
  590. def hVA = if IsNaN(vol.getHighestValueArea()) and con then hVA[1] else vol.getHighestValueArea();
  591. def lVA = if IsNaN(vol.getLowestValueArea()) and con then lVA[1] else vol.getLowestValueArea();
  592.  
  593. def hProfile = if IsNaN(vol.getHighest()) and con then hProfile[1] else vol.getHighest();
  594. def lProfile = if IsNaN(vol.getLowest()) and con then lProfile[1] else vol.getLowest();
  595. def plotsDomain = IsNaN(close) == onExpansion;
  596.  
  597. plot POC = if plotsDomain then pc else Double.NaN;
  598. plot ProfileHigh = if plotsDomain then hProfile else Double.NaN;
  599. plot ProfileLow = if plotsDomain then lProfile else Double.NaN;
  600. plot VAHigh = if plotsDomain then hVA else Double.NaN;
  601. plot VALow = if plotsDomain then lVA else Double.NaN;
  602.  
  603. DefineGlobalColor("Profile", GetColor(1));
  604. DefineGlobalColor("Point Of Control", GetColor(5));
  605. DefineGlobalColor("Value Area", GetColor(8));
  606.  
  607. vol.Show(Color.CURRENT, if showPointOfControl then GlobalColor("Point Of Control") else Color.CURRENT, if showValueArea then GlobalColor("Value Area") else Color.CURRENT, opacity);
  608. POC.SetDefaultColor(globalColor("Point Of Control"));
  609. POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
  610. VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
  611. VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
  612. VAHigh.SetDefaultColor(globalColor("Value Area"));
  613. VALow.SetDefaultColor(globalColor("Value Area"));
  614. ProfileHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
  615. ProfileLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
  616. ProfileHigh.SetDefaultColor(GetColor(3));
  617. ProfileLow.SetDefaultColor(GetColor(3));
  618. ProfileHigh.hide();
  619. ProfileLow.hide();
  620.  
  621. input showbubbleperperiod = no;
  622. input bubblemoverperperiodhorizontal = 3;
  623. input bubblemoverperperiodvertical = 2;
  624. def bubble = if state[1] != state
  625. then BarNumber() + bubblemoverperperiodhorizontal
  626. else bubble[1];
  627. AddChartBubble(showbubbleperperiod and BarNumber() == (bubble),
  628. profilehigh + bubblemoverperperiodvertical * TickSize(),
  629. (VAHigh - VALow),
  630. Color.GRAY, yes);
  631.  
  632. 14:21 AJayKC: hi i need help please. I was trying to create a simple colored label with spyticker symbol to put on my chart. for thich it will have green color it the last price is above closing price and red label if last price is below previous closing price.
  633. 14:21 AJayKC: input SYMB = " SPY ";
  634. def AD = close(symbol = SYMB);
  635. AddLabel(1, " SPY " + SYMB + " = " + AD, if close < Average(close,1) then color.green else color.red);
  636. 14:21 AJayKC: what am i missing?
  637. 14:23 AJayKC: any help or suggestion is much appreciated. thanks.
  638. 14:26 Vimes: se if this works:
  639. input SYMB = "SPY";
  640. def AD = close(symbol = SYMB);
  641. AddLabel(1,SYMB + " = " + AD, if AD > AD[1] then color.green else color.red);
  642. 14:27 AJayKC: ok let me try thank you.
  643. 14:33 FrankB3: 15:19 optntradrsuntd: #ATR: you can ask Kuba where he got if from:: seems similar :: http://tos.mx/FyhHJF
  644. 14:35 AJayKC: looks like its working. thanks vimes. i just wanted to makes sure if its giving green label if current price > previous day's close price? or previous candle?
  645. 14:36 optntradrsuntd: That is exactly it Frank haha
  646. 14:36 Vimes: np, if that's a question that is what the AD>AD[1] is doing
  647. 14:36 Nube: bubblemover makes me think that's a BLT script.
  648. 14:36 optntradrsuntd: Modified it slightly to 1.41, better results for scalping
  649. 14:37 AlphaInvestor: That ATR study is from BLT, I don't know why he didn't put his name in it
  650. 14:37 AJayKC: current price > previous day's close?
  651. 14:38 Nube: Is there any script Frank doesn't have?
  652. 14:38 amalia:
  653. #amalia - OpenClose stats
  654.  
  655. def A = AggregationPeriod.DAY;
  656. def T = TickSize();
  657. def N = Double.NaN;
  658. def B = BarNumber();
  659.  
  660. input showLabels = YES;
  661. input sLength = 10;
  662. def C = close(period = A)[1];
  663. def O = open(period = A)[1];
  664. def L = low(period = A)[1];
  665. def H = high(period = A)[1];
  666.  
  667.  
  668. # Labels only good for Daily aggregation
  669. def countUp = if C[1] > O[1] and C > O
  670. then countUp[1] + 1
  671. else countUp[1];
  672. def Pup = (B - countUp) / B;
  673. AddLabel(showLabels, " %PrevC > PrevO and C > O = " + AsPercent(Pup) + " | Happenstance = " + AsPercent(countUp / B) + " or " + countUp + " out of " + B ,
  674. Color.BLUE);
  675.  
  676. def countDn = if C[1] < O[1] and C < O
  677. then countDn[1] + 1
  678. else countDn[1];
  679. def Pdn = (B - countDn) / B;
  680. AddLabel(showLabels, " %PrevC < PrevO and C < O = " + AsPercent(Pdn) + " | Happenstance = " + AsPercent(countDn / B) + " or " + countDn + " out of " + B ,
  681. Color.DARK_GREEN);
  682.  
  683. def countR = if C[1] > O[1] and C < O
  684. then countR[1] + 1
  685. else countR[1];
  686. def Pr = (B - countR) / B;
  687. AddLabel(showLabels, " %PrevC > PrevO and C < O = " + AsPercent(Pr) + " | Happenstance = " + AsPercent(countR / B) + " or " + countR + " out of " + B ,
  688. Color.DARK_ORANGE);
  689.  
  690. def countL = if C[1] < O[1] and C > O
  691. then countL[1] + 1
  692. else countL[1];
  693. def Pl = (B - countL) / B;
  694. AddLabel(showLabels, " %PrevC < PrevO and C > O = " + AsPercent(Pl) + " | Happenstance = " + AsPercent(countL / B) + " or " + countL + " out of " + B ,
  695. Color.GRAY);
  696. 14:38 AJayKC: thank you so much Vimes. i am really thankful that u took time to fix this .
  697. 14:38 Vimes: Ajay, if you are on a daily chart yes
  698. 14:38 AJayKC: i was on 5min chart
  699. 14:38 Vimes: if you are on a intraday chart you would have to add something else for the daily agg
  700. 14:39 Nube: amalia, thank you. I will be stealing that.
  701. 14:40 AJayKC: ok what would i have to add?
  702. 14:41 Vimes: input SYMB = "SPY";
  703. def AD = close(SYMB,aggregationPeriod.DAY);
  704. def c = close(SYMB);
  705. AddLabel(1,SYMB + " = " + c, if c > AD[1] then color.green else color.red);
  706. 14:41 Vimes: should work for intraday
  707. 14:42 AJayKC: thank you so much. u are awesome Vimes. God bless.
  708. 14:43 Vimes: np
  709. 15:46 twoshoes: Wow! 24 pages of buffer! Thank you, tculs
  710. 15:55 amalia: =)
  711. 16:11 optntradrsuntd: Amalia what is that study you shared? Not at the computer at the moment
  712. 16:11 optntradrsuntd: How is it best used
  713. 16:22 RayK: It is almost time for Mr. Script. The Mr Script Webcast is at 5:30 EDT Tuesdays and can be found either in the Thinkscript Lounge (click Watch) - close the room and reopen it no more than 10 minutes before 5:30 EDT. Or, on the Web at https://events.thinkorswim.com/#/webcast - Login no more than 10 minutes in advance of the session.
  714. 16:26 deucescooter: Does anybody have a script to ONLY show the extended hours trading Monkey Bars? Can it be done?
  715. 16:27 MTS1: Not via script; would be in settings if possible.
  716. 16:29 deucescooter: Can't figure out by settings. Of course you can get composite for extended and normal.
  717. 16:31 sugar: does anyone know how to write a scan on price average crossover, i want to be able to pick up all the stocks with green arrow up?
  718. 16:34 Farmin: something wrong with the built-in one?
  719. 16:34 sugar: never mind I figure it ouy
  720. 16:34 sugar: out
  721. 16:41 amalia: opt, just a code to show what happens with daily closes along with percentage and percentage of it happening
  722. 16:50 pom909090: Hi guys, I have a very interesting question would like to seek your help...
  723. 16:50 pom909090: I have used the default custom study script provided by TOS in Stock Hacker, namely "AfterHours_Percent_Change". I copied the script and paste it as custom Study under a chart.
  724.  
  725. I found out that, the result of the Chart is DIFFERENT to the result from either the Scan or as a Watchlist column.
  726.  
  727. For example - ticker FB:
  728.  
  729. [Watchlist column]
  730. The calculated "closing price" from the script is 176.27, which is correct as the Prior day closing price for FB.
  731.  
  732. [Chart]
  733. I copied the entire script into custom Chart, and created a Label output for "closing price". The result of "closing price" in the label is 172.9, which is the closing price around 4 trading days ago.
  734.  
  735. Please assist...
  736. 16:56 AlphaInvestor: Thanks Ken!! - glad you are doing a deep dive on FOLD
  737. 16:59 Nube: Sure! It's a Fold session that would be the one I'd miss
  738. 17:00 pom909090: Sorry, please ignore my request. I found out that i iniitally used 5min chart, which will create this issue. If I changed to 1min chart, its fixed. Cheers guys!
  739. 17:06 amalia: Ok.
  740. 17:07 optntradrsuntd: Thanks amalia
  741. 17:33 ACE66: does anyone have any cup and handle codes?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement