Ever dreamed of being able to code tick logic in an indicator, and being able to use on historical bars ? This is for you.
Here's the GomRecordingIndicator indicator that you just have to derive your own indicator from, implement GomOnMarketData and GomInitialize, and you're done !
The GomRecordingIndicator class takes care of recording data on real-time ticks, ans sending recorded data to GomOnMarketData like a virtual data source would do.
Here's how you would code a VWMA for instance :
///////Derive your indicator from GomRecorderClass
public class GomVWMA : GomRecorderIndicator
{
double volsum=0;
double vwma=0;
double currentvwsma;
//////Use GomInitialize like you would use Initialize
protected override void GomInitialize()
{
Add(new Plot(Color.Orange, "GomVWAP"));
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}
//////Put your code here in GomOnMarketData
//////usr it like OnMarketData, and check firstTickOfBar
//////TickType is TickTypeEnum=BelowBid,AtBid,BetweenBidAsk,AtAsk,AboveAsk
/////CAUTION IF NO DATA PRESENT FOR THE BAR YOU WILL RECEIVE (BetweenBidAsk,last known price,0,true) SO VOLUME CAN BE NULL
protected override void GomOnMarketData(TickTypeEnum tickType,double price,int volume,bool firstTickOfBar)
{
if ((firstTickOfBar))
{
volsum=0;
vwma=0;
}
volsum += volume;
vwma += price*volume;
currentvwsma=(volsum>0?vwma/volsum:price);
Value.Set(currentvwsma);
}
}
Caution complete tick info is not recorded, it's limited to price, volume, and ticktype which is : BelowBid,AtBid,BetweenBidAsk,AtAsk,AboveAsk. You can't to bid/ask spread analysis, for instance.
Implementation of the types is less naïve than a simple >=ask or <=bid method, which doesn't take account of the fact that we can have bid=ask or even bid>ask.
Here's what I used :
if (ask<bid) // should not happen but does
{
if (e.Price<ask) tickType=TickTypeEnum.BelowBid;
else if (e.Price==ask) tickType=TickTypeEnum.AtAsk;
else if (e.Price<bid) tickType=TickTypeEnum.BetweenBidAsk;
else if (e.Price==bid) tickType=TickTypeEnum.AtBid;
else tickType=TickTypeEnum.AboveAsk;
}
else if (bid<ask) //normal case
{
if (e.Price<bid) tickType=TickTypeEnum.BelowBid;
else if (e.Price==bid) tickType=TickTypeEnum.AtBid;
else if (e.Price<ask) tickType=TickTypeEnum.BetweenBidAsk;
else if (e.Price==ask) tickType=TickTypeEnum.AtAsk;
else tickType=TickTypeEnum.AboveAsk;
}
else //bid==ask, should not happen
{
if (e.Price<bid) tickType=TickTypeEnum.BelowBid;
else if (e.Price>ask) tickType=TickTypeEnum.AboveAsk;
else tickType=tickType=TickTypeEnum.BetweenBidAsk;
}
There is one file for each Instrument Name and for each file format, so you can use both formats at a time.
You can use multiple indicators implementing the framework on the same instrument, only one of them per file format will have recording capabilities, identified by "Recording OK". Caution : NT logic is sometimes strange, and depending on what you click in Indicators properties, indicators might lose the writing handle : you get a "Recording KO". Press F5 to refresh an recover the handle.
That's about it. You'll find below a picture of VWMA and CD indicator, sharing the same file, the GomRecorderIndicator and the example VWMA example


Comment