RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        


««12

spread trading Expand / Collapse
Message
Posted 6/30/2010 16:49:21 Post #11859
 

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru
The system himself creates a dictionary<symbol, MACD>

public Dictionary<Symbol, MACD> RatioMACD = new Dictionary<Symbol, MACD>();

foreach (Symbol symbol in SystemData.Symbols)

{

    Ratios[symbol] = new DataSeries();

    RatioMACD[symbol] = new MACD(12, 26,Ratios[symbol]);

}

i already checked the Ratios[symbol] is fine !!!

But the RatioMACD[symbol].Current for instance only returns double.NAN...

I´ll post all code down if you can see any problem..

using System;

using System.Drawing;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using RightEdge.Common;

using RightEdge.Indicators;

public class SystemMain : SystemBase

{

// This is the symbol you want to compare other symbols against

public Symbol BaseSymbol;// = new Symbol("ACG");

public Dictionary<Symbol, MACD> RatioMACD = new Dictionary<Symbol, MACD>();

public Dictionary<Symbol, DataSeries> Ratios = new Dictionary<Symbol, DataSeries>();

double proportion = 10;

public override void Startup()

{

BaseSymbol = SystemData.Symbols[0];

if (SystemData.Symbols.Count < 2)

{

throw new RightEdgeError("Must select at least two symbols (including " +

BaseSymbol + " to run the system against.");

}

// We will use this to plot the close values of our base series along

// with each symbol

Series[BaseSymbol.ToString()].CreateSeries();

Series[BaseSymbol.ToString()].SeriesColor = Color.Blue;

Series[BaseSymbol.ToString()].AddToCharts();

// The ratio

Series["RATIO"].CreateSeries();

Series["RATIO"].ChartPaneName = "Ratio";

Series["RATIO"].SeriesColor = Color.Red;

Series["RATIO"].AddToCharts();

// The MACD of the ratio

Series["RATIOMACD"].CreateSeries();

Series["RATIOMACD"].ChartPaneName = "RatioMACD";

Series["RATIOMACD"].SeriesColor = Color.Orange;

Series["RATIOMACD"].AddToCharts();

// For each symbol, create a DataSeries which will be used to store

// the ratio values, and a MACD of that ratio.

foreach (Symbol symbol in SystemData.Symbols)

{

Ratios[symbol] = new DataSeries();

RatioMACD[symbol] = new MACD(12, 26,Ratios[symbol]);

}

}

public override void NewSymbolBar(Symbol symbol, BarData bar)

{

//if (symbol == BaseSymbol)

//{

// Do nothing

// return;

//}

BarData baseBar = BarUtils.LastValidBar(Bars[BaseSymbol]);

double baseValue;

double ratio;

if (baseBar == null)

{

// No valid bars for the base symbol yet

baseValue = double.NaN;

ratio = double.NaN;

}

else

{

///baseValue = baseBar.Close * proportion;

if(proportion == 10)

{

proportion = bar.Close / baseBar.Close;

}

// Calculate ratio

baseValue = baseBar.Close * proportion;

ratio = bar.Close / baseBar.Close / proportion;

}

// Add base value and ratio to the corresponding series on the charts

Series[BaseSymbol.ToString()][symbol].SetCurrentValue(baseValue);//serie do primeiro do par

Series["RATIO"][symbol].SetCurrentValue(ratio);

// Add the ratio to the DataSeries which the MACD uses as its input

Ratios[symbol].Add(ratio);

//Console.WriteLine(Ratios[symbol].Current);

RatioMACD[symbol].NewBar();

Series["RATIOMACD"][symbol].SetCurrentValue(RatioMACD[symbol].Current);

// Tell MACD to calculate its new value

//foreach(Symbol kvp in RatioMACD.Keys)

//{

Console.WriteLine(RatioMACD[symbol].Current);

//}

}

}

public class DataSeries : ISeries

{

public List<double> Values = new List<double>();

SeriesChartSettings st = new SeriesChartSettings();

public double this[int index]{

get

{

return Values[index];

}

}

public void Add(double Value){

Values.Add(Value);

}

public SeriesChartSettings ChartSettings{

get

{

return st;

}

set

{

}

}

public double LookBack(int periodos){

return Double.NaN;

}

public double Current

{

get

{

return Values[Values.Count-1];

}

}

public int OldestValueChanged

{

get

{

return 1;

}

}

public int Count

{

get

{

return Values.Count;

}

}

public double Value(int per)

{

return Values[per];

}

public bool OldValuesChange {

get

{

return false;

}

}

}

Posted 7/2/2010 11:09:43 Post #11865
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
I'm not sure what's going on, but it still looks like you're basing this on old code. Have a look at the UserSeries sample that ships with RightEdge. It is much cleaner and easier to understand. Plus it works.
Posted 7/5/2010 20:55:15 Post #11880
 

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru
Ok, i see . . .    really the new way is easier !!! But when i tried to create an bollinger band over the user serie, it returned an error message "Input 0 to indicator bb2 was a user series.  User series cannot be used as inputs to indicators.".

So if i create a ratio between two asset´s and need a indicator over that ratio, how should i proceed ??  Any idea ???

                                          and Again thank´s for the best support !!!

                                                                Vitor

Posted 7/6/2010 08:04:30 Post #11887
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
You might consider making your ratio an ISeries.  Here is a sample class that implements an ISeries.  You could add your ratio values to this class and then pass this into the BB.

public class MyRatioValues : ISeries

{

      List<double> myRatioValues = new List<double>();

      public SeriesChartSettings ChartSettings { get; set; }

     

      public double LookBack(int nBars)

      {

            return myRatioValues[myRatioValues.Count - nBars];

      }

 

      public double Current

      {

            get { return myRatioValues[myRatioValues.Count - 1]; }

      }

     

      public int Count

      {

            get { return myRatioValues.Count; }

      }

 

      public bool OldValuesChange

      {

            get { return false; }

      }

      public int OldestValueChanged

      {

            get { return 0; }

      }

}

 

vitor dantas (7/5/2010)
Ok, i see . . .    really the new way is easier !!! But when i tried to create an bollinger band over the user serie, it returned an error message "Input 0 to indicator bb2 was a user series.  User series cannot be used as inputs to indicators.".

So if i create a ratio between two asset´s and need a indicator over that ratio, how should i proceed ??  Any idea ???

                                          and Again thank´s for the best support !!!

                                                                Vitor

« Prev Topic | Next Topic »

««12

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:06am

2005-2007 © RightEdge Systems