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);
    MY GetCursorYPosition);
    LeftClick GetCursorMouseButtons() == 9;

    // Place Ranging Button
    ButtonSize=20;
    X2 Status"pxchartright" )+1;
    X1 X2 ButtonSize;
    Y1 0;
    Y2 Y1 ButtonSize;
    GfxSelectFont"Tahoma"ButtonSize 1.5800 );
    GfxSelectPencolorBlack );
    GfxSelectSolidBrushcolorYellow );
    GfxRectangleX1Y1X2Y2 );
    GfxSetTextColorcolorBlack );
    GfxSetBkMode);
    GfxDrawText"R"X1Y1X2Y241 );
    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 LastValueValueWhenFirstBarIndex == BIDT ) );
        LastDateTime LastValueValueWhenLastBarIndex == BIDT ) );
        FirstDateTimestr DateTimeToStrFirstDateTime );
        LastDateTimestr DateTimeToStrLastDateTime );
        AB CreateObject"Broker.Application" );
        docs AB.Documents;
        Qty docs.Count;

        for ( 0Qtyi++ ) // Range all windows
        {
            doc docs.Item);
            AW doc.ActiveWindow;
            AW.Activate();
            AW.ZoomToRangeFirstDateTimestrLastDateTimestr );
            // correct shift due to blank bars
            WSHShell CreateObject"WScript.Shell" );
            WSHShell.AppActivate"AmiBroker" );
            WSHShell.Sendkeys"{PGDN}" );
        }
    }
}

//Demo Code
RangeAllWindows();
Plot(C,"",1,128);

Comments are closed.