Posted 2/9/2010 01:08:24
|
|
|
|
I generated a special frequency which raises a NewMinuteBar function (I run on hourly system frequency). My question is, can I only access the minute data of the symbol that I associated with that frquency? Lets say I have 2 stock symbols, can I access the one minute data of each symbol AT THE SAME TIME? Please note that I run everything in SystemClass not SymbolClass which has the precise reason that I need to access the data at the same time not one after another. Here are my definitions and functions, thanks for taking a look.
public class MySystem : MySystemBase
{
//System Frequency: 1 hour
//Short Frequency : 1 minute
//Long Frequency : 1 day
Symbol mySymbol;
SMA builtInIndicatorSMAFast;
SMA builtInIndicatorSMASlow;
CustomInd customIndicatorSMAFast;
CustomInd customIndicatorSMASlow;
UserSeries UserSeriesSMAFast;
UserSeries UserSeriesSMASlow;
Frequency myMinuteFrequency;
Frequency myDailyFrequency;
public override void Startup(SystemData data)
{
base.Startup(data);
mySymbol = SystemData.GetSymbolByName("USD/JPY");
SymbolScriptBase mySymbolScript;
mySymbolScript = SymbolScripts[mySymbol];
myMinuteFrequency = SystemData.GetFrequency(mySymbol,TimeSpan.FromMinutes(1));
myMinuteFrequency.NewBar += NewMinuteBar;
myDailyFrequency = SystemData.GetFrequency(mySymbol,TimeSpan.FromDays(1));
myDailyFrequency.NewBar += NewDailyBar;
builtInIndicatorSMAFast = new SMA(30,myMinuteFrequency.Close);
builtInIndicatorSMASlow = new SMA(30,myDailyFrequency.Close);
customIndicatorSMAFast = new CustomInd(SystemData,SymbolScripts["USD/JPY"]);
customIndicatorSMASlow = new CustomInd(SystemData,SymbolScripts["USD/JPY"]);
UserSeriesSMAFast = new UserSeries();
UserSeriesSMASlow = new UserSeries();
}
public override void NewBar()
{
//Called each System
Console.WriteLine("SystemFrequency FX Value: " + Bars[mySymbol].Current.Close);
}
public void NewMinuteBar(object sender, SingleBarEventArgs args)
{
if(Bars[mySymbol].Count < 1) return;
Console.WriteLine("Minute Frequency FX Value: " + args.Bar.Close);
}
public void NewDailyBar(object sender, SingleBarEventArgs args)
{
}
}
public class MySymbolScript : MySymbolScriptBase
{
public override void Startup()
{
// Perform initialization here.
}
public override void NewBar()
{
// Put your trading code here
}
public override void OrderFilled(Position position, Trade trade)
{
// This method is called when an order is filled
}
public override void OrderCancelled(Position position, Order order, string information)
{
// This method is called when an order is cancelled or rejected
}
}
|
|
Posted 2/9/2010 09:52:05
|
|
|
|
| Sure, the member in SymbolScript is OtherSymbols. It's a Dictionary indexed by Symbol.
|
|
Posted 2/9/2010 10:20:57
|
|
|
|
great thanks. I have one additional question:
The below code sets up an SMA with 30 periods on Hourly Bars. Every Hour the SMA is updated and stored. However, when I omit
SystemData.IndicatorManager.SetFrequency(builtInIndicatorSMAFast,myShortFrequency);
and when I output that SMA every minute in NewBar I see an SMA which sometimes changes each minute, sometimes over several minute bars stays the same. How do I interpret this value? Is that the 30 period SMA calculated on hourly bars but recalculated at every minute? I am surprised that the SMA values change when displaying in NewBar on 1-minute System Frequency. I was always under the impression that RE is not yet capable to continuously update Indicators that run on a special frequency which, however, are displayed on a higher frequency, such as an hourly SMA shown on a 1 minute system frequency.
Any ideas?
Thanks
public class MySymbolScript : MySymbolScriptBase
{
public SMA builtInIndicatorSMAFast;
Frequency myShortFrequency;
public override void Startup()
{
myShortFrequency = GetFrequency(BarFrequency.SixtyMinute);
builtInIndicatorSMAFast = new SMA(30,myShortFrequency.Close);
SystemData.IndicatorManager.SetFrequency(builtInIndicatorSMAFast,myShortFrequency);
//SystemData.IndicatorManager.Register(builtInIndicatorSMAFast,this.Symbol,"Hour Frequency");
}
public override void NewBar()
{
// Put your trading code here
}
public override void OrderFilled(Position position, Trade trade)
{
// This method is called when an order is filled
}
public override void OrderCancelled(Position position, Order order, string information)
{
// This method is called when an order is cancelled or rejected
}
}
Access the data (in SystemClass):
if(SymbolScripts[mySymbol].builtInIndicatorSMAFast.Count < 1) return;
double value = SymbolScripts[mySymbol].builtInIndicatorSMAFast.Current;
Console.WriteLine("SMA: " + value);
|
|
Posted 2/9/2010 10:29:21
|
|
|
|
Also, one thing I am confused about is why I need to feed a symbol into myShortFrequency = SystemData.GetFrequency(mySymbol,BarFrequency.SixtyMinute); to define a frequency?
The problem I am having is I want to define an SMA inside SystemClass for several symbols but it seems the frequency is always linked to a specific symbol? Does it mean I have to create a frequency object for each symbol? I know for symbols its probably best to do all in SymbolScript but nonetheless I like to do all of it in SystemClass.
Thanks for the pointers...
|
|
Posted 2/10/2010 08:18:16
|
|
|
|
It should not be updated each minute on the hourly frequency. Are you sure the collection size of the hourly bars is the same? In other words, it's not adding a new value to the collection, is it? Could you do an OutputMessage demonstrating the different values for SMA.Current on your hourly frequency?
Regarding your second question, when you're in SymbolScript, you're effectively creating a new object for every symbol for everything declared at that level. RightEdge just does the context switching for you so it feels transparent to your code. And yes, you have to register it at the symbol level, this is how RightEdge keeps track of the symbols needing updates for each frequency.
|
|
Posted 2/10/2010 10:11:01
|
|
|
|
| If you do want to keep everything in your MySystem class, it should work OK as long as you call IndicatorManager.Register with the correct symbol for all of your indicators.
|
|
Posted 2/13/2010 08:12:37
|
|
|
|
Sorry my second question pertained to a system of 1 minute system frequency and hourly special frequency. Basically I define the SMA on the hourly frequency but omitting the command mentioned above I get different SMA values each minute when outputting the SMA on the new bar of system frequency which confused me. Thats why I was wondering....
billb (2/10/2010) It should not be updated each minute on the hourly frequency. Are you sure the collection size of the hourly bars is the same? In other words, it's not adding a new value to the collection, is it? Could you do an OutputMessage demonstrating the different values for SMA.Current on your hourly frequency?
Regarding your second question, when you're in SymbolScript, you're effectively creating a new object for every symbol for everything declared at that level. RightEdge just does the context switching for you so it feels transparent to your code. And yes, you have to register it at the symbol level, this is how RightEdge keeps track of the symbols needing updates for each frequency.
|
|
Posted 2/13/2010 20:51:42
|
|
|
|
OK, so you have an SMA where the input is set to the hourly bar close, but you have not set the frequency on the indicator itself, so it defaults to your system frequency of one minute.
What happens here is RightEdge uses a "wrapper" around the hourly close to adapt it to the one minute frequency. So the SMA gets a view of the input where each item in the series corresponds to a single 1-minute bar. Now since the hourly bar doesn't change for 60 minutes, the value of this input series will only change every 60 bars. However, the SMA value will change because as new 1-minute bars complete, it will be averaging more data points from the current bar. IE when a new hourly bar completes, it will be averaging 1 data point from the new hourly bar and 29 from the previous hour's close. When the next 1-minute bar completes, the average will be using 2 data points for the most recent 1-hour bar and 28 of the previous one.
Hopefully that helps.
Thanks,
Daniel
|
|
|
|