lvl2 indicator

Questions about MultiCharts and user contributed studies.
User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

lvl2 indicator

Postby siscop » 06 Dec 2011

Hi,
are there any lvl 2 indicator or are there any lvl2 keywords i can use to code the indicator myself? IB gives me the next 5 ask and bid amounts.

User avatar
Henry MultiСharts
Posts: 8443
Joined: 25 Aug 2011
Has thanked: 1207 times
Been thanked: 2704 times

Re: lvl2 indicator

Postby Henry MultiСharts » 06 Dec 2011

There are no lvl2 indicators or keywords in MultiCharts.
Lvl2 data can only be accessed through DOM.

SP
Posts: 444
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 280 times

Re: lvl2 indicator

Postby SP » 06 Dec 2011

Not the best solution, but you could use the IB TwsDDE Excel file to request the Level II and then feed it into Multicharts.

I have coded it some months ago, but it should still work.

Code: Select all


inputs:
   int ExcelRow( 27 ),
   int AskExcelColumn (17),
   int BidExcelColumn( 11 ),
   int StartTime( 0800 ),
   string WorkbookName( "TwsDde_MD.xlsm" ),
   string WorksheetName( "Market Depth" ) ;
Inputs:

Text.Size    ( 8 ),
Text.Font    ("Comic Sans MS"),
Spacer    ( 2 ),
TimeSpacer    ( 3 );      
variables:
   TextBegin ( 0 ), Barspace ( 0 ),
   bool InRealTime( false ),
   intrabarpersist bool Initialized( false ),
   bool XLStarted( false ),
   intrabarpersist bool WorksheetReady( false ),
   bool Bid1   ( false ),
   bool Bid2   ( false ),
   bool Bid3   ( false ),
   bool Bid4   ( false ),
   bool Bid5   ( false ),
   bool Ask1   ( false ),
   bool Ask2   ( false ),
   bool Ask3   ( false ),
   bool Ask4   ( false ),
   bool Ask5   ( false ),
   intrabarpersist double oBid1( 0 ),
   intrabarpersist double oBid2( 0 ),
   intrabarpersist double oBid3( 0 ),
   intrabarpersist double oBid4( 0 ),
   intrabarpersist double oBid5( 0 ),
   intrabarpersist double oAsk1( 0 ),
   intrabarpersist double oAsk2( 0 ),
   intrabarpersist double oAsk3( 0 ),
   intrabarpersist double oAsk4( 0 ),
   intrabarpersist double oAsk5( 0 ),
   intrabarpersist BidSize1( 0 ),
   intrabarpersist BidSize2( 0 ),
   intrabarpersist BidSize3( 0 ),
   intrabarpersist BidSize4( 0 ),
   intrabarpersist BidSize5( 0 ),
   intrabarpersist AskSize1( 0 ),
   intrabarpersist AskSize2( 0 ),
   intrabarpersist AskSize3( 0 ),
   intrabarpersist AskSize4( 0 ),
   intrabarpersist AskSize5( 0 ),
   txt1         (0),
   txt2         (0),
   txt3         (0),
   txt4         (0),
   txt5         (0),
   txt6         (0),
   txt7         (0),
   txt8         (0),
   txt9         (0),
   txt10         (0),
   tickvalue(minmove/pricescale),
   HalfTick(tickvalue/2),
   intrabarpersist rightdate(0),
   intrabarpersist righttime(0),
   intrabarpersist thisbar(0) ;

//---------------------------
// calculate date/time for text
//---------------------------
  if GetAppInfo(aiRightDispDateTime)<>thisbar then begin

    thisbar=GetAppInfo(aiRightDispDateTime);
    rightdate=juliantodate(intportion(thisbar));
    righttime=minutestotime( fracportion(thisbar) * 1440)-TimeSpacer ;

  end;
