RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        


123»»»

Bars Since? Expand / Collapse
Message
Posted 8/13/2007 17:03:05 Post #3336
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
How do I determine how many bars ago a particular event occurred?

For instance, Bars Since ( close == highestvalue(close,last 20 bars) );
Posted 8/13/2007 17:16:02 Post #3337
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
It depends on the event.  Much of our bar analysis functions are in the BarUtils class.  You can get things like HighestHigh, LowestLow, Lookback, etc.

jthorne (8/13/2007)
How do I determine how many bars ago a particular event occurred?

For instance, Bars Since ( close == highestvalue(close,last 20 bars) );
Posted 8/13/2007 17:21:38 Post #3338
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Right. And I am using a couple of them... but I need something that basically tells me how many bars it has been since a condition was true. Any condition.

For example:
Condition = Close <= 5

bars.since(Condition) = how many bars since Close crossed above 5

Does this clarify my initial question? In other words, take any condition that would evaluate true or false (such as those used in an "if" statement), and tell me how many bars it has been since it evaluated true.
Posted 8/13/2007 17:25:50 Post #3339
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
BTW, while I'm asking newbie questions....

What's the easiest way to find out if the last trade made in your strategy was long or short? I have a different trailing stop level I used based on whether it is long or short, so once I have a position open, I'll adjust the stop each bar, but the distance I'm trailing is dependent on short/long.
Posted 8/13/2007 17:43:47 Post #3340
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
Not out of the box, no.  For now, you'd have to write a quick function to handle this.

Here's a rough idea of how I'd approach it.

double highestValue = 0.0;
int since = 0;

List<BarData> bars = BarCollections[symbol];
for (int index = bars.Count - 20; index < bars.Count; index++)
{
    if (bar.Close > highestValue)
    {
        highestValue = bar.Close;
        int since = index;
    }
}

since = bars.Count - since;

This may be a good utility class for us to implement though.

billb (8/13/2007)
It depends on the event.  Much of our bar analysis functions are in the BarUtils class.  You can get things like HighestHigh, LowestLow, Lookback, etc.

jthorne (8/13/2007)
How do I determine how many bars ago a particular event occurred?

For instance, Bars Since ( close == highestvalue(close,last 20 bars) );
Posted 8/13/2007 17:51:18 Post #3341
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Yeah, it is super handy.

Thanks for the code snippet. Still adjusting my code from NinjaTrader over to RightEdge and sorting out the differences. They have an MRO function (Most Recent Occurrence)... that's where I hit the wall.
Posted 8/13/2007 18:03:15 Post #3342
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
A few ways to go about this.

If it's an open position, call PositionManager.GetOpenPositions() and get the last one in the list.  If it's closed, apply the same except for call GetClosedPositions().  Another option here is to handle the OrderFilled event.  When you get this, set your last position filled as a member variable in your class.  From the Position class the PositionType member contains the value of long or short.

jthorne (8/13/2007)
BTW, while I'm asking newbie questions....

What's the easiest way to find out if the last trade made in your strategy was long or short? I have a different trailing stop level I used based on whether it is long or short, so once I have a position open, I'll adjust the stop each bar, but the distance I'm trailing is dependent on short/long.
Posted 8/13/2007 18:04:05 Post #3343
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
We'll put that on the feature list.  We're always very interested in making life a little easier with our class library.

jthorne (8/13/2007)
Yeah, it is super handy.

Thanks for the code snippet. Still adjusting my code from NinjaTrader over to RightEdge and sorting out the differences. They have an MRO function (Most Recent Occurrence)... that's where I hit the wall.
Posted 8/13/2007 18:45:25 Post #3344
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
For some reason, I can't get anything to compile... here's a code snippet:

List openPositions = PositionManager.GetOpenPositions(symbol);

if (openPositions.Count >= 1)
{
if ( openPositions.PositionType == Long )
{
... long code ...
}
...
Posted 8/13/2007 19:01:12 Post #3345
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
What's the error message?

It looks like you should have "List<Position> openPositions = ...", though.

Additionally, this looks suspect:  "openPositions.PositionType".  You need to access a specific index into this collection.  openPosistions[0].PositionType would be the first element in the list.  Without knowing your itentions, though, it's hard to say what you should have there.

« Prev Topic | Next Topic »

123»»»

Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: billb, young, dplaisted

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 1:12am

2005-2007 © RightEdge Systems