Page 1 of 1

TRAILING RESISTANCE &ND SUPPORT STOPS (TR&NDS)

Posted: 23 Sep 2009
by LTG
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

Posted: 23 Sep 2009
by tcat
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

Posted: 23 Sep 2009
by LTG
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 ;

Posted: 23 Sep 2009
by TJ
Why isn't MC there as a vendor though?

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

Posted: 23 Sep 2009
by TJ
I tried to use the code below but it won't compile:

it would help if you post the error message.

Posted: 23 Sep 2009
by LTG
that would help:

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

Posted: 23 Sep 2009
by tcat
Sorry, both the codes on the S&C site and the code you posted here compiled and ran successfully for me.

Posted: 23 Sep 2009
by TJ
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

Posted: 23 Sep 2009
by LTG
think the problem was me using indicator rather than signal. it compiles now.