Recode Strategy as Stop-and-Reverse
Author: Christos
Creation Date: 4/19/2011 7:22 AM
profile picture

Christos

#1
Can you please help me code the phollowing strategy on a stop and reverse scheme?



CODE:
Please log in to see this code.
profile picture

Eugene

#2
Since the entry and exit are NOT symmetrical as there's an AtClose exit, the short side is missing altogether, are we supposed to guess/suggest/invent the rules? ;)
profile picture

Christos

#3
Well, I am somewhat confused by your answer...

Could the answer to your question be that I want to exit AtClose on the same conditions both long and short trades?

So this would be a SAR strategy that would reset at the end of each quarter.

Am I missing something?

profile picture

Eugene

#4
CODE:
Please log in to see this code.
profile picture

Christos

#5
Eugene - thanks a lot for the code!

I have added ShortAtStop in "entry following reset" and in "first trade" so as to let the system trade whichever comes first (did't want to lose some trades after reset) and I don't see any problem. What are your thoughts on this?

I also noticed that you deleted the if condition I had written for a backtest only mode vs an alert only mode. The reason I had that in place was that I was getting an "index out of range" error (when I had the loop ending at Bars.Count) since I had that end of quarter condition. Did you see any problem with that?

profile picture

Eugene

#6
QUOTE:
I have added ShortAtStop in "entry following reset" and in "first trade" so as to let the system trade whichever comes first (did't want to lose some trades after reset) and I don't see any problem.

Sure, if the syntax is correct, it's OK to enter both orders there.
QUOTE:
The reason I had that in place was that I was getting an "index out of range" error (when I had the loop ending at Bars.Count) since I had that end of quarter condition. Did you see any problem with that?

No I don't. This way, the code unintentionally accesses the data at an invalid bar number, so what you and I did were ways to avoid violating the boundary.
profile picture

akardar1

#7
Hi All,

I am also implementing a SAR system.

I am using this code snippet from Eugene's example:

QUOTE:


Position p = LastPosition;

if ( p.PositionType == PositionType.Long )
{
if(SellAtStop( bar+1, p, stop ))
ShortAtStop( bar+1, stop );
}
else
{
if(CoverAtStop( bar+1, p, stop ))
BuyAtStop( bar+1, stop );
}



One thing I have noticed is that the exits and entries are not taken on the same bar even though they are passed the same bar number and stop value.

Is this a design of the methods or am I missing something?

Thanks
profile picture

Eugene

#8
The exits and entries ARE taken on the same bar at at the same price. If your experience is different, more details would help (as per this checklist: How to report a Problem?)
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).