I want to write an very interesting RT indicator and therefore I 
need the same RT data the Time & Sales window uses. As a start, I 
wrote some test code for catching Trades only – just to check if it 
works. Unfortunately it doesn't and I would highly appreciate some 
advice, since it's not much RT coding examples out there to look at.

The below code catch Trade data- but the problem is that it misses a 
lots of it and especially duplicates (Time, price and size- all the 
same). It creates its own duplicates. It also seems that for stocks 
like AAPL, the program just can't keep up with the speed of data 
coming in….

Advice is highly appreciated! Thanks- Jorgen

_SECTION_BEGIN("Time and Sales Data Collection Test");
RequestTimedRefresh(0);

// This simple method to check if we have changed Symbol only works 
if you 
// use only one chart! But good enough for testing and let change of 
symbol reset
// the Static data and start with a new test.
if(StaticVarGetText( "Old_Symbol_Name" ) != Name())
{
        //Say("New Symbol");
        StaticVarSetText( "Old_Symbol_Name", Name()); 
        StaticVarSet("Bull_Volume", 0);
        StaticVarSet("Bear_Volume", 0);
        StaticVarSet("Neutral_Volume", 0);
        StaticVarSet("TradedTotalVolume", 1);
// Put 1 since with 0, the variable will be "{Empty}"
        StaticVarSet("AskPrice", 0);
        StaticVarSet("BidPrice", 0);
}       

// ====== RETRIEVE RT DATA: ======
AskPrice                = GetRTData("Ask"); 
AskSize                 = GetRTData("AskSize"); 
BidPrice                = GetRTData("Bid");
BidSize         = GetRTData("BidSize");
LastPrice               = GetRTData("Last"); 
TradeVolume     = GetRTData("TradeVolume");
TotalVolume     = GetRTData("TotalVolume");
UpdateTime              = GetRTData("UpdateTime");
//ChangeTime            = GetRTData("ChangeTime");
// UpdateTime will unfortunately give the same time as
// "ChangeTime"- at least when using IQFeed.

Trade   = IIf(StaticVarGet("TradedTotalVolume") < TotalVolume, 1, 0);
if(Trade)
{
 StaticVarSet("TradedTotalVolume", TotalVolume); 
 // Write the Data to file:
 Symbol = Name();
 fh = fopen( "C:\\SaveData\\" + Symbol + " Time and Sales 
Data.txt", "a");
 if(fh)
        { 
                qsA = StrFormat("%.0f", UpdateTime); 
                qsB = StrFormat("%.2f,%.0f\n", LastPrice, 
TradeVolume); 
                fputs(qsA + "," + "Trade" + "," + qsB , fh);
                fclose(fh);     
        }
}

_SECTION_END();



Reply via email to