TRAILING RESISTANCE &ND SUPPORT STOPS (TR&NDS)

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
LTG
Posts: 30
Joined: 08 Sep 2009

TRAILING RESISTANCE &ND SUPPORT STOPS (TR&NDS)

Postby LTG » 23 Sep 2009

I noticed that the monthly Trader Tips section of S&C offers various codes based on trading strategy pieces written that month for a lot of charting programs including:

TS, Esignal, Wealthlab, Metastock etc...

is there a reason MC isn't up there as well?

http://traders.com/Documentation/FEEDbk ... sTips.html

tcat
Posts: 166
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Postby tcat » 23 Sep 2009

TS code can be used as such. In power language editor, create a new signal named VTSR, Cut & Paste the code, // the first line and compile.
Thierry

LTG
Posts: 30
Joined: 08 Sep 2009

Postby LTG » 23 Sep 2009

Why isn't MC there as a vendor though? I tried to use the code below but it won't compile:

Code: Select all

inputs:
TrailType ( 1 ), { enter 1 for modified version, any
other number for unmodified version }
ATR_Period( 5 ),
ATR_Factor( 3.5 ),
Quantity( 100 ),
InitialMonth( 1 ),
InitialDay( 1 ),
InitialYear( 2009 ),
FirstTrade( 1 ) ; { enter 1 for long, any other
number for short }

variables:
Loss( 0 ),
HiLo( 0 ),
HRef( 0 ),
LRef( 0 ),
HiLoHRefMax( 0 ),
HiLoHRefMaxLRefMax( 0 ),
ATRMod( 0 ),
WaitingForEntry( true ),
Trail( 0 ),
LineNum( 0 ),
ReturnVal( 0 ) ;

if TrailType <> 1 then
Loss = ATR_Factor * AvgTrueRange( ATR_Period )
else
begin
HiLo = iff( High - Low < 1.5 * Average( High - Low,
ATR_Period ), High - Low, 1.5 * Average( High -
Low, ATR_Period ) ) ;
HRef = iff( Low <= High[1], High - Close[1],( High -
Close[1] ) - 0.5 * ( Low - High[1] ) ) ;
LRef = iff( High >= Low[1], Close[1] - Low,
( Close[1] - Low ) - 0.5 * ( Low[1] - High ) ) ;
HiLoHRefMax = Maxlist( HiLo, HRef ) ;
HiLoHRefMaxLRefMax = Maxlist( HiLoHRefMax, LRef ) ;
ATRMod = XAverage( HiLoHRefMaxLRefMax, 2 *
ATR_Period - 1 ) ;
Loss = ATR_Factor * ATRMod ;
end ;

if WaitingForEntry
and Year( Date ) + 1900 >= InitialYear
and Month( Date ) >= InitialMonth
and DayOfMonth( Date ) >= InitialDay
then
begin
if FirstTrade = 1 then
begin
Buy Quantity shares this bar Close ;
WaitingForEntry = false ;
Trail = Close - Loss ;
end
else
begin
Sell short Quantity shares this bar at Close ;
WaitingForEntry = false ;
Trail = Close + Loss ;
end ;
end
else if WaitingForEntry[1] = false then
begin
if Close > Trail[1] and Close[1] > Trail[2] then
{ continued long }
Trail = MaxList( Trail[1], Close - Loss )
else if Close < Trail[1] and Close[1] < Trail[2]
then
{ continued short }
Trail = MinList( Trail[1], Close + Loss )
else if Close > Trail[1] then
{ close is above trail }
Trail = Close - Loss
else
Trail = Close + Loss ;

if MarketPosition = -1 and Close > Trail and
Trail > 0 then
begin
Buy Quantity shares this bar Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end
else if MarketPosition = 1 and Close < Trail then
begin
Sell short Quantity shares this bar at Close ;
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail[1] ) ;
ReturnVal = TL_SetColor( LineNum, Magenta ) ;
end
else if Trail[1] > 0 then
begin
LineNum = TL_New( Date[1], Time[1], Trail[1],
Date, Time, Trail ) ;
if Close > Trail then
ReturnVal = TL_SetColor( LineNum, Magenta )
else
ReturnVal = TL_SetColor( LineNum, Cyan ) ;
end ;
end ;

User avatar
TJ
Posts: 7458
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 999 times
Been thanked: 2137 times

Postby TJ » 23 Sep 2009

Why isn't MC there as a vendor though?

because a lot of the articles are OLD --- before the invention of MultiCharts.

User avatar
TJ
Posts: 7458
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 999 times
Been thanked: 2137 times

Postby TJ » 23 Sep 2009

I tried to use the code below but it won't compile:

it would help if you post the error message.

LTG
Posts: 30
Joined: 08 Sep 2009

Postby LTG » 23 Sep 2009

that would help:

------ Compiled with error(s): ------
syntax error, unexpected ';', expecting 'end of file'
errLine 104, errColumn 0, errLineEnd 104, errColumnEnd 0

tcat
Posts: 166
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Postby tcat » 23 Sep 2009

Sorry, both the codes on the S&C site and the code you posted here compiled and ran successfully for me.

User avatar
TJ
Posts: 7458
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 999 times
Been thanked: 2137 times

Postby TJ » 23 Sep 2009

that would help:

------ Compiled with error(s): ------
syntax error, unexpected ';', expecting 'end of file'
errLine 104, errColumn 0, errLineEnd 104, errColumnEnd 0

I have compiled, both the article code and your modified code, with no problem.

I am using PLE 5.5.2723.400

LTG
Posts: 30
Joined: 08 Sep 2009

Postby LTG » 23 Sep 2009

think the problem was me using indicator rather than signal. it compiles now.


Return to “User Contributed Studies and Indicator Library”