Profile Picture

"System.ArgumentOutOfRangeException was thrown"........ added Bars.Count but still not working

Posted By adam01527 Last Year

"System.ArgumentOutOfRangeException was thrown"........ added...

Message
Posted Friday May 27 2016
hi, 

try to test system in live, but get below error msg, have addd Bars.Count, still not working,

An exception of type System.ArgumentOutOfRangeException was thrown.
Value must be between 0 and -1, value was 1
Parameter name: nBars
 at RightEdge.Common.RList`1.LookBack(Int32 nBars)
 at RightEdge.Common.FrequencyBarElementSeries.LookBack(Int32 nBars)
 at MySymbolScript.Startup() in c:\Users\user\Desktop\RightEdge\myProjects\EliteLab\EliteLab.cs:line 46
 at MySystemBase.Startup(SystemData data) in c:\Users\user\Desktop\RightEdge\myProjects\EliteLab\BaseClasses.cs:line 23
 at RightEdge.Common.Internal.SystemRunner.Startup(SystemRunSettings runSettings)
 at RightEdge.Shared.SystemWrapper.InitializeModule(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
 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()


below is my beginner level coding,


Frequency dailyFreq1;
Frequency dailyFreq2;
public double predayClose1;
public double predayClose2;

public override void Startup()
{
if (Symbol.Name == symbol1)
{
dailyFreq1 = GetFrequency(BarFrequency.Daily);
dailyFreq1.NewBar += NewDailyBar;

this.predayClose1 = dailyFreq1.Close.LookBack(1);
}

if (Symbol.Name == symbol2)
{
dailyFreq2 = GetFrequency(BarFrequency.Daily);
dailyFreq2.NewBar += NewDailyBar;

this.predayClose2 = dailyFreq2.Close.LookBack(1);
}
}

public override void NewBar()
{
if (Symbol.AssetClass == AssetClass.Future)
{
if (Symbol.Name == symbol1)
{
BarData bar2 = OtherSymbols[symbol2].Bars.Current;

if(Bars.Count < 2 && OtherSymbols[bar2].Bars.Count <2)
{
return;
}
else
{
OutputMessage("5minClose1= " + Close.Current.ToString() + " pClose1= " + this.predayClose1.ToString() +"pClose2" + this.predayClose2.ToString() +" 5minClose2= " + bar2.Close.ToString());
}
}
else
{
return;
}
}
else
{
return;
}
}


any help is appreciate,
thanks,
Adam
Posted Friday May 27 2016
The Startup() method is called once before the system starts processing any data.  You are getting this error because you are calling LookBack() to get a previous bar when there are no bars at all yet.

Thanks,
Daniel
Posted Sunday May 29 2016
thanks Daniel,
i changed the code little bit as below, "system build success" this time and there are output,
5minClose1 and  5minClose2 works well, but both of predayClose printing 0........

guess im not doing right in NewDailyBar??
many thanks,
Adam


Frequency dailyFreq;
public double predayClose1;
public double predayClose2;

public override void Startup()
{
   dailyFreq = GetFrequency(BarFrequency.Daily);
   dailyFreq.NewBar += NewDailyBar;
}

public void NewDailyBar(object sender, SingleBarEventArgs args)
{
//save the daily value for use in minutes bar
   if(Symbol.Name == "symbol1")
   {
    this.predayClose1 = args.Bar.Close;
   }

   if(Symbol.Name == "symbol2")
   {
    this.predayClose1 = args.Bar.Close;
   }
}


public override void NewBar()
{
if (Symbol.AssetClass == AssetClass.Future)
{
if (Symbol.Name == "symbol1")
{
BarData sym2 = OtherSymbols["symbol2"].Bars.Current;

if(Bars.Count < 2)
{
return;
}
else
{
OutputMessage("5minClose1= " + Close.Current.ToString() + " pClose1= " + this.predayClose1.ToString() +" pClose2= " + this.predayClose2.ToString() +" 5minClose2= " + sym2.Close.ToString());
}
}
else
{
return;
}
}
else
{
return;
}
}

Posted Wednesday June 01 2016
it seems the NewDailyBar() didn't trigger anything?
pClose1 & pClose2 is printing out "NaN",

pls help? many thanks,


public override void Startup()
{
   dailyFreq = GetFrequency(BarFrequency.Daily);
   dailyFreq.NewBar += NewDailyBar;

    predayClose1 = double.NaN;
    predayClose2 = double.NaN;
  }

public void NewDailyBar(object sender, SingleBarEventArgs args)
{
   if (Symbol.AssetClass == AssetClass.Future)
   {
    if (Symbol.Name == "sym1")
    {
      this.predayClose1 = args.Bar.Close;
    }

    if (Symbol.Name == "sym2")
    {
      this.predayClose2 = args.Bar.Close;
    }
   }
}

Posted Friday June 03 2016
Probably what is happening is that you are seeing messages from the first trading day, where there hasn't been a daily bar generated yet.  So NewDailyBar() hasn't been called and the predayClose values remain 0 or NaN.

In your case, I don't think you need NewDailyBar() so far.  Just make dailyFreq public.  Then in your NewBar method you can do something like this:


RList<BarData> sym2Daily = OtherSymbols["symbol2"].dailyFreq;
if (sym2Daily.Count > 0)
{
    double sym2DailyClose = sym2Daily.Current.Close;
}


Does that help?

Thanks,
Daniel
Posted Tuesday July 05 2016
thanks Daniel,

i tried your suggestion above, using RList<BarData> sym2Daily = OtherSymbols["symbol2"].dailyFreq;
and public the dailyFreq as public Frequency dailyFreq,

but it give me a warning msg.......
http://www.rightedgesystems.com/forums/uploads/images/2c787c40-3d8a-48e1-bdbb-fca1.jpg



Edited: Tuesday July 05 2016 by adam01527
Posted Monday July 11 2016
hi Daniel, finally figured it out, problem solved by adding "Bars" 
RList<BarData> sym2Daily = OtherSymbols["symbol2"].dailyFreq.Bars;

thanks,
Adam
Posted Monday July 18 2016
hi,
just wonder how can i print the data in real time?
i've tried the FilteredDailyFrequency, still nth print out in live,

dailyFreq = GetFrequency(new FilteredDailyFrequency() { StartTime = TimeSpan.FromHours(9.30), EndTime = TimeSpan.FromHours(16.00) });


i've tried both of RList and NewDailyBar,

pls help,

many thanks,
Adam
Posted Friday August 05 2016
adam01527 (7/18/2016)
just wonder how can i print the data in real time?
i've tried the FilteredDailyFrequency, still nth print out in live,


Hi Adam,

I'm afraid I didn't understand what you are trying to do here.  Can you clarify?  You say "in real time", does that mean you are running a live system and want to print out information about bars at certain times?  When do you want what to be displayed?

Thanks,
Daniel
Posted Saturday August 06 2016
hi Daniel,

yes, you are correct,
im actually calculating the number as below red circle, i need this number every 5 mins in real time,
thats why im looking for the previous day close,

http://www.rightedgesystems.com/forums/uploads/images/1eadac22-7914-4662-b54a-9ed9.png

as you suggested before, below code works well, but only in simulation mode (CTRL + F5), no output at all during trading hour.....
RList<BarData> sym2Daily = OtherSymbols["symbol2"].dailyFreq.Bars;

secondly, i've got a currency exception, it appear when i add SGX traded futures, which valued in USD,
i've tried to create a new watchlist folder setting currency in USD, but still not working,
the account currency is in HKD,

pls help,

thanks,
Adam



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems