Profile Picture

An exception of type System.ArgumentOutOfRangeException was thrown

Posted By pincheblake 2 Years Ago

An exception of type System.ArgumentOutOfRangeException was thrown

Message
Posted Wednesday July 29 2015
I am very new to C# (or any programming language) but have been able to fix some errors thanks to older posts in the forums. However, now I'm stuck and would appreciate some guidance.

This is the error I'm getting:

An exception of type System.ArgumentOutOfRangeException was thrown.
Value must be between 0 and -1, value was 0
Parameter name: nBars
 at RightEdge.Common.BarElementSeries.LookBack(Int32 nBars)
 at MySymbolScript.NewBar() in c:\Users\blakeg\AppData\Roaming\Dynamic\MF.cs:line 59
 at RightEdge.Common.SymbolScriptCollection`1.NewBar()
 at MySystemBase.NewBar() in c:\Users\blakeg\AppData\Roaming\Dynamic\BaseClasses.cs:line 31
 at RightEdge.Common.Internal.SystemRunner.CallSystemNewBar(FrequencyNewBarEventArgs args)
 at RightEdge.Common.Internal.SystemRunner.ProcessBarEvents(IEnumerable`1 eventList)
 at RightEdge.Common.FrequencyManager.SendPendingBars()
 at RightEdge.Common.FrequencyManager.UpdateTime(DateTime dateTime)
 at RightEdge.Common.Internal.SystemRunner._tickGenerator_NewBar(Object sender, NewBarEventArgs e)
 at RightEdge.Common.TickGenerator.ProcessBar(NewBarEventArgs args)
 at RightEdge.Common.Internal.SystemRunner.ProcessBar(NewBarEventArgs newBars)
 at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
 at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
 at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
 at RightEdge.Shared.TradingModuleWrapper.Run(String filename)
 at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData)
 at RightEdge.SystemProgress.InitAndRunSystem()

I think this issue is somewhere in here:

public class MySymbolScript : MySymbolScriptBase
{
// Construct our two simple moving averages.
SMA SMA100 = new SMA(100);
SMA SMA200 = new SMA(200);


public override void Startup()
{

SMA100.SetInputs(Close);

SMA100.ChartSettings.Color = Color.Green;

SMA100.ChartSettings.LineType = SeriesLineType.Dashed;

SMA200.SetInputs(Close);

SMA200.ChartSettings.Color = Color.Blue;
}

public override void NewBar()
{
if (Symbol.Name == "ACWI")
{
  // Don't do any trading for this symbol
  return;
}
// Test for a crossover. This is our buy signal
if (SystemUtils.CrossOver(Close, SMA100) &&
OtherSymbols["ACWI"].Close.Current > OtherSymbols["ACWI"].SMA200.Current)
{
// They've crossed, open a long position
OpenPosition(PositionType.Long, OrderType.Market);/code]
[code language="c#"]

Posted Thursday July 30 2015
It looks like all of your code may not have been pasted in correctly.  But the problem is probably that you have bar data for another symbol before there are any bars for ACWI.  So you get an error when you try to access the current close or SMA200 value of that symbol, because there isn't any current value.

You probably want a check like the following before the rest of your logic:

if (OtherSymbols["ACWI"].Bars.Count < 200)
{
    //  Not enough ACWI data yet
    return;
}


Thanks,
Daniel

Posted Thursday July 30 2015
Looks like that worked. Thanks for your help!


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems