converting useful Pine Script into Multicharts code - futures io
futures io futures trading



converting useful Pine Script into Multicharts code


Discussion in EasyLanguage Programming

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

converting useful Pine Script into Multicharts code

(login for full post details)
  #1 (permalink)
hong kong
 
 
Posts: 1 since Jun 2020
Thanks: 0 given, 0 received

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 futures io?
Locate candles 15 cent
ThinkOrSwim
VWAP Scanner
ThinkOrSwim
S&P 500 from 1789 until today: free data
Emini and Emicro Index
the link between CFDs brokers and bank spot liquidity?
Currencies
Market trading data-streaming or gaming in NT8?
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Big Mike in Ecuador
166 thanks
How did you learn to trade?
101 thanks
2020 profit and loss results
40 thanks
NT8 making rules up as they go along?
37 thanks
Finally Turning the Corner, tha "its 80% Psychology" thing...
31 thanks
 
(login for full post details)
  #2 (permalink)
Los Angels
 
Experience: Intermediate
Platform: MultiChart
Trading: Emini ES
 
Posts: 115 since Aug 2018
Thanks: 173 given, 70 received


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
 
(login for full post details)
  #3 (permalink)
Seattle, WA/USA
 
Experience: Intermediate
Platform: TOS, TS
Trading: Forex, crude
 
Posts: 86 since Sep 2016
Thanks: 7 given, 31 received


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


futures io Trading Community Platforms and Indicators EasyLanguage Programming > converting useful Pine Script into Multicharts code


Last Updated on November 30, 2020


Upcoming Webinars and Events
 

Journal Challenge!

February
 

Battlestations!

March
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts