Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 04-09-2009, 12:05 PM   #1

Join Date: Oct 2008
Location: new york
Posts: 54
Ignore this user

Thanks: 17
Thanked 8 Times in 4 Posts

Help Understanding This Code

i want to use the following code in my indicator.
however, i cannot read it correctly as what its doing.
i am an ok TS programmer. i have my own indictor that i am working on.
i want to integrate the following code so that it only draws the buy or sell lines when i am long or short.

right now it works completly independent of my code. please help!




{Type : Indicator, Name : Variable Volatility Stops}

INPUT: LENGTH (21), CONST(3.05);

vaR: SWITCH(1), TR(0), ARC(0), SAR(0),HISIC(0),LOSIC(0);

TR= VOLATILITY (LENGTH);
ARC= TR* CONST;
IF CURRENTbar = length then begin
hisic=c;
losic=c;
if h>= xaverage (h,length-1) [1] then begin
hisic= highest(c,length);
Sar=hisic-arc;
switch= 1;
end;
if l <= xaverage (l,length-1) [1] then begin
losic= lowest (c,length);
sar = losic +arc;
switch=0;
end;
end;

if switch =1 then begin
if c>hisic then hisic=c;
sar=hisic - arc;
if c< sar then begin
switch=0;
losic=c;
sar = losic + arc;
end;

end;
if switch=0 then begin
if c< losic then losic=c;
sar= losic +arc;
if c> sar then begin
switch=1;
hisic=c;
saR=HISIC- ARC;
END;
END;

IF C > SAR { AND C[1] < SAR } THEN

Plot1(SAR,"Sell");

IF C < SAR { AND C[1] > SAR} THEN

Plot2(sar,"Buy");
ephi144 is offline  
Reply With Quote
Old 04-09-2009, 12:10 PM   #2

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Help Understanding This Code

SWITCH is a reserved word. You cannot use it as a variable.
Tams is offline  
Reply With Quote
Old 04-09-2009, 07:10 PM   #3

Join Date: Oct 2008
Location: new york
Posts: 54
Ignore this user

Thanks: 17
Thanked 8 Times in 4 Posts

Re: Help Understanding This Code

yeah but it still works. nonetheless, i think might have it figured out.
ephi144 is offline  
Reply With Quote
Old 04-09-2009, 10:15 PM   #4

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Help Understanding This Code

I don't understand what you need.
Tams is offline  
Reply With Quote
The Following User Says Thank You to Tams For This Useful Post:
ephi144 (04-10-2009)
Old 04-09-2009, 11:03 PM   #5

Join Date: Feb 2007
Location: US
Posts: 314
Ignore this user

Thanks: 86
Thanked 206 Times in 89 Posts

Re: Help Understanding This Code

Use the TS I_MarketPosition (Reserved Word) to show volatility stop only when a position is in the market. Strategy not included, code can be verified as indicator or showme.

I_MarketPosition can only be used in a study.

I_MarketPosition will only return a value if a strategy is applied to the same data.


Code:
inputs:  
     ATRLength( 10 ) ,  
     NumATRs( 3 ) ; 
 
variables:  
     ATRCalc( 0 ),  
     MP( 0 ),  
     PosHigh( 0 ),  
     PosLow( 0 ) ; 
 
ATRCalc = AvgTrueRange( ATRLength ) * NumATRs ; 
MP = I_MarketPosition ; 
 
if MP > 0 then 
     begin 
     if MP[1] <> 1 or High > PosHigh then  
          PosHigh = High ;  
     Plot1( PosHigh - ATRCalc, "Plot1" ) ; 
     end   
else 
     if MP < 0 then  
          begin 
          if MP[1] <> -1 or Low < PosLow then  
               PosLow = Low ; 
          Plot2 (PosLow + ATRCalc, "Plot2"); 
          end ;
Attached Thumbnails
Help Understanding This Code-mp_-i_marketposition.gif  
thrunner is offline  
Reply With Quote
The Following User Says Thank You to thrunner For This Useful Post:
ephi144 (04-10-2009)
Old 04-10-2009, 09:28 AM   #6

Join Date: Oct 2008
Location: new york
Posts: 54
Ignore this user

Thanks: 17
Thanked 8 Times in 4 Posts

Re: Help Understanding This Code

hi guys,

thank you for helping me. i just wanted to know what the heck the code was doing. i wanted the sar to paint based on my position. if u use the code as an indicator you will see that the it switches to long or short whenever the price closes above the SAR value.
which did not play well within my code.


i think i have it figured out. as well as therunners help is making much more sense now.
i will try to integrate your code within my strategy today.
however, i have made the following changes. please let me know if the following looks ok to make sure i was understanding the code correctly.



TR= VOLATILITY (VOL_LENGTH);
ARC= TR * VOL_CONST;
IF CURRENTbar = length then begin
HISIC = close;
LOSIC = close;
if high >= xaverage (high,VOL_LENGTH-1) [1] then begin
HISIC = highest(close,VOL_LENGTH) ;
SAR = HISIC-arc;
SWITCH_IT= 1;
end;
if low <= xaverage (low,VOL_LENGTH-1) [1] then begin
LOSIC = lowest (close,VOL_LENGTH);
SAR = LOSIC + ARC;
SWITCH_IT=0;
end;
end;

if SWITCH_IT = 1 then begin
if close >hisic then hisic = close;
SAR = hisic - arc;
if close < SAR and AreWeShort = true then begin
SWITCH_IT = 0;
LOSIC = close;
SAR = LOSIC + ARC;
end;
end;
if SWITCH_IT=0 then begin
if close < losic then losic = close;
SAR = losic +arc;
if close > SAR and AreWeLong = true then begin
SWITCH_IT = 1;
HISIC = close;
SAR = HISIC- ARC;
END;
END;
ephi144 is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Understanding Put Options januson Beginners Forum 5 10-02-2008 11:18 PM
Help understanding the Tape. Yigal E-mini Futures Trading Laboratory 16 04-11-2007 11:55 PM
[Understanding the TICK] Soultrader Trading Videos 14 03-12-2007 12:29 AM
Understanding the TICK Soultrader Market Internals 3 08-20-2006 06:55 PM
[Understanding the TRIN] by The Lab Soultrader Trading Videos 0 08-07-2006 02:05 AM

All times are GMT -4. The time now is 12:48 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.