Community ideas
Thinking in Pine - Functions Containing Var VariablesHello everyone, welcome back to "Thinking in Pine" short video tutorials. In this video, we have discussed special cases of using var variables inside function definitions.
If you are not familiar with var variables, please take a step back and watch our earlier video - "Thinking in Pine - var, varip and regular variables"
🎲 Summary
Using var within a function scope and how it behaves with multiple invocations.
Using the functions containing var variable definitions within a loop.
🎯 Example Program Used
increment()=>
var i = 0
i+=1
var1 = increment()
var2 = increment()
var3 = increment()
// The code above is equivalent to
// var i1 = 0
// i1+=1
// var1 = i1
// var i2 = 0
// i2+=1
// var2 = i2
// var i3 = 0
// i3+=1
// var3 = i3
plot(var1, "Counter 1", color=color.blue)
plot(var2, "Counter 2", color=color.red)
plot(var3, "Counter 3", color=color.purple)
arr = array.from(var1, var2, var3)
for i=1 to 3
arr.push(increment())
// The code above is equivalent to
// var i4 = 0
// i4+=1
// arr.push(i4)
if(bar_index == 4)
log.info('Value of array containing incremental values : {0}', arr)
🎲 References
Pine Script® User Manual - Variable declarations
Pine Script® Reference Manual - var
Price Action for BTC 15-MinuteBecoming the best price action trader in the world requires a combination of in-depth knowledge, experience, and a keen eye for market patterns. Price action trading focuses on the movement of security prices to make trading decisions, rather than relying on technical indicators. Here are several nuanced aspects to focus on in this video tutorial.
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
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!