Learning Understanding ta.change//First script I have published. Constructive criticism is welcome.
// I hope this may be helpful to you.
// Initially, I did this for myself as I was getting some odd results from the ta.change function. Turns out it was my error LOL. What a surprise!
// Typical syntax: ta.change(source, value)
// value doesn't need to be included. If it isn't, it will only calculate the change between the last and current value.
// Conclusion. ta.change simply calculates the difference between a previous value/candle and the latest value/candle current value in that series. Positive number states that the recent is higher.
// Bonus :-) Function on line 34 outputs the changes in a positive figure (so as to be able to sum the changes/volatility of the series of values)
Basic
consoleLibrary "console"
Simple debug console to print messages from your strategy code.
USAGE :
Make sure your strategy overlay is false
Import the library :
import keio/console/1 as console
init(lines, panes)
Initialise function.
USAGE :
var log = console.init()
Parameters:
lines : Optional. Number of lines to display
panes : Optional. Number of panes to display
Returns: initialised log
print(log)
Prints a message to the console.
USAGE :
log := console.print(log, "message")
Parameters:
log : Mandatory. The log returned from the init() function
Returns: The log
ObjectStackLibrary "ObjectStack"
init()
push()
push()
push()
push()
push()
nextIndex()
nextIndex()
nextIndex()
nextIndex()
nextIndex()
delete()
delete()
delete()
delete()
delete()
cleanOldest()
cleanOldest()
cleanOldest()
cleanOldest()
cleanOldest()
Double Exponential Moving Average 8-20-63 StrategyHello, this script was made upon the request of aliergin63, one of my followers.
I do not know exactly from whom it is quoted. (It may be author HighProfit.)
Long position when 8 dema is over 20 dema and 63 dema,
it opens a short position for the vice versa.
Alarms have been added.
%0.1 comission added.
Regards.
Note : DEMA = Double Exponential Moving Average
Simple Study for Sean (threshold-triggered alert)This script illustrates how to create simple alerts, triggered by a share price moving above (or below) an arbitrary threshold.
Multiple Moving Averages [clean]Very simple indicator script to display multiple simple moving averages. I know others have made this but they often are too feature-rich and can get cluttered.
Can optionally show a cross when MA 1 crosses MA 3. These are colors such that when MA 1 crosses BELOW MA 3 a red cross is shown, and green when crossing above.
Back to zero: Understanding seriestype: pine series basic example
time required: 10 minutes
level: medium (need to know the "array" data variable as a generic programming concept, basic Pine syntax)
tl;dr how variables and series work in Pine
Pine is an array/vector language. That's something that twists how it behaves, and how we have to think about it. A lot of misunderstandings come from forgetting this fact. This example tries to clear that concept.
First, you need to know what an array is, and how it works in a programmig language. Also, having javascript under your belt helps too. If you don't, google "javascript array basic tutorial" is your friend :)
So, in pine arrays are called "series". Every variable is an array with values for each candle in the chart. if we do:
myVar = true
this is not a constant. It is a series of values for each candle, { true, true,....., true }
In practice, the result is the same, but we can access each of the values in the series, like myVar{0}, myVar{7}, myVar{anyNumber}....
Again, it is not a constant, since you can access/modify the each value individually
so, lets show it:
plot (myVar, clolor = gray)
this plots an horizontal line of value 1 ( 1 is equal to true ) so it's all good.
On to a more usual series:
tipicalSeries = close > open ? true : false
plot(tipicalSeries, color= blue)
This gives the expected result, a tipical up and down line with values at 1 or 0. Naturally, "tipicalSeries" is an array, the "ups" and "downs" are all stored under the same variable, indexed by the candles.
In Pine, the ZERO position in the array is the last one, which corresponds to the last candle on the right. Say you have a chart with 12 candles. The close would be the closing value of what we intuitively think as first candle, the one on the left. then close ... and so on.... until close , the value of the "last" candle, the one on the right. It actually helps to start thinking of the positions backwards, counting down to zero, rocket launch style :)
And back to our series. The myVar will also be the same size, from myVar to myVar .
When we do some operation with them, something simple like
if ( myVar == tipicalSeries)
what is really happening is that internally, Pine is checking each of the indexes, as in myVar == tipicalSeries , myVar == tipicalSeries .... myVar == tipicalSeries
And we can store that stuff to check it. simply:
result = (myVar == tipicalSeries) ? true : false //yes, this is the same as tipicalSeries, but we're not in a boolean logic tut ;)
plot (result)
The reason we can plot the result is that it is an array, not a single value. The example indicator i provide shows a plot where the values are obtained from different places in the array, this line here:
mySeries3 = mySeries2 and mySeries1
this creates a series that is the result of the PREVIOUS values stored (the zero index is the one most at the right, or the "current" one), which here just causes a shift in the plotted line by one candle.
Go ahead, grab a copy of my code, try to change the indexes and see the results. Understanding this stuff is critical to go deeper into Pine :)
Basic MAAll-in-one basic indicators:
- MA Fast (12)
- MA Medium (26)
- MA Slow (200)
- Parabolic SAR www.investopedia.com
- Dynamic Fibonnaci channel with 2 channels - www.forexstrategiesresources.com