code debug

Questions about MultiCharts and user contributed studies.
liang323
Posts: 27
Joined: 12 Mar 2006

code debug

Postby liang323 » 02 May 2008

hi guys,

anyone have the code or knows how to code a volatility-based stop for multicharts?
Last edited by liang323 on 06 May 2008, edited 5 times in total.

liang323
Posts: 27
Joined: 12 Mar 2006

Postby liang323 » 02 May 2008

Hello, I have tried to convert the VT-Trader codes into EasyLanguage, but somehow it is not plotting as what it supposed to be comparing with VT's Chart that i attached above.

Could anyone help to identify what I did wrong in the code? I have attached a screen shot of the plotted indicator in MC, it doesn't looks right, the red line is the trailing stop indicator. Thanks!
Here is the code in EasyLanguage:

Code: Select all

inputs:   
ATRLength( 14 ), SmthLength( 14 ), Factor( 2.824 );

variables:
DeltaStop( 0 ), TrStop( 0 );

DeltaStop = Factor * XAverage(AvgTrueRange( ATRLength ), SmthLength);

If Close = TrStop[1] then
TrStop = TrStop[1];

If Close[1] <= TrStop[1] and Close < TrStop[1] then
TrStop = minlist(TrStop[1], (Close+DeltaStop));

If Close[1] >= TrStop[1] and Close > TrStop[1] then
TrStop = maxlist(TrStop[1], (Close-DeltaStop));

If Close > TrStop[1] then
TrStop = Close - DeltaStop
else TrStop = Close + DeltaStop;

Plot1(TrStop, "Trailing Stop");
Last edited by liang323 on 19 May 2008, edited 2 times in total.

SUPER
Posts: 624
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Postby SUPER » 03 May 2008

Try this out:

Code: Select all

inputs:   
ATRLength( 14 ), SmthLength( 14 ), Factor( 2.824 );

variables:
DeltaStop( 0 ), TrStop( 0 );

DeltaStop = Factor * XAverage(AvgTrueRange( ATRLength ), SmthLength);

If Close = TrStop[1] then
TrStop = TrStop[1]
else
If Close[1] <= TrStop[1] and Close < TrStop[1] then
TrStop = minlist(TrStop[1], (Close+DeltaStop))
else
If Close[1] >= TrStop[1] and Close > TrStop[1] then
TrStop = maxlist(TrStop[1], (Close-DeltaStop))
else
If Close > TrStop[1] then
TrStop = Close - DeltaStop
else
TrStop = Close + DeltaStop;

Plot1(TrStop, "TrailingStop");


liang323
Posts: 27
Joined: 12 Mar 2006

Postby liang323 » 03 May 2008

hi Super, it works now, thanks very much for the help man! I forgot the IFs should be nested.

all the best to your trading man!


Return to “MultiCharts”