Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.57 KB | None | 0 0
  1. 15:26 AutoElliott: anybody now how i can get my indicator on tos
  2. 15:26 AutoElliott: know
  3. 15:29 harndog2: yes, and we're independent traders who don't read minds.
  4. 15:30 harndog2: So, you to privide context
  5. 15:30 harndog2: need to
  6. 15:30 harndog2: provide
  7. 15:30 harndog2: Kinda like school...
  8. 15:31 AutoElliott: anyone from TOS here
  9. 15:31 JPera: HI AI
  10. 15:31 harndog2: Yes, admins on right
  11. 15:32 harndog2: The rest of us are independent and TOS does not do auto trading, if that's your question
  12. 15:34 AutoElliott: i would like to get my EW inicator on the TOS platform for all to use but i do not want to expose the code
  13. 15:34 harndog2: Contact John Hart via Twitter
  14. 15:34 harndog2: Make a proposal
  15. 15:35 AutoElliott: cool thanks
  16. 15:35 harndog2: Or, contract support at Thinkorswim.com
  17. 15:36 harndog2: My experience is TOS does not do "locked codes, unless a grandfathered relationship
  18. 15:36 harndog2: However, you might be special, so go for it.
  19. 15:38 AutoElliott: no john hart twitter
  20. 15:38 harndog2: jhart@tda
  21. 15:39 harndog2: later traders
  22. 15:40 JPera: BYE
  23. 15:52 brian_s: K-9, Your request wasn't clear, 3 lengths, 3 agg's , 3 symbols , ???
  24. then what, all displayed as one, or seperate lines, or ??
  25. What's adxSPYrange ?
  26. If you were more clear then maybe someone will have the time.
  27. 15:55 brian_s: BbL
  28. 16:04 K-9: brian_s: 3 seperate level lines,I call it each range, ,for each SPY,IWM,QQQ. to display when def Exp = ADX>=20 and ADX25 ;as red
  29. and def NExp = ADX20; as green, Hope it makes it clear...
  30. 16:38 les1: How to plot uparrow when ever stock falls in squeeze (TTM_Squeeze indicator) i.e on red dot red arrow and on green dot green arrow in top chart not in bottom one
  31. 16:42 Melissaq: Hi traders,
  32. 16:42 Melissaq: Good Evening
  33. 16:43 Melissaq: does anyone has autoplot of the fibinacci extention scripts.
  34. 16:43 Mobius: les1 - this study plots a squeeze on the upper chart as a channel so that you can plainly see when price is breaking out of a squeeze. Much better than that TTM_CACA
  35.  
  36. # Volatility Compression Pivots (Squeeze Pivots)
  37. # Mobius
  38. # V01.01.2015
  39. #hint: Squeeze Pivots \n A different way to look at the traditional Squeeze. Plots the mean, high and low of the squeeze zone, making it easier to see which way price expansion is likely to go.
  40.  
  41. # User Inputs
  42. input n = 20; #hint n: Length for calculations.
  43. input MeanValue = HL2; #hint MeanValue: Point of origen.
  44. input SdMulti = 2.0; #hint SdMulti: Multiplier for St Dev.
  45. input AtrMulti = 1.5; #hint AtrMulti: Multipliter for ATR.
  46. input DisplayPoints = yes;#hint DisplayPoints: No Points.
  47. input OnExpansion = yes; #hint OnExpansion: Line extensions.
  48.  
  49. # Variables
  50. def o = open;
  51. def h = high;
  52. def l = low;
  53. def c = close;
  54. def bar = BarNumber();
  55. def Avg = Average(c, n);
  56. def SD = StDev(c, n);
  57. def ATR = Average(TrueRange(h, c, l), n);
  58. def upperSD = Avg + (SdMulti * SD);
  59. def lowerSD = Avg + (-SdMulti * SD);
  60. def upperATR = Avg + (AtrMulti * ATR);
  61. def Squeeze1 = if upperSD crosses below UpperATR
  62. then MeanValue
  63. else Squeeze1[1];
  64. def Squeeze = upperSD < upperATR;
  65. def SqueezeBars = if upperSD < upperATR
  66. then bar
  67. else Double.NaN;
  68. def StartBar = if upperSD crosses below upperATR
  69. then bar
  70. else StartBar[1];
  71. def LastSqBar = if upperSD crosses above upperATR
  72. then bar
  73. else LastSqBar[1];
  74. def PP = if upperSD crosses below upperATR
  75. then MeanValue
  76. else PP[1];
  77. def Mean_Limit = if bar != StartBar
  78. then bar - StartBar
  79. else if bar == StartBar
  80. then Double.NaN
  81. else Mean_Limit[1];
  82. def SqHigh = if upperSD crosses below upperATR
  83. then h
  84. else if bar > StartBar and Squeeze and
  85. h > SqHigh[1]
  86. then h
  87. else SqHigh[1];
  88. def SqHighBar = if Squeeze and
  89. h == SqHigh
  90. then bar
  91. else SqHighBar[1];
  92. def SqHigh_Limit = if bar == StartBar
  93. then Double.NaN
  94. else if bar > StartBar
  95. then bar - SqHighBar
  96. else SqHigh_Limit[1];
  97. def SqLow = if upperSD crosses below upperATR
  98. then l
  99. else if Squeeze and
  100. l < SqLow[1]
  101. then l
  102. else SqLow[1];
  103. def SqLowBar = if Squeeze and
  104. l == SqLow
  105. then bar
  106. else SqLowBar[1];
  107. def SqLow_Limit = if bar == StartBar
  108. then Double.NaN
  109. else if bar > StartBar
  110. then bar - SqLowBar
  111. else SqLow_Limit[1];
  112. def PercentSD = Round((c - lowerSD) / (upperSD - lowerSD), 2);
  113. def PSDhigh = highest(percentSD, n);
  114. def PSDlow = lowest(percentSD, n);
  115.  
  116. # Internal Script Reference
  117. script LinePlot {
  118. input LineLimit = 0;
  119. input OnExpansion = yes;
  120. input data = close;
  121. input bar = 0;
  122. def ThisBar = HighestAll(bar);
  123. def cLine = if bar == ThisBar
  124. then data
  125. else Double.NaN;
  126. def cond1 = CompoundValue(1, if IsNaN(data)
  127. then cond1[1]
  128. else data, data);
  129. plot P = if ThisBar - LineLimit <= bar
  130. then HighestAll(cLine)
  131. else Double.NaN;
  132. plot ExpLine = if OnExpansion and
  133. IsNaN(data[-1])
  134. then cond1
  135. else Double.NaN;
  136. }
  137. # Plots
  138. plot SD_Pivot = LinePlot(data = PP, LineLimit = Mean_Limit, OnExpansion = OnExpansion, bar = StartBar).P;
  139. plot SD_Pivot_X = LinePlot(data = PP, LineLimit = StartBar).ExpLine;
  140. SD_Pivot.SetDefaultColor(Color.CYAN);
  141. SD_Pivot_X.SetDefaultColor(Color.CYAN);
  142. plot SD_R1 = LinePlot(data = SqHigh, LineLimit = SqHigh_Limit, OnExpansion = OnExpansion, bar = SqHighBar).P;
  143. plot SD_R1_X = LinePlot(data = SqHigh, LineLimit = SqHigh_Limit).ExpLine;
  144. SD_R1.SetDefaultColor(Color.Light_GREEN);
  145. SD_R1_X.SetDefaultColor(Color.Light_GREEN);
  146. plot SD_S1 = LinePlot(data = SqLow, LineLimit = SqLow_Limit, OnExpansion = OnExpansion, bar = SqLowBar).P;
  147. plot SD_S1_X = LinePlot(data = SqLow, LineLimit = SqLow_Limit).ExpLine;
  148. SD_S1.SetDefaultColor(Color.Light_RED);
  149. SD_S1_X.SetDefaultColor(Color.Light_RED);
  150. plot SqueezePlot = if Squeeze
  151. then Squeeze1 #l - (2 * TickSize())
  152. else Double.NaN;
  153. SqueezePlot.SetHiding(!DisplayPoints);
  154. SqueezePlot.SetPaintingStrategy(PaintingStrategy.POINTS);
  155. SqueezePlot.SetLineWeight(1);
  156. SqueezePlot.SetDefaultColor(Color.Yellow);
  157. addCloud(SD_pivot, SD_R1, CreateColor(50,150,75), CreateColor(50,150,70));
  158. addCloud(SD_S1, SD_pivot, CreateColor(175,0,50), CreateColor(175,0,50));
  159. addCloud(SD_pivot_X, SD_R1_X, CreateColor(50,150,75), CreateColor(50,150,70));
  160. addCloud(SD_S1_X, SD_pivot_X, CreateColor(175,0,50), CreateColor(175,0,50));
  161. def SDCD = if AbsValue(upperSD - upperATR) > AbsValue(upperSD[1] - upperATR[1])
  162. then 1
  163. else 0;
  164. # Audible Alerts
  165. Alert(upperSD crosses above upperATR, "Squeeze Exit", Alert.BAR, Sound.Bell);
  166. Alert(c crosses above upperSD, "Violation of Upper Band", Alert.BAR, Sound.Bell);
  167. AddLabel(Squeeze, if close > SD_Pivot
  168. then "Squeeze Expanding Up"
  169. else if close < SD_Pivot
  170. then "Squeeze Expanding Down"
  171. else "In Squeeze",
  172. if close > SD_Pivot
  173. then Color.Green
  174. else if close < SD_Pivot
  175. then Color.Red
  176. else Color.Yellow);
  177.  
  178. # End Code Volatility Compression Pivots
  179.  
  180.  
  181. 16:43 Melissaq: es anyone has autoplot of the fibonacci extention scripts.
  182.  
  183. 16:48 JPera: mo
  184. 16:48 JPera: lol
  185. 16:48 JPera: ttmcaca
  186. 16:48 JPera: mo
  187. 16:48 JPera: i have a request
  188. 16:48 JPera: that i was working on yesterday
  189. 16:48 JPera: but got too sleepy and tired
  190. 16:49 les1: Thanks Mobius, I tried below it is plotting arrow for all candles# Squeeze watchlist column
  191. def sqz = !TTM_Squeeze().SqueezeAlert;
  192. def count = if sqz and !sqz[1] then 1 else count[1]+1;
  193. def fired = if !sqz and sqz[1] then 1 else 0;
  194. addLabel(yes, if sqz then "Squeeze:" + count else if fired then "Fired" else "-", if sqz then color.red else
  195. color.green);
  196. plot UP = sqz > 0;
  197. UP.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
  198. 16:49 les1: I'll try your study
  199. 16:50 strategyman: I have a questoin
  200. 16:51 strategyman: Hello, I was wondering. I have two studies. One line that shows the 50 day moving average and one that shows that 10 day moving average. How do I set an alert for when the 10 day moving avergage crosses above the 50 day moving avergage? and an alert for when it crosse below the 50 day ine
  201. 16:52 Melissaq: Hello Mobius,
  202. 16:52 strategyman: anyone know?
  203. 16:52 razorbackfan: Does anybody have a label created for an RSI overbought 70 oversold 30 created?
  204. 16:53 Melissaq: Do you have Fibonacci extention autoplot scripts.Thanks
  205.  
  206. 16:53 Mobius: Melissa.. there are quite a few fibonacci retracement studies floating around but I've not seen a Fibonacci Extension study as the TOS drawing tool draws one in TOS. You can add extension coefficients above 100 and below 0 on the Retracement studies.
  207. 16:53 les1: @Melissaq, here is the auto fib code working only on daily. select 1day 15min ...............modify and let me know if you can fix for multi days http://tos.mx/QV13w2##....................I got this from here only
  208. 16:54 Melissaq: Les!...The URL is broken, ls send again
  209. 16:55 strategyman: ?
  210. 16:55 Melissaq: OK. Thanks Mobius . Will try it out
  211. 16:55 les1: the one which i gave is for fib retracement not for extensions
  212. 16:55 AlphaInvestor: copy the 6 characters after the / and put into the Setup - Open Shared Item box
  213. 16:55 Mobius: strategy... Without seeing your plot expressions I can give you a general idea
  214.  
  215. Alert(condition, "Text", Alert.Type, Alert.Sound);
  216. 16:57 strategyman: yes but when i put alert "study" i can choose condition of true or false
  217. 16:57 strategyman: but first id need to tell the platform what is true adn what is false
  218. 16:57 strategyman: any idea of how to do it
  219. 16:57 strategyman: basically i have two lines one 10 day and one 50 day averagle lines
  220. 16:57 strategyman: thats all thats on my chart along with the price movements
  221. 16:58 Mobius: razor...
  222.  
  223. Alert(RSI() crosses above OverSold, "RSI crosses OverSold", Alert.Bar, Sound.Bell);
  224. Alert(RSI() crosses below OverBought, "RSI crosses OverBought", Alert.Bar, Sound.Ring);
  225.  
  226. 16:58 strategyman: where do i write that in?
  227. 16:59 les1: @Melissaq remove ## at the end
  228. 16:59 AlphaInvestor: As I said in the trader lounge, if you really have 2 stuies they need to be combined into one
  229. 16:59 strategyman: no one has told me how to combine them
  230. 16:59 AlphaInvestor: or just start with the Moving Average Two Line study
  231. 16:59 strategyman: sorry I am new to this platform
  232. 16:59 JPera: AI
  233. 16:59 JPera: i need help
  234. 16:59 trader990: Hi guys, is it possible to get alerted when the value of a plot is returning as "N/A",please advise thanks.
  235. 17:00 AlphaInvestor: Strategy - copy/paste - then clean up duplicates
  236. 17:01 AlphaInvestor: Strategy - I would look at the MovingAverageTwoLine study to see if it would work as a starting point.
  237. 17:03 Mobius: trader - if isNaN(condition) then 1 else 0;
  238. 17:06 trader990: Thanks Mobius, here is what i am trying to accomplish ,i got this study in the room a while back and i added the bid and ask values to it to be displayed as a chart bubble
  239. 17:06 trader990: def lastbar = HighestAll(if !isNaN(close) and IsNaN(close[-1]) then BarNumber() else Double.NaN);
  240. #AddChartBubble(barnumber() == lastbar, high, "O: " + open + "\nHi: " + high + "\nLo: " + low + "\nClose: " + close, Color.cyan, yes);
  241. def A = close(priceType = "Ask");
  242. def B = close(priceType = "Bid");
  243. 17:06 trader990: AddChartBubble(barnumber() == lastbar, high, "O: " + open + "\nHi: " + high + "\nLo: " + low + "\nClose: " + close +"\nBid:" +B + "\nAsk:"+ A, Color.cyan, yes);
  244. 17:07 trader990: but sometimes in fast markets the bid and ask values return as N/A
  245. 17:08 thegoodman19: how do I get access to the TD-A API? there is no other way than the email they provide? what is the criteria for access to the API? not for me just to mess with it seems?
  246. 17:08 trader990: I want to be alerted when this N/A happens
  247. 17:08 Mobius: trader your bubble placement can be one bar into the future or many the code is ambiguous
  248. 17:09 Mobius: if the bubble is in the expansion area then there may not be a value for it to find
  249. 17:09 trader990: Mobius it returns the OHLC bid and ask of the current bar
  250. 17:10 trader990: in fast markets or the beginning of each bar it could be both the N/A value appears
  251. 17:11 Mobius: trader - last bar with a OHLC or ask or bid is
  252. last_bar = if isNaN(close) then barNumber() else last_bar[1];
  253. 17:11 Mobius: sorry missed an indexer
  254. last_bar = if isNaN(close[-1]) then barNumber() else last_bar[1];
  255. 17:12 trader990: so if i want to get alerted when N/A occurs what would be the syntax for the alert
  256. 17:12 Mobius: I told you that already
  257. 17:12 trader990: ok i will try Mobius
  258. 17:13 trader990: thanks so much
  259. 17:13 Mobius: I also told you your lastbar isn't producing what you think it is
  260. 17:15 trader990: but the OHLC values is corrrect though
  261. 17:19 Mobius: Where did you want your bubble located, on top of the last bar?
  262. 17:20 trader990: yes it is on the last bar
  263. 17:20 razorbackfan: Thank you, Mobius
  264. 17:21 Mobius: OK never mind then my mistake
  265. 17:21 trader990: so when ASK is N/A or the bid is N/A i just want to get alerted
  266. 17:22 trader990: i think your code is working Mobius , i just put A instead of close to identify the ask
  267. 17:23 trader990: here is what i added
  268. Alert(lastbar == if isNaN(A) then barNumber() else lastbar[1]
  269. , "CLOSE=ASK ALERT!", Alert.TICK, Sound.CHimes);
  270. 17:25 Mobius: trader - as an FYI these three methods are all equivalent
  271.  
  272. def lastbar = HighestAll(if !isNaN(close) and IsNaN(close[-1]) then BarNumber() else Double.NaN);
  273. def Last_Bar = if isNaN(close[-1]) then barNumber() else Last_Bar[1];
  274. def bar = barNumber();
  275. AddLabel(1, "lastbar = " + lastbar +
  276. " Last_Bar = " + Last_Bar +
  277. " Current Bar Number = " + bar, color.white);
  278. 17:25 AlphaInvestor: trader - the first position in Alert() is supposed to be a boolean - you have it coming out as a number (barnumbe, or lastbar)
  279. 17:26 Mobius: Alpha.. it will always be true sp it's a go around your elbow to get to your butt way of writting yes or 1
  280. 17:26 AlphaInvestor: How is Dilbert today, got any good Options stuff going on
  281. 17:26 Dilbert: Besides the VIX products what other symbols can be traded to benifit from contango?
  282. 17:26 Mobius: oil
  283. 17:27 AlphaInvestor: dilbert - any /Future could go into backwardation
  284. 17:27 JPera: which study are you guys talking about?
  285. 17:27 Dilbert: Dilbert is good, very good.
  286. 17:27 AlphaInvestor: /CL /NG are common tho
  287. 17:27 Mobius: backwardation and contangio I love it when there's dirty options talk around here
  288. 17:27 trader990: Thanks Mobius ,Alpha ,always learning from you guys ,trying to get my head wrapped around the code logic
  289. 17:28 noitadrawkcaB: Mobius - me too
  290. 17:28 Mobius: yw trader
  291. 17:29 Dilbert: USO suffers from contango, but the effect is not as strong as like for VXX or XIV.
  292. 17:31 Dilbert: What kind of study could be coded to get signals between the relationship between /VX and VXX or XIV?
  293. 17:36 twoshoes:
  294. 17:40 mtroche: Good afteernoon, everyone! I need your help. I am trying to test my startegy and added this line to my code "AddOrder(OrderType.BUY_TO_OPEN, BuyCondition, close, 5000, Color.ORANGE, 0);", but it is not working. By the way, I already defined "BuyCondition". What I am doing wrong?
  295. 17:45 mtroche: Am sorry, guys... This is he right code I have issues: AddOrder(OrderType.BUY_TO_OPEN, BuyCondition, close, 5000, Color.ORANGE, 0, "Bought @ " + close); For some reason itis is not working and AddOrder is in red. does anyone have some time to help me out?
  296. 17:53 Mobius: mtroche = your conditions need work
  297. AddOrder(inttype.IDataHolder, condition, price, tradeSize, CustomColor.tickColor,CustomColor.arrowColor, String name);
  298. 17:54 Mobius: your arrow color can not be 0
  299. 17:55 mtroche: Mobius - Thank youu, Mobius. What can I do if I do not want an arrow to show?
  300. 17:55 Mobius: color it the background color
  301. 17:56 AlphaInvestor: there should be two colors in there too
  302. AddOrder(OrderType.BUY_TO_OPEN, BuyCondition, close, 5000,color.orange,color.orange, "Bought @ " + close);
  303. 17:56 AlphaInvestor: oh, that is what Mobius said first - my bad
  304. 17:57 mtroche: AlphaInvestor and Mobius -- Thank both! What can i do if I do not want the arrow to show?
  305. 17:58 les1: Hi, I'm looking for the below study, if anyone has the code already can you please share....Expected up or down move of a stock. Standard deviation 1 and 2 as expected up move, -1 and -2 as downward expected . plot two up and two down price lines in the right
  306. 17:58 Mobius: mtroche - I Told you already. You can color it the background color. TOS will plot it regardless of what you want so all you can do is hide it
  307. 18:02 strategyman: question does this code.....SimpleMovingAvg("length" = 10) crosses above SimpleMovingAvg("length" = 50) and SimpleMovingAvg("length" = 10) crosses below SimpleMovingAvg("length" = 50) have two alerts at once
  308. 18:02 Mobius: les.. There are expected move studies on MyTrade. Bollinger Bands can be used for Standard Deviation Bands as can Standard Deviation Bands and TOS native VWAP and Linear regression with standard deviation bands
  309. 18:02 strategyman: ?
  310. 18:02 mtroche: Mobius - I'm sorry Mobius. I just saw you already answered. Thank you so much, Mobius!
  311. 18:05 Mobius: strategyman - as you've written that line of code it is looking for the opposite condition in the same bar
  312. 18:06 strategyman: so it should be and SimpleMovingAvg("length" = 10) crosses below SimpleMovingAvg("length" = 50)
  313. 18:06 Mobius: that would be a single condition and a good signal for an alert
  314. 18:07 Mobius: A simpler way to write that would be
  315.  
  316. Average(close, 10) crosses below Average(close, 50);
  317. 18:07 strategyman: okay and i set "1m" and in the condition part i can pick "close" does that mean it will only tell me if it does it at the close or will it check every minute during the day?
  318. 18:07 strategyman: whats "close" mean?
  319. 18:08 Mobius: in TOS close is the current floating price
  320. close[1] is the close of the previous bar
  321. 18:10 strategyman: ok so ig at 2:50 its below the 50 day then at 2:52 its above it will alert me?
  322. 18:11 Mobius: if it crosses below it will alert
  323. 18:12 Mobius: your asking if it crosses above will it alert
  324. 18:12 Mobius: if the price is closer to your head and crosses closer to your toes it will alert
  325. 18:13 strategyman: ok and whats this "1m" thing I clicked on?
  326. 18:13 Mobius: that is 1 minute aggregation. Like a 1 minute chart. 1 minute bars
  327. 18:14 strategyman: should i have that on?
  328. 18:14 Mobius: these are all questions you can learn from the manual
  329.  
  330. http://tlc.thinkorswim.com/center/charting/thinkscript.html
  331. 18:15 Mobius: I charge 300.00 per hour and your asking me two cent questions. Read the manual and come back
  332. 18:16 mtroche: Mobius - Please, could you heck my code and let me know what else I am doing wrong? AddOrder(OrderType.BUY_TO_OPEN, BuyCondition, close[0], 5000, Color.ORANGE, Color.BLACK, "Bought @ " + close[0]); When I add it to the end of my code no signals are shown including the ones I already have in my code, and i have no idea what else I am missing.
  333. 18:17 Mobius: mtroche - the line is correct so check the BuyCondition
  334. 18:18 strategyman: okay thank you
  335. 18:18 mtroche: Mobius - Here's my buy conditionn in my code:
  336. def BuyCondition2 = AC crosses above 0;
  337. #def BuyCondition3 = DiffMACD[1] >= 0;
  338. #def BuyCondition4 = DiffMACD <= 0;
  339. #def BuyCondition4 = DiffMACD crosses above 0 within 3 bars;
  340. def BuyCondition4 = DiffMACD crosses above 0;
  341. #def BuyCondition = BuyCondition1 + BuyCondition2 + BuyCondition3 + BuyCondition4;
  342. def BuyCondition = (BuyCondition2 and BuyCondition4);
  343. 18:20 Mobius: Condition 2 and 4 are excluding one another
  344. 18:21 Mobius: select one or the other. Crossing is a Boolean Conditon while greater than or equal is a State condition
  345. 18:22 Mobius: your askig for 2 different algorithms to align to the same bar. This would be more likely
  346.  
  347. Condition 2 = AO >= 0
  348. Condition 4 = DiffMACD crosses above 0
  349. 18:23 Mobius: or visa versa
  350. 18:24 mtroche: Mobius - :-( So... Even though I have no issues with the rest of my coe using BuyCondition, I cannot use it with AddOrder...? I need BuyCondition to happen to buy; so, is there any way around it?
  351. 18:25 Mobius: your not making any sense
  352. 18:25 Mobius: You have 2 Boolean conditions trying to signal a buy.. How likely is that to happen on the same bar??
  353. 18:26 Mobius: Either make if fuzzy by adding within bar condition or make one of the variables a State conditon and the other Boolean
  354. 18:28 Mobius: Your trying to run before you can walk too.. You should read the manual and understand the difference in condational variables before trying to write a strategy.
  355. 18:33 mtroche: Obviously, I am a very biginning with ThinkScript and coding... Also, BuyCondition works with the rest of my code, and I am reading the manual, but I am not a fast learner and I need a lot of practive to learn; so, that's the reason I am asking to you guys that have a lot of experience and time working with ThinkScript.
  356.  
  357. How can i change them to be the same condition?
  358. 18:36 Mobius: I told you already above.
  359. Change your lines of code so that one is Boolean and one is a State
  360.  
  361. def BuyCondition2 = AC >= 0;
  362.  
  363. def BuyCondition4 = DiffMACD crosses above 0;
  364.  
  365. def BuyCondition = (BuyCondition2 and BuyCondition4);
  366. 18:38 Mobius: This is the difference
  367.  
  368. def BuyCondition2 = AC >= 0; # State Condition
  369.  
  370. def BuyCondition4 = DiffMACD crosses above 0; # Boolean
  371.  
  372. def BuyCondition = (BuyCondition2 and BuyCondition4);
  373.  
  374. 18:42 TradeKind: quikc last question and i am very grateful ...If I Created an alert and set up my email and phone number, will i get email and text alerts even if think or swing is not open?
  375. 18:43 Mobius: Trade.. Yes. Once a MarketWatch Alert is set the platform can be closed and you will still get the alert since it is set Server side
  376. 18:47 mtroche: Mobius - Thank you, Mabius. I think I got it. I think it iwll work out if I use:
  377.  
  378. def BuyCondition2 = AC crosses above 0:
  379. def BuyCondition4 = DiffMACD crosses above 0:
  380.  
  381. Thank you fro your time, Mobius.
  382. 18:47 Mobius: Nope you don't have it
  383. 18:54 mtroche: Mobius - Yeap, I think got it after reading your answer twice... Thank you for your patience.
  384. 18:58 mtroche: Mobius - No wait.... I need those values to not be just over 0, but to be the values when the histograms are crossing over 0; so, >=0 is nt going to work for me. Any other idea?
  385. 19:18 KRFL: van anyone tell me what is a modadx?
  386. 19:20 mtroche: Mobius - I just changed them but the situation persists. Here's my code,, now:
  387. 19:23 mtroche: Mobius - I just changed them but the situation persists. Here's my code, now:
  388.  
  389. def BuyCondition2 = AC crosses above 0;
  390. def BuyCondition4 = if DiffMACD[-1]<=0 and DiffMACD[0]>0 then 1 else 0;
  391. 19:25 KRFL: does it exist in TOS....?
  392. 19:26 Mobius: KRFL that could be anything. There is no function like that in TOS so it's most likely a variable name
  393. 19:27 Mobius: mt... You cna use a within range to allow more flexability
  394.  
  395. Example:
  396. def BuyCondition2 = AC crosses above 0;
  397. def BuyCondition4 = DiffMACD crosses above 0 within 3 bars;
  398. 19:27 KRFL: OK THANKS
  399. 19:27 Mobius: can
  400. 19:41 les1: @Mobius, thanks Mobius, I'll look bollingerband and vwap studies
  401. 19:51 mtroche: Mobius - I have tried everything but every time I add AddOrder command all my signs are not shwon any more and the AddOrder does not show either. Just to make it clear... from time to time bith histograms cross the zero line at the same time -- you couls take any company and play with the time and you will see. Any way, let's assume it does happen... here's my last code:
  402.  
  403. input fastLength = 12;
  404. input slowLength = 26;
  405. input MACDLength = 9;
  406. input averageType = AverageType.EXPONENTIAL;
  407. def DiffMACD = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
  408. def AO = AwesomeOscillator();
  409. def AC = AO - Average(AO, 5);
  410. def BuyCondition2 = AC crosses above 0;
  411. def BuyConditionBuy2 = if AC[-1]<=0 and AC>0 then 1 else 0;
  412. def BuyCondition4 = DiffMACD crosses above 0;
  413. def BuyConditionBuy4 = if DiffMACD[-1]<=0 and DiffMACD>0 then 1 else 0;
  414. def BuyCondition = (BuyCondition2 and BuyCondition4);
  415. def BuyConditionBuy = BuyConditionBuy2 + BuyConditionBuy4;
  416. def ShortSellCondition2 = AC crosses below 0;
  417. def ShortSellConditionShortSell2 = if AC[-1]>=0 and AC<0 then 1 else 0;
  418. def ShortSellCondition4 = DiffMACD crosses below 0;
  419. def ShortSellConditionShortSell4 = if DiffMACD[-1]>=0 and DiffMACD<0 then 1 else 0;
  420. def ShortSellCondition = (ShortSellCondition2 and ShortSellCondition4);
  421. def ShortSellConditionShortSell = ShortSellConditionShortSell2 + ShortSellConditionShortSell4;
  422. plot uparrow = if BuyCondition then low else Double.NaN;
  423. uparrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
  424. uparrow.SetDefaultColor(Color.WHITE);
  425. uparrow.SetLineWeight(5);
  426. plot uparrowB = if BuyCondition then high else Double.NaN;
  427. uparrowB.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
  428. uparrowB.SetDefaultColor(Color.WHITE);
  429. uparrowB.SetLineWeight(5);
  430. plot downarrow = if ShortSellCondition then high else Double.NaN;
  431. downarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
  432. downarrow.SetDefaultColor(Color.WHITE);
  433. downarrow.SetLineWeight(5);
  434. plot downarrowB = if ShortSellCondition then low else Double.NaN;
  435. downarrowB.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
  436. downarrowB.SetDefaultColor(Color.WHITE);
  437. downarrowB.SetLineWeight(5);
  438. def GreenChgA = if DiffMACD > 0 then if DiffMACD[1] > DiffMACD[2] and DiffMACD < DiffMACD[1] then 1 else 0 else 0;
  439. plot GreenChg = if GreenChgA then high else Double.NaN ;
  440. GreenChg .SetPaintingStrategy(PaintingStrategy.POINTS);
  441. GreenChg .SetDefaultColor(Color.WHITE);
  442. GreenChg .SetLineWeight(1);
  443. plot GreenChgB = if GreenChgA then low else Double.NaN ;
  444. GreenChgB .SetPaintingStrategy(PaintingStrategy.POINTS);
  445. GreenChgB .SetDefaultColor(Color.WHITE);
  446. GreenChgB .SetLineWeight(1);
  447. def RedChgA = if DiffMACD < 0 then if DiffMACD[1] < DiffMACD[2] and DiffMACD > DiffMACD[1] then 1 else 0 else 0;
  448. plot RedChg = if RedChgA then high else Double.NaN ;
  449. RedChg .SetPaintingStrategy(PaintingStrategy.POINTS);
  450. RedChg .SetDefaultColor(Color.WHITE);
  451. RedChg .SetLineWeight(1);
  452. plot RedChgB = if RedChgA then low else Double.NaN ;
  453. RedChgB .SetPaintingStrategy(PaintingStrategy.POINTS);
  454. RedChgB .SetDefaultColor(Color.WHITE);
  455. RedChgB .SetLineWeight(1);
  456. AddOrder(OrderType.BUY_TO_OPEN, BuyConditionBUY==2, close[0], 5000, Color.ORANGE, Color.BLACK, "Bought @ " + close[0]);
  457. 19:52 mtroche: Mobius - So, what AM I doing wrong? :-(
  458. 19:53 mtroche: Mobius - Am sorry... What am I doing wrong? :-(
  459. 20:09 brian_s: mtroche, Try setting the Global Settings to allow multiple entries in the same direction to see more buys, as you need a sell AddOrder to counter the buy otherwise.
  460. 20:14 TradeKind: Hello, i am trying to creat a auto buy code using simple avergages. For it set an auto buy if simple 9 day avergage goes above the 50 day avergage....is this the right code:
  461. 20:14 TradeKind: input price1 = close;
  462. input lenght1 = 9;
  463. input displace1 = 0;
  464. input price2 = close;
  465. input length2 = 50;
  466. input displace2 = 0;
  467. def smg1 = simpleMovingAvg (price1,lenght1,displace1);
  468. def smg2 = simpleMovingAvg (price2,length2,displace2);
  469.  
  470. AddOrder(OrderType.BUY_AUTO, smg1 crosses above smg2);
  471. 20:18 DownTheHatch: Put it on a chart and see.
  472. 20:18 brian_s: it won't do any real trades
  473. 20:19 TradeKind: what do you mean put it on a chart
  474. 20:19 Mobius: mtroche - first here is your code plotting in a lower graph with arrows as you first described. Is it plotting as you want?
  475.  
  476. declare lower;
  477.  
  478. input fastLength = 12;
  479. input slowLength = 26;
  480. input MACDLength = 9;
  481. input averageType = AverageType.EXPONENTIAL;
  482.  
  483. plot DiffMACD = MACD(fastLength, slowLength, MACDLength, averageType);
  484. plot AC = AwesomeOscillator() - Average(AwesomeOscillator(), 5);
  485. plot zero = if isNaN(close) then double.nan else 0;
  486. plot upArrow = if DiffMACD crosses above 0 and AC crosses above 0 then 0 else double.nan;
  487. upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
  488. plot dnArrow = if DiffMACD crosses below 0 and AC crosses below 0 then 0 else double.nan;
  489. dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
  490.  
  491.  
  492. 20:19 TradeKind: and can i make a strategy that automatically buys a sertian number of shares
  493. 20:19 brian_s: you need a crosses above line
  494. 20:20 TradeKind: yes but what do you mean put it in a chart
  495. 20:20 brian_s: thinkscript does NO real trades
  496. 20:21 TradeKind: okay
  497. 20:21 TradeKind: so just would alert me
  498. 20:21 TradeKind: or signal a buy and i have to accept
  499. 20:22 TradeKind: and thank you but how do I put it in a chart?
  500. 20:22 brian_s: if you can get it to work on an OCO order, but you have to reset it after every trade
  501. 20:23 brian_s: see what Mobius just posted above, like that
  502. 20:23 mtroche: brian_s - It loooks like nobody believes that both histograms cann cross at the same time at the same direction, but they do from time to time.
  503.  
  504. Assuming that it does happen, what's wrong with my code?
  505.  
  506. I added to my code the MACDStrat, and all my sogns disapear and the MACDStrat does not show either; even though, if I use MACDStrat with my chart without my signals it does show. What's wrong with my code?
  507.  
  508. Please, Brian, could you take a look at my code and let me know how to fix it? My code is at 18:51 line.
  509. 20:26 brian_s: TradeKind, So, what does your crosses above line look like?
  510. http://tlc.thinkorswim.com/center/charting/thinkscript/reference/Reserved-Words/crosses.html
  511. 20:26 TradeKind: where is this code plotting in lower gtaph i dont understand declare lower
  512. 20:27 brian_s: Trade,
  513. http://tlc.thinkorswim.com/center/charting/thinkscript/reference/Reserved-Words/declare.html
  514. 20:29 TradeKind: i went to that site i just dont know where or what to click to lead me to a place to put the code
  515. 20:29 brian_s: mtroche, Did you find the Global settings in the Edit Studies and Strategies window?
  516. 20:30 brian_s: Trade,
  517. On the top of the chart select the beaker next to the gear.
  518. The "Edit Studies and Strategies" window opens.
  519. On the top left of the window select the Studies, or Strategies tab.
  520. Click on the new button, bottom left.
  521. The editor opens, delete the one line of existing script, and paste in your script.
  522.  
  523. 20:31 TradeKind: i see the global settings
  524. 20:32 brian_s: Trade, It seems you are trying to make a strategy, so select the strategy tab, then new.
  525. 20:32 TradeKind: and then put the delcare lower in there
  526. 20:32 TradeKind: from what i saw on the site?
  527. 20:32 TradeKind: thanks
  528. 20:33 brian_s: Use your code and fit the correct Plots style from Mobius code above
  529. 20:34 Paris: Brian - last I looked TOS has a standard MovingAverage Strategy so perhaps he can use that
  530. 20:37 brian_s: FYI, yes paris, thanks, I was just typing that in, There are built in 2 movavg strats built in already. In the Edit Studies window, there is a search box top laft above list of strats, type in avg . Make sure you are under the strat tab.
  531. 20:39 mtroche: brian_s: I did and I changed the "Allow up to..." to "Allow up to 100 entry order(s)...", but the same situation persists. Please, could you try my code to see what's going on? I am feeling I am going in circles, here. :-(
  532. 20:39 brian_s: Gotta go eat, BbL
  533. 20:40 buzzkeeto: I would like to find the code to be able to capture a close price for x bars ago. I want to use a dynamic variable to get the number of bars as follows:
  534. 20:40 buzzkeeto: AddChartBubble(
  535. HasEarnings(),
  536. high,
  537. "The last Earnings was " +
  538. GetEventOffset(Events.EARNINGS, -1) +
  539. " bars ago");
  540. def E1 = getday() - geteventoffset(events.earnings,-1);
  541. def E1Close = close [E1];
  542.  
  543. 20:40 buzzkeeto: I get an error for 'E1' as it wants a constant.
  544. 20:42 Mobius: You can't index a close with anything but a constant
  545. 20:43 Mobius: you will need to find the barNumber() your condition happened on then get the close at that bar.
  546. 20:47 mtroche: Please, could someone help me out? I have tried everything but every time I add an AddOrder command to my code all my signs are not shown any more and the AddOrder does not show either. Here's my code:
  547.  
  548. input fastLength = 12;
  549. input slowLength = 26;
  550. input MACDLength = 9;
  551. input averageType = AverageType.EXPONENTIAL;
  552. def DiffMACD = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
  553. def AO = AwesomeOscillator();
  554. def AC = AO - Average(AO, 5);
  555. def BuyCondition2 = AC crosses above 0;
  556. def BuyConditionBuy2 = if AC[-1]=0 and AC>0 then 1 else 0;
  557. def BuyCondition4 = DiffMACD crosses above 0;
  558. def BuyConditionBuy4 = if DiffMACD[-1]=0 and DiffMACD>0 then 1 else 0;
  559. def BuyCondition = (BuyCondition2 and BuyCondition4);
  560. def BuyConditionBuy = BuyConditionBuy2 + BuyConditionBuy4;
  561. def ShortSellCondition2 = AC crosses below 0;
  562. def ShortSellConditionShortSell2 = if AC[-1]>=0 and AC0 then 1 else 0;
  563. def ShortSellCondition4 = DiffMACD crosses below 0;
  564. def ShortSellConditionShortSell4 = if DiffMACD[-1]>=0 and DiffMACD0 then 1 else 0;
  565. def ShortSellCondition = (ShortSellCondition2 and ShortSellCondition4);
  566. def ShortSellConditionShortSell = ShortSellConditionShortSell2 + ShortSellConditionShortSell4;
  567. plot uparrow = if BuyCondition then low else Double.NaN;
  568. uparrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
  569. uparrow.SetDefaultColor(Color.WHITE);
  570. uparrow.SetLineWeight(5);
  571. plot uparrowB = if BuyCondition then high else Double.NaN;
  572. uparrowB.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
  573. uparrowB.SetDefaultColor(Color.WHITE);
  574. uparrowB.SetLineWeight(5);
  575. plot downarrow = if ShortSellCondition then high else Double.NaN;
  576. downarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
  577. downarrow.SetDefaultColor(Color.WHITE);
  578. downarrow.SetLineWeight(5);
  579. plot downarrowB = if ShortSellCondition then low else Double.NaN;
  580. downarrowB.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
  581. downarrowB.SetDefaultColor(Color.WHITE);
  582. downarrowB.SetLineWeight(5);
  583. def GreenChgA = if DiffMACD > 0 then if DiffMACD[1] > DiffMACD[2] and DiffMACD DiffMACD[1] then 1 else 0 else 0;
  584. plot GreenChg = if GreenChgA then high else Double.NaN ;
  585. GreenChg .SetPaintingStrategy(PaintingStrategy.POINTS);
  586. GreenChg .SetDefaultColor(Color.WHITE);
  587. GreenChg .SetLineWeight(1);
  588. plot GreenChgB = if GreenChgA then low else Double.NaN ;
  589. GreenChgB .SetPaintingStrategy(PaintingStrategy.POINTS);
  590. GreenChgB .SetDefaultColor(Color.WHITE);
  591. GreenChgB .SetLineWeight(1);
  592. def RedChgA = if DiffMACD 0 then if DiffMACD[1] DiffMACD[2] and DiffMACD > DiffMACD[1] then 1 else 0 else 0;
  593. plot RedChg = if RedChgA then high else Double.NaN ;
  594. RedChg .SetPaintingStrategy(PaintingStrategy.POINTS);
  595. RedChg .SetDefaultColor(Color.WHITE);
  596. RedChg .SetLineWeight(1);
  597. plot RedChgB = if RedChgA then low else Double.NaN ;
  598. RedChgB .SetPaintingStrategy(PaintingStrategy.POINTS);
  599. RedChgB .SetDefaultColor(Color.WHITE);
  600. RedChgB .SetLineWeight(1);
  601. AddOrder(OrderType.BUY_TO_OPEN, BuyConditionBUY==2, close[0], 5000, Color.ORANGE, Color.BLACK, "Bought @ " + close[0]);
  602. 20:52 DownTheHatch: mtroche, kindly click on the 'B' just above where you type and get out of BOLD mode.
  603. 20:52 DownTheHatch: have you entered your code as a study or a strategy?
  604. 20:57 Mobius: Down.. I've already posted mtroche's code as a study. But it was ignored.
  605. 20:58 DownTheHatch: yeah, I know, Got some personal experience with people not listening/reading what they are told.
  606. 21:01 Mobius: Always amazes me.
  607. 21:03 mtroche: Please, guys, remeber that I am new to coding and ThinkScript. What's the difference between entering my code a a study or strategy? Do you right he coide diferently? I am sorry, but I really do not understand. Could you explain?
  608. 21:03 DownTheHatch: maybe same reason people blow up their accounts, refuse to pay attention to what's in fromt of them.
  609. 21:05 DownTheHatch: AddOrder is not allowed in a study.
  610. 21:05 twoshoes: Mobius, sir. Appreciate your recent update to the ORB study. However, I cannot get the daily range lines to display for previous days. This example is part of a 5 min, 5 day ES chart, with the 'todayonly' option set to "No". ATR Targets display for the last four days, once triggered. Is there a style setting I need to set?
  611. 21:07 DMonkey: mtroche....https://tlc.thinkorswim.com/center/charting/thinkscript/tutorials.html.....read through all of these and take the quiz at the end of the chapters to get a basic understanding
  612. 21:08 mtroche: So, that's the problem.... how do I create a startegy? I opened the ciode of noe strategy (MACDStrat), and it loooks to me just like a study with the AddOrder.
  613. 21:09 Mobius: mtroche - here is your code as a strategy. Needs to be copy and pasted to a NEW STRATEGY.
  614.  
  615. # MACD and Awsome Oscillator Strategy
  616.  
  617. input fastLength = 12;
  618. input slowLength = 26;
  619. input MACDLength = 9;
  620. input averageType = AverageType.EXPONENTIAL;
  621.  
  622. def DiffMACD = MACD(fastLength, slowLength, MACDLength, averageType);
  623. def AC = AwesomeOscillator() - Average(AwesomeOscillator(), 5);
  624. def zero = if isNaN(close) then double.nan else 0;
  625. def upArrow = if DiffMACD crosses above 0 and AC crosses above 0 then 1 else double.nan;
  626. def dnArrow = if DiffMACD crosses below 0 and AC crosses below 0 then 1 else double.nan;
  627.  
  628. addOrder(OrderType.BUY_TO_Open, upArrow);
  629. addOrder(orderType.Sell_TO_Close, dnArrow);
  630.  
  631. 21:12 UpTheCreek: twoshoes, I'm getting multiple days with the most recent ORB code that Mobius posted
  632. 21:15 syracuse: S&C Magazine, May 2017, Strategy: http://tos.mx/dGNlkr
  633. 21:17 mtroche: Mobius - Thank you fro the code, but it did not work. I copied it and went to "Edit Studies and Strategies" then to "Strategies" then to "New", and paste it there, but the startegy is not shown.
  634. 21:21 Mobius: my guess is your chart shows nothing because there's not entries to show. It does work.
  635. 21:24 Mobius: mtroche - your strategy on a 1 year daily /ES chart showing one entry and one exit
  636. 21:25 jay44: From recent chats in this room, it appears a HOLY GRAIL is still escaping everyone as there is always a quest for new study/strategy/indicator/scan.
  637. 21:26 Mobius: mtroche = your strategy on the upper chart and your study on the lower chart showing the arrows where the upper chart does
  638.  
  639. 21:26 mtroche: Mobius - PLease, try it withh 1 a i minute. Intertsing enough, I copied and pasted the startegy that syracuse shared in at line 20:15, and both startegies yours and his show in my chart, buyt if I turn off his, your study disapears, too.
  640. 21:28 Mobius: 2 day 1min chart of /ES Yes it plots on that too
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement