NexusFi: Find Your Edge


Home Menu

 





converting useful Pine Script into Multicharts code


Discussion in EasyLanguage Programming

Updated
    1. trending_up 5,336 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

converting useful Pine Script into Multicharts code

  #1 (permalink)
traderaaa
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//

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
48 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #2 (permalink)
 SidewalkAerobics 
Los Angels
 
Experience: Intermediate
Platform: MultiChart
Trading: Emini ES
Posts: 115 since Aug 2018
Thanks Given: 173
Thanks Received: 71


traderaaa View Post
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.

Reply With Quote
  #3 (permalink)
 kjhosken 
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;

Follow me on Twitter Reply With Quote
The following user says Thank You to kjhosken for this post:





Last Updated on November 30, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts