RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        



MultiSymbol and MultiFrequency project Expand / Collapse
Message
Posted 3/7/2010 16:29:07 Post #11063
 

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member
Hi,

I am trying to port to RE a project I had developed with EL and Multicharts.
This project references some symbols as signal generators (I have taken here the example of the DJStoxx600 ^STOXX) and makes investment decisions on other symbols.
Here is the code :

public class MySymbolScript : MySymbolScriptBase
{
Frequency DailyFreq;
static string symbolName;
private HistoricalVolatility vol;


public override void Startup()
{
// Perform initialization here.
symbolName = "^STOXX";
DailyFreq = GetFrequency(BarFrequency.Daily);
vol = new HistoricalVolatility(15,220,OtherSymbols[symbolName].DailyFreq.Close); // line 33 of Test_MultiFreq.cs

}

public override void NewBar()
{
// Put your trading code here
if ((Symbol.Name == symbolName) || Bars.Count < 10) return;

}

When I try to run the attached project, which does virtually nothing, I have no problem selecting the ^STOXX as signal and any equity of the Nasdaq 100 for investment. The project executes correctly and does nothing as expected. The same happens when I run it on the ^STOXX50E (EuroStoxx50) as investment. It runs well.
But when I try the DAX30 for instance (^GDAXI), or any other index (^GSPC, ^NDX), then I receive an error which I don't understand.
Here is the message sent by RE :

An exception of type System.NullReferenceException was thrown.
Object reference not set to an instance of an object.
at MySymbolScript.Startup() in c:\Users\PCH\Documents\Investissements\RightEdge\Projets\Test_MultiFreq\Test_MultiFreq.cs:line 33
at MySystemBase.Startup(SystemData data) in c:\Users\PCH\Documents\Investissements\RightEdge\Projets\Test_MultiFreq\BaseClasses.cs:line 23
at RightEdge.Common.Internal.SystemRunner.Startup()
at RightEdge.Shared.SystemWrapper.InitializeModule(SystemData systemData, SystemRunSettings runSettings, ServiceFactory brokerFactory)
at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginReference dataStore, SystemParameters systemParameterOverrides)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginReference dataStore, SystemParameters systemParameterOverrides)
at RightEdge.Shared.TradingModuleWrapper.Run(String filename, ServiceAppDomainFactory brokerFactoryFactory, PluginReference dataStore, SystemParameters systemParameterOverrides)
at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData, ServiceAppDomainFactory brokerFactoryFactory, Func`2 dataStoreFactory)
at RightEdge.SystemProgress.InitAndRunSystem()
Could you please help ?

If I change the instruction :
vol = new HistoricalVolatility(15,220,OtherSymbols[symbolName].DailyFreq.Close);
to
vol = new HistoricalVolatility(15,220,DailyFreq.Close);
then the project runs well on DAX as well.

Removing the reference to DailyFreq does not seem to help.
Thanks in advance for your assistance,

Pierre
Posted 3/7/2010 23:27:59 Post #11067
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
There is a separate SymbolScript for each symbol, and the StartUp method is run for each one sequentially, in an arbitrary order.  What is happening is that the Startup method for ^STOXX is not being run first.  So the first Startup method that is called tries to access the DailyFreq for the ^STOXX symbol.  This is still null because the Startup method that would initialize it hasn't been called yet, hence the NullReferenceException.

You can't control the order in which Startup is called on your SymbolScripts, so you probably want to do a two-phased startup.  In your normal Startup method, just create the frequencies you need.  Then create another method called SetupIndicators, where you will create your indicators and link them to the inputs on other symbols.  Then you need to set it up so that SetupIndicators will be called after Startup has been called for all symbols, which you can do by adding the following code to your MySystem (NOT the MySymbolScript) class:

public override void Startup(SystemData data)

{

      base.Startup(data);

      foreach (MySymbolScript symbolScript in SymbolScripts)

      {

            symbolScript.SetupIndicators();

      }
}

Thanks,
Daniel

Posted 3/8/2010 09:00:50 Post #11080
 

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member
Hello Daniel,

First thank you very much for your support. I really appreciate it even if your comments are sometimes a little bit cryptic for my level of expertise.

I did what you suggested, and it seems that the indicators are not evaluated any more (the program is throwing a lot of exceptions when I am calling an RSI.Current or whatever).
I circumvented these difficulties adding adequate tests for each and every indicator I am using prior to using it to check whether is has been defined or not.
Now, the real program does not do anything anymore.
The initialization loop is executed as expected, but the indicators are not created.

I am typically creating the indicator via this syntax :
rsi = new RelativeStrength(21,OtherSymbols[vSymbolName].Close);

Did I miss something ?

BTW, is there a place where I could find a documentation which would explain the dynamic of the execution ?
Thanks again,

Pierre
Posted 3/9/2010 22:26:42 Post #11115
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
There is some information on how system execution works in the Developing Trading Systems in RightEdge help topic.

I need to look at your code to figure out what is wrong with it. Can you post it or attach it here?

Thanks,
Daniel
Posted 3/10/2010 05:01:00 Post #11125
 

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member
Daniel,

I had gone through the Help Topic, but did not find it consistent enough. Maybe the sole weakness of your product for someone, not a skilled enough programmer, like me.

I think I might see were my problem is. My mistake was to rely on the general setting of the strategy to define a weekly frequency, and not explicitly redefine the weekly frequency for each of the indicators I am using with this frequency. Setting the general frequency to "Automatic" and defining the frequency for each indicator would solve the issue.

But I still have a problem when I am trying to rely on a general frequency, which could be weekly in my case : if I am not redefining it for each and every indicator (lines 51 and 52 commented), they are not created and updated (see Message_1.txt). If I try to redefine their frequency(remove the comments in lines 51 and 52), then I receive a message of error because I am redefining a key which has already been defined (see Message_2.txt).

I am enclosing the code of my "sample" strategy for you to highlight my mistakes.

I noticed in the sample of code you have published when you released the multifrequency facility that you had defined new events for each and every frequency used in the system.
Is this mandatory ?
If set to "Automatic" frequency, what will be the triggering frequency for the NewBar event ?

Thanks again,

Pierre

  Post Attachments 
Test_MultiFreq.cs (94 views, 2.35 KB)
Message_1.txt (72 views, 1.90 KB)
Message_2.txt (79 views, 1.52 KB)
Posted 3/12/2010 03:57:48 Post #11146
 

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member
Hi Daniel,

I am not sure if you had a chance to have a look at my code. After further testing, I am not sure if my code has bugs or if there is a small problem in the way SetupIndicators is operating.

I have found out that when SetupIndicators is called to start only one indicator, then the code is executed perfectly.
But when there are at least two indicators to start, then the backtest will abort during execution (with the errors already posted into the thread).

In continuation of this topic, I have tried to develop an indicator (first level indicator), outside of the MySymbolScript logic (in order to produce a separate DLL), and include some standard indicators (second level indicators) into the code of this object.

I have included the call to the constructors of these second level indicators into the constructor of the first level one, and the call to the constructor of the first level indicator into the code of the MySymbolScript -> Startup method.

I have noticed that the object would compile properly, but that an error, similar to the one above, would happen during execution which suggests that the second level indicators have not been properly constructed.

Is there some subtlety I have missed in the process ?
Thanks in advance,

Pierre
Posted 3/15/2010 01:43:21 Post #11165
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
I investigated this and it turns out there are some bugs in RightEdge when you create indicators after Startup() has been called, which is the case when you use SetupIndicators(). This will be fixed in the next build. To avoid the bug until then, simply call IndicatorManager.Register on each indicator you create in the SetupIndicators method, like this:

SystemData.IndicatorManager.Register(slowMA, Symbol, "Slow MA");
SystemData.IndicatorManager.Register(fastMA, Symbol, "Fast MA");

Thanks,
Daniel
Posted 3/15/2010 02:06:52 Post #11166
 

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member
Great, Thanks,

Pierre
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: billb, young, dplaisted

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 1:04am

2005-2007 © RightEdge Systems