Profile Picture

NewB Q: Better C# start guide?

Posted By trender08 12 Years Ago
Message
Posted Tuesday January 06 2009
Hi,

I am trying to migrate over from being a less-than-great programmer of the WealthLab script to C#.  I just finished reading Murach's book on learning c#, which helped a lot for learning the logic, but wasn't a great introduction to the functions of Right Edge.  I tried both developers' guides on the documentation tab of the website, but the help section is too simplistic (not enough examples to try to replicate / solve my problems) and the developer guide is a bit too much of a reference to teach me how to code.

Any suggestions on where to start?

I am trying to create a very simple script where I count the number of events (in this case, the number of times a custom indicator I've created and "pushed" to the system from a chart setting indicator crosses a predefined constant) that I can use to set up histograms in excel to predict the probability of future events.

Unfortunately I'm lost on several fronts:  how to call the indicator series to determine the value, what the indicator name is, how to plot the resultant series numberEvents or eventCounts on the chart graphically...

Many newbie items that seem to me just to require a more comprehensive start up guide.

Suggestions are welcome!

Happy holidays,

-Matt

Posted Tuesday January 06 2009
Yes, I'm afraid the Getting Started guide and the reference are not really good ways to learn to code.  As you learn C#, the best way to bridge the gap between the language and the RightEdge class library is to do.  Learn by the samples and write your own bite sized pieces ... and of course, ask here.  The best thing to do is to break the problem down into smaller parts.

Accessing indicator values is documented in the Developing Trading Systems with RightEdge.  Current accesses the current value of an indicator.  Indicators can be created and accessed two ways.  First, you can drag and drop it onto the System Designer and second, you can create an instance of it in the system itself.

The code below demonstrates both concepts.

public class MySymbolScript : MySymbolScriptBase
{
 private SMA sma50;
 
 public override void Startup()
 {
  // Perform initialization here.
  sma50 = new SMA(50, Close);
 }

 public override void NewBar()
 {
  // Accessing the current indicator value from the DnD designer
  double dndValue = Indicators["SMA50"].Current;
  
  // Accessing the current value from an instantiated SMA 50.
  double value = sma50.Current;
 }
}

Use the Lookback method to access bars beyond the current bar.

The second concept it sounds like you need help with is creating your own series to track some values.  Again, this is something covered in the Developing Trading Systems under the topic User Series (search for "User Series" in the topic, it's near the bottom).

Here's an example of creating and accessing a UserSeries as an add-on to the previous example.

public class MySymbolScript : MySymbolScriptBase
{
 private SMA sma50;
 private UserSeries mySeries;
 
 public override void Startup()
 {
  // Perform initialization here.
  sma50 = new SMA(50, Close);
  mySeries = new UserSeries();
  mySeries.ChartSettings.ChartPaneName = "My Chart Pane";
  mySeries.ChartSettings.ShowInChart = true;
 }

 public override void NewBar()
 {
  // Accessing the current indicator value from the DnD designer
  double dndValue = Indicators["SMA50"].Current;

  // Accessing the current value from an instantiated SMA 50.
  double value = sma50.Current;
  
  if (value > 50)
  {
   // My Series is going to add 1 to the current value
   // every time the SMA 50 is > 50.
   mySeries.SetCurrentValue(mySeries.Current++);
  }
 }
}

Hope this helps.

trender08 (1/6/2009)
Hi,

I am trying to migrate over from being a less-than-great programmer of the WealthLab script to C#.  I just finished reading Murach's book on learning c#, which helped a lot for learning the logic, but wasn't a great introduction to the functions of Right Edge.  I tried both developers' guides on the documentation tab of the website, but the help section is too simplistic (not enough examples to try to replicate / solve my problems) and the developer guide is a bit too much of a reference to teach me how to code.

Any suggestions on where to start?

I am trying to create a very simple script where I count the number of events (in this case, the number of times a custom indicator I've created and "pushed" to the system from a chart setting indicator crosses a predefined constant) that I can use to set up histograms in excel to predict the probability of future events.

Unfortunately I'm lost on several fronts:  how to call the indicator series to determine the value, what the indicator name is, how to plot the resultant series numberEvents or eventCounts on the chart graphically...

Many newbie items that seem to me just to require a more comprehensive start up guide.

Suggestions are welcome!

Happy holidays,

-Matt

Posted Thursday January 08 2009
Thanks, that is helpful.

Here is the simple counter script I am working on, after attempting to integrate your format.  Is the i = 0 ... i++ loop appropriate here?

Also, the other major question is that I've used indicators created with the custom indicator method for viewing a chart, then I right-clicked and pushed these to the script.  I can't seem to get the indicator name to reference correctly.  Ideas are welcome, as always.


Thanks!

Script below, followed by indicator definitions.

#region Using statements

using System;

using System.Drawing;

using System.Collections.Generic;

using RightEdge.Common;

using RightEdge.Common.ChartObjects;

using RightEdge.Indicators;

#endregion

#region System class

public class MySystem : MySystemBase

{

public override void Startup()

{

// Perform initialization or set system wide options here

}

}

#endregion

public class MySymbolScript : MySymbolScriptBase

public class IndicatorManager

{

// How do I define the indicator series already defined in the System Designer?

private UserSeries countCall;

public override void Startup()

{

// Perform initialization here.

int callOTMAmount = 0;

int putOTMAmount = 0;

int countCall = 0;

int period = 15;

countCall = new userSeries ();

countCall.ChartSettings.ChartPaneName = "Call Count";

countCall.ChartSettings.ShowInChart = true;

}

public override void NewBar()

{

// Put your trading code here

if ( Bars.Count < period )

return;

for ( int i = 0; i < period; i++ )

{

if ( Up15d%High.current >= CallOTMAmount )

countCall++;

}

}

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

}

}

Indicator references from the BaseClasses.cs file.  I am interested in correctly referencing the ["% 15d Up Move"] indicator in the script above. Doesn't appear that I have it correct...

public ISeries _15dUpMove

{

get { return TradingSystem.SystemData.Indicators["% 15d Up Move"][Symbol]; }

}

public ISeries Up15dHigh

{

get { return TradingSystem.SystemData.Indicators["Up 15d % High"][Symbol]; }

}

}

Posted Thursday January 08 2009
trender08 (1/8/2009)
Thanks, that is helpful.

Here is the simple counter script I am working on, after attempting to integrate your format.  Is the i = 0 ... i++ loop appropriate here?

Hrm, I don't think you need to loop through all of the bars every time.  I believe you can omit the loop and get the desired effect.  The index of the loop (i) is not being used anywhere.

Also, the other major question is that I've used indicators created with the custom indicator method for viewing a chart, then I right-clicked and pushed these to the script.  I can't seem to get the indicator name to reference correctly.  Ideas are welcome, as always.

I'm not sure I understand what you mean by "custom indicator method".  Indicators that you DnD to a chart are not necessarily available in a system.  You need to put them either on the design surface where you give them a name or directly underneath the Indicators node on the Trading System pane.  You can also give them a name there and set parameters for chart settings such as color, chart pane, etc.

When you're in a system you can reference them as I demonstrated in my previous post.

Posted Thursday January 08 2009
Are you trying to figure out the number of times that the "Up 15% high" was greater than CallOTMAmount in the last 15 bars, or over all time?  If it's for the last 15 bars, the for loop should probably look like this:

countCall = 0;
for ( int i = 0
; i < period; i++ )
{
    if ( Up15dHigh.LookBack(i) >= CallOTMAmount )
        countCall++;
}

Notice that you can't use the percent symbol when accessing an indicator from code.

If you want the count over all time, you don't need a loop at all.

Thanks,
Daniel



Similar Topics


Reading This Topic


2005-2021 © RightEdge Systems