TradingView Indicator - Target Lines

tom

Well-known member
Administrator
<div class="bbWrapper">I republished this. Hopefully you can find it at <a href="https://www.tradingview.com/script/wnRg4LVI-Target-Lines/" target="_blank" class="link link--external" rel="noopener">https://www.tradingview.com/script/wnRg4LVI-Target-Lines/</a><br /> <br /> <hr /><br /> This script let&#039;s you monitor four prices:<br /> <br /> 1. The expected move range. This is typically the at-the-money straddle price. There is roughly a 68% probability that prices will stay inside the expected move.<br /> 2. The Magic 8-Ball price. This is from Bryan Cairns&#039;s Magic 8-Ball, which is an AI predication of where the market will close today. More information at <a href="https://launchpass.com/magic-8-ball/members" target="_blank" class="link link--external" rel="noopener">https://launchpass.com/magic-8-ball/memb...</a><br /> 3. Two short strikes. Option traders will typically have one short strike for a credit spread or two for a <a href="https://www.tradingview.com/scripts/butterflypattern/" target="_blank" class="link link--external" rel="noopener">butterfly</a> or iron condor.<br /> <br /> The EM Ratio is the distance of the monitored short strike divided by the expected move. If this ratio is less greater than 2.0, the likelihood of prices getting to the short strike are very low (&lt;5% typically)<br /> <br /> Here is a sample of what a chart might look like:<br /> <br /> <a href="https://s3.us-east-2.amazonaws.com/f1.aeromir.com/2/2023/01/2023-01-22_15-13-38.jpg" target="_blank" class="link link--external" rel="noopener">https://s3.us-east-2.amazonaws.com/f1.aeromir.com/2/2023/01/2023-01-22_15-13-38.jpg</a><br /> <br /> IMPORTANT: All data is manually entered. I update the expected move and Magic 8-Ball Prices every 5-minutes during the trading day on my chart.<br /> <br /> There are fields to adjust how far above or below the lines the text will appear. This is sometimes necessary if you change time frames.<br /> <br /> <div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"> <div class="bbCodeBlock-title"> Code: </div> <div class="bbCodeBlock-content" dir="ltr"> <pre class="bbCodeCode" dir="ltr" data-xf-init="code-block" data-lang=""><code>// Target Lines // By Tom Nunamaker [email protected] // https://aeromir.com/ //@version=5 indicator(&quot;Target Lines&quot;, overlay=true) _lastTradedPrice = close[0] expectedmove = input.float(32.0, &quot;Expected Move&quot;, inline = &quot;01&quot;) showExpectedMove = input.bool(true, &quot;Visible&quot;, inline = &quot;01&quot;) color cEMline = input.color(color.purple, &quot;Lines&quot;, inline = &quot;01&quot;) color cEMText = input.color(color.rgb(236, 131, 255), &quot;Text&quot;, inline = &quot;01&quot;) magic8ball = input.price(title=&quot;Magic 8-Ball&quot;, defval=4060, inline = &quot;02&quot;) showMagic8ball = input.bool(true, &quot;Visible&quot;, inline = &quot;02&quot;) color cM8Bline = input.color(color.rgb(255, 152, 0), &quot;Line&quot;, inline = &quot;02&quot;) color cM8BText = input.color(color.rgb(255, 152, 0), &quot;Text&quot;, inline = &quot;02&quot;) shortstrike1 = input.price(title=&quot;Short Strike 1&quot;, defval=4080.00, inline = &quot;03&quot;) showShortStrike1 = input.bool(true, &quot;Visible&quot;, inline = &quot;03&quot;) color cSSline = input.color(color.red, &quot;Lines&quot;, inline = &quot;03&quot;) color cSSText = input.color(color.red, &quot;Text &quot;, inline = &quot;03&quot;) shortstrike2 = input.price(title=&quot;Short Strike 2&quot;, defval=4050.00, inline = &quot;04&quot;) showShortStrike2 = input.bool(true, &quot;Visible&quot;, inline = &quot;04&quot;) baroffset = input.int(3, &quot;Bar Offset&quot;, inline = &quot;05&quot;) show200MA = input.bool(false, &quot;Show 200 SMA &quot;, inline = &quot;06&quot;) show50MA = input.bool(false, &quot;Show 50 SMA&quot;, inline = &quot;06&quot;) abEMUpper = input.float(.25,&quot;Distance EM #1 text above line&quot;) abEMLower = input.float(-2,&quot;Distance EM #2 text below line&quot;) abSSUpper = input.float(.25,&quot;Distance SS #1 text above line&quot;) abSSLower = input.float(-2.25,&quot;Distance SS #2 text below line&quot;) abM8BUpper = input.float(.25,&quot;Distance Magic 8-Ball text above line&quot;) emupper = close[0] + expectedmove emlower = close[0] - expectedmove labelupper = label.new(na,na) labellower = label.new(na,na) labelshortstrike1 = label.new(na,na) labelshortstrike2 = label.new(na,na) labelmagic8ball = label.new(na,na) labelSMA200 = label.new(na,na) sma200 = ta.sma(close, 200) plot1 = request.security(syminfo.tickerid, &#039;D&#039;, sma200) plot(show200MA ? plot1 : na,title=&quot;200-Day SMA&quot;,linewidth=2,color=color.lime) sma50 = ta.sma(close, 50) plot2 = request.security(syminfo.tickerid, &#039;D&#039;, sma50) plot(show50MA ? plot2 : na,title=&quot;5-Day SMA&quot;,linewidth=2,color=color.orange) // Expected Move lines if barstate.islast and showExpectedMove labelupper := label.new(x=bar_index + baroffset, y=close, color=color.black, textcolor=cEMText, style=label.style_none) label.delete(labelupper[1]) label.set_text(id=labelupper, text=&quot;EM: +&quot; + str.tostring(expectedmove, &quot;0.00&quot;) + &quot; &quot; + str.tostring(close + expectedmove, &quot;0.00&quot;)) label.set_size(id=labelupper, size=size.normal) label.set_y(labelupper, emupper + abEMUpper) labelx = label.get_x(labelupper) + baroffset label.set_x(labelupper,labelx) if barstate.islast and showExpectedMove labellower := label.new(x=bar_index + baroffset, y=close, color=color.black, textcolor=cEMText, style=label.style_none) label.delete(labellower[1]) label.set_text(id=labellower, text=&quot;EM: -&quot; + str.tostring(expectedmove, &#039;0.00&#039;) + &quot; &quot; + str.tostring(close - expectedmove, &#039;0.00&#039;)) label.set_size(id=labellower, size=size.normal) label.set_y(labellower, emlower + abEMLower) labelx = label.get_x(labellower) + baroffset label.set_x(labellower,labelx) if showExpectedMove var line line11 = line.new(0, 0, 0, 0, extend=extend.right, style=line.style_solid, color=cEMline, width=3) var line line12 = line.new(0, 0, 0, 0, extend=extend.right, style=line.style_solid, color=cEMline, width=3) line.set_xy1(line11, bar_index-1, _lastTradedPrice + expectedmove) line.set_xy2(line11, bar_index, _lastTradedPrice + expectedmove) line.set_xy1(line12, bar_index-1, _lastTradedPrice - expectedmove) line.set_xy2(line12, bar_index, _lastTradedPrice - expectedmove) // Short Strike 1 SS1ToMark = shortstrike1 - close[1] EMRatio1 = SS1ToMark/expectedmove if showShortStrike1 var line line13 = line.new(0, 0, 0, 0, extend=extend.right, style=line.style_solid, color=cSSline, width=3) line.set_xy1(line13, bar_index-1, shortstrike1) line.set_xy2(line13, bar_index, shortstrike1) if barstate.islast and showShortStrike1 labelshortstrike1 := label.new(x=bar_index + baroffset, y=shortstrike1, color=color.black, textcolor=cSSText, style=label.style_none) label.delete(labelshortstrike1[1]) label.set_text(id=labelshortstrike1, text=&quot;Short: &quot; + str.tostring(shortstrike1, &#039;#&#039;) + &quot; Dist: &quot; + str.tostring(SS1ToMark, &#039;0.00&#039;) + &quot; EM Ratio: &quot; + str.tostring(EMRatio1, &#039;0.00&#039;) ) label.set_y(labelshortstrike1, shortstrike1 + abSSUpper) labelx = label.get_x(labelshortstrike1) + 3 +baroffset label.set_x(labelshortstrike1,labelx) // Short Strike #2 SS2ToMark = close[1] - shortstrike2 EMRatio2 = SS2ToMark/expectedmove if showShortStrike2 var line line14 = line.new(0, 0, 0, 0, extend=extend.right, style=line.style_solid, color=cSSline, width=3) line.set_xy1(line14, bar_index-1, shortstrike2) line.set_xy2(line14, bar_index, shortstrike2) if barstate.islast and showShortStrike2 labelshortstrike2 := label.new(x=bar_index + baroffset, y=shortstrike2, color=color.black, textcolor=cSSText, style=label.style_none) label.delete(labelshortstrike2[1]) label.set_text(id=labelshortstrike2, text=&quot;Short: &quot; + str.tostring(shortstrike2, &#039;#&#039;) + &quot; Dist: &quot; + str.tostring(SS2ToMark, &#039;0.00&#039;) + &quot; EM Ratio: &quot; + str.tostring(EMRatio2, &#039;0.00&#039;) ) label.set_y(labelshortstrike2, shortstrike2 + abSSLower) labelx = label.get_x(labelshortstrike2) + 3 + baroffset label.set_x(labelshortstrike2,labelx) // Magic 8-Ball M8BDist = magic8ball - close[1] M8BEMration = M8BDist/expectedmove if showMagic8ball var line linemagic8ball = line.new(0, 0, 0, 0, extend=extend.right, style=line.style_solid, color=cM8Bline, width=3) line.set_xy1(linemagic8ball, bar_index-1, magic8ball) line.set_xy2(linemagic8ball, bar_index, magic8ball) if barstate.islast and showMagic8ball labelmagic8ball := label.new(x=bar_index + baroffset, y=magic8ball, color=color.black, textcolor=cM8BText, style=label.style_none) label.delete(labelmagic8ball[1]) label.set_text(id=labelmagic8ball, text=&quot;8-Ball: &quot; + str.tostring(magic8ball, &#039;0.00&#039;) + &quot; Dist: &quot; + str.tostring(M8BDist, &#039;0.00&#039;) + &quot; EM Ratio: &quot; + str.tostring(M8BEMration, &#039;0.00&#039;) ) label.set_y(labelmagic8ball, magic8ball + abM8BUpper) labelx = label.get_x(labelmagic8ball) + 3 + baroffset label.set_x(labelmagic8ball,labelx)</code></pre> </div> </div></div>
 
