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

Reply
Old 12-15-2011, 12:25 PM   #1

Join Date: Nov 2011
Posts: 7
Ignore this user

Thanks: 0
Thanked 0 Times in 0 Posts

What Am I Missing with My Slope Calculation Code ?

I seem to be having a little bit of an issue with my slope calculation and was hoping someone could double check that I had written it properly.

The issue is basically that even with the slope degree input adjusted to extremes, some of these flat spots still trigger differently. If working properly the small transition in the middle should have stayed magenta as opposed to going green for 2-3 bars and back to magenta. Am I missing something in my code ?




Here is a snippet of the EasyLanguage code in question.

Code:
Inputs: 
SlopeAv(5); 
 
Vars; 
Slope(0); 
 
Avg = average( Close, length) ; 
Slope =(TLSlopeEasy(Avg,1,SlopeAv)); 
 
if colorMode = 1  
	then setplotcolor[1](1, iff( Avg <Avg [1] and (Slope < .01 ), magenta, green ) ); 
plot1 (Avg , "Avg ");

Below is a snippet from the diagnostics file (area highlighted in blue is where the color shift occurs). Am I missing something ...seems like just the type of scenario I was trying to smooth. The answer could be staring me in the face and I might not be seeing it.

------------------------------------------------------------------------------
1111214 1419Avg 3.48Avg[1] 3.51|slope -0.04|condition FALSE
1111214 1419Avg 3.45Avg[1] 3.48|slope -0.03|condition FALSE
1111214 1420Avg 3.42Avg[1] 3.45|slope -0.03|condition FALSE
1111214 1420Avg 3.40Avg[1] 3.42|slope -0.03|condition FALSE
1111214 1420Avg 3.38Avg[1] 3.40|slope -0.03|condition FALSE
1111214 1420Avg 3.37Avg[1] 3.38|slope -0.02|condition FALSE
1111214 1420Avg 3.36Avg[1] 3.37|slope -0.02|condition FALSE
1111214 1420Avg 3.35Avg[1] 3.36|slope -0.02|condition FALSE
1111214 1421Avg 3.34Avg[1] 3.35|slope -0.01|condition FALSE
1111214 1421Avg 3.34Avg[1] 3.34|slope -0.01|condition FALSE
1111214 1423Avg 3.35Avg[1] 3.34|slope -0.01|condition FALSE
1111214 1424Avg 3.35Avg[1] 3.35|slope -0.00|condition FALSE
1111214 1426Avg 3.35Avg[1] 3.35|slope 0.00| condition FALSE
1111214 1429Avg 3.36Avg[1] 3.35|slope 0.00| condition FALSE
1111214 1429Avg 3.36Avg[1] 3.36|slope 0.00| condition FALSE
1111214 1429Avg 3.36Avg[1] 3.36|slope 0.00| condition FALSE

1111214 1430Avg 3.36Avg[1] 3.36|slope 0.00| condition FALSE
1111214 1430Avg 3.36Avg[1] 3.36|slope 0.00| condition FALSE
1111214 1430Avg 3.36Avg[1] 3.36|slope 0.00| condition FALSE
1111214 1431Avg 3.35Avg[1] 3.36|slope -0.00|condition FALSE

Any help would be much appreciated
Aston01 is offline  
Reply With Quote
Old 12-16-2011, 03:31 AM   #2

Join Date: May 2010
Posts: 180
Ignore this user

Thanks: 0
Thanked 47 Times in 38 Posts

Re: What Am I Missing with My Slope Calculation Code ?

The code you posted is not the code that produced the chart you posted. When asking for help it is best if your chart includes the symbol name in the picture. The symbol should be set to exchange time. This enables calibrating a test case to the aproximately 14:30 time (on this unknown symbol) using some code other than the code you posted.
onesmith is offline  
Reply With Quote
The Following User Says Thank You to onesmith For This Useful Post:
Tams (12-16-2011)
Old 12-16-2011, 06:59 PM   #3

Tradewinds's Avatar

Join Date: Nov 2008
Location: Northeast U.S.
Posts: 891
Ignore this user

Thanks: 373
Thanked 231 Times in 164 Posts
Blog Entries: 6

Re: What Am I Missing with My Slope Calculation Code ?

Quote:
Originally Posted by Aston01 »
the middle should have stayed magenta as opposed to going green for 2-3 bars and back to magenta. Am I missing something in my code ?

if colorMode = 1
then setplotcolor[1](1, iff( Avg <Avg [1] and (Slope < .01 ), magenta, green ) );
plot1 (Avg , "Avg ");
The color is controlled by 'Avg' being up or down since the last bar. Avg <Avg [1]. If you wanted it delayed, wouldn't you need to check multiple bars?

