-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathConnors_HighProbEtfTrading.cs
More file actions
605 lines (464 loc) · 22 KB
/
Copy pathConnors_HighProbEtfTrading.cs
File metadata and controls
605 lines (464 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
//==============================================================================
// Project: TuringTrader, algorithms from books & publications
// Name: Connors_HighProbEtfTrading
// Description: Strategy, as published in Larry Connors and Cesar Alvarez book
// 'High Probability ETF Trading'.
// History: 2019iii28, EFB, created
//------------------------------------------------------------------------------
// Copyright: (c) 2011-2025, Bertram Enterprises LLC dba TuringTrader.
// https://www.turingtrader.org
// License: This file is part of TuringTrader, an open-source backtesting
// engine/ trading simulator.
// TuringTrader is free software: you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
// TuringTrader is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public
// License along with TuringTrader. If not, see
// https://www.gnu.org/licenses/agpl-3.0.
//==============================================================================
#region libraries
using System;
using System.Collections.Generic;
using System.Linq;
using TuringTrader.Algorithms.Glue;
using TuringTrader.Indicators;
using TuringTrader.Optimizer;
using TuringTrader.Simulator;
#endregion
namespace TuringTrader.BooksAndPubs
{
#region common algorithm core
public abstract class Connors_HighProbEtfTrading_Core : AlgorithmPlusGlue
{
#region settings
protected virtual string MARKET => "SPY";
[OptimizerParam(0, 1, 1)]
public virtual int AGGRESSIVE_ON { get; set; } = 0;
public virtual OrderType ORDER_TYPE => OrderType.closeThisBar;
#endregion
protected abstract double Rules(Instrument i);
#region public override IEnumerable<Bar> Run(DateTime? startTime, DateTime? endTime)
public override IEnumerable<Bar> Run(DateTime? startTime, DateTime? endTime)
{
//========== initialization ==========
StartTime = startTime ?? Globals.START_TIME;
EndTime = endTime ?? Globals.END_TIME;
WarmupStartTime = StartTime - TimeSpan.FromDays(63);
Deposit(Globals.INITIAL_CAPITAL);
CommissionPerShare = Globals.COMMISSION;
var market = AddDataSource(MARKET);
//========== simulation loop ==========
var entryPrices = new Dictionary<Instrument, double>();
foreach (var s in SimTimes)
{
if (!Alloc.Allocation.ContainsKey(market.Instrument))
Alloc.Allocation[market.Instrument] = 0.0;
double percentToBuySell = Rules(market.Instrument);
//----- entries
if (market.Instrument.Position >= 0 && percentToBuySell > 0
|| market.Instrument.Position <= 0 && percentToBuySell < 0)
{
int sharesToBuySell = (int)(Math.Sign(percentToBuySell) * Math.Floor(
Math.Abs(percentToBuySell) * NetAssetValue[0] / market.Instrument.Close[0]));
Alloc.Allocation[market.Instrument] += percentToBuySell;
market.Instrument.Trade(sharesToBuySell, ORDER_TYPE);
}
//----- exits
if (market.Instrument.Position > 0 && percentToBuySell < 0
|| market.Instrument.Position < 0 && percentToBuySell > 0)
{
// none of the algorithms attempt to gradually
// exit positions, so this is good enough
Alloc.Allocation[market.Instrument] = 0.0;
market.Instrument.Trade(-market.Instrument.Position, OrderType.closeThisBar);
}
//----- output
if (!IsOptimizing && TradingDays > 0)
{
_plotter.AddNavAndBenchmark(this, market.Instrument);
_plotter.AddStrategyHoldings(this, market.Instrument);
if (Alloc.LastUpdate == SimTime[0])
_plotter.AddTargetAllocationRow(Alloc);
}
var v = 10.0 * NetAssetValue[0] / Globals.INITIAL_CAPITAL;
yield return Bar.NewOHLC(
string.Format("{0}-{1}", this.GetType().Name, market.Instrument.Symbol),
SimTime[0],
v, v, v, v, 0);
}
//========== post processing ==========
if (!IsOptimizing)
{
_plotter.AddTargetAllocation(Alloc);
_plotter.AddOrderLog(this);
_plotter.AddPositionLog(this);
_plotter.AddPnLHoldTime(this);
_plotter.AddMfeMae(this);
_plotter.AddParameters(this);
}
FitnessValue = this.CalcFitness();
}
#endregion
}
#endregion
//===== 7 strategies
#region 3-Day High/Low
public class Connors_HighProbEtfTrading_3DayHighLow : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' 3-Day High/Low";
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var sma5 = i.Close.SMA(5);
var down3 = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev
&& i.High[idx] < i.High[idx + 1]
&& i.Low[idx] < i.Low[idx + 1]);
var up3 = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev
&& i.High[idx] > i.High[idx + 1]
&& i.Low[idx] > i.Low[idx + 1]);
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && down3) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && up3)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && i.Close[0] > sma5[0]) // long
|| (i.Position < 0 && i.Close[0] < sma5[0])) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && i.Close[0] < _entryPrices[i]) // long
|| (i.Position < 0 && i.Close[0] > _entryPrices[i]))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region RSI 25 & RSI 75
public class Connors_HighProbEtfTrading_Rsi25Rsi75 : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' RSI 25 & RSI 75";
[OptimizerParam(10, 30, 5)]
public int ENTRY_MAX_RSI_LONG = 25;
[OptimizerParam(10, 30, 5)]
public int ENTRY2_MAX_RSI_LONG = 20;
[OptimizerParam(50, 75, 5)]
public int EXIT_MIN_RSI_LONG = 55;
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
int ENTRY_MIN_RSI_SHORT = 100 - ENTRY_MAX_RSI_LONG;
int ENTRY2_MIN_RSI_SHORT = 100 - ENTRY2_MAX_RSI_LONG;
int EXIT_MAX_RSI_SHORT = 100 - EXIT_MIN_RSI_LONG;
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var rsi4 = i.Close.RSI(4);
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && rsi4[0] < ENTRY_MAX_RSI_LONG) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && rsi4[0] > ENTRY_MIN_RSI_SHORT)) // short
{
_numPositions[i] = 1;
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && rsi4[0] > EXIT_MIN_RSI_LONG)
|| (i.Position < 0 && rsi4[0] < EXIT_MAX_RSI_SHORT))
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && rsi4[0] < ENTRY2_MAX_RSI_LONG) // long
|| (i.Position < 0 && rsi4[0] > ENTRY2_MIN_RSI_SHORT))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region R3
public class Connors_HighProbEtfTrading_R3 : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' R3";
[OptimizerParam(50, 70, 5)]
public int ENTRY_MAX_RSI_2_LONG = 60;
[OptimizerParam(5, 30, 5)]
public int ENTRY_MAX_RSI_0_LONG = 10;
[OptimizerParam(55, 85, 5)]
public int EXIT_MIN_RSI_LONG = 70;
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
int ENTRY_MIN_RSI_2_SHORT = 100 - ENTRY_MAX_RSI_2_LONG;
int ENTRY_MIN_RSI_0_SHORT = 100 - ENTRY_MAX_RSI_0_LONG;
int EXIT_MAX_RSI_SHORT = 100 - EXIT_MIN_RSI_LONG;
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var rsi2 = i.Close.RSI(2);
var rsiDown = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev && rsi2[idx] < rsi2[idx + 1])
&& rsi2[0] < ENTRY_MAX_RSI_0_LONG
&& rsi2[2] < ENTRY_MAX_RSI_2_LONG;
var rsiUp = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev && rsi2[idx] > rsi2[idx + 1])
&& rsi2[0] > ENTRY_MIN_RSI_0_SHORT
&& rsi2[2] > ENTRY_MIN_RSI_2_SHORT;
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && rsiDown) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && rsiUp)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && rsi2[0] > EXIT_MIN_RSI_LONG) // long
|| (i.Position < 0 && rsi2[0] < EXIT_MAX_RSI_SHORT)) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && i.Close[0] < _entryPrices[i]) // long
|| (i.Position < 0 && i.Close[0] > _entryPrices[i]))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region %b
public class Connors_HighProbEtfTrading_PercentB : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' %b";
[OptimizerParam(10, 30, 5)]
public int ENTRY_MAX_BB_LONG = 20;
[OptimizerParam(70, 90, 5)]
public int EXIT_MIN_BB_LONG = 80;
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
int ENTRY_MIN_BB_SHORT = 100 - ENTRY_MAX_BB_LONG;
int EXIT_MAX_BB_SHORT = 100 - EXIT_MIN_BB_LONG;
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var percentB = i.Close.BollingerBands(5, 1.0).PercentB;
var bLo = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev && percentB[idx] < ENTRY_MAX_BB_LONG / 100.0);
var bHi = Enumerable.Range(0, 3)
.Aggregate(true, (prev, idx) => prev && percentB[idx] > ENTRY_MIN_BB_SHORT / 100.0);
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && bLo) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && bHi)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && percentB[0] > EXIT_MIN_BB_LONG / 100.0) // long
|| (i.Position < 0 && percentB[0] < EXIT_MAX_BB_SHORT / 100.0)) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && percentB[0] < ENTRY_MAX_BB_LONG / 100.0) // long
|| (i.Position < 0 && percentB[0] > ENTRY_MIN_BB_SHORT / 100.0))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region MDU and MDD
public class Connors_HighProbEtfTrading_MduMdd : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' MDU and MDD";
[OptimizerParam(3, 6, 1)]
public int ENTRY_MIN_UP_DN = 4;
[OptimizerParam(4, 7, 1)]
public int UP_DN_WINDOW = 5;
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var sma5 = i.Close.SMA(5);
var daysDn = Enumerable.Range(0, UP_DN_WINDOW)
.Aggregate(0, (prev, idx) => prev + (i.Close[idx] < i.Close[idx + 1] ? 1 : 0));
var daysUp = Enumerable.Range(0, UP_DN_WINDOW)
.Aggregate(0, (prev, idx) => prev + (i.Close[idx] > i.Close[idx + 1] ? 1 : 0));
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && i.Close[0] < sma5[0] && daysDn >= ENTRY_MIN_UP_DN) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && i.Close[0] > sma5[0] && daysUp >= ENTRY_MIN_UP_DN)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && i.Close[0] > sma5[0]) // long
|| (i.Position < 0 && i.Close[0] < sma5[0])) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && i.Close[0] < _entryPrices[i]) // long
|| (i.Position < 0 && i.Close[0] > _entryPrices[i]))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region RSI 10/6 & RSI 90/94
public class Connors_HighProbEtfTrading_Rsi1006Rsi9094 : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' RSI 10/6 & RSI 90/94";
[OptimizerParam(5, 10, 1)]
public int ENTRY_MAX_RSI_LONG = 10;
[OptimizerParam(3, 7, 1)]
public int ENTRY2_MAX_RSI_LONG = 6;
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
protected override double Rules(Instrument i)
{
int ENTRY_MIN_RSI_SHORT = 100 - ENTRY_MAX_RSI_LONG;
int ENTRY2_MIN_RSI_SHORT = 100 - ENTRY2_MAX_RSI_LONG;
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var sma5 = i.Close.SMA(5);
var rsi2 = i.Close.RSI(2);
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && rsi2[0] < ENTRY_MAX_RSI_LONG) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && rsi2[0] > ENTRY_MIN_RSI_SHORT)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return (i.Close[0] > sma200[0] ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
//----- exit positions
else if ((i.Position > 0 && i.Close[0] > sma5[0]) // long
|| (i.Position < 0 && i.Close[0] < sma5[0])) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (AGGRESSIVE_ON > 0 && _numPositions[i] < 2
&& ((i.Position > 0 && rsi2[0] < ENTRY2_MAX_RSI_LONG) // long
|| (i.Position < 0 && rsi2[0] > ENTRY2_MIN_RSI_SHORT))) // short
{
// make sure we increase position size only once
_numPositions[i]++;
return (i.Position > 0 ? 1.0 : -1.0) / (1.0 + AGGRESSIVE_ON);
}
return 0.0;
}
}
#endregion
#region TPS
public class Connors_HighProbEtfTrading_Tps : Connors_HighProbEtfTrading_Core
{
public override string Name => "Connors' TPS";
new public int AGGRESSIVE_ON => 1;
[OptimizerParam(10, 40, 5)]
public virtual int ENTRY_MAX_RSI_LONG { get; set; } = 25;
[OptimizerParam(60, 80, 5)]
public virtual int EXIT_MIN_RSI_LONG { get; set; } = 70;
private Dictionary<Instrument, double> _entryPrices = new Dictionary<Instrument, double>();
private Dictionary<Instrument, int> _numPositions = new Dictionary<Instrument, int>();
private readonly double[] ENTRY_SIZE = { 0.1, 0.2, 0.3, 0.4 };
protected override double Rules(Instrument i)
{
int ENTRY_MIN_RSI_SHORT = 100 - ENTRY_MAX_RSI_LONG;
int EXIT_MAX_RSI_SHORT = 100 - EXIT_MIN_RSI_LONG;
//----- calculate indicators
var sma200 = i.Close.SMA(200);
var rsi2 = i.Close.RSI(2);
if (i.Position == 0)
_numPositions[i] = 0;
//----- enter positions
if ((i.Position == 0 && i.Close[0] > sma200[0] && rsi2[0] < ENTRY_MAX_RSI_LONG && rsi2[1] < ENTRY_MAX_RSI_LONG) // long
|| (i.Position == 0 && i.Close[0] < sma200[0] && rsi2[0] > ENTRY_MIN_RSI_SHORT && rsi2[1] > ENTRY_MIN_RSI_SHORT)) // short
{
_numPositions[i] = 1;
_entryPrices[i] = i.Close[0];
return i.Close[0] > sma200[0]
? ENTRY_SIZE[_numPositions[i] - 1]
: -ENTRY_SIZE[_numPositions[i] - 1];
}
//----- exit positions
else if ((i.Position > 0 && rsi2[0] > EXIT_MIN_RSI_LONG) // long
|| (i.Position < 0 && rsi2[0] < EXIT_MAX_RSI_SHORT)) // short
{
return i.Position > 0 ? -1 : 1;
}
//----- aggressive version: increase position size
else if (_numPositions[i] < 4
&& ((i.Position > 0 && i.Close[0] < _entryPrices[i]) // long
|| (i.Position < 0 && i.Close[0] > _entryPrices[i]))) // short
{
// increase position size up to 3 times
_numPositions[i]++;
_entryPrices[i] = i.Close[0]; // update entry price!
return i.Position > 0
? ENTRY_SIZE[_numPositions[i] - 1]
: -ENTRY_SIZE[_numPositions[i] - 1];
}
return 0.0;
}
//protected override string MARKET => Assets.SPUU; // 2x leveraged
//protected override string MARKET => Assets.SPXL; // 3x leveraged
}
#endregion
}
//==============================================================================
// end of file