Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
converting useful Pine Script into Multicharts code
Updated November 30, 2020
trending_up
5,336 views
thumb_up
1 thanks given
group
2 followers
forum
2 posts
attach_file
0 attachments
converting useful Pine Script into Multicharts code
November 25th, 2020, 01:03 AM
hong kong
Posts: 4 since Jun 2020
Thanks Given: 2
Thanks Received: 0
Hi, this is my first post here, I am a newbie for Multicharts ,
nice to meet all veterans.
I am facing coding problems during converting a Pine Script into Multicharts language.
The problems I guess is caused by linearRegValue, it showed error every time:
"source: UI checker .........user interface of multicharts64.exe.......process is not responding..........."
The code is an essential indicator for me, it and I have found it's very useful, it cannot be absent in my trading.
"""This is a derivative of John Carter's "TTM Squeeze" volatility indicator, as discussed in his book "Mastering the Trade" (chapter 11).
Black crosses on the midline show that the market just entered a squeeze ( Bollinger Bands are with in Keltner Channel). This signifies low volatility , market preparing itself for an explosive move (up or down). Gray crosses signify "Squeeze release".
Mr.Carter suggests waiting till the first gray after a black cross, and taking a position in the direction of the momentum (for ex., if momentum value is above zero, go long). Exit the position when the momentum changes (increase or decrease --- signified by a color change). My (limited) experience with this shows, an additional indicator like ADX / WaveTrend, is needed to not miss good entry points . Also, Mr.Carter uses simple momentum indicator , while I have used a different method (linreg based) to plot the histogram.""" @lazy bear
//
// @author LazyBear
// List of all my indicators:
// ... sp=sharing
// v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @ucsgears ]
//
study(shorttitle = "SMI", title="SMI", overlay=false)
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis = sma (source, length)
dev = mult * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, green),
iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
My version, however it's not working, calculating bollinger and Keltner Channel seems OK, but not the LinearRegValue:
//my version
var :length(0),mult(0),lengthkc(0),multkc(0);
length = 20;
mult = 2;
lengthkc =2;
multkc = 1.5;
//BB
var: basis(0), dev(0),upperbb(0),lowerbb(0);
basis = averagefc(close,length);
dev = mult* stddev(close,length);
upperbb = basis + dev;
lowerbb = basis - dev;
//plot1(basis,"",yellow);
plot2(upperbb,"",red);
plot3(lowerbb,"",red);
//KC
var: ma(0),rangex(0),rangema(0),upperkc(0),lowerkc(0);
ma = averagefc(close,lengthkc);
rangex = truerange;
rangema = averagefc(rangex,lengthkc);
upperkc = ma + (rangema*multkc);
lowerkc = ma - (rangema*multkc);
//plot4(rangema,"",yellow);
plot5(upperkc,"",blue);
plot6(lowerkc,"",blue);
//sqz on or off
condition1 = (lowerbb>lowerkc) and (upperbb<upperkc);
if condition1 then value1 = arw_new(date,time,close,false);
//linearregvalue
var:val(0),val2(0);
val2= close - average(average(highest(high, lengthkc), lowest(low, lengthkc)),average(close,lengthkc));
val = LinearRegvalue(val2,lengthkc,0);
plot7(val,"",yellow);
// Thanks to everyone, from my bottom of hearts, sorry for poor English//
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
November 29th, 2020, 06:39 PM
Los Angels
Experience: Intermediate
Platform: MultiChart
Trading: Emini ES
Posts: 115 since Aug 2018
Thanks Given: 173
Thanks Received: 71
traderaaa
I am facing coding problems during converting a Pine Script into
Multicharts language.
The problems I guess is caused by linearRegValue, it showed error every time:
"source: UI checker .........user interface of multicharts64.exe.......process is not responding..........."
//
// @author LazyBear
// List of all my indicators:
// ... sp=sharing
// v2 - fixed a typo, where BB multipler was always stuck at 1.5. [Thanks @
ucsgears ]
//
study(shorttitle = "SMI", title="SMI", overlay=false)
length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")
useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)
// Calculate BB
source = close
basis =
sma (source, length)
dev = mult * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev
// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC
sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz = (sqzOn == false) and (sqzOff == false)
val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)),
lengthKC,0)
bcolor = iff( val > 0,
iff( val > nz(val[1]), lime, green),
iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)
My version, however it's not working, calculating bollinger and Keltner Channel seems OK, but not the LinearRegValue:
//my version
var :length(0),mult(0),lengthkc(0),multkc(0);
length = 20;
mult = 2;
lengthkc =2;
multkc = 1.5;
//BB
var: basis(0), dev(0),upperbb(0),lowerbb(0);
basis = averagefc(close,length);
dev = mult* stddev(close,length);
upperbb = basis + dev;
lowerbb = basis - dev;
//plot1(basis,"",yellow);
plot2(upperbb,"",red);
plot3(lowerbb,"",red);
//KC
var: ma(0),rangex(0),rangema(0),upperkc(0),lowerkc(0);
ma = averagefc(close,lengthkc);
rangex = truerange;
rangema = averagefc(rangex,lengthkc);
upperkc = ma + (rangema*multkc);
lowerkc = ma - (rangema*multkc);
//plot4(rangema,"",yellow);
plot5(upperkc,"",blue);
plot6(lowerkc,"",blue);
//sqz on or off
condition1 = (lowerbb>lowerkc) and (upperbb<upperkc);
if condition1 then value1 = arw_new(date,time,close,false);
//linearregvalue
var:val(0),val2(0);
val2= close - average(average(highest(high, lengthkc), lowest(low, lengthkc)),average(close,lengthkc));
val = LinearRegvalue(val2,lengthkc,0);
plot7(val,"",yellow);
// Thanks to everyone, from my bottom of hearts, sorry for poor English//
Check the variables such as "averagefc" which are "function" in easyslanguage. You may need to write them in your code. Please ask for help if you need assistance.
November 30th, 2020, 05:15 PM
Seattle, WA/USA
Experience: Intermediate
Platform: TOS, TS
Trading: Forex, crude
Posts: 96 since Sep 2016
Thanks Given: 7
Thanks Received: 35
Here is the tradestation code for the TTM squeeze from an internet google. Maybe this can be a start
Code
inputs:
Price(Close),
BollingerPrice(Close),
Length(20),
NumDevsUp(2),
NumDevsDn(-2),
NumATRs(1.5),
SQBreakoutColor(Blue),
SQColor(Yellow),
MLength(12),
ColorNormLength( 14 ),
UpColor( Green ),
DnColor( Red ),
GridForegroundColor( Black ),
Displace(0);
variables:
ApplicationType( 0 ),
Avg(0),
Shift(0),
SDev(0),
KLowerBand(0), KUpperBand(0),
BLowerBand(0), BUpperBand(0),
Mom( 0 ),
Accel( 0 ),
LinReg( 0 ),
ColorLevel( 0 );
{ Bollinger Band Calculations }
Avg = AverageFC( BollingerPrice, Length ) ;
SDev = StandardDev( BollingerPrice, Length, 1 ) ;
BUpperBand = Avg + NumDevsUp * SDev ;
BLowerBand = Avg + NumDevsDn * SDev ;
{ Ketler Channel Calculations }
Avg = AverageFC( Price, Length ) ;
Shift = NumATRs * AvgTrueRange( Length ) ;
KUpperBand = Avg + Shift ;
KLowerBand = Avg - Shift ;
{ Now show me the Squeeze }
Plot1[Displace](0, "Signal");
{ If Bollinger bands are insize the ketler channel then alert, get ready for squeeze }
if (BUpperBand <= KUpperBand and BLowerBand >= KLowerBand) then
begin
SetPlotColor(1, SQColor);
end;
{ If you see this after the alert above then play the squeeze depending on the direction of momentum }
if (BUpperBand > KUpperBand and BlowerBand < KLowerBand) then
begin
SetPlotColor(1, SQBreakoutColor);
end;
{ Plot Momentum }
if CurrentBar = 1 then
ApplicationType = GetAppInfo( aiApplicationType ) ;
LinReg = LinearRegValue(Price, Mlength, 0); // Smooth out the price, you can use close/high/low/average
Mom = Momentum(LinReg, MLength); // Now get the momentum of the above value.
Accel = Momentum(Mom, 1) ; { 1 bar acceleration }
Plot2(Mom, "Momentum") ;
{ Gradient coloring }
if CurrentBar > 1 and UpColor >= 0 and DnColor >= 0 then
begin
ColorLevel = NormGradientColor( Mom, true, ColorNormLength, UpColor, DnColor ) ;
if ApplicationType = 1 then { study is applied to a chart }
SetPlotColor(2, ColorLevel )
else if ApplicationType > 1 then { study is applied to grid app }
begin
SetPlotColor(2, GridForegroundColor) ;
SetPlotBGColor(2, ColorLevel) ;
end;
end;
The following user says Thank You to kjhosken for this post:
Last Updated on November 30, 2020