RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        



CrossOver/Under function on previous bars Expand / Collapse
Message
Posted 2/19/2010 14:27:05 Post #10915
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Hi,

I have the following code. Essentially, the problem I had to solve was when the 2 EMAs cross over, close positions at next day open. First, I couldn't find a function to close an order on next day open. So, what I had to do was check for a cross under yesterday and submit a closeatmarket order. Is there a better way of doing this? Also, can the SystemUtils.CrossUnder() function check for previous day instead of only the current day?

// if( SystemUtils.CrossUnder(ShortEMA, LongEMA) )
if( Bars.Count > 2 && ShortEMA.LookBack(1) < LongEMA.LookBack(1) && ShortEMA.LookBack(2) >= LongEMA.LookBack(2) )
{
foreach(Position pos in OpenPositions)
{
pos.CloseAtMarket();
}
}

Thanks in advance.
RightEdge seems to be really awesome. I've just started evaluating it, and I really like the flexibility and plugins, etc.
Posted 2/22/2010 08:16:20 Post #10929
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
A couple of style pointers. One, you could move the if Bars.Count check to the top to take it out of that larger if.

if (Bars.Count < 3)
{
return;
}

Second, you can check yesterday, but it would involve creating a "shifted" indicator. So declare the Shift indicator and shift your EMA back one period. That would remove the need to do a lookback, since Shift is essentially looking back for you.

zykem (2/19/2010)
Hi,

I have the following code. Essentially, the problem I had to solve was when the 2 EMAs cross over, close positions at next day open. First, I couldn't find a function to close an order on next day open. So, what I had to do was check for a cross under yesterday and submit a closeatmarket order. Is there a better way of doing this? Also, can the SystemUtils.CrossUnder() function check for previous day instead of only the current day?

// if( SystemUtils.CrossUnder(ShortEMA, LongEMA) )
if( Bars.Count > 2 && ShortEMA.LookBack(1) < LongEMA.LookBack(1) && ShortEMA.LookBack(2) >= LongEMA.LookBack(2) )
{
foreach(Position pos in OpenPositions)
{
pos.CloseAtMarket();
}
}

Thanks in advance.
RightEdge seems to be really awesome. I've just started evaluating it, and I really like the flexibility and plugins, etc.
« Prev Topic | Next Topic »


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

Permissions Expand / Collapse

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

2005-2007 © RightEdge Systems