Heffae Resolution Commander (RAW)This is a script to call resolutions with some math on top of your base resolution.
Using the modulo operator to quantize integer values, it works by converting the modified resolution integer to a 4 digit string value.
Use the function within your own scripts to call funny resolutions otherwise difficult to calculate.
You cannot add series expressions to the resolution value since pine does not allow "series" as a resolution for a security call
However, you could easily stack a crapload of these together and use an expression to switch the referenced security function for your purposes.
This is the raw timeframe output as integer, not string.
To go back to string outputs (for use in security calls etc) unslash line 52 //resvalue
For those interested in the verbose version of the timeframe mod function, showing all the steps, here is a pastebin:
pastebin.com
Cheers! Drop a line / comment if you enjoy or have any questions on how to integrate this into your script@!
The Modulo operator is so much fun!
Pinescript
Heffae Resolution CommanderThis is a script to call resolutions with some math on top of your base resolution.
THIS IS NOT AN INDICATOR TO USE ON A CHART!!! The resolution call function is really useful for your own scripting ideas!
Using the modulo operator to quantize integer values, it works by converting the modified resolution integer to a 4 digit string value.
The function within this script is what is valuable, use it within your own scripts to call funny resolutions otherwise difficult to calculate.
You cannot add series expressions to the resolution value since pine does not allow "series " as a resolution for a security call
However, you could easily stack a crapload of these together and use
an expression to switch the referenced security function for your purposes.
The SMA and plot overlay are just there to show a visual example of how the function works.
You can view the raw timeframe output integer by getting rid of tostring(x) and // out the security calls,
plotting the raw function outputs.
For those interested in the verbose version of the timeframe mod function, showing all the steps, here is a pastebin:
pastebin.com
Cheers! Drop a line / comment if you enjoy or have any questions on how to integrate this into your script@!
The Modulo operator is so much fun!
CM_Ultimate_MA_MTF_V2 with Alert Long and Short Hello All,
Here is a scirpt of ChrisMoody modified with the alerts of purchases and sales.
I just have a problem with automation. At the bottom of my script my alerts "Buy1" and "Sell2" give alerts constantly and I wish to have a single alert before the order is completed. Before "Sell1" or Buy2 ".
I found the function "barstate.isfirst" that could possibly work?
Does anyone have an idea ? :)
Script functionality test - work in progress (2RS + BB + MA)This is the first script I've written. Its sole purpose is to make me learn a bit of pine script. Its not intended to trade live.
Feel free to modify it if you wish and let me know if you do it. Also any comments are welcome!
Also i need help in two things:
1. Im unable to print the "in-strategy" rsi on chart
2. I want to ignore the first buy signal after each sell. I was looking to ad a counter to the signals but im unable to do it.
Any help will be greatly appreciated!
Having problems setting up alertsHi, I have overlayed the script I have prepared previously and figured out how to set alerts although they don't seem to match up correctly with my strategy.
Could anyone please help me fix the problem? It seems to be revolving around my exit conditions.
Thanks in advance.
K
Volume & Intraday ScriptI am still learning pinescript, and part of this was created using the Pine Script language reference manual. This includes looking at the time series, a fixed length, and the default intraday_loss variables. This also includes the basic fixed lengths for an swma (Symmetrically weighted moving average) and the script to start creating a strategy. All in all this is just a basic sample of pinescript that you can customize for your trading needs. This can work with Cryptocurrency but these moving averages usually work more efficiently for forex.
Renko CandlesThis is a script to place Renko candles on your chart alongside another candle type or more importantly, using the variables from this script, you can build a strategy using Renko candles that will depict true/proper entries and exits in a strategy when using the backtest feature.
We hope this helps!
Pine Script Tutorial #2In this second tutorial we build upon the previous tutorial. We add color shading for each different day and highlight Wednesday.
The idea here is to manually count if on Wednesdays close is bigger then open.
Hope it helps.
Feel free to comment.
MartinMystere
My Tutorial #1If you are just like me and cant just get your head around pine script, I have created this simple code so you get the main concept.
Unfortunately there are no good step by step tutorials out there teaching scripting.
Hope this helps.
Comments are welcome.
MatinMystere
15 Minute Gold Trend-Following StrategyThis is the main strategy that I will be forward testing on demo for a month or two, then making it an EA in MetaTrader4
You can see the code for yourself this time, all the strategy is, is a crossover of various moving averages.
Commission included, $10,000 account.
Results over the past 3 months, beginning in January 2017.
alert reloadedtype: alert creation
required time: 5 minutes
level: easy
Getting alerts for indicators and strats is good to easy the eyes of the charts for a while :)
After my first script itroducing how to do alerts here there is an easier, more clear way to create an alert. It's still good to do it the "old way" to understand/debug an alert, but after that you'll want this extra tool for sure.
I assume you read my previous post, or understand how alerts are set up on a chart.
So, there is this function called alercondition() that does (almost)the whole job for us :)
The function does NOT create the alert automatically, what is does is introducing a new option in the alerts popup. While in the v1.0 of my script the alert was triggered checking for the plot value against 0.9 or -0.9, in this example the alertcondition() function just fires the alert by itself.
Get the script for yourself, in favourites, copy/paste, whatever. Add it to any chart. Then, open the popup to create an alert(the little clock at the top). There will be a drop menu with the options and "Alert reloaded". This is the title provided in the study() parameter. Choose this one.
Now, the second drop menu has the "going UP" and "going DOWN" options. These are the titles from the alertcondition() function. Select one. Make all the aditional choices for the alert you want. Save it.
And that's it, the alert will fire when the conditions become true. You can still keep the plot() for graphical reference, but it's now an extra, removing it will not affect the alert, so more space in the chart. Yey!! :)
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 :)
Backtesting Period Selector | ComponentDescription
It's nice to quickly be able to set the backtesting period when writing strategies.
To make this process faster I wrote a simple 'component'.
So this is not a strategy but rather code you can plug-into your strategy and use
if you need that specific functionality.
Then it's just a matter of selecting which dates you want to backtest.
You can also chose to color the background to visually show the testing period.
Unfortunately, the background color is fixed at 'blue' for now.
Ps. I like the idea of writing small components to be pluged into other strategies
I'll try to develop this idea a bit further and see how small pieces of code can
easily provide specific functionality to assist and make deving strategies a bit less 'Pineful'.
Usage
First copy the instructed part of the component code over to your strategy.
Next, use the testPeriod() function to limit strategies to the specified backtesting period.
Example usage:
if testPeriod()
strategy.entry("LE", strategy.long)
Todo / Improvements
There are many ways to improve this component and I'm not a very good coder so this is a very crude solutions.
Anyway, here are some things which would be nice to improve:
1. Enable color selection so that the user can choose the background color of his own liking.
2. Improve naming of variables.
3. Test for ilogical choices, such as test period start being at a later date, than test period stop.
4. Account for time zones.
As always, any feedback, corrections or thoughts are very much welcome!
/pbergden
Simple Strategy Code StubThis is a very basic strategy implementation
Use as a code stub for your strategy code. I wrote it because I could not find one.
This particular strategy goes long on Tuesdays at 10 am and goes short at 3 pm on Thursdays.
Because US markets open at 9:30 you have to have your chart in 30 minute or less resolution for trades to fire.
You can gut that code and replace it with your own to start testing your own indicators and strategies.
If you build a strategy that doesn't use "hour" like I have this resolution requirement won't apply.
For giggles, compare its performance to other strategies. Weird, huh? About 53% effective on most equities and indexes.
This strategy does the minimum needed to get a strategy working
and uses default position sizes and buys at market with no stops.
Again, it is the minimal code stub needed to test an indicator/rule based strategy.
A great code reference for building more sophisticated strategies can be
found here =>
The code is written by @greatwolf and is very well structured for anyone looking to fully utilize
strategy features for position sizing, limit orders, stops and cancellations.
"Smoothed" CandlesHi!
This new functions plotbar and plotcandle are amazing! Just look at this smoothed candles here)))
Higher Resolution Bars on Intraday ChartHi everybody!
With new plotbar and plotcandle functions you may plot somewhat "stretched" daily bars over intraday chart. Enjoy!
Code for Cup With Handle calculations (using Pine)Cup with Handle formation calculations using Pine.
First of all, ignore all other lines in the example chart except the two FAT lines. The two fat lines are the ones that define the Cup With handle or in the example chart: a Reversed Cup With Handle.
Note: Handle does not always develop and sometimes the final target price is reached without forming any handle.
This script can calculate both Cup With Handle ( CH ) and Reversed Cup With Handle ( RCH ). Just order the input values accordingly.
For more information about Cup With Handle, use google:
www.google.se
The script need two input parameters : The highest price in the Cup formation and the lowest price in the cup formation or vice versa for the Reversed Cup formation.
Best regards,
/Hull, 2015.05.20.16:31
CM_3-Stochastics_No%D_UserRequestCreated By ChrisMoody on 1-19-2014 by User Request
Plots 3 Stochastic Lines.....No %D Lines...by User Request.
CM_Donchian Channels Modified_V2 - Alert CapableCM_Donchian Channels Modified_V2 With Alert Capability
***This Indicator was created by user Request to Add Alerts Capabilities for Donchian Channels.
New Features:
***Alerts Work - Ability To Create Alerts From Main Indicator.
***Can Also Be Used In Conjunction with Lower Indicator - CM_Donchian Channels Modified_V2_Lower_Alert
***Added Ability To Turn On/Off Highlight Bars.
***Added Ability to Turn On/Off Donch Channel Midline
***Added Ability to Turn On/Off Triangles That Plot At Top and Bottom Of Chart When Breakout Condition is TRUE.
Special Indicator Features:
***Ability To Use Different LookBack Period on Upper and Lower Donch Channel Lines.
How To Create Alerts:
***Create Alert by selecting Indicator - Either the name of the Upper Or Lower Indicator...
***Then select either Alert Breakout Upside or Downside(To The Right Of Indicator Name)
***Select Greater Than
***Select Value
***For Value put .99
Original Post Explaining Indicator is -
***If You Need Help Getting Custom Indicators to Trigger Alerts then View This Post.
CM_Donchian Channels Modified_V2_Lower_Alert***This Indicator was created by user Request to Add Alerts Capabilities for Donchian Channels.
New Features:
***Alerts Work - Ability To Create Alerts From Main Indicator.
***Can Also Be Used In Conjunction with Upper Indicator - CM_Donchian Channels Modified_V2 With Alert Capability
***Added Ability To Turn On/Off Highlight Bars.
***Added Ability to Turn On/Off Donch Channel Midline
***Added Ability to Turn On/Off Triangles That Plot At Top and Bottom Of Chart When Breakout Condition is TRUE.
Special Indicator Features:
***Ability To Use Different LookBack Period on Upper and Lower Donch Channel Lines.
How To Create Alerts:
***Create Alert by selecting Indicator - Either the name of the Upper Or Lower Indicator...
***Then select either Alert Breakout Upside or Downside(To The Right Of Indicator Name)
***Select Greater Than
***Select Value
***For Value put .99
Original Post Explaining Indicator is -
***If You Need Help Getting Custom Indicators to Trigger Alerts then View This Post.
CM ATR Stops/Bands - Multi-TimeFrameCM_MTF ATR Bands/Stops
Many Options Available Via Input Tab:
-Chart Defaults to Upper and Lower ATR's Based on Current Chart TimeFrame
-Ability to Plot either Upper and/or Lower ATR's
-Ability to Change the Time Frame ATR's are Based On!
-Ability to change Look Back Period and ATR Multiplier Individually for Both Time Frames
-This Gives you the ability to plot same Time Frame with (for ex.) a 5 ATR with a 1.5 Mult and a 14 ATR with a 2.0 Mult etc.
-Or you can plot Daily ATR's on a 60 minute Chart etc.
-ATR Multipliers are Calculated with Code that allows "Non Whole Numbers" Allowing Ability to use 1.5 ATR's, 1.8 ATR's etc.
***Endless # of Combinations can be used!!!!