March 7, 2011
Equalize X-Range for all windows
This function was requested on the main list, and was solved with the help of several expert programmers from the list. Thanks guys!
This function can be copied to an include file that is included in each program from which you might want to synchronize the datetime range for all visible windows. The function places a small [R] button at the right top of your chart. Clicking this button will set the datetime ranges of all windows equal to the one you click the button in. Note that this window has to be active for the button to work, i.e., if the window was not active (selected) it will require two clicks for the button to respond.
function RangeAllWindows() { MX = GetCursorXPosition( 1 ); MY = GetCursorYPosition( 1 ); LeftClick = GetCursorMouseButtons() == 9; // Place Ranging Button ButtonSize=20; X2 = Status( "pxchartright" )+1; X1 = X2 - ButtonSize; Y1 = 0; Y2 = Y1 + ButtonSize; GfxSelectFont( "Tahoma", ButtonSize / 1.5, 800 ); GfxSelectPen( colorBlack , 1 ); GfxSelectSolidBrush( colorYellow ); GfxRectangle( X1, Y1, X2, Y2 ); GfxSetTextColor( colorBlack ); GfxSetBkMode( 1 ); GfxDrawText( "R", X1, Y1, X2, Y2, 41 ); OnButton = MX >= X1 AND MY >= Y1 AND MX <= X2 AND MY <= Y2; if ( OnButton AND LeftClick ) { DT = DateTime(); BI = BarIndex(); FirstBarIndex = Status( "firstvisiblebarindex" ); LastBarIndex = Status( "lastvisiblebarindex" ); FirstDateTime = LastValue( ValueWhen( FirstBarIndex == BI, DT ) ); LastDateTime = LastValue( ValueWhen( LastBarIndex == BI, DT ) ); FirstDateTimestr = DateTimeToStr( FirstDateTime ); LastDateTimestr = DateTimeToStr( LastDateTime ); AB = CreateObject( "Broker.Application" ); docs = AB.Documents; Qty = docs.Count; for ( i = 0; i < Qty; i++ ) // Range all windows { doc = docs.Item( i ); AW = doc.ActiveWindow; AW.Activate(); AW.ZoomToRange( FirstDateTimestr, LastDateTimestr ); // correct shift due to blank bars WSHShell = CreateObject( "WScript.Shell" ); WSHShell.AppActivate( "AmiBroker" ); WSHShell.Sendkeys( "{PGDN}" ); } } } //Demo Code RangeAllWindows(); Plot(C,"",1,128);
Filed by Herman at 7:17 am under AFL - Utilities and Functions
Comments Off on Equalize X-Range for all windows