Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Real Code Help Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
douga98
Posted : Monday, January 28, 2008 4:02:21 PM
Registered User
Joined: 11/16/2007
Posts: 127
I would like to do something like the following

'# CoT = indicator.CountofTest11
Dim aaa As Single
aaa = Cot.value
Plot= aaa

I would like to do this on Chart 1 but CoT coming from Chart 2 and maybe Chart 2 on a different time frame.
Kuf
Posted : Monday, January 28, 2008 5:03:34 PM


Administration

Joined: 9/18/2004
Posts: 3,522
Cross chart calculations are not supported in RealCode.

Ken Gilb (Kuf)
Chief Software Engineer - Worden Brothers Inc.
Try/Catch - My RealCode Blog
douga98
Posted : Monday, January 28, 2008 5:08:54 PM
Registered User
Joined: 11/16/2007
Posts: 127
Can I write to a file and then read from the file (spreadsheet)?

What I want to do is use weekly data on a daily chart. Any suggestions?
Kuf
Posted : Monday, January 28, 2008 5:35:34 PM


Administration

Joined: 9/18/2004
Posts: 3,522
What do you want to do with the weekly data? You could make your own weekly data out of the daily data in your own custom indicator.

Please elaborate and maybe we can show you how to write it.

Ken Gilb (Kuf)
Chief Software Engineer - Worden Brothers Inc.
Try/Catch - My RealCode Blog
douga98
Posted : Monday, January 28, 2008 6:04:58 PM
Registered User
Joined: 11/16/2007
Posts: 127
QUOTE (Kuf)
What do you want to do with the weekly data? You could make your own weekly data out of the daily data in your own custom indicator.

Please elaborate and maybe we can show you how to write it.


One example would be to draw a weekly Pivot Line (PP). Weekly PP are calculated as of close on Friday not everyday. The Fri PP is plotted as a constant for each of the next five days when it is recalulated and used starting the following Monday.

current PP = 0
If Monday then PP =(price.high + price.low + price.close)/3  {price.high etc are the previous weeks high and low and  Friday close}
End If
Plot PP

In this way PP would be updated each Monday and then used each day until the next Monday.
Kuf
Posted : Monday, January 28, 2008 6:58:48 PM


Administration

Joined: 9/18/2004
Posts: 3,522
Here is your pivot point code. It requires build 58 (to be released this week) that has the new Me.CurrentDate property.


Static PP As Single = 0
Dim currDate As Date = Me.CurrentDate
Dim newPP As Single = 0

If currdate.DayOfWeek = System.DayOfWeek.Friday Then
    plot = pp
    pp = (price.high + price.low + price.close)/3   
Else
    plot = pp
End If


Ken Gilb (Kuf)
Chief Software Engineer - Worden Brothers Inc.
Try/Catch - My RealCode Blog
douga98
Posted : Monday, January 28, 2008 11:03:07 PM
Registered User
Joined: 11/16/2007
Posts: 127
Thanks you are a true Wizard.
Reno
Posted : Tuesday, January 29, 2008 2:18:58 PM
Registered User
Joined: 7/23/2006
Posts: 9
thanks Kuf
billion
Posted : Wednesday, May 28, 2008 5:57:45 PM
Registered User
Joined: 2/8/2005
Posts: 81

I need some advises in extending the weekly PP.

(1) How could I extend this to monthly PP, in recalculating the PP on the close of the last trading day of the month?

(2) Can I make a UserInput to switch between Daily, Weekly, and Monthly PP using the same RealCode Indicator.

(3) Can I combine R1/R2/S1/S2 into the same RealCode Indicator with different colors and, even better, line thickness?

(4) I will need to overlay this to Price Chart so I assume Copy-and-paste would work with the fancy Real Code plots.

Thanks.

tozwp
Posted : Thursday, May 29, 2008 8:29:18 AM
Registered User
Joined: 1/22/2005
Posts: 16
Is it possible to draw only the horizontal portion of the plot (i.e., eliminate the vertical transition line drawn between Friday and Monday)?

