PL-Code for Traders' Tips October 2019

Questions about MultiCharts and user contributed studies.
User avatar
LRP
Posts: 153
Joined: 07 Apr 2008
Location: Switzerland
Has thanked: 96 times
Been thanked: 15 times

PL-Code for Traders' Tips October 2019

Postby LRP » 30 Sep 2019

Hi AlI

Is somebody able and so kind to convert this TS-Code from Pawel Kosinski (Traders' Tips 10/2919) to a working MC-PL Code?
http://technical.traders.com/content/ba ... rchive.asp

Thanks a lot

Code: Select all

PaintBar Indicator: BB with Candlesticks

inputs:
Length( 14 ),
NumDevs( 1 ),
Price( close ) ;

variables:
Sdev( 0 ),
BBUpper( 0 ),
BBMid( 0 ),
BBLower( 0 ) ;

method bool IsBullEngulfing()
begin
return ( Close > Open )
and ( Close[1] < Open[1] )
and ( Close > Open[1] )
and ( Open < Close[1] ) ;
end ;

method bool BollingerBandTrigger()
begin
return ( Close[1] < BBLower[1] )
and ( Close > BBLower )
and ( Low < BBLower ) ;
end ;

BBMid = Average( Price, Length ) ;
SDev = StandardDev( Price, Length, 1 ) ;
BBUpper = BBMid + NumDevs * SDev ;
BBLower = BBMid - NumDevs * SDev ;


if IsBullEngulfing() and BollingerBandTrigger() then
begin
PlotPB( High, Low, "Trade Signal" ) ;
Alert( "Trade Signal Long" ) ;
end ;

Code: Select all

Strategy: BB with Candlesticks

inputs:
Length( 20 ),
NumDevs( 2 ),
Price( close ) ;

variables:
Sdev( 0 ),
BBUpper( 0 ),
BBMid( 0 ),
BBLower( 0 ) ;

method bool IsBullEngulfing()
begin
return ( Close > Open )
and ( Close[1] < Open[1] )
and ( Close > Open[1] )
and ( Open < Close[1] ) ;
end ;

method bool BollingerBandTrigger()
begin
return ( Close[1] < BBLower[1] )
and ( Close > BBLower )
and ( Low < BBLower ) ;
end ;

BBMid = Average( Price, Length ) ;
SDev = StandardDev( Price, Length, 1 ) ;
BBUpper = BBMid + NumDevs * SDev ;
BBLower = BBMid - NumDevs * SDev ;


if IsBullEngulfing() then
Plot1( High ) ;

if BollingerBandTrigger() then
PLot2( Low ) ;

Plot3( BBUpper ) ;
Plot4( BBLower ) ;

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: PL-Code for Traders' Tips October 2019

Postby rrams » 30 Sep 2019

I didn't have access to read the article, so I don't know what lesson the author is trying to teach.
I assume you wanted the signal to test.
Attachments
BB with Candlesticks.pla
(2.67 KiB) Downloaded 163 times

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: PL-Code for Traders' Tips October 2019

Postby rrams » 03 Oct 2019

After finally being able to read the article by Pawel Kosinski, I can see that his trading method is more complicated than the included TS code someone else wrote and his system is designed to be run on all the stocks in the S&P 500; not futures. Not even his NT script is written how he describes in the article. For one thing the share size is fixed and he describes a fixed dollar amount.

It's kind of comical just how difficult to nail down exactly what those article writers did so you can recreate thier results. I would never recomend this trading system because it has significant flaws in survivorship bias that are magnifyed by long only testing during a strong bullish market regime. But here is another version I wrote with everything in it that he explained. I haven't tested it yet. You can look it over and let me know if you find any flaws.

Code: Select all

// Signal by rrams derived from October 2019 Technical Analysis of Stocks &
// Commodities, Trader's Tips article entitled Bollinger Bands with Candlesticks.
// Designed for daily bars of S&P 500 stocks with Data 2 containing SPY ETF.
inputs: Length(20), NumDevs(2.2), Mult(3); // NumDevs=(1.8-2.2) Mult=(2-4)
vars: BBUp(0), BBLo(0), BE(False), BB(False), SL(0), RR(0), D2(True);
if C<5 or C>500 or V<100000 or Symbol_Length<500 then #return;
// Bullish Engulfing pattern
BE=C[2]<O[2] and O[1]<C[2] and C[1]>O[2] and C>H[1] and C[1]-O[1]>20*TickSize;
BBUp=Average(C, Length)+NumDevs*StandardDev(C, Length, 1);
BBLo=Average(C, Length)-NumDevs*StandardDev(C, Length, 1);
// Bollinger Band trigger
BB=(C[1]>BBLo[1] and L[1]<BBLo[1]) or L[2]<BBLo[2];
// ATR Stop Loss
SL=Mult*AvgTrueRange(14);
// Reward to Risk Ratio
RR=100*(BBUp-H)/(H-SL);
// Comment out if you don't want to use a second data source for confirmation.
D2=Average(C Data2, 100)>Average(C Data2, 400);
if marketposition=0 and BE and BB and RR>1.0 and D2 then buy next bar market;
if marketposition>0 and H>BBUp then sell next bar market;
SetStopLoss(SL);

User avatar
LRP
Posts: 153
Joined: 07 Apr 2008
Location: Switzerland
Has thanked: 96 times
Been thanked: 15 times

Re: PL-Code for Traders' Tips October 2019

Postby LRP » 03 Oct 2019

Cool, thanks a lot rrams, you pointed it out! I will have a look at your suggested Code asap.
Kind regards, Rob


Return to “MultiCharts”