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;
|