To change color down it would need to pass this test:

Avg <Avg [1] and Avg[1] < Avg [2] and Avg[2] < Avg [3]

otherwise stay the same color, or display a neutral color.

var: ChangeDown(False), ChangeUp(False);

ChangeDown = Avg <Avg [1] and Avg[1] < Avg [2] and Avg[2] < Avg [3];
ChangeUp = Avg >Avg [1] and Avg[1] > Avg [2] and Avg[2] > Avg [3];

if ChangeDown then
setplotcolor[1](1, magenta )
else if ChangeUp then
setplotcolor[1](1, Green );
__________________
Precise, "dialed-in", targeted combination setups, like opening a combination lock; is the experience you should be having while trading. Dial left, right, left, . . . click - the lock opens.
Tradewinds is offline  
Reply With Quote
Old 12-17-2011, 12:27 AM   #4

Do Or Die's Avatar

Join Date: Jun 2011
Posts: 403
Ignore this user

Thanks: 133
Thanked 172 Times in 91 Posts

Re: What Am I Missing with My Slope Calculation Code ?

LOL, just curious as onesmith, how does the software actually calculates slope.
__________________
Fear none, frighten none.
-My Best Contribution So Far
-Open Source Trading Platforms (Master List)
Do Or Die is offline  
Reply With Quote
Old 12-17-2011, 07:49 AM   #5

Join Date: May 2010
Posts: 180
Ignore this user

Thanks: 0
Thanked 47 Times in 38 Posts

Re: What Am I Missing with My Slope Calculation Code ?

The formula for slope is slope=(endprice-startprice)/length; A threshold can be optimized to filter out undesirable slope levels.
Code:
input: threshold(.1);
var: avg(0), slope(0);

avg=average(c,10); 
slope=(avg-avg[10])/10;

if slope > threshold then setplotcolor(1,green) 
else if slope < -threshold then setplotcolor(1,red);

plot1(avg,"avg");
onesmith is offline  
Reply With Quote
Old 12-17-2011, 07:55 AM   #6

Do Or Die's Avatar

Join Date: Jun 2011
Posts: 403
Ignore this user

Thanks: 133
Thanked 172 Times in 91 Posts

Re: What Am I Missing with My Slope Calculation Code ?

Thanks for confirming, that is the classical definition. Many people use the regression line slope also.
__________________
Fear none, frighten none.
-My Best Contribution So Far
-Open Source Trading Platforms (Master List)
Do Or Die is offline  
Reply With Quote
The Following User Says Thank You to Do Or Die For This Useful Post:
tommaso (12-20-2011)
Old 12-20-2011, 07:48 AM   #7

Join Date: Aug 2009
Location: rome
Posts: 26
Ignore this user

Thanks: 2
Thanked 7 Times in 6 Posts

Thumbs up Re: What Am I Missing with My Slope Calculation Code ?

Quote:
Originally Posted by Do Or Die »
Thanks for confirming, that is the classical definition. Many people use the regression line slope also.
another effective (and more robust) way to determine direction (actually a form of "slope") can be the SDX - signed direction index

SDX

Tom
tommaso is offline  
Reply With Quote
The Following User Says Thank You to tommaso For This Useful Post:
Do Or Die (12-20-2011)
Old 12-21-2011, 07:02 AM   #8

Join Date: May 2010
Posts: 180
Ignore this user

Thanks: 0
Thanked 47 Times in 38 Posts

Re: What Am I Missing with My Slope Calculation Code ?

Quote:
Originally Posted by tommaso »
another effective (and more robust) way to determine direction (actually a form of "slope") can be the SDX - signed direction index

SDX

Tom
Tom, I'm trying to translate sdx. Please post source code. From the formula, I understand S=Speed but I don't understand the line below.

S(i) = P(i) - P(i-1) i= 1, ... , k-1

If i represents an index from 1 to 10 what does k represent? ... a 1 point increment in grid? Can you help me visualize k in the code below?

Code:
for i=1 to 10 begin
    s(i)=p(i)-p(i-1);
end;
onesmith is offline  
Reply With Quote
The Following User Says Thank You to onesmith For This Useful Post:
Do Or Die (12-21-2011)

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
Slope of MACD Calculate Angle v101 Technical Analysis 7 07-13-2010 04:33 AM
MA Slope PeterBrazel Coding Forum 4 08-18-2009 12:05 AM
Tick Size Calculation PeterBrazel Coding Forum 1 08-17-2009 08:55 PM
MA Slope PeterBrazel Coding Forum 19 07-05-2009 11:27 PM
Determine Slope End or Start januson Technical Analysis 11 11-20-2008 04:39 PM

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