Last edited:
<div class="bbWrapper">Is this works only on SPX or /ES ?<br /> I tried /CL and at first the chart disappeared but later I found that it was moved all the way to the left off the screen because the indicator lines moved way to the right <br /> Maybe it&#039;s a scaling issue or some offset <br /> It&#039;s not a big deal as I don&#039;t use tradingview when I look at the chart I just wanted to mention it if someone is using it for other than SPX <br /> <br /> After looking at it again just now it looks like it&#039;s a scaling issue as the indicator lines are around 4000 while /CL is in the 80 range so I changed the settings closer to the 80 range and it&#039;s working now</div>
 
<div class="bbWrapper">I use it for SPX during trading hour but ES should work. I haven&#039;t tried it with CL but I&#039;ll take a look. Thanks for the feedback!</div>
 
<div class="bbWrapper">Im getting an error message when accessing that tradingview script <br /> <br /> <blockquote data-attributes="" data-quote="" data-source="" class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch"> <div class="bbCodeBlock-content"> <div class="bbCodeBlock-expandContent js-expandContent "> <h3 class="bbHeading">Script not available&#8203;</h3> <br /> We hid this script because it violates one or more of our <a href="https://www.tradingview.com/house-rules/" target="_blank" class="link link--external" rel="nofollow ugc noopener">House Rules</a>. <br /> <br /> <br /> <a href="https://forums.aeromir.com/" class="link link--internal">Head back</a>, or move along to the homepage to find a new way forward. </div> <div class="bbCodeBlock-expandLink js-expandLink"><a role="button" tabindex="0">Click to expand...</a></div> </div> </blockquote><br /> any ideas?</div>
 
<div class="bbWrapper">The house rules says you can&#039;t include links except premium subscribers (which I am) but apparently it has to be in my signature field. I&#039;ll research it. In the mean time, just use the code above.</div>
 
<div class="bbWrapper">I removed my email and phone number from the script and republished it. Hopefully they won&#039;t kill it again:<br /> <br /> <div class="bbCodeBlock bbCodeBlock--unfurl js-unfurl fauxBlockLink" data-unfurl="true" data-result-id="1543" data-url="https://www.tradingview.com/script/GNAKqBX7-Target-Lines/" data-host="www.tradingview.com" data-pending="false"> <div class="contentRow"> <div class="contentRow-figure contentRow-figure--fixedSmall js-unfurl-figure"> <img src="https://s3.tradingview.com/g/GNAKqBX7_big.png" loading="lazy" alt="www.tradingview.com" class="bbCodeBlockUnfurl-image" data-onerror="hide-parent"/> </div> <div class="contentRow-main"> <h3 class="contentRow-header js-unfurl-title"> <a href="https://www.tradingview.com/script/GNAKqBX7-Target-Lines/" class="link link--external fauxBlockLink-blockLink" target="_blank" rel="noopener" data-proxy-href=""> Target Lines — Indicator by aeromircorp </a> </h3> <div class="contentRow-snippet js-unfurl-desc">This script let&#039;s you monitor four prices: 1. The expected move range. This is typically the at-the-money straddle price. There is roughly a 68% probability that prices will stay inside the expected move. 2. The Magic 8-Ball price. This is from Bryan Cairns&#039;s Magic 8-Ball, which is an AI...</div> <div class="contentRow-minor contentRow-minor--hideLinks"> <span class="js-unfurl-favicon"> <img src="https://static.tradingview.com/static/images/favicon.ico" loading="lazy" alt="www.tradingview.com" class="bbCodeBlockUnfurl-icon" data-onerror="hide-parent"/> </span> www.tradingview.com </div> </div> </div> </div></div>
 
<div class="bbWrapper">Did not think of adding the script manually. It works ! Thanks!</div>
 
<div class="bbWrapper">Awesome <img src="https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png" class="smilie smilie--emoji" loading="lazy" width="64" height="64" alt=":)" title="Smile :)" data-smilie="1"data-shortname=":)" /></div>
 
Top
Contact Us