if Barnumber = 1 then  // First bar print the number text
begin
      txt1 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt1,0,2);
      text_SetColor  (txt1,blue);
      txt2 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt2,0,2);
      text_SetColor  (txt2,blue);
      txt3 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt3,0,2);
      text_SetColor  (txt3,blue);
      txt4 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt4,0,2);
      text_SetColor  (txt4,blue);
      txt5 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt5,0,2);
      text_SetColor  (txt5,blue);
      txt6 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt6,0,2);
      text_SetColor  (txt6,red);
      txt7 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt7,0,2);
      text_SetColor  (txt7,red);
      txt8 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt8,0,2);
      text_SetColor  (txt8,red);
      txt9 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt9,0,2);
      text_SetColor  (txt9,red);
      txt10 = text_new (date,Calctime( Time, 5),close ,"");
      text_SetStyle  (txt10,0,2);
      text_SetColor  (txt10,red);
      
      
end;
if Time >= StartTime then
   begin
   
   InRealTime = GetAppInfo( aiRealtimeCalc ) = 1 ;
   
   if InRealTime and Initialized = false then
      begin
      Initialized = true ;
      XLStarted = ELXL_Initialize ;
      WorksheetReady = ELXL_WithSheet( WorkbookName, WorksheetName ) ;
      end ;
      
   
   if InRealTime then
      begin
      
      Bid1= ELXL_GetCellNumberRC( ExcelRow, BidExcelColumn, oBid1) ;
      if Bid1 then BidSize1 = oBid1;
      text_SetLocation(txt1,rightdate,righttime,insidebid);
          text_SetString(txt1,numtostr(bidsize1,0)+ "       "+NumToStr(bidsize1,0));
      
      Bid2= ELXL_GetCellNumberRC( ExcelRow+1, BidExcelColumn, oBid2) ;
      if Bid2 then BidSize2 = oBid2;
      text_SetLocation(txt2,rightdate,righttime,insidebid-onetick);
          text_SetString(txt2,numtostr(bidsize2,0)+ "      "+NumToStr(bidsize1+bidsize2,0));
          
          Bid3= ELXL_GetCellNumberRC( ExcelRow+2, BidExcelColumn, oBid3) ;
      if Bid3 then BidSize3 = oBid3;
      text_SetLocation(txt3,rightdate,righttime,insidebid-2*onetick);
          text_SetString(txt3,numtostr(bidsize3,0)+ "      "+NumToStr(bidsize1+bidsize2+bidsize3,0));
          
          Bid4= ELXL_GetCellNumberRC( ExcelRow+3, BidExcelColumn, oBid4) ;
      if Bid4 then BidSize4 = oBid4;
      text_SetLocation(txt4,rightdate,righttime,insidebid-3*onetick);
          text_SetString(txt4,numtostr(bidsize4,0)+ "      "+NumToStr(bidsize1+bidsize2+bidsize3+bidsize4,0));
          
          Bid5= ELXL_GetCellNumberRC( ExcelRow+4, BidExcelColumn, oBid5) ;
      if Bid5 then BidSize5 = oBid5;
      text_SetLocation(txt5,rightdate,righttime,insidebid-4*onetick);
          text_SetString(txt5,numtostr(bidsize5,0)+ "      "+NumToStr(bidsize1+bidsize2+bidsize3+bidsize4+bidsize5,0));
      
      Ask1= ELXL_GetCellNumberRC( ExcelRow, AskExcelColumn, oAsk1) ;
      if Ask1 then AskSize1 = oAsk1;
      text_SetLocation(txt6,rightdate,righttime,insideAsk);
          text_SetString(txt6,numtostr(Asksize1,0)+ "       "+NumToStr(Asksize1,0));
      
      Ask2= ELXL_GetCellNumberRC( ExcelRow+1, AskExcelColumn, oAsk2) ;
      if Ask2 then AskSize2 = oAsk2;
      text_SetLocation(txt7,rightdate,righttime,insideAsk+onetick);
          text_SetString(txt7,numtostr(Asksize2,0)+"      "+NumToStr(Asksize1+Asksize2,0));
          
          Ask3= ELXL_GetCellNumberRC( ExcelRow+2, AskExcelColumn, oAsk3) ;
      if Ask3 then AskSize3 = oAsk3;
      text_SetLocation(txt8,rightdate,righttime,insideAsk+2*onetick);
          text_SetString(txt8,numtostr(Asksize3,0)+"      "+NumToStr(Asksize1+Asksize2+Asksize3,0));
          
          Ask4= ELXL_GetCellNumberRC( ExcelRow+3, AskExcelColumn, oAsk4) ;
      if Ask4 then AskSize4 = oAsk4;
      text_SetLocation(txt9,rightdate,righttime,insideAsk+3*onetick);
          text_SetString(txt9,numtostr(Asksize4,0)+"      "+NumToStr(Asksize1+Asksize2+Asksize3+Asksize4,0));
          
          Ask5= ELXL_GetCellNumberRC( ExcelRow+4, AskExcelColumn, oAsk5) ;
      if Ask5 then AskSize5 = oAsk5;
      text_SetLocation(txt10,rightdate,righttime,insideAsk+4*onetick);
          text_SetString(txt10,numtostr(Asksize5,0)+"      "+NumToStr(Asksize1+Asksize2+Asksize3+Asksize4+Asksize5,0));
      end ;
      
         
   end ;
   

