Profile Picture

Position Priority / Sort Order Execution

Posted By mmayer 3 Years Ago
Message
Posted Wednesday March 12 2014
Hi there,

I'm new to RightEdge but coming from WealthLab I'd like to convert a strategy that uses Position Priority.

As a default it seems like RightEdge goes thru the symbol-list (let's say 500) and on each signal when I use OpenPosition() an order is placed. Then it tries to execute these trades or send it to the backtest-paper-broker in the same order. So this is done in alphabetic order it seems to me, which basically makes sense.

But if for example I get 30 signals for 30 stocks on a day that should be executed Market the next day at the open and I only want 5 positions I'd like to change that sorting-mechanism. For example by an indicator or something else...let's say place the 5 stocks with the highest volume to keep this simple.

How would I do this the easiest way? I'm really End-Of-Day here, not using Limit- or Stop-Orders to enter trades so I don't need to think about that (yet).

Thanks!

Marco
Posted Wednesday March 12 2014
Marco,

Call a method on your SymbolScript via System.NewBar, eg., SymbolScripts[symbol].DetermineEntry(), which returns a List() with each PositionSetting containing a tag that indicates its priority, sort the list via the priority, and open the positions in System.NewBar.

Duane
phg
Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)
Posted Thursday March 13 2014
It reads like the signals are generated throughout the day, possibly including on the last bar (EOD), to be acted upon the next morning. As as alternative approach, the signals could be recorded, as they are generated, in a flat file. On starting the strategy the next morning sort the signals and submit orders to open.

-Pete

See also Yahoo group about applying RE.

Posted Thursday March 13 2014
Signals are generated after the close, so it's really EOD-based but I need this first of all for backtesting and so it should be applied there. Otherwise the flatfile idea would be nice, thanks!

Duane if I got it right this means that each time NewBar is called (so in my case on a new day) RightEdge then goes thru the symbol list. And the idea is to simply change the order of that symbol list each day. Would I do that in the NewBar() where I have my usual code or somewhere else? Sorry for the question but I'm very new to this and still didn't understand exactly how RightEdge goes thru bars/symbols. If there's some documentation about this I'd be happy to read into it but I couldn't find it yet. Maybe you have a simple sample-code for this?

Have a nice day!

Marco
Posted Thursday March 13 2014
Here is a sample which shows one way to control the order in which the symbols are processed: Symbol Ranking Sample

In this sample, SymbolScript.NewBar() gets called in the default order, but the Trade() method gets called in the order specified by the system and that's where the orders are actually submitted.

Thanks,
Daniel
Posted Thursday March 13 2014
Hi Daniel,

thanks a lot. This is very helpful. So what happens is that NewBar() from MySystem:MySystemBase is always called first.

In there for each symbol NewBar from MySymbolScript:MySymbolScriptBase is called explicitly and here for each symbol the rank-value gets calculated, nothing else. Then we're back in MySystem:MySystemBase where we go thru the now ranked symbols and what usually happens in NewBar() in MySystem:MySystemBase now happens in MySystem:MySystemBase Trade().

Did I get the principle right? Any pitfalls here I have to keep an eye on?

Marco
Posted Thursday March 13 2014
The system class (ie MySystem) NewBar() method is called first. By default, the implementation of this method (in MySystemBase) iterates through each symbol and calls SymbolScript.NewBar() for each one. If you override the NewBar() method in MySystem, then the SymbolScript NewBar methods will be called when you call base.NewBar(). If you don't call base.NewBar() then the SymbolScript NewBar methods won't be called automatically, which gives you the chance to call them explicitly in whatever order you want.

In the symbol ranking sample, the call to base.NewBar in MySystem.NewBar causes each SymbolScript NewBar to be called, which updates the rank value. Then the MySystem.NewBar method orders the symbols by the rank and calls the Trade() method for each of them.

Hopefully that helps make it clearer.

Thanks,
Daniel

EDIT: Fixed second paragraph, as pointed out by Pete.
phg
Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)
Posted Friday March 14 2014
Daniel, that is an informative and helpful post. Thanks. Just to further help my understanding along I have two follow-ups. First, in your second paragraph, shouldn't it be 'MySystem.NewBar' rather than "MySymbolScript.NewBar"?

Second, I am not clear how "SymbolScripts.NewBar();" works? Does that cause an iteration? Probably one source of confusion is where does base.NewBar get handled? Isn't that always handled in SystemBase? I'm not understanding something, but what?

-Pete

See also Yahoo group about applying RE.

phg
Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)Supreme Being (44,661 reputation)
Posted Monday March 17 2014
I understand part of it: 'base.NewBar' cascades back and then each 'base' is executed in turn on the way back up. That's part of how inheritance works. Good education for me.

-Pete

See also Yahoo group about applying RE.



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems