How to store the price at daily specific time?

Questions about MultiCharts and user contributed studies.
elvis1984
Posts: 6
Joined: 19 Sep 2013
Has thanked: 1 time

How to store the price at daily specific time?

Postby elvis1984 » 10 Oct 2013

for example, I want to use the price at 9:00 2 days ago or the vwap close of market yesterday?

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to store the price at daily specific time?

Postby TJ » 10 Oct 2013

for example, I want to use the price at 9:00 2 days ago or the vwap close of market yesterday?
if you want to store a specific price at a specific time...

Code: Select all

var:
specific.price(0),
specific.time(0);

if time = specific.time then special.price = close;
The above will hold the value for a day... until you encounter 9:00 again the next day. At which time the variable will be replenished with the current price.

If you need to access multiple day's historic data, you will need to create an ARRAY.

clonardo
Posts: 16
Joined: 27 Sep 2013
Has thanked: 1 time
Been thanked: 1 time

Re: How to store the price at daily specific time?

Postby clonardo » 11 Oct 2013

Bars.TimeValue gives you what you need. Example:

Code: Select all

if ((Bars.TimeValue.Month == 9) && (Bars.TimeValue.Year == 2011)) {do whatever}
you can set this for hours, minutes, date, etc.

edit- sorry, I seem to have wandered over from the MC.NET forum. This is the C# answer.

elvis1984
Posts: 6
Joined: 19 Sep 2013
Has thanked: 1 time

Re: How to store the price at daily specific time?

Postby elvis1984 » 12 Oct 2013

Bars.TimeValue gives you what you need. Example:

Code: Select all

if ((Bars.TimeValue.Month == 9) && (Bars.TimeValue.Year == 2011)) {do whatever}
you can set this for hours, minutes, date, etc.

edit- sorry, I seem to have wandered over from the MC.NET forum. This is the C# answer.
Would you give me a example using array to solve this problem? Since in the above answer, you still cant quote the price efficiently. special.price will be(0,0,0...,close[1],0,..0,close,0,0,...) how to save to (...,close_900_[1],close_900...)
Thanks

clonardo
Posts: 16
Joined: 27 Sep 2013
Has thanked: 1 time
Been thanked: 1 time

Re: How to store the price at daily specific time?

Postby clonardo » 12 Oct 2013

Here, I've done it with ArrayList and printing the close price from 2 days ago in the Output window of the PL.NET editor-

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using System.Collections;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
public class bars2daysback : SignalObject {
public bars2daysback(object _ctx):base(_ctx){}
public ArrayList closeprices = new ArrayList();
public double closepr;
protected override void Create() {
// create variable objects, function objects, order objects etc.

}
protected override void StartCalc() {
Output.Clear();
}
protected override void CalcBar(){
if (Bars.TimeValue.Hour == 16)
{
Output.WriteLine(Bars.TimeValue.ToString()+ " close: "+ Bars.CloseValue.ToString());
closeprices.Add(Bars.CloseValue);

if (closeprices.Count >3 )
{
Output.WriteLine("close 2 days ago: "+closeprices[(closeprices.Count-3)].ToString());
}
}
}
}
}
Bars.TimeValue gives you what you need. Example:

Code: Select all

if ((Bars.TimeValue.Month == 9) && (Bars.TimeValue.Year == 2011)) {do whatever}
you can set this for hours, minutes, date, etc.

edit- sorry, I seem to have wandered over from the MC.NET forum. This is the C# answer.
Would you give me a example using array to solve this problem? Since in the above answer, you still cant quote the price efficiently. special.price will be(0,0,0...,close[1],0,..0,close,0,0,...) how to save to (...,close_900_[1],close_900...)
Thanks
Last edited by clonardo on 12 Oct 2013, edited 1 time in total.

clonardo
Posts: 16
Joined: 27 Sep 2013
Has thanked: 1 time
Been thanked: 1 time

Re: How to store the price at daily specific time?

Postby clonardo » 12 Oct 2013

To further clarify, that's just printing out the price from 2 days ago in output. If you want to use the lagged price, set a variable = closeprices[(closeprices.Count-3)].

Sample output using the code that I posted is as follows:

note: format is date/time, day's close, (newline) 2 day ago's close.
9/30/2013 4:00:00 PM close: 105.23
close 2 days ago: 113.79
10/1/2013 4:00:00 PM close: 108.72
close 2 days ago: 109.18
10/2/2013 4:00:00 PM close: 105.39
close 2 days ago: 105.23
10/3/2013 4:00:00 PM close: 101.27
close 2 days ago: 108.72
10/4/2013 4:00:00 PM close: 101.97
close 2 days ago: 105.39
10/7/2013 4:00:00 PM close: 94.18
close 2 days ago: 101.27

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to store the price at daily specific time?

Postby Henry MultiСharts » 05 Nov 2013

Please keep in mind that clonardo's replies are referring to MultiCharts .Net.
If you are still unable to implement your logic with PowerLanguage – please let me know the particular difficulty you have.


Return to “MultiCharts”