These users thanked the author SP for the post (total 6):
TJsiscopsptraderSquibHenry MultiСhartsStan Bokov

User avatar
Henrik
Posts: 140
Joined: 13 Apr 2010
Has thanked: 25 times
Been thanked: 11 times

Re: lvl2 indicator

Postby Henrik » 07 Dec 2011

ELXL_GetCellNumberRC


What is that? I can't find this function in MC...
I can't compile this, because of "unknown function".
Thank you!

SP
Posts: 444
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 280 times

Re: lvl2 indicator

Postby SP » 08 Dec 2011

Henrik,

not sure if it is the lastest version.
Attachments
20080521174732ELXL 1.3.1 - Demo Files.zip
(271.5 KiB) Downloaded 45 times
These users thanked the author SP for the post (total 2):
Henriksiscop

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: lvl2 indicator

Postby siscop » 13 Dec 2011

SP,
thank you for your indicator.
On the excel sheet I can update the refresh rate to 0.5 sec and it works. How do I change the refresh rate on your indicator? It seem to only update when the Tradingprice changes. When the marketparticipance keep on trading the same price and the lvl2 data keeps on changing your indicator still shows the old lvl2 data. Is there a way to make it timebased (eg. 0.5 sec) and not MKT price based?

SP
Posts: 444
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 280 times

Re: lvl2 indicator

Postby SP » 13 Dec 2011

At the moment you could only update it once per second with adding the line

RecalcLastbarAfter(1);

at the code. Some months ago i created a pm for that, but it is still under review.
https://www.multicharts.com/pm/viewissue ... _no=MC-451
These users thanked the author SP for the post (total 2):
Henriksiscop

User avatar
siscop
Posts: 188
Joined: 09 Jan 2011
Has thanked: 33 times
Been thanked: 25 times

Re: lvl2 indicator

Postby siscop » 13 Dec 2011

Looking at the screenshot below I see on the left side the Excelsheet with Lvl2 Data, on the right side your indicator with the same data as on the Excelsheet and in the middle the DOM from MC.
The sizes are all the same BUT NOT the Cum size
Do I understand that on the DOM we only see the size of one Person (next one in line) and not the cumulating of all the participance who wants to trade at that price?
Shouldn’t the DOM show all Orders at that LVL?
Attachments
3piclvl22.png
3piclvl22.png (67.34 KiB) Viewed 316 times
3piclvl2.png
3piclvl2.png (75.23 KiB) Viewed 304 times


Return to “MultiCharts”