string_utilsLibrary "string_utils"
Collection of string utilities that can be used to replace sub-strings in a string and string functions
that are not part of the standard library.
This a more simple replacement of my previous string_variables library since it uses types for better
performance due to data locality and methods that give a more intuitive API.
Variable
TurntLibraryLibrary "TurntLibrary"
Collection of functions created for simplification/easy referencing. Includes variations of moving averages, length value oscillators, and a few other simple functions based upon HH/LL values.
ma(source, length, type)
Apply a moving average to a float value
Parameters:
source : Value to be used
length : Number of bars to include in calculation
type : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Smoothed value of initial float value
curve(src, len, lb1, lb2)
Exaggerates curves of a float value designed for use as an exit signal.
Parameters:
src : Initial value to curve
len : Number of bars to include in calculation
lb1 : (Default = 1) First lookback length
lb2 : (Default = 2) Second lookback length
Returns: Curved Average
fragma(src, len, space, str)
Average of a moving average and the previous value of the moving average
Parameters:
src : Initial float value to use
len : Number of bars to include in calculation
space : Lookback integer for second half of average
str : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Fragmented Average
maxmin(x, y)
Difference of 2 float values, subtracting the lowest from the highest
Parameters:
x : Value 1
y : Value 2
Returns: The +Difference between 2 float values
oscLen(val, type)
Variable Length using a oscillator value and a corresponding slope shape ("Incline",Decline","Peak","Trough")
Parameters:
val : Oscillator Value to use
type : Slope of length curve ("Incline",Decline","Peak","Trough")
Returns: Variable Length Integer
hlAverage(val, smooth, max, min, type, include)
Average of HH,LL with variable lengths based on the slope shape ("Incline","Decline","Trough") value relative to highest and lowest
Parameters:
val : Source Value to use
smooth
max
min
type
include : Add "val" to the averaging process, instead of more weight to highest or lowest value
Returns: Variable Length Average of Highest Lowest "val"
pct(val)
Convert a positive float / price to a percentage of it's highest value on record
Parameters:
val : Value To convert to a percentage of it's highest value ever
Returns: Percentage
hlrange(x, len)
Difference between Highest High and Lowest Low of float value
Parameters:
x : Value to use in calculation
len : Number of bars to include in calculation
Returns: Difference
midpoint(x, len, smooth)
The average value of the float's Highest High and Lowest Low in a number of bars
Parameters:
x : Value to use in calculation
len
smooth : (Default=na) Optional smoothing type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Midpoint
Dynamic Highest Lowest Moving AverageSimilar to my last script, although this one uses the RSI value of
(highest high - price) / (price - lowest low)
to feed into the the logic creating the dynamic length. Choose how the length curve works by selecting either Incline, Decline, Peak or Trough.
Lastly select the moving average type to filter the result through to smoothen things out a bit
to find something that works for your strategy. This is useful as an entry/exit indicator along with other moving averages, or even just a standalone if you play with the settings enough.
Market MonitorThe script can be used to send a JSON message to the webhook once per time. For example, to store market conditions in an external database. The latter is make sense for smaller timeframes due to TradingView limitations on the number of available bars. The interval between messages can be set in the settings. To set up transmitted market metrics, you will probably need to modify the script code to add metrics that are important to you.
Multiple MTF Variable Moving Average by HassonyaVMA(Variable Moving Average) automatically adjusts its smoothing constant on the basis of Market Volatility.
Use VMA like other Moving Averages. This indicator lazybear's variable moving average has been upgraded and arranged in multi-time frame.
There are 5 variable moving averages whose periods can be changed.
Trend Direction Colors: GREEN COLOR = UpTrend, BLUE COLOR = Potential Congestion, RED COLOR = DownTrend.
If you want, you can use multi-time frame period breakouts
If you want, you can use moving average breakouts of different lengths in the same period.
In this way, you can use 5 moving moving averages in the same period or in different periods.
To activate, go to settings and activate the box to the left of the name. If you uncheck the box, the moving average will disappear.
Stay with the trade and investment. I wish you abundance.
[FN] Strategy - Store Level on ConditionThis is a function that you can use in strategies. Not a strategy in and of itself.
Example thumbnail is showing the function applied to a strategy.
Oftentimes, I am asked a question regarding how to hold a variable at a specific, constant level over a conditional period of time. This question is always asked in a very long convoluted way like "I want the strategy to know what the high of the last pivot was while I'm in a long." or some other variation of wanting a script to remember something from prior bars.
This function is designed to store a price or some numeric level on the bar that your conditional (bool) statements determine that it should be stored. In this construct, you would set conditional statement(s) to flip the 'hold condition' to be true on the next bar, then hold that value until either the "hold condition" is no longer true or the initial conditions trigger again, causing an update to the level that you want to capture.
You still have to come up with the logic for the start condition and hold condition on your own, but I've provided an example that should give you an idea of how to accomplish this and customize/deploy the function for your purposes.
The function will return 'na' when neither the start condition nor hold condition are true. There's multiple ways to implement this and variations on how the level is chosen. I've written extensive notes in the script to guide you through the logic behind the function. My hope is that it will be useful to those trying to build strategies or anyone attempting to get their script to remember a level under given conditions.
In the thumbnail example, the take profit level is defined at the beginning of the trade and held until the take profit order executes. The order execution is a separate matter. However, storing the take-profit level at a static value is key to telling the strategy.exit() function what price to execute a limit exit order at.
Example: strategy.exit("Exit Long", from_entry = "long", qty_percent = 100, limit = stored_value)
Let me know how it works out for you and if I can be of any assistance.
Note: Strategy results are mainly derived from the fact that the strategy is long-only, the NQ only goes up, and there is no stop loss in place. So don't ask for the specific strategy, because unless you're trading a single contract with a $500,000 account, you'll probably get liquidated using this strategy as it is presented.
Ultimate Moving Average [CC+RedK]The Ultimate Moving Average was created by myself and @RedKTrader and I can proudly say that this is the holy grail of moving averages. Not only does this moving average react to the current price trends like a normal moving average but we have also included the ability to react to volume, momentum, and volatility. The only thing this moving average can't do is wash your car.
The Ultimate Moving Average doesn't even use a set length so it is fully adaptable to any type of market whether it is choppy or trending. It tightens during volatile markets and loosens during choppy markets. I have included 3 of the main moving averages of a fixed length of 20 days to show you just how much better our moving average is.
The overall concept of this moving average was to fully adapt to any and all changes of the underlying stock. We used my Variable Power Weighted Moving Average as a base and changed the script to adapt to momentum instead. The idea behind this was when momentum reaches an extreme in either direction we tighten the moving average to be able to react accordingly. We then used the idea behind my Variable Length Moving Average to be able to react to volatility and make the length itself into a separate variable.
All of this work combined to create the most reactive moving average out there and I guarantee you will be using this in your daily trading! Let me know if there are any other scripts you would like to see me publish.
Visualizing Behaviors of barstate VariablesThe title pretty much sums up what this script does. It's intended for Pine Script developers, but especially for newcomers to Pine Editor contemplating the use of barstate variables. I would recommend using this on 15 second or 1 minute chart intervals for a quick and obvious analysis of barstate behaviors.
These barstate variables change from TRUE to FALSE or FALSE to TRUE during specific times/conditions of script operation. One unique state you might not ever see change is barstate.isfirst. This is only TRUE when bar_index==0, most easily viewed on the monthly "All" chart on the far left. I provided a label displaying the current bar_index for perspective. I hope this provides an improved grasp of barstate understanding for fellow members, as it did for myself.
When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members , I may implement more ideas when they present themselves as worthy additions. Have a profitable future everyone!
Variable Length Moving AverageThe Variable Length Moving Average was created by George R. Arrington Ph.D. (Stocks & Commodities V. 9:6 (219-223)) and I'm really loving this indicator. It is a great moving average that hugs the price very closely and it is fully adjustable to your needs. It detects signals extremely well and I have color coded the moving average line to make it very easy to interpret.
This is not to be confused with the Variable Moving Average created by Tushar S. Chande and as of now I haven't seen any other script for this moving average out there yet.
Please let me know if you would like me to write any other scripts for indicators you would like to see!
Function StochRSI Stochastic Relative Strength Index developed by Tushar Chande and Stanley Kroll.
This script has been written to eliminate the period variable.(Integer)
Thus, it can be used comfortably in adaptive period scripts ! (For example : Adaptive Moving Average , KAMA , FAMA .. etc. )
All efforts goes to ChaosTrader () ,
RicardoSantos () ,
Hpotter for barcolor codes (iff) ()
I hope it will help your new ideas . Best regards ! Noldo .
Bryant Adaptive Moving Average@ChartArt got my attention to this idea.
This type of moving average was originally developed by Michael R. Bryant (Adaptrade Software newsletter, April 2014). Mr. Bryant suggested a new approach, so called Variable Efficiency Ratio (VER), to obtain adaptive behaviour for the moving average. This approach is based on Perry Kaufman' idea with Efficiency Ratio (ER) which was used by Mr. Kaufman to create KAMA.
As result Mr. Bryant got a moving average with adaptive lookback period. This moving average has 3 parameters:
Initial lookback
Trend Parameter
Maximum lookback
The 2nd parameter, Trend Parameter can take any positive or negative value and determines whether the lookback length will increase or decrease with increasing ER.
Changing Trend Parameter we can obtain KAMA' behaviour
To learn more see www.adaptrade.com