da420078
 ( 48.44% )
- ago
I have an error message.

Ok, let me ask you this, if I may.

How would you code the following in WL7:

if the current bar is at least 3 bars later than the entry bar.


Thank you.
0
842
Solved
7 Replies

Reply

Bookmark

Sort
- ago
#1
CODE:
Position pos = LastPosition; if (idx - pos.EntryBar + 1 > 3) {    PlaceTrade(bars, TransactionType.Sell, OrderType.Market); }
0
da420078
 ( 48.44% )
- ago
#2
Thanks Eugene.
Ok, so I already have that.
Compiles OK, but gives an error on backtesting "Object reference not set to an instance of an object."

Out of respect to other members, I was avoiding creating a new discussion thread.
0
- ago
#3
QUOTE:
Compiles OK, but gives an error on backtesting "Object reference not set to an instance of an object."

Please give me some context i.e. DataSet / symbols, data range and a more complete sample code that demonstrates the issue.
0
Cone8
 ( 7.72% )
- ago
#4
It's because LastPosition is null. Make sure you've got a position first, like this -

CODE:
public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else {             Position pos = LastPosition;             if (idx - pos.EntryBar + 1 > 3)             {                PlaceTrade(bars, TransactionType.Sell, OrderType.Market);             } } }
0
Best Answer
- ago
#5
It's just a snippet for exit in Post #1, of course it's incomplete.
0
da420078
 ( 48.44% )
- ago
#6
Thanks for your help.
I made some changes and it ran without error.
But no trades ...
There is now quite a large dent in the wall next to me.
In 6.9, I could figure things out more easily.
A quadruple espresso may help.
0
Glitch8
 ( 10.58% )
- ago
#7
If you want to describe your basic entry and exit conditions i’d be happy to mock something up to get you started?
0

Reply

Bookmark

Sort