Thanks.

tozwp...
billion
Posted : Monday, June 2, 2008 3:21:05 PM
Registered User
Joined: 2/8/2005
Posts: 81
Hi Bruce,

     Do you have any insights to my questions? Or my questions serve as suggestions to future releases?

     Thanks,

Billion-

QUOTE (billion)

I need some advises in extending the weekly PP.

(1) How could I extend this to monthly PP, in recalculating the PP on the close of the last trading day of the month?

(2) Can I make a UserInput to switch between Daily, Weekly, and Monthly PP using the same RealCode Indicator.

(3) Can I combine R1/R2/S1/S2 into the same RealCode Indicator with different colors and, even better, line thickness?

(4) I will need to overlay this to Price Chart so I assume Copy-and-paste would work with the fancy Real Code plots.

Thanks.

Bruce_L
Posted : Tuesday, June 3, 2008 1:41:05 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
billion,
The following RealCode can be used to Plot the Daily, Weekly or Monthly PP, R1, S1, R2, S2, R3 or S3 using the underlying data as the basis (the Charted Time Frame should be the same or shorter than the Indicator's Time Frame - and in Weekly, the Charted Time Frame should not be the same, it should be shorter):

'# PointType = UserInput.String = PP
'# TimeFrame = UserInput.String = D
Static Time As Date
Static High(1) As Single
Static Low(1) As Single
Static Close(1) As Single
If isFirstBar Then
    Time = CurrentDate
    High(0) = Price.High
    Low(0) = Price.Low
    Close(0) = Price.Last
    High(1) = Single.NaN
    Low(1) = Single.NaN
    Close(1) = Single.NaN
End If
If (TimeFrame = "D" And _
    Time.DayOfYear <> CurrentDate.DayOfYear) Or _
    (TimeFrame = "W" And _
    Time.DayOfWeek > CurrentDate.DayOfWeek) Or _
    (TimeFrame = "M" And _
    Time.Month <> CurrentDate.Month) Or _
    (TimeFrame = "Y" And _
    Time.Year <> CurrentDate.Year) Then
        High(1) = High(0)
        Low(1) = Low(0)
        Close(1) = Close(0)
        High(0) = Price.High
        Low(0) = Price.Low
        Close(0) = Price.Last
End If
If PointType = "PP" Then
    Plot = (High(1) + Low(1) + Close(1)) / 3
Else If PointType = "S1" Then
    Plot = 2 * (High(1) + Low(1) + Close(1)) / 3 - High(1)
Else If PointType = "S2" Then
    Plot = (High(1) + Low(1) + Close(1)) / 3 - High(1) + Low(1)
Else If PointType = "S3" Then
    Plot = Low(1) - 2 * (High(1) - (High(1) + Low(1) + Close(1)) / 3)
Else If PointType = "R1" Then
    Plot = 2 * (High(1) + Low(1) + Close(1)) / 3 - Low(1)
Else If PointType = "R2" Then
    Plot = (High(1) + Low(1) + Close(1)) / 3 + High(1) - Low(1)
Else If PointType = "R3" Then
    Plot = High(1) + 2 * ((High(1) + Low(1) + Close(1)) / 3 - Low(1))
End If
Time = CurrentDate
High(0) = System.Math.Max(High(0),Price.High)
Low(0) = System.Math.Min(Low(0),Price.Low)
Close(0) = Price.Last

It does not Plot all of the Indicators as one Indicator. You need to have an Indicator for each Plot with the appropriate settings (you should be able to see from looking at the RealCode how to specify the Time Frame and Pivot Point Type. Copy and Paste should work.

The first Plotted Pivot Point will most likely be plotted using only a partial Day, Week, Month or Year of data as it starts plotting the first time the data enters a new Day, Week, Month or Year.

tozwp,
I do not know of a way to get rid of the non-horizontal portions of a Line Plot.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
billion
Posted : Tuesday, June 3, 2008 2:10:09 PM
Registered User
Joined: 2/8/2005
Posts: 81
Thanks, Bruce.  I will try it out today.  The flexibility of RealCode is just fantastic.   Can we expect a more comprehensive user guide for RealCode sometime soon?

Thanks and best regards
Bruce_L
Posted : Tuesday, June 3, 2008 2:17:21 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
billion,
I don't have some sort of "inside track" on RealCode and I'm not a programmer. Everything I know about RealCode was learned from the RealCode Programmer's Reference.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
billion
Posted : Tuesday, June 3, 2008 5:16:19 PM
Registered User
Joined: 2/8/2005
Posts: 81
Bruce, I am a programmer (not in VB though) and I am ashamed. :)
billion
Posted : Tuesday, June 3, 2008 7:41:22 PM
Registered User
Joined: 2/8/2005
Posts: 81
I checked out Bruce's RealCode and compared the weekly PP with Kuf's code above. They somehow dont behave the same.

(1) Kuf's RealCode referenced System.DayOfWeek.Friday. I am not clear how Bruce's RealCode tells Friday of a week.

      (Question) Is there a correspondence for the last trading day of a month, just like the Friday of a week? Does Bruce's RealCode automatically consider the last trading day of a week in W and the last trading day of a month in M?

(2) Kuf's RealCode is designed for the "weekly chart with weekly PP" instead of the "daily chart with weekly PP". 

     (Question) While this looks like an easy fix by checking the high/low of the last 5 bars, how could I consider the holidays that would make short trading weeks (4 trading days or less in a week)?

     (Question) How could I get the high/low of the current month, in the daily chart, given the number of trading days is different?

(3) I am still trying to figure out Bruce's RealCode in depth.

To make this simpler, I am mainly interested in having monthly PP with a daily chart. Any suggestions?

Thanks and regards,

(tozwp) If you like me, you may change the Style to Shape instead of Line.
Bruce_L
Posted : Tuesday, June 3, 2008 9:43:08 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (billion)
I checked out Bruce's RealCode and compared the weekly PP with Kuf's code above. They somehow dont behave the same.

In looking at Kuf's RealCode, it seems to calculate the PP using:

pp = (price.high + price.low + price.close)/3

This works when the data is Weekly, but if the charted data is Daily, it bases the Pivot Point entirely on Friday's data. I believe this is the primary cause of the differences when this is plotted on a Daily Chart when TimeFrame is set to W and PointType is set to PP in my version.

QUOTE (billion)
Kuf's RealCode referenced System.DayOfWeek.Friday. I am not clear how Bruce's RealCode tells Friday of a week.

      (Question) Is there a correspondence for the last trading day of a month, just like the Friday of a week? Does Bruce's RealCode automatically consider the last trading day of a week in W and the last trading day of a month in M?

My RealCode doesn't check for Fridays. It's actually checking for Mondays although it is a bit more flexible than just looking for Monday. It uses the following RealCode to do this:

If Time.DayOfWeek > CurrentDate.DayOfWeek Then

It checks for the Current Date to have a Day of the Week that is less then the Day of the Week for the Previous Bar (where Monday = 1 and Friday = 5). This should automatically account for short weeks (although in looking at your questions and re-examining my code, it doesn't work for Weekly Charts at all, just for Time Frames shorter than Weekly).

When TimeFrame is set to M, it uses the following RealCode to determine when the Month changes:

If Time.Month <> CurrentDate.Month Then

QUOTE (billion)
Kuf's RealCode is designed for the "weekly chart with weekly PP" instead of the "daily chart with weekly PP". 

     (Question) While this looks like an easy fix by checking the high/low of the last 5 bars, how could I consider the holidays that would make short trading weeks (4 trading days or less in a week)?

I think you are getting at my first point that Kuf's RealCode is based entirely on Friday's values when used on Daily data. I use System.Math.Min and System.Math.Max to keep track of the Highs and Lows during the Week.

QUOTE (billion)
(Question) How could I get the high/low of the current month, in the daily chart, given the number of trading days is different?

The same technique I used for Weekly works for Monthly as well.

QUOTE (billion)
I am still trying to figure out Bruce's RealCode in depth.

To make this simpler, I am mainly interested in having monthly PP with a daily chart. Any suggestions?

One of the big faults I have in writing code as a non-programmer is a lack of proper in code documentation using comments (then again, that might just be a bad habit). To get a Monthly PP on a Daily Chart just set the TimeFrame to M and the PointType to PP in the QuickEdit for the RealCode I provided and change the Chart Time Frame to Daily.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
billion
Posted : Wednesday, June 4, 2008 3:39:18 AM
Registered User
Joined: 2/8/2005
Posts: 81
Hi Bruce, thanks a billion for the detailed explanation. That really helps.

I figured out a typo in your RealCode; Low(0) = System.Math.Max(Low(0),Price.Low) should be System.Math.Min().  With this fix, it looks great in my chart and I can even get the yearly PP easily.

BTW, do you have the list of member properties associated with Date, in addition to Hour, Month, DayOfWeek, and DayOfYear? Why is DayOfMonth not made available?

Thanks and regards.
Bruce_L
Posted : Wednesday, June 4, 2008 8:30:39 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
No, I don't have a list. I just start typing something I want, hit the period key (.) on my keyboard and look at what pops up as possible ways to complete what I started. That said, such lists do exist on the internet. You just need to search for VB or Visual Basic and what you want.

I will correct the System.Math.Min issue in my code (I wanted to adjust the RealCode to avoid repeating the sequence that happens whenever you hit a new Day, Week or Month anyway).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
takacsj
Posted : Sunday, August 31, 2008 1:12:31 AM
Registered User
Joined: 11/24/2006
Posts: 9
QUOTE (Kuf)
Here is your pivot point code. It requires build 58 (to be released this week) that has the new Me.CurrentDate property.


Static PP As Single = 0
Dim currDate As Date = Me.CurrentDate
Dim newPP As Single = 0

If currdate.DayOfWeek = System.DayOfWeek.Friday Then
    plot = pp
    pp = (price.high + price.low + price.close)/3   
Else
    plot = pp
End If


I'm a newbie when it comes to Blocks code, however I do have several years of Java and a few years of Python programming under my belt.  I can't see where your code knows that PP is the prior week's (H+L+C)/3.
takacsj
Posted : Sunday, August 31, 2008 1:24:26 AM
Registered User
Joined: 11/24/2006
Posts: 9
OK, what I would like to do is the following.

In the price chart see:

1)  A 3 year pivot.  This 3 year pivot would be going back 3 years from 31 Dec 2007.
2)  A 3 quarter pivot.  This pivot would be for 3 quarters, going back from 30 June 2008.
3) A 3 month pivot.  This pivot would be for 3 months going back from 31 Aug 2008.
4)  A 3 week pivot.  This pivot would be for 3 weeks, going back from any previous Friday.

Any quick start ideas.
takacsj
Posted : Saturday, September 6, 2008 7:20:34 PM
Registered User
Joined: 11/24/2006
Posts: 9
Any ideas on above?

Is it better to create a new thread?
jschott
Posted : Saturday, January 24, 2009 11:03:41 PM
Registered User
Joined: 10/27/2004
Posts: 821
Location: Philly area

Also take a look at the "real code help" in Blocks 3.1 forum where Kuf and Bruce provide some "stealable" code in answer to questions about Pivot Points.  It's long but some good code snippets can be lifted and adapted for use.

Bruce_L
Posted : Monday, January 26, 2009 9:38:09 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
The Sunday, August 31, 2008 1:24:26 AM ET post was also made in Advanced Pivot help where it received an answer.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.