NexusFi: Find Your Edge


Home Menu

 





Error: (EL) Invalid index used to access element of a collection


Discussion in TradeStation

Updated
    1. trending_up 2,018 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

Error: (EL) Invalid index used to access element of a collection

  #1 (permalink)
DirtyGoats
Lakeville
 
Posts: 11 since Dec 2017
Thanks Given: 3
Thanks Received: 1

Good Day.
I've been trying to work with the Price Series Provider by watching/reading different sources and I'm coming across an error that Googling isn't helping. The error I'm receiving is: Invalid index used to access element of a collection.

My EL skills are very green. A lot of trial by error.

Below is all my code and wondering if someone could lend a hand in identification of my issue at hand. Also, any pointers/recommendations to how I'm typing this code would be appreciated, too.

Appreciate the time looking/reading/commenting.

****Code****

using
elsystem;

Inputs:
//Price Series Provider
Underlying_Symbol ("SPY"),

//Trading Time
Start_Time(0830),
End_Time(1430),
Exit_All_Time(1455),

//Trailing and Stop Loss
StartTrailing( 5 ) [DisplayName = "FloorAmt", ToolTip =
"Floor Amount. Enter amount of open profit required to activate this trailing stop."],
TrailingPct( 10 ) [DisplayName = "TrailingPct", ToolTip =
"Trailing Percentage. Enter the percent to trail the stop. For 20%, enter 20, not 0.20."],
PositionBasis( false ) [DisplayName = "PositionBasis", ToolTip =
"Enter true if currency amounts (profit targets, stops, etc.) are for the entire position; enter false if currency amounts are per share or per contract."],
StopLossPercent( .10 ) [DisplayName = "StopLossPct", ToolTip =
"Stop Loss Percent. Enter the percentage at which to exit using a stop loss, as a decimal, or 0 for no stop loss. Example: 0.1 = 10%."],

//SuperTrend
atrPeriod(20),
atrMultA(1),
atrMultB(1.5),
atrMultC(2),


Variable:
//Price Series Provider
tsdata.marketdata.PriceSeriesProvider PSP(NULL) ,

//SuperTrend
//SuperTrend A
atrA(0),
tsA(0),
shstpA(0),
lgstpA(0),
trendA(0),
//SuperTrend B
atrB(0),
tsB(0),
shstpB(0),
lgstpB(0),
trendB(0),
//SuperTrend C
atrC(0),
tsC(0),
shstpC(0),
lgstpC(0),
trendC(0),


//Trailing and Stop Loss
double FloorAmt ( 0 ),
double StopLossPct ( 0 ),



begin
PSP = new tsdata.marketdata.PriceSeriesProvider;

PSP.Symbol = Underlying_Symbol;
PSP.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
PSP.Interval.IntervalType = tsdata.marketdata.DataIntervalType.minutes;
PSP.Interval.IntervalSpan = 5;
PSP.Interval.Name = "(Unknown name)";
PSP.Range.Type = tsdata.marketdata.DataRangeType.Bars;
PSP.Range.FirstDate = DateTime.fromELDateandTime ( D, T);
PSP.Range.Name = "(Unknown name)";
PSP.IncludeVolumeInfo = false;
PSP.IncludeTicksInfo = false;
PSP.UseNaturalHours = false;
PSP.Realtime = true;
PSP.TimeZone = tsdata.common.TimeZone.local;
PSP.Load = true;
PSP.Name = "PSP";
end;



//SuperTrend
//SuperTrend A
atrA = AvgTrueRange(AtrPeriod);

lgstpA = PSP.close[0] - atrA * atrMultA;
shstpA = PSP.close[0] + atrA * atrMultA;

if PSP.close[0] >= tsA[1] then
trendA = 1
else if close < tsA[1] then
trendA = -1;

if trendA > 0 then
if trendA[1] < 0 then tsA=lgstpA[0]
else if lgstpA >= tsA[1] then tsA=lgstpA[0]
else tsA=tsA[1];

if trendA < 0 then
if trendA[1] > 0 then tsA=shstpA[0]
else if shstpA <= tsA[1] then tsA=shstpA[0]
else tsA=tsA[1];

//SuperTrend B
atrB = AvgTrueRange(AtrPeriod);

lgstpB = PSP.close[0] - atrB * atrMultB;
shstpB = PSP.close[0] + atrB * atrMultB;

if PSP.close[0] >= tsB[1] then
trendB = 1
else if close < tsB[1] then
trendB = -1;

if trendB > 0 then
if trendB[1] < 0 then tsB=lgstpB[0]
else if lgstpB >= tsB[1] then tsB=lgstpB[0]
else tsB=tsB[1];

if trendB < 0 then
if trendB[1] > 0 then tsB=shstpB[0]
else if shstpB <= tsB[1] then tsB=shstpB[0]
else tsB=tsB[1];

//SuperTrend C
atrC = AvgTrueRange(AtrPeriod);

lgstpC = PSP.close[0] - atrC * atrMultC;
shstpC = PSP.close[0] + atrC * atrMultC;

if PSP.close[0] >= tsC[1] then
trendC = 1
else if close < tsC[1] then
trendC = -1;

if trendC > 0 then
if trendC[1] < 0 then tsC=lgstpC[0]
else if lgstpC >= tsC[1] then tsC=lgstpC[0]
else tsC=tsC[1];

if trendC < 0 then
if trendC[1] > 0 then tsC=shstpC[0]
else if shstpC <= tsC[1] then tsC=shstpC[0]
else tsC=tsC[1];


If Marketposition = 0 and Time > Start_Time and Time < End_Time then
Begin
If trendA = -1 and trendB = -1 and trendC = -1 then buy ("Put") 1 contract next bar at market;

end;

SetStopContract;
SetPercentTrailing( StartTrailing , TrailingPct );

If Marketposition <> 0 then
Begin
If trendA = 1 and trendB = 1 and trendC = -1 then sell ("P-Exit1") from entry ("Put") 1 contract next bar at market;
If trendA = 1 and trendB = 1 and trendC = 1 then sell ("P-Exit2") from entry ("Put") 1 contract next bar at market;
if time > Exit_All_Time then sell ALL contracts next bar at market;

End;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
NexusFi Journal Challenge - May 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
48 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,435 since Apr 2013
Thanks Given: 482
Thanks Received: 1,628

DirtyGoats,

the error message could come up when you are trying to access an index of a collection that doesn't exist. In your case the PSP might not be loaded when you try to access it. You could add a check that the Count of the PSP is >= 1 before trying to access PSP.Close[0].

This link provides some more information and links for PSPs: https://community.tradestation.com/wiki/display/EasyLanguage/PriceSeriesProvider+%28PSP%29+Class

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on March 13, 2018


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts