Thinking in Pine - Time Series Special CasesHello Everyone,
Welcome back to "Thinking in Pine" short video series. In this session, we have discussed few special cases of time series variables and using historical operator within local scope.
If you have not watched our previous video - "Thinking in Pine - Time Series" , request you to do that before continuing this video.
🎲 Summary of our today's discussion
How historical operator works for variables defined inside an conditional block
How historical operator works for variables defined in a loop.
🎯 Example Program Used
// Time series for variables within a condition
varip showLogInLoop = true
if(bar_index%3 == 0)
specialBarIndex = bar_index
if(bar_index > last_bar_index-3 and showLogInLoop)
log.info('Current and Previous special bar index are : {0} and {1}', specialBarIndex, specialBarIndex )
showLogInLoop := false
// Time series of variables within a loop
arrayOfX = array.new()
arrayOfLastX = array.new()
for i = 1 to 5
x = i*10
arrayOfX.push(x)
arrayOfLastX.push(x )
if(barstate.islastconfirmedhistory)
log.info('Array of X : {0}', arrayOfX)
log.info('Array of last X : {0}', arrayOfLastX)
🎲 References:
Pine Script® User Manual - Execution Model
Pine Script® User Manual - Time Series
Pine Script® User Manual - History Referencing Operator
Pine Script® Reference Manual - History Referencing Operator
Community ideas
Trading a Choppy MarketPer request, someone asked to share my strategy and how / why I enter/exit trades.
I decided to be specific and applicable to the current market sentiment and discuss how I trade “choppy markets”.
My personal rules for trading choppy markets are:
1) No options, shares only
2) GTFI and GTFO ASAP
3) Only trade when there is a support or resistance respected
4) Trail once you are in decent profit!
Other points:
Some things I did not elaborate in the video but I think are important to touch on and one of the reasons I avoid options are, there is a huge decay that comes with ranging markets on options. I have went really ITM on options lately and I noticed the profits are equivalent to that of shares by the time the stock finally decides to move. Thus, I am risking quite a lot by the inherent decay in options vs just taking the raw share trade.
And I forgot to disclose in the video, but I half my position at the next resistance level. Unfortunately today we just traded between 2 support and resistance levels, so there was no really halving to be had, but that is the general rule of thumb. Halve the position at the next resistance and trail.
Leveraged Shares vs Options
Another point that I missed in the idea is, Leveraged ETFs, to which is the instrument I traded today and describe in this idea, do have a degree of decay associated with them. However, for daytraders this decay is not noticeable. It will only become noticeable and costly if you chose to hold these shares for greater than a 1 month period, as the decay tends to transition with the month turnover and on any massive move that goes against the share (for example, if you are long via UPRO or TQQQ and we see a 5% sell in 2 days, it will take UPRO and TQQQ longer to catch up to QQQ and SPY because that massive sell just cost the management firm a lot of money on that position (it’s a very simplistic way of looking at it and its much more complex than this, but for ease of explanation, I will use this haha).
To put it in perspective, here is TQQQ next to QQQ on the day:
You can see, there is no observable decay from the chop. If you bought in off open and held till mid day or EOD, you would be able to get out for flat or even a profit if you exited right at the new high.
Now if we look at an ITM 1 DTE option, here is the chart for today:
You can see that the option never retraced the daily high, despite QQQ doing so two times, in fact even breaking it at end of day. It is because the decay impacts options, especially shorter dated ones.
Now you can mitigate against this by going further out in expiries, but the cost of entry into those options increase and the risk of losses also increase, to the point of making your stop outs more costly than had you done a leveraged share position. As well, going further out in expiry doesn't stop the decay from chop, it simply 'mitigates it'. Chop will not destroy a leveraged share, the only two things that will destroy a leveraged share are
a) Time > 3 to 6 months, share depending and
b) Moves against the share > 3 % to 4% on the underlying in a short period of time (i.e. 1 to 2 days).
That said, the gains on options can be better than the gains on shares, its just it comes with a risk. So it is important to weigh your prerogatives, account size and risk tolerance when deciding on these things.
That also said, there are many other things to trade other than leveraged shares. For example, NYSE:AI is an affordable ticker for new share traders, NASDAQ:RIVN , as well as NASDAQ:LCID and if you are Canadian, BA Canadian leveraged shares, though I admit I haven't tried to short sell these yet so not sure if they are easy to borrow.
Concluding remarks
That concludes the idea and request. If you have any questions, as always, leave them below.
Safe trades everyone and take care!
Live stream - Bitcoin, Gold & Forex Breakdown.. Outlook Chart TGame Time !.. 🙌 Tune in to see what i will be trading for this Week! Let's see what opportunities are showing 🙌 8 years of experience🏌🏽📉 ❤️Please support by liking/hitting the rocket button, thank you!❤️ #forex #forexanalysis #forexoutlook
Thinking in Pine - Time SeriesHello everyone,
Welcome back to "Thinking in Pine" short video series. In this video, we discuss the concept of time series variables in Pinescript.
If you are not familiar with var and varip type of variables - please step back and watch this video before continuing - "Thinking in Pine - var, varip and regular variables"
🎲 Summary of our discussion is as follows
What are time series variables, and how are they used in Pinescript?
How do we access historical values of time series?
Limitations of accessing historical values
🎯 Example Program Used
currentBar = bar_index
var currentBarUsingVar = 0
currentBarUsingVar := bar_index
varip showLog = true
valueAt200thBar = ta.valuewhen(bar_index == 500, currentBar, 0)
if(barstate.islast and showLog)
log.info("Current Bar Values using regular and var variables : {0}, {1}", currentBar, currentBarUsingVar)
log.info("Last Bar Values using regular and var variables : {0}, {1}", currentBar , currentBarUsingVar )
log.info("Values 500 bars ago using regular and var variables : {0}, {1}", currentBar , currentBarUsingVar )
offset = bar_index-25000
log.info("Values at 25000th bar using regular and var variables : {0}, {1}", currentBar , currentBarUsingVar )
showLog := false
plot(bar_index, "Bar Index", color = color.blue, display = display.data_window)
There are pitfalls of using historical operators within loop or under if condition. We will discuss that in our next video.
🎲 References:
Pine Script® User Manual - Execution Model
Pine Script® User Manual - Time Series
Pine Script® User Manual - History Referencing Operator
]Pine Script® Reference Manual - History Referencing Operator
'Slow December' is a Myth.In this video I break down just two positions that shaped up last week on EURCAD and GBPNZD, both sells with a minimum return of 10% on both positions. Why is there always an industry gimmick of 'don't trade in December' when people have not even tested the data. Go back to December 2022, 2021, 2020, you will find positions in the market. Keep your focus on the task at hand and not on 'myths'.
Thinking in Pine - var, varip and regular variablesThis is our first video session on "Thinking in Pine" series. Before we start, we want to explain a bit about our new initiative.
🎲 What is "Thinking in Pine"?
In our journey to empower the trading community, we're excited to introduce "Thinking in Pine," a series of concise, 5-10 minute videos dedicated to unraveling the complexities of Pine Script®. We have our own list of topics to be covered, and we will start releasing the videos one by one. However, if you're grappling with any aspect of Pine Script® or stuck on an implementation, we encourage you to reach out to us or drop a comment here. We aim to address your queries by breaking down challenging concepts or implementations into easily digestible content.
What kind of videos are covered in "Thinking in Pine"?
Pine Script® Focus: We try to keep our focus on Pine Script® concepts and implementations.
General Utility: We prioritize topics that offer broader learning value. Though it's challenging to quantify this, we'll use our judgment to select topics that benefit the wider audience.
Time-Efficient Demonstrations: Ideally, we want to keep our demonstrations to 5–10 mins of time.
We're here to demystify Pine Script®, one topic at a time, making it accessible for everyone from beginners to advanced users. Stay tuned for insightful sessions with "Thinking in Pine"!
🎲 Demonstrating var, varip and regular variables in Pine Script®
In this video, we have demonstrated the difference between var, varip and regular variables by using an example implementation of OBV indicator.
🎯 Logic of OBV Calculation
Start with the value 0
On each bar, add volume to the indicator if close price is higher than previous bar close price.
On each bar, remove volume from the indicator is close price is lesser than previous bar close price
🎯 Highlights
Regular variables are initialized separately on each bar and does not propagate value to next bar unless coded to do it.
var variables are initialized once and then can be reassigned any number of times using := operator . The variables declared as var will propagate the current values to the next bar.
varip variables are initialized once and then can be reassigned any number of times using := operator . varip will behave similar to var on historical bars. However, on real time bars, they are recalculated on every tick, and they remember the state of each tick.
🎯 Example Program Used
Here is the example program used in the demonstration.
//Plot built-in OBV value for reference
plot(ta.obv, "OBV Built In", color=color.yellow)
//Volume multiplied by +-1 based on change in close price compared to previous bar.
volumeBySign = math.sign(nz(ta.change(close), 0))*volume
//Obv calculation by using regular variable. Code need to access and add last bar value using obvByRegular
obvByRegular = 0.0
obvByRegular += nz(obvByRegular , 0) + volumeBySign
plot(obvByRegular, "OBV By Regular Variable", color=color.blue)
//Obv calculation using var variable. Since var variables propagate values to next bar,
// we do not need to use historical operator to get the last bar value
var obvByVar = 0.0
obvByVar += volumeBySign
plot(obvByVar, "OBV by var Variable", color = color.maroon)
//Obv implementation using varip. The OBV is calculated based on every tick. Histoical values will match the same as that of other implementation.
//However, in real time, the calculations are done based on the tick values
varip obvByVarip = 0.0
varip lastPrice = close
varip lastVolume = volume
if(barstate.isnew)
lastVolume := 0
obvByVarip += math.sign(close-lastPrice)*(volume-lastVolume)
lastPrice := close
lastVolume := volume
plot(obvByVarip, "OBV by varip Variable", color = color.purple)
🎲 References:
Pine Script® User Manual - Variable declarations
Pine Script® Reference Manual - var
Pine Script® Reference Manual - varip
Pine Script® User Manual - Operators
Live stream - Christmas Forex Breakdown .. Outlook Chart Time!Game Time !.. 🙌 Tune in to see what i will be trading for this Week! Let's see what opportunities are showing 🙌 8 years of experience🏌🏽📉 ❤️Please support by liking/hitting the rocket button, thank you!❤️ #forex #forexanalysis #forexoutlook
How to Confirm a DivergenceI get a lot of messages from you guys talking about how #diivergences seem to play out or not get initiated or that you're having problems entering A #divergence trade.
In this video I'm presenting you a reminder of one of the steps you need to use and it is the the confirmation step that you need to use for confirming whether a divergence is actually going to start going in your favor.
By that I mean that you have already found the divergence and you're simply waiting to enter on the trade because as you should know by now just because you see a divergence doesn't mean it triggers you to start trading in a direction.
Finding the divergence is only step one but finding the entry is based off of the structure in price action that I have outlined in this video idea.
In this video I'm simply using the RSI to find a bullish divergence based off of the difference in bearish price action and you can see clearly how I implement drawing a area around the start of the divergence and wait for price to reach that area. If price never reaches that area then I do not trade bullish according to the bullish divergence instead you simply ignore the divergence and carry on with the rest of your #priceaction #trading.
You To EXIT SP500 @ 4698.34 And Here's WhyWhen you look at the historical chart you will see the pattern of why.
When you see the stocks in the main news.
Remember that this is at the correction level.
Right now the market is oversold.
The best time to exit your position is when the main news
is talking about it.
This is not a good short position but a good exit to take profit position.
Historically it crashed at this level in 2022.
Rocket boost this content to learn more.
**Disclaimer:**
The information provided above is for educational and informational purposes only.
--
It does not constitute financial advice, and trading always involves
--
a risk of substantial losses, regardless of the margin levels
--
used. Before engaging in any trading activities, it is crucial to
--
conduct thorough research, consider your financial situation,
--
and, if necessary, consult with a qualified financial advisor. Past
--
performance is not indicative of future results, and market
--
conditions can change rapidly. Trading decisions should be made
--
based on careful analysis and consideration of individual
--
circumstances. The user is solely responsible for any decisions made
--
and should be aware of the inherent risks associated with trading in
--
financial markets.
Navigating the Markets with Fibonacci ChannelsToday we delve into the fascinating world of Fibonacci Channels, a powerful tool for traders looking to identify potential non-horizontal support and resistance levels in the market.
Throughout the video, we provide a step-by-step guide on how to place Fibonacci Channels on price charts, allowing you to visualize and understand their significance in identifying key price levels. We also showcase real-world examples to demonstrate how Fibonacci Channels can be used to find points of interest, such as trend reversals and price targets.
Furthermore, we discuss the integration of Fibonacci Channels with other technical indicators, providing insights into how this combination can enhance your trading strategy. By the end of this video, you will have a comprehensive understanding of Fibonacci Channels and the ability to confidently incorporate them into your trading approach. Get ready to unlock the potential of Fibonacci Channels and take your trading skills to the next level!
Review, plan for 20th December & New pattern explained!Nifty future and banknifty future analysis and intraday plan in kannada.
This video is for information/education purpose only. you are 100% responsible for any actions you take by reading/viewing this post.
please consult your financial advisor before taking any action.
----Vinaykumar hiremath, CMT
Live stream - Forex and Bitcoin Charts .. Outlook Chart Time!Game Time !.. 🙌 Tune in to see what i will be trading for this Week! Let's see what opportunities are showing 🙌 8 years of experience🏌🏽📉 ❤️Please support by liking/hitting the rocket button, thank you!❤️ #forex #forexanalysis #forexoutlook