Posted 2/19/2010 14:27:05
|
|
|
|
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
|
|
|
|
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.
|
|
|
|