SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Feb 27, 2020 9:33 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Mon Aug 23, 2010 3:21 pm 
Offline

Joined: Tue Jun 22, 2010 5:34 am
Posts: 11
Location: Moscow
Dr. Anton Fokin wrote:
2.

OpenQuant installation folder -> Samples -> Sample Indicators...

Just put all indicators in another project in the same solution and you will have them as dll.

Anton



I don't see that folder in the latest version ... Is it obsolete?


Top
 Profile  
 
PostPosted: Tue Aug 23, 2011 11:16 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
<OpenQuant installation folder>\Samples\sampleindicators.zip

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Sun Aug 26, 2012 8:07 pm 
Offline

Joined: Sun Jun 01, 2008 1:18 pm
Posts: 32
Location: Paris France
/*Is it possible to publish some sample code for obtaining Public Method/Property values of UserIndicator in Strategy code section? Especially .Crosses(Above)Below, .Ago() and .Last!!....not present in samples.

///PUBLIC PROPERTIES

Color Gets or sets indicator color (inherited from Indicator)
Count Overidden. Gets the number of items in this indicator
Description Gets or sets indicator description (inherited from Indicator)
FirstDateTime Overidden. Gets first date-time
Input
Item Overloaded. Gets indicator value at specified bar
Last Overidden. Gets last value of this indicator
LastDateTime Overidden. Gets last date-time
Name
Width Gets or sets indicator width (inherited from Indicator)

///PUBLIC METHODS
Ago Overidden. Returns n-bars-ago indicator value
Contains Overloaded. Checks if this indicator contains an entry with specified time stamp
Crosses Overloaded. Checks if this indicator crosses a bar series at specified bar
CrossesAbove Overloaded. Checks if this indicator crosses a bar series above at specified bar
CrossesBelow Overloaded. Checks if this indicator crosses a bar series below at specified bar
GetDateTime Overidden.
GetIndex Returns index by specified date time (inherited from Indicator)
Init Initializes user indicator

///Following compiles but at runtime :
///System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
///à MyStrategy.OnBar(Bar bar) dans c:\Users\admin\AppData\Roaming\SmartQuant Ltd\OpenQuant ///2\Projects\userindicatorexample\code.cs:ligne 48

*/


//amfuserindicatorex.cs from smartquant forum (fokin)
using System;using System.Drawing;using OpenQuant.API;using OpenQuant.API.Indicators;
using OpenQuant.API.Plugins;
public class AMF: UserIndicator
{
double volume = 0;
public AMF(BarSeries input) : base(input)
{
Name = "AMF";
}
public override double Calculate(int index)
{
if (index > 1)
{
if (Input[index, BarData.Close] > Input[index-1, BarData.Close])
volume += Input[index, BarData.Volume];
else
volume -= Input[index, BarData.Volume];

return volume;
}
else
return Double.NaN;
}
}
public class MyStrategy : Strategy
{
AMF amf;
public override void OnStrategyStart()
{
AMF amf = new AMF(Bars);
amf.Color = Color.White;
Draw(amf, 2);
}
public override void OnBar(Bar bar)
{
Console.WriteLine("amf.Last {0} amf.Ago(1) {1} amf.Color {2}",amf.Last,amf.Ago(1),amf.Color);
//above line=ligne 48...same error for ALL WriteLine vars (including Color despite Strategy assignment).
}
}//:=)

_________________
Thx!!


Top
 Profile  
 
PostPosted: Mon Aug 27, 2012 11:02 am 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
Hi, your mistake is:
Code:
AMF amf = new AMF(Bars);

in OnStrategyStart method.
The line should look like
Code:
amf = new AMF(Bars);


Also, check amf.Count property before call 'Last' or 'Ago' methods. The series may be empty and you will get an error.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Tue Aug 28, 2012 8:17 pm 
Offline

Joined: Sun Jun 01, 2008 1:18 pm
Posts: 32
Location: Paris France
:D Which of course works. Thanks for quick response!!! Still, to the subject of UserIndicator objects, when and how is the Init public method triggered? Is there a way, other than creating an external (Visual C#) dll, or using spaghetti (goto) code, to create subroutines called by the Calculate public method? If not, could someone post some working external dll code?

_________________
Thx!!


Top
 Profile  
 
PostPosted: Wed Aug 29, 2012 11:17 am 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

Init method is called when your code (or OQ charting engine for example) first time access the indicator (taking .Count of it or .Name or an element by index). You can though call it manually in the code right after you create it.

If you don't like to create a separate .dll - you can create a static class right below your custom indicator code and use it in the Calculate method of the indicator.

Regards,
Sergey.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group