Hi guys, time for a YAGOF (Yet another Gom framework ;-) )
I had a problem not being able to access Trades and Trade history from Indicators.
In Ninja's mind, Indicators do the drawing , Strategies run the trades, but what if you want to draw stuff depending on your past trades ?
You can't.
Moreover, if you trade multiple contracts, it's very hard to see your future PnL because of Nninja's average price calculations.
So I coded an interface that directly reads Ninja database and computes the Realized and Unrealized PnL of the day, specific to the instrument being traded on the chart.
This is implemented as an indicator you can derive from, like GomRecorder etc..
Important : prerequisite
You need to add some references in your Ninja's config.xml file.
To do that, close Ninja, open Config.xml in My Documents\NinjaTrader 7\
Add
System.Data.dll
System.Data.SqlServerCe.dll
in the section
Restart Ninja.
Ninja Trader may fail to find SqlServerCe.dll, in that case you must add the full path :
Open any indicator,
Click on right button, choose "References".
Add the System.Data.SqlServerCe.dll which is in the same directory as WilsonORMapper.dll in the same screen.
protected void GomOnTradesModified()
=> this method is called when the database has been modified and a new position has been computed.
Objects
At anytime you can access the TC object, that contains :
TC.RealizedPnL
And if you are in a trade you can use those :
TC.UnrealizedPnL
TC.Size
TC.EntryPrice
TC.IsLong
Be sure to always check is TC object is null.
Sample indicators in the package
GomTradeCalculatorTest :
Prints current PnL and position in the above right corner.
61008
GomDailyProfitLossShow
This indicators uses a parameterized daily profit /loss settings.1. If no trade is in progress, it will show on the chart where you should put your target and stop loss to fill your daily profit/losses.
There are 2 pairs of levels, one for the long side, one for the short side.
Levels are recalculated if you change your position size setting in the trade manager.
2. If a trade is in progress, it will show exits for daily target,daily loss, and daily breakenven
3. If current pnl is above daily target, background goes green, it current pnl is below daily loss, background goes red.
610096101061011 Technical details
The indicator uses a File Watcher to check when the DB is modified, to recompute positions.
Data access is done with a Read Only connection, except the first time, where a writing -enabled connection is used to create an index on a table, to avoid full scanning the executions table
To get the same Unrealized values than in Ninja's Trade Manager, you need to check "use FIFO" in Ninja Options/General