NexusFi: Find Your Edge


Home Menu

 





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


Discussion in TradeStation

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




 
Search this Thread
  #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?
requesting .nrd replay files from 2026 spy and qqq
The Elite Circle
Datafeed for Atas
Platforms and Indicators
No book, only a stair: journaling fills where price move …
Cryptocurrency
Trump Media to sell instant access to market-moving soci …
Traders Hideout
EA
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
BERN ALGOS algo trading journal
3 thanks
NexusFi site changelog and issues/problem reporting
2 thanks
TopStep Trader disappointment
2 thanks
Want your NinjaTrader indicator created, free?
1 thanks
Running trading strategies on a VPS
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

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 X Reply With Quote
Thanked by:




Last Updated on March 13, 2018


© 2026 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 - Downloads - Top
no new posts