EnableTextOutput( False); RED = colorRed; // for shorter function calls BLK = colorBlack; DGN = colorGreen; BGN = colorBrightGreen; PGN = colorPaleGreen; BLU = colorBlue; LBU = colorLightBlue; YEL = colorYellow; WHT = colorWhite; IND = colorIndigo; TEA = colorTeal; GRY = colorLightGrey; PNK = colorPink; G50 = colorGrey50; GLD = colorGold; function xTrace( Msg ) { TraceOn = Nz( StaticVarGet( "~TraceOn" ) ); if ( TraceOn ) _TRACE( Msg ); } function xSay( Text ) { global VoiceOn; if ( VoiceOn ) { Say( Text, 0 ); } StaticVarSetText( "~SilentVoice", Text ); } function PerformBacktest() { TDashReportsPath = StaticVarGetText( "~TDashPathReports" ); TDashJSPath = StaticVarGetText( "~TDashJSPath" ); fdelete( TDashReportsPath + "TDashAAReport.txt" ); // Delete old file to make sure we can't ever use old data ShellExecute( TDashJSPath + "TDashBacktest.js", "", "", 0 ); StaticVarSet( "~NewBTPerformed", True ); xtrace( "Perform Backtest" ); } function gfxBlinkingMsg( Msg, x1, y1, x2, y2, TextColor1, TextColor2, FontSize ) { global FontName; local BlinkState, textcolor, fontSize, msg; GfxSelectFont( FontName, FontSize, 700 ); GfxSetBkMode( 1 ); BlinkState = Nz( StaticVarGet( "~BlinkState" ) ); if ( BlinkState ) { StaticVarSet( "~BlinkState", 0 ); GfxSetTextColor( TextColor1 ); } else { StaticVarSet( "~BlinkState", 1 ); GfxSetTextColor( TextColor2 ); } GfxDrawText( Msg, x1, y1, x2, y2, 37 ); } EnableScript( "jscript" ); <% function JSDeletePersistentVariables( TDashPath ) { var fso, tf, f, fc, TDashPath, SysList, filename; fso = new ActiveXObject( "Scripting.FileSystemObject" ); f = fso.GetFolder( TDashPath ); fc = new Enumerator( f.files ); SysList = ""; for ( ; !fc.atEnd(); fc.moveNext() ) { filename = "" + fc.item(); if ( filename.substr( filename.length - 4 ).toUpperCase() == ".PVA" ) { //SysList = SysList + filename + ","; fso.DeleteFile( filename ); } } return SysList; } %> function EmptyTDashFolder() { global TDashPath; script = GetScriptObject(); SysFPList = script.JSDeletePersistentVariables( TDashPath ); } function DeleteComposite( CompositeName ) { xTrace( "Delete Composite" ); oAB = CreateObject( "Broker.Application" ); oStocks = oAB.Stocks(); oStocks.Remove( CompositeName ); oAB.RefreshAll(); } function AddTradeToComposite( OID, Ticker, Action, Qty, Price ) { local Ticker, Action, Price; AutoRunBT = Nz( StaticVarGet( "~AutoRunBT" )); BI = BarIndex(); LBI = LastValue( BI ); if ( Action != "" ) { SignalArray = Nz( Foreign( Ticker + "~SignalArrays", "V", False ) ); BuyPriceArray = Nz( Foreign( Ticker + "~SignalArrays", "O", False ) ); SellPriceArray = Nz( Foreign( Ticker + "~SignalArrays", "H", False ) ); ShortPriceArray = Nz( Foreign( Ticker + "~SignalArrays", "L", False ) ); CoverPriceArray = Nz( Foreign( Ticker + "~SignalArrays", "C", False ) ); TradeQtyArray = Nz( Foreign( Ticker + "~SignalArrays", "I", False ) ); switch ( Action ) { case "BUY": SignalArray[LBI] = SignalArray[LBI] | 1; BuyPriceArray[LBI] = Price; TradeQtyArray[LBI] = Qty; break; case "SELL": SignalArray[LBI] = SignalArray[LBI] | 2; SellPriceArray[LBI] = Price; TradeQtyArray[LBI] = -Qty; break; case "SHORT": SignalArray[LBI] = SignalArray[LBI] | 4; ShortPriceArray[LBI] = Price; TradeQtyArray[LBI] = -Qty; break; case "COVER": SignalArray[LBI] = SignalArray[LBI] | 8; CoverPriceArray[LBI] = Price; TradeQtyArray[LBI] = Qty; break; case "REVLONG": CurrentPos = Nz( StaticVarGet( "~CurrentPosition" ) ); SignalArray[LBI] = SignalArray[LBI] | 8 | 1; CoverPriceArray[LBI] = BuyPriceArray[LBI] = Price; TradeQtyArray[LBI] = 2*abs( CurrentPos ); break; case "REVSHORT": CurrentPos = Nz( StaticVarGet( "~CurrentPosition" ) ); SignalArray[LBI] = SignalArray[LBI] | 2 | 4; SellPriceArray[LBI] = ShortPriceArray[LBI] = Price; TradeQtyArray[LBI] = -( 2*CurrentPos ); break; } AddToComposite( SignalArray, Ticker + "~SignalArrays", "V", 7 | atcFlagEnableInIndicator ); AddToComposite( BuyPriceArray, Ticker + "~SignalArrays", "O", 7 | atcFlagEnableInIndicator ); AddToComposite( SellPriceArray, Ticker + "~SignalArrays", "H", 7 | atcFlagEnableInIndicator ); AddToComposite( ShortPriceArray, Ticker + "~SignalArrays", "L", 7 | atcFlagEnableInIndicator ); AddToComposite( CoverPriceArray, Ticker + "~SignalArrays", "C", 7 | atcFlagEnableInIndicator ); AddToComposite( TradeQtyArray, Ticker + "~SignalArrays", "I", 7 | atcFlagEnableInIndicator ); StaticVarSetText( "~BROrderStatus_" + OID, "Filled" ); // order pending and visible on chart if( AutoRunBT ) PerformBacktest(); } } function RefreshAll( type ) { local type; oAB = CreateObject( "Broker.Application" ); oAB.RefreshAll( Type ); } function gfxDrawVerticalLine( x, Color ) { GfxSelectPen( Color, 1, 0 ); GfxMoveTo( x, 0 ); GfxLineTo( x, Status( "pxheight" ) ); } function gfxDrawHorizontalLine( y, Color ) { GfxSelectPen( Color, 1, 0 ); GfxMoveTo( 0, y ); GfxLineTo( Status( "pxwidth" ), y ); } function AddRowTogfxTitle( Msg, Color, FontName, FontSize, FontWeight ) { local VOrder; Vorder = Nz( VarGet( "VOrder" ) ); LTVPos = FontSize; //Status( "pxwidth" ) / 2; if ( Msg != "" ) { VPos = VOrder * ( 1.4 * FontSize ) + LTVPos/2; HCtr = Status( "pxwidth" )/50; GfxSelectFont( FontName, FontSize, FontWeight ); GfxSetTextAlign( 0 ); // 6 = center alignment GfxSetTextColor( Color ); //ColorRGB( Color , 200 , Color ) ); GfxSetBkMode( 1 ); // transparent GfxTextOut( Msg, HCtr, VPos ); VarSet( "VOrder", ++Vorder ); } } function PersistentVarRemove( VarName ) { global TDashPath; Fn = TDashPath + VarName + ".pva"; fh = fdelete( Fn ) ; return fh; } function PersistentVarGet( VarName ) { global TDashPath; fh = fopen( TDashPath + VarName + ".pva", "r" ); if ( fh ) { String = fgets( fh ); fclose( fh ); Number = StrToNum( String ); } else Number = Null; return Number; } function PersistentVarSet( VarName, Number ) { global TDashPath; String = NumToStr( Number ); fh = fopen( TDashPath + VarName + ".pva", "w" ); if ( fh ) { fputs( String, fh ); fclose( fh ); } return fh; } function PersistentVarSetText( VarName, String ) { global TDashPath; fh = fopen( TDashPath + VarName + ".csv", "w" ); if ( fh ) { fputs( String, fh ); fclose( fh ); } return fh; } function PersistentVarGetText( VarName ) { global TDashPath; fh = fopen( TDashPath + VarName + ".csv", "r" ); if ( fh ) { String = fgets( fh ); fclose( fh ); } else string = ""; return String; } function PersistentListAdd( VarName, String ) { SubStrExists = 0; List = ""; if ( String != "" ) { List = PersistentVarGetText( VarName ); for ( i = 0; ( LoopItem = StrExtract( List, i ) ) != ""; i++ ) { if ( LoopItem == String ) SubStrExists = 1; } if ( NOT SubStrExists ) { List = List + String + ","; PersistentVarSetText( VarName, List ); } } return List; } function PersistentListRemove( VarName, String ) { NewList = ""; if ( String != "" ) { List = PersistentVarGetText( VarName ); for ( i = 0; ( LoopItem = StrExtract( List, i ) ) != ""; i++ ) { if ( LoopItem != String ) NewList = NewList + LoopItem + ","; } PersistentVarSetText( VarName, NewList ); } return NewList; } function PersistentListGet( VarName ) { global TDashPath; fh = fopen( TDashPath + VarName + ".csv", "r" ); if ( fh ) { String = fgets( fh ); fclose( fh ); } else string = ""; return String; } function PersistentVarAddLine( VarName, Line ) { global TDashPath; fh = 0; if ( Line != "" ) { fh = fopen( TDashPath + VarName + ".pva", "a" ); if ( fh ) { fputs( Line + "\n", fh ); fclose( fh ); } } return fh; } function GetLineFromFile( FilePathName, RowNumber ) { fh1 = fopen( FilePathName, "r" ); if ( fh1 ) { RowNum = 0; RLine = ""; while ( ! feof( fh1 ) ) { Line = fgets( fh1 ); if ( RowNum == RowNumber )RLine = Line; Rownum++; } StaticVarSet("NumberTrades", RowNum); fclose( fh1 ); } return StrReplace(RLine,"\n",""); } function setBackGroundColor( BackgroundColor ) { GfxSelectSolidBrush( BackgroundColor ); GfxSelectPen( BackgroundColor ); x2 = Status( "pxwidth" ); y2 = Status( "pxheight" ); GfxRectangle( 0, 0, x2, y2 ); } function gfxOctogonal( x1, y1, x2, y2, z ) { local x1, y1, x2, y2, z; x1 = Nz( x1 ); x2 = Nz( x2 ) - 1; y1 = Nz( y1 ); y2 = Nz( y2 ) - 1; GfxPolygon( x1 + z, y1, x2 - z, y1, x2, y1 + z, x2, y2 - z, x2 - z, y2, x1 + z, y2, x1, y2 - z, x1, y1 + z, x1 + z, y1 ); } function ShowTip( BrushColor, OutlineColor, TextColor, TipWidth, TipHeight, TipFontSize ) { global FontName, FontWeight, pxwidth, pxheight; TipsOn = Nz( StaticVarGet( "~TipsOn" ) ); MXTip = GetCursorXPosition( 1 ); MYTip = GetCursorYPosition( 1 ); x1 = x2 = x3 = x4 = x5 = y1 = y2 = y3 = y4 = y5 = 0; D = 30; TipMsg = VarGetText( "Tip" ); if ( TipsOn AND TipMsg != "" ) { XMid = pxwidth / 2; YMid = pxheight / 2; if ( MXTip < XMid AND MYTip < YMid ) // in Left Top of pane { X1 = MXTip; Y1 = MYTip + D * 0.75; X2 = MXTip + TipWidth; Y2 = MYTip + TipHeight + D * 0.75; X3 = MXTip + D * 0.75; Y3 = Y1; X4 = MXTip + D * 2; Y4 = Y1; X5 = MXTip; Y5 = MYTip; } if ( MXTip > XMid AND MYTip < YMid ) // in Right Top of pane { X1 = MXTip - TipWidth; Y1 = MYTip + D * 0.75; X2 = MXTip; Y2 = MYTip + TipHeight + D * 0.75; X3 = MXTip - D * 0.75; Y3 = Y1; X4 = MXTip - D * 2; Y4 = Y1; X5 = MXTip; Y5 = MYTip; } if ( MXTip < XMid AND MYTip > YMid ) // in left bottom of pane { X1 = MXTip; Y1 = MYTip - TipHeight - D * 0.75; X2 = X1 + TipWidth; Y2 = Y1 + TipHeight; X3 = MXTip + 2 * D; Y3 = Y2 - 1; X4 = MXTip + D * 0.75; Y4 = Y2 - 1; X5 = MXTip; Y5 = y2 + D * 0.75; } if ( MXTip > XMid AND MYTip > YMid ) // In right bottom of pane { X1 = MXTip - TipWidth; Y1 = MYTip - TipHeight - D * 0.75; // Rectangle X2 = X1 + TipWidth; Y2 = Y1 + TipHeight; X3 = X2 - 2 * D; Y3 = Y2 - 1; // Pointer X4 = X2 - D * 0.75; Y4 = Y2 - 1; X5 = X2; Y5 = y2 + D * 0.75; } GfxSetBkMode( 0 ); GfxSelectPen( OutlineColor ); GfxSelectFont( FontName, TipFontSize, FontWeight ); GfxSetTextColor( TextColor ); GfxSelectSolidBrush( BrushColor ); GfxRoundRect( X1, y1, x2, y2, D, D ); GfxPolygon( X3, Y3 , X4 , Y4, X5, Y5 ); // Pointer GfxSelectPen( BrushColor ); // Hide line between RoundRect and Pointer GfxMoveTo( X3, Y3 ); GfxLineTo( X4, Y4 ); GfxDrawText( TipMsg, x1 + 10, y1 + 3, x2 - 10, y2 - 5, 16 + 65 ); } } function ButtonFunctions3D( GroupName, Header, OffLabel, OnLabel, OnButton ) { global LeftClick, LeftDown, LeftButtonRelease, ShowGroupHeader, FontName, FontWeight; ButtonID = GroupName +","+Header+","+OffLabel+","+ OnLabel; ButtonType = VarGetText( "ButtonType_" + ButtonID ); ButtonType = StrToUpper( ButtonType ); ActionString = ""; switch ( ButtonType ) { case "TRIGGER": if ( OnButton AND LeftClick ) { VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOnColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOnTextColor_" + ButtonID ) ); VarSetText( "ButtonLabel_" + ButtonID, VarGetText( "ButtonOnLabel_" + ButtonID ) ); StaticVarSet( "~" + ButtonID + "_State", True ); } else { VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOffColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOffTextColor_" + ButtonID ) ); VarSetText( "ButtonLabel_" + ButtonID, VarGetText( "ButtonOffLabel_" + ButtonID ) ); StaticVarSet( "~" + ButtonID + "_State", False ); } ActionString = GroupName+","+Header+","+VarGetText( "ButtonLabel_" + ButtonID ); break; case "TOGGLE": ToggleState = StaticVarGet( "~" + ButtonID + "_State" ); if ( IsNull( ToggleState ) ) // Initialize if needed, or recall setup! { ToggleState = PersistentVarget( ButtonID + "_State" ); if ( IsNull( ToggleState ) ) PersistentVarSet( ButtonID + "_State", ToggleState = 0 ); StaticVarSet( "~" + ButtonID + "_State", ToggleState ); } if ( LeftClick AND OnButton ) // Change State { if ( ToggleState ) ToggleState = 0; else ToggleState = 1; StaticVarSet( "~" + ButtonID + "_State", ToggleState ); PersistentVarSet( ButtonID + "_State", ToggleState ); OffLabel = VarGetText( "ButtonOffLabel_" + ButtonID ); OnLabel = VarGetText( "ButtonOnLabel_" + ButtonID ); } ToggleState = StaticVarGet( "~" + ButtonID + "_State" ); if ( ToggleState ) // Set new button values { VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOnColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOnTextColor_" + ButtonID ) ); VarSetText( "ButtonLabel_" + ButtonID, VarGetText( "ButtonOnLabel_" + ButtonID ) ); } else { VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOffColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOffTextColor_" + ButtonID ) ); VarSetText( "ButtonLabel_" + ButtonID, VarGetText( "ButtonOffLabel_" + ButtonID ) ); } ActionString = GroupName+","+Header+","+VarGetText( "ButtonLabel_" + ButtonID ); break; case "ROTATE": OffText = VarGetText( "ButtonOffLabel_" + ButtonID ); // get csv list of labels RotateLabels = StrReplace( OffText, "|", "," ); // allow for | separators NumRotates = StrCount( RotateLabels, "," ); // count number of options RotatePos = StaticVarGet( "~" + ButtonID + "_State" ); // Get last static setting if ( IsNull( RotatePos ) ) // Initialize if needed { RotatePos = PersistentVarget( ButtonID + "_State" ); if ( IsNull( RotatePos ) ) PersistentVarSet( ButtonID + "_State", RotatePos = 0 ); StaticVarSet( "~" + ButtonID + "_State", RotatePos ); } if ( LeftClick AND OnButton ) // change option { if ( ++RotatePos > NumRotates ) RotatePos = 0; StaticVarSet( "~" + ButtonID + "_State", RotatePos ); PersistentVarSet( ButtonID + "_State", RotatePos ); VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOnColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOnTextColor_" + ButtonID ) ); } else { VarSet( "ButtonColor_" + ButtonID, VarGet( "ButtonOffColor_" + ButtonID ) ); VarSet( "ButtonTextColor_" + ButtonID, VarGet( "ButtonOffTextColor_" + ButtonID ) ); } RotatePos = StaticVarGet( "~" + ButtonID + "_State" ); Offtext = VarGetText( "ButtonOffLabel_" + ButtonID ); // set new colors VarSetText( "ButtonLabel_" + ButtonID, StrExtract( OffText, RotatePos ) ); ActionString = GroupName+","+Header+","+VarGetText( "ButtonLabel_" + ButtonID ); break; } return ActionString; } function Button3D( Type, X1, Y1, Width, Height, GroupName, Header, OffLabel, OnLabel, OffColor, OnColor, OffTextColor, OnTextColor, ShowState, ActiveState, Tip ) { global FontName, FontWeight, MY, MX, LeftClick, LeftDown, NumChar, ShowHover; global EdgeWidth, HeaderFormat, LabelFormat, ShowGroupHeader, FontWeight3D, pxheight, TextBoxHeight; if ( IsNull( GroupColor = VarGet( "GroupColor" ) ) ) GroupColor = colorBlack; ButtonID = GroupName + "," + Header + "," + OffLabel + "," + OnLabel; // Unique name in this layout X1 = X1 + 1; // outside edge coordinates Y1 = Y1 + 1; X2 = X1 + Width - 2; Y2 = Y1 + Height; X1a = X1 + EdgeWidth; // inside edge coordinates Y1a = Y1 + EdgeWidth + 1; X2a = X2 - EdgeWidth; Y2a = Y2 - EdgeWidth; OnButton = MX > x1a AND MX < x2a AND MY > y1a AND MY < y2a; VarSetText( "ButtonType_" + ButtonID, Type ); VarSetText( "ButtonHeader_" + ButtonID, Header ); VarSetText( "ButtonOffLabel_" + ButtonID, OffLabel ); VarSetText( "ButtonOnLabel_" + ButtonID, OnLabel ); VarSet( "ButtonOffColor_" + ButtonID, OffColor ); VarSet( "ButtonOnColor_" + ButtonID, OnColor ); VarSet( "ButtonOffTextColor_" + ButtonID, OffTextColor ); VarSet( "ButtonOnTextColor_" + ButtonID, OnTextColor ); VarSet( "ButtonOutlineColor", colorGrey50 ); OnButton = OnButton AND ActiveState; ActionString = ButtonFunctions3D( GroupName, Header, OffLabel, OnLabel, OnButton ); if ( ShowState ) { if ( OnButton ) // prefix mouse qualifiers { VarSetText( "TDashAction", ActionString ); if ( LeftClick ) VarSetText( "TDashAction", "~" + ActionString ); else if ( LeftDown ) VarSetText( "TDashAction", "~~" + ActionString ); if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~" + ActionString ); VarSetText( "Tip", Tip ); } if ( OnButton AND ( LeftDown OR LeftClick ) ) // Down shadow patterns { LeftUpperColor = colorGrey50; LowerRightColor = colorLightGrey; } else // Up shadows { LeftUpperColor = colorLightGrey; LowerRightColor = colorGrey50; } if ( ActiveState ) // if in-active greye-out button { FaceColor = VarGet( "ButtonColor_" + ButtonID ); TextColor = VarGet( "ButtonTextColor_" + ButtonID ); } else { FaceColor = colorLightGrey; TextColor = colorGrey50; } ButtonOutlineColor = VarGet( "ButtonOutlineColor" ); Label = VarGetText( "ButtonLabel_" + ButtonID ); Header = VarGetText( "ButtonHeader_" + ButtonID ); GfxSelectSolidBrush( FaceColor ); // Draw button face GfxSelectPen( colorBlack, 1 ); GfxRectangle( x1a, y1a, x2a, y2a ); // Left-Upper Edge GfxSelectPen( LeftUpperColor, 1 ); GfxSelectSolidBrush( LeftUpperColor ); // Top segment GfxPolygon( x1, y1, x2, y1, x2a, y1a, x1a, y1a ); GfxSelectSolidBrush( LeftUpperColor ); // Left segment GfxPolygon( x1, y1, x1, y2, x1a, y2a, x1a, y1a ); GfxSelectPen( ButtonOutlineColor , 1 ); GfxMoveTo( x1, y1 + 1 ); GfxLineTo( x1a + 1, y1a + 1 ); GfxMoveTo( x1 - 1, y1 + 1 ); // Left outline GfxLineTo( x1 - 1, y2 + 1 ); GfxMoveTo( x1, y1 ); // Top outline GfxLineTo( x2, y1 ); // Lower-Right edges GfxSelectPen( LowerRightColor, 1 ); GfxSelectSolidBrush( LowerRightColor ); // Right segment GfxPolygon( x2, y1, x2 - 1, y2 - 1, x2a - 1, y2a - 1, x2a - 1, y1a ); GfxSelectSolidBrush( LowerRightColor ); // Bottom segment GfxPolygon( x1, y2 - 1, x2 - 1, y2 - 1, x2a - 1, y2a - 1, x1a, y2a - 1 ); GfxSelectPen( ButtonOutlineColor , 1 ); GfxMoveTo( x2a - 1, y2a - 1 ); GfxLineTo( x2 + 1, y2 + 1 ); // bottom and right outline GfxSelectPen( ButtonOutlineColor , 1 ); GfxMoveTo( x1, y2 ); GfxLineTo( x2, y2 ); GfxLineTo( x2, y1 - 1 ); if ( OnButton AND NOT LeftDown AND ShowHover ) // Indicate hover { x1b = x1a + 2; y1b = y1a + 2; x2b = x2a - 3; y2b = y2a - 3; GfxSelectPen( TextColor, 1, 2 ); GfxMoveTo( x1b, y1b ); GfxLineTo( x2b, y1b ); GfxLineTo( x2b, y2b ); GfxLineTo( x1b, y2b ); GfxLineTo( x1b, y1b ); } // Auto-size font wrt width and height of button F1 = ( Y2a - Y1a ) / 3; // wrt height F2 = ( X2a - X1a ) / NumChar; // wrt width HFontSize = Min( F1, F2 ); GfxSelectFont( FontName, HFontSize, FontWeight3D ); // add Header and Label (if there is one) to button GfxSetBkMode( 1 ); GfxSetTextColor( TextColor ); if ( Label == "" ) // No label provided { GfxDrawText( Header, x1a, y1a, X2a, Y2a, 37 ); // only header available } else // Header and Label available { Ym = ( Y1a + Y2a ) / 2; GfxDrawText( Header, x1a, y1a, X2a, Ym + 2, HeaderFormat ); GfxDrawText( Label, x1a, Ym - 2, X2a, Y2a, LabelFormat ); } GfxSelectPen( ButtonOutlineColor ); // Button outline GfxMoveTo( x1a, y1a ); GfxLineTo( x2a - 1, y1a ); GfxLineTo( x2a - 1, y2a - 1 ); GfxLineTo( x1a, y2a - 1 ); GfxLineTo( x1a, y1a ); GfxSelectPen( groupcolor ); // Group outline GfxMoveTo( x1 - 1, y1 ); GfxLineTo( x2, y1 ); GfxLineTo( x2, y2 ); GfxLineTo( x1 - 1, y2 ); GfxLineTo( x1 - 1, y1 ); if ( Type == "FILLER" ) // overlay empty button space with group color { GroupColor = VarGet( "GroupColor" ); GfxSelectSolidBrush( GroupColor ); GfxSelectPen( GroupColor, 1 ); GfxRectangle( x1, y1, x2, y2 ); } // count number of buttons for auto-sizing NumButtonRows = Nz( VarGet( "NumButtonRows" ) ); LastYPosition = Nz( VarGet( "LastYPosition" ) ); if ( Y1 > LastYPosition ) { VarSet( "LastYPosition", Y1 ); VarSet( "NumButtonRows", ++NumButtonRows ); } VarSet( "LastYPos", Y2 + 1 ); // to help place next button VarSet( "LastXPos", X2 + 1 ); // add 1 to separate columns } return StaticVarGet( "~" + ButtonID + "_State" ); } function Click() { PlaySound( "C:\\Program Files (x86)\\AmiBroker\\Wav files\\Click.wav" ); } function LinkWithMainChart() { global LeftClick, MX, MY, LeftDown, LeftButtonRelease; QBarVisible = Nz(StaticVarGet( "~QBarVisible" )); if ( QBarVisible ) { StaticVarSet( "~NowDragging_", True ); } else if ( LeftButtonRelease ) { StaticVarSet( "~NowDragging_", False ); StaticVarSet( "~LeftButtonRelease", True ); } if ( Nz( StaticVarGet( "~NowDragging_" ) ) ) StaticVarSet( "~TDashYPixels", MY ); } function DrawControlButton( Type, x1, y1, x2, y2, ControlDown ) { GfxSelectSolidBrush( colorLightGrey); GfxSelectPen( colorBlack, 1); if( ControlDown ) { Edge1Color = colorWhite; Edge2Color = colorGrey50; } else { Edge2Color = colorWhite; Edge1Color = colorGrey50; } GfxRectangle( X1, y1, X2, Y2+1 ); GfxSelectPen( Edge2Color, 1); // left upper edge GfxMoveTo( x1+1, Y1+1 ); GfxLineTo( x2-1, y1+1 ); GfxMoveTo( x1+1, Y1+1 ); GfxLineTo( x1+1, y2 ); GfxSelectPen( Edge1Color, 1); //right lower edge GfxMoveTo( x2-2, Y1+1 ); GfxLineTo( x2-2, y2 ); GfxMoveTo( x1+1, Y2-1 ); GfxLineTo( x2-1, y2-1 ); GfxSelectPen( colorBlack, 1); switch( Type ) { case "CANCEL": GfxMoveTo( X1+4, Y1+4 ); // "X" GfxLineTo( X2-4, Y2-3 ); GfxMoveTo( X1+4, Y2-4 ); GfxLineTo( X2-4, Y1+3 ); break; case "DECREMENT": // "-" GfxMoveTo( X1+4, Y1+8 ); GfxLineTo( X2-4, Y1+8 ); break; case "INCREMENT": // "+" GfxMoveTo( X1+4, Y1+8 ); GfxLineTo( X2-4, Y1+8 ); GfxMoveTo( X1+8, Y1+4 ); GfxLineTo( X1+8, Y2-3 ); break; } } function Posmarker( Posname, EntryPrice, MArkerColor, MArkerTextColor, MArkerPenColor, Tip ) { global MArkerheight, pxheight, MarkerWidth, MArkerXOffset, MX, MY, LeftDown, LeftClick, LeftButtonRelease, MarkerFontSize; // Save colors in Static variables so that main chart can use them StaticVarSet( "~MarkerColor_CurrentPos", MArkerColor ); StaticVarSet( "~MarkerTextColor_CurrentPos", MArkerTextColor ); StaticVarSet( "~MarkerPenColor_CurrentPos", MArkerPenColor ); if ( EntryPrice > 0 ) { StaticVarSet( "~EntryPrice", EntryPrice ); // send to Main chart EntryYPixels = Nz( StaticVarGet( "~EntryYPixels") ); y = MArkerheight; ym = EntryYPixels; y3 = y / 2; y1 = ym - y3; // Top of marker Y2 = ym + y3; // bottom of marker X1 = MArkerXOffset; X2 = X1 + MarkerWidth + y3; // add a little width for right-side point GfxSelectSolidBrush( MArkerColor ); GfxSelectPen( MArkerColor, 1 ); // Leading line GfxMoveTo( 0, ym); GfxLineTo( X2, ym); GfxSelectPen( MArkerPenColor, 1 ); GfxPolygon( x1,ym, x1+y3,ym-y3, x2-y3,y1, x2,ym, x2-y3,y2, x1+y3, y2 ); GfxSetBkMode( 1 ); GfxSelectFont( FontName, MarkerFontSize, FontWeight ); GfxSetTextColor( MArkerTextColor ); GfxDrawText( "$"+NumToStr( EntryPrice,1.2), x1, y1, X2, Y2, 1 ); OnPosMarker = MX > X1 AND MX < X2 AND MY > Y1 AND MY < Y2; if( OnPosMarker ) { VarSetText( "TDashAction", "POSITION," + Posname ); // Hover POSITION if ( LeftClick ) VarSetText( "TDashAction", "~POSITION," + Posname ); else if ( LeftDown ) VarSetText( "TDashAction", "~~POSITION," + Posname ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~POSITION," + Posname ); VarSetText( "Tip", "POSITION: " + Tip ); } } } function CheckPosMarker( Tip ) { global MArkerheight, pxheight, MarkerWidth, MArkerXOffset, MX, MY, LeftDown, LeftClick, LeftButtonRelease, MarkerFontSize; EntryPrice = Nz( StaticVarGet( "~PosMarkerEntryPrice" ) ); if ( EntryPrice > 0 ) { PosMarkerName = StaticVarGetText( "~PosMarkerName" ); MArkerColor = Nz( StaticVarGet( "~PosMarkerColor" ) ); MArkerTextColor = Nz( StaticVarGet( "~PosMarkerTextColor" ) ); MArkerPenColor = Nz( StaticVarGet( "~PosMarkerPenColor" ) ); EntryYPixels = Nz( StaticVarGet( "~EntryYPixels" ) ); // From conversion in main chart y = MArkerheight; ym = EntryYPixels; y3 = y / 2; y1 = ym - y3; // Top of marker Y2 = ym + y3; // bottom of marker X1 = MArkerXOffset; X2 = X1 + MarkerWidth + y3; // add a little width for right-side point GfxSelectSolidBrush( MArkerColor ); GfxSelectPen( MArkerColor, 1 ); // Leading line GfxMoveTo( 0, ym); GfxLineTo( X2, ym); GfxSelectPen( MArkerPenColor, 1 ); GfxPolygon( x1,ym, x1+y3,ym-y3, x2-y3,y1, x2,ym, x2-y3,y2, x1+y3, y2 ); GfxSetBkMode( 1 ); GfxSelectFont( FontName, MarkerFontSize, FontWeight ); GfxSetTextColor( MArkerTextColor ); GfxDrawText( "$"+NumToStr( EntryPrice,1.2), x1, y1, X2, Y2, 1 ); OnPosMarker = MX > X1 AND MX < X2 AND MY > Y1 AND MY < Y2; if( OnPosMarker ) { VarSetText( "TDashAction", "POSITION," + PosMarkerName ); // Hover POSITION if ( LeftClick ) VarSetText( "TDashAction", "~POSITION," + PosMarkerName ); else if ( LeftDown ) VarSetText( "TDashAction", "~~POSITION," + PosMarkerName ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~POSITION," + PosMarkerName ); VarSetText( "Tip", "POSITION: " + Tip ); } } } function PlacePositionMarker( MArkerName, EntryPrice, MArkerColor, MArkerTextColor, MArkerPenColor ) { StaticVarSet( "~PosMarkerEntryPrice", EntryPrice); StaticVarSetText( "~PosMarkerName", MarkerName); StaticVarSet( "~PosMarkerColor", MArkerColor ); StaticVarSet( "~PosMarkerTextColor", MArkerTextColor ); StaticVarSet( "~PosMarkerPenColor", MArkerPenColor ); } function RemovePositionMarker() { StaticVarRemove( "~PosMarkerEntryPrice"); StaticVarRemove( "~PosMarkerName"); StaticVarRemove( "~PosMarkerColor"); StaticVarRemove( "~PosMarkerTextColor"); StaticVarRemove( "~PosMarkerPenColor"); } function DisplayOrderMarker( OID ) { global MArkerHeight, FontName, FontWeight, MX, MY, OnTDash, pxheight, MArkerXOffset; global LeftClick, LeftDown, LeftButtonRelease, TDashStartup, MarkerWidth, MarkerFontSize; if( IsNull(MY) ) MYm = Nz( StaticVarGet( "~LastMarkerYPosition" ) ); else { MYm = MY; StaticVarSet( "~LastMarkerYPosition", MY ); } price = StaticVarGet( "~MarkerPrice_" + OID ); if ( IsNull( price ) ) //Init price if undefined { price = PersistentVarGet( "MarkerPrice_" + OID); if( price > 0 ) { price = PersistentVarGet( "MarkerPrice_" + OID); StaticVarSet( "~MainChartPrice_"+OID, Price ); StaticVarSet( "~MarkerPrice_"+OID, Price ); } } MArkerColor = Nz( StaticVarGet( "~MarkerColor_" + OID ) ); MArkerTextColor = Nz( StaticVarGet( "~MarkerTextColor_" + OID ) ); MArkerPenColor = Nz( StaticVarGet( "~MarkerPenColor_" + OID ) ); Tip = StaticVarGetText( "~MarkerTip_" + OID ); OnMarker = Nz( StaticVarGet( "~OnTDashMarker_" + OID ) ); if ( OnMarker ) { VarSetText( "TDashAction", "MARKER," + OID ); if ( LeftClick ) VarSetText( "TDashAction", "~MARKER," + OID ); else if ( LeftDown ) VarSetText( "TDashAction", "~~MARKER," + OID ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~MARKER," + OID ); VarSetText( "Tip", Tip ); } InDrag = Nz( StaticVarGet( "~InDrag" ) ); // Skip the next if() if already dragging a marker if ( LeftClick AND OnMarker AND NOT InDrag ) { StaticVarSet( "~NowDragging_" + OID, True ); // Set drag status for marker StaticVarSet( "~InDrag", True ); // Set when dragging any marker StaticVarSet( "~ActiveMarker_" + OID, True ); // activate marker //VarSetText( "TDashAction", "~MARKER," + OID ); // Left Click on marker MarkerMidY = Nz( StaticVarGet( "~TDashYPixels_" + OID ) );// sample position of cursor StaticVarSet( "~MarkerClickYOffset", MarkerMidY - MYm ); } if( !OnTDash ) // abort drag when moving cursor outside window { StaticVarSet( "~NowDragging_" + OID, False ); // Disengage this Marker StaticVarSet( "~InDrag", False ); // Indicate all dragging stopped } // If button is released from dragging the current price is saved if ( LeftButtonRelease ) { NowDragging = Nz(StaticVarGet( "~NowDragging_" + OID )); if ( NowDragging ) { Price = Nz( StaticVarGet( "~MainChartPrice_" + OID ) ); // Sample last price PersistentVarSet( "MainChartPrice_" + OID, Price ); // Set marker to this price //_TRACE( "Stop Drag and save price "+Price ); } StaticVarSet( "~NowDragging_" + OID, False ); // Disengage this Marker StaticVarSet( "~InDrag", False ); // Indicate all dragging stopped } if ( Nz( StaticVarGet( "~NowDragging_" + OID ) ) ) // If still dragging: { MarkerClickYOffset = Nz( StaticVarGet( "~MarkerClickYOffset" ) ); // subtract MarkerClickYOffset from MYm to prevent Marker "jump" when starting to drag StaticVarSet( "~TDashYPixels_" + OID, MYm + MarkerClickYOffset ); // Tell main Chart where cursor is //VarSetText( "TDashAction", "~~MARKER," + OID ); // Indicate dragging in progress } MarkerMidY = Nz( StaticVarGet( "~TDashYPixels_" + OID ) ); // Else main chart Y-position is used X1 = MArkerXOffset; X2 = X1 + MarkerWidth; // Width of marker y = MArkerheight; // Height of marker MarkerMidY = Min( pxheight - y / 2, Max( y / 2, MarkerMidY ) ); // add code to prevent overlap of several markers y1 = MarkerMidY - y / 2; // Top of marker Y2 = MarkerMidY + y / 2; // bottom of marker OnMarker = MX > x1 AND MX < x2 AND MYm > y1 AND MYm < y2; StaticVarSet( "~OnTDashMarker_" + OID, OnMarker ); ControlWidth = Y2 - Y1; MarkerDown = LeftDown AND OnMarker; Label = " " + OID; y = MArkerheight; // Height of marker p = y / 2; //MarkerMidY = Min( pxheight - y/2, Max( y/2, MarkerMidY )); if ( MarkerDown ) { LowerEdge = colorWhite; UpperEdge = colorGrey50; } else { UpperEdge = colorWhite; LowerEdge = colorGrey50; } Price = Nz( StaticVarGet( "~MainChartPrice_" + OID ) ); if ( Price > 0 ) { GfxSelectSolidBrush( MArkerColor ); GfxSelectPen( MArkerColor, 1 ); // Leading line GfxMoveTo( 0, MarkerMidY ); GfxLineTo( X2, MarkerMidY ); GfxSelectPen( MArkerPenColor, 1 ); GfxPolygon( MArkerXOffset, MarkerMidY, p + MArkerXOffset, y1, x2, y1, x2, y2, p + MArkerXOffset, y2 ); GfxSelectPen( UpperEdge, 1 ); GfxMoveTo( X1 + 1, MarkerMidY ); GfxLineTo( p + MArkerXOffset, y1 + 1 ); GfxLineTo( X2, y1 + 1 ); GfxSelectPen( LowerEdge, 1 ); GfxMoveTo( X1 + 1, MarkerMidY ); GfxLineTo( p + MArkerXOffset, y2 - 1 ); GfxLineTo( X2 - 1, y2 - 1 ); GfxLineTo( X2 - 1, y1 ); GfxSetBkMode( 1 ); GfxSelectFont( FontName, MarkerFontSize, FontWeight ); GfxSetTextColor( MArkerTextColor ); GfxDrawText( " " + NumToStr( Price, 1.2, False ), x1, y1, X2, Y2, 1 ); ORderRecord = StaticVarGetText( "~BROrderRecord_"+OID ); TDashType = StrExtract( ORderRecord, -1); if( TDashType != "" ) { GfxDrawText( TDashType, x2+2, y1, X2+100, Y2, 4 ); // Show Bracket type } } OnControl = MX > x1 AND MX < x2 + 3 * MArkerHeight AND MYm > y1 AND MYm < y2; if ( OnControl ) { X1 = X2; // Add Increment control to right of marker X2 = X1 + ControlWidth + 1; Y2 = y2; OnIncrementPrice = MX > x1 AND MX < x2 AND MYm > y1 AND MYm < Y2; IncrDown = OnIncrementPrice AND LeftDown; if ( OnIncrementPrice ) { VarSetText( "TDashAction", "MARKER," + OID + ",+" ); // Hover Marker if ( LeftClick ) VarSetText( "TDashAction", "~MARKER," + OID + ",+" ); else if ( LeftDown ) VarSetText( "TDashAction", "~~MARKER," + OID + ",+" ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~MARKER," + OID + ",+" ); VarSetText( "Tip", "Marker: " + Tip ); } if ( Price > 0 ) DrawControlButton( "INCREMENT", x1, y1, x2, y2, IncrDown ); X1 = X2 - 1; // Add Decrement control to right of marker X2 = X1 + ControlWidth; OnDecrementPrice = MX > x1 AND MX < x2 AND MYm > y1 AND MYm < Y2; DecrDown = OnDecrementPrice AND LeftDown; if ( OnDecrementPrice ) { VarSetText( "TDashAction", "MARKER," + OID + ",-" ); // Hover Marker if ( LeftClick ) VarSetText( "TDashAction", "~MARKER," + OID + ",-" ); else if ( LeftDown ) VarSetText( "TDashAction", "~~MARKER," + OID + ",+" ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~MARKER," + OID + ",-" ); VarSetText( "Tip", Tip ); } if ( Price > 0 ) DrawControlButton( "DECREMENT", x1, y1, x2, y2, DecrDown ); X1 = X2 - 1; // Add CANCEL control to right of marker X2 = X1 + ControlWidth + 1; OnCancel = MX > x1 AND MX < x2 AND MYm > y1 AND MYm < Y2; CancelDown = OnCancel AND LeftDown; if ( OnCancel ) { VarSetText( "TDashAction", "MARKER," + OID + ",X" ); // Hover Marker if ( LeftClick ) VarSetText( "TDashAction", "~MARKER," + OID + ",X" ); else if ( LeftDown ) VarSetText( "TDashAction", "~~MARKER," + OID + ",+" ); else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~MARKER," + OID + ",X" ); VarSetText( "Tip", Tip ); } if ( Price > 0 ) DrawControlButton( "CANCEL", x1, y1, x2, y2, CancelDown ); VarSet( "LastXPos", X2 + 1 ); // add one to separate colums } return MarkerMidY; } function DrawQBarButton( QBarCol, x1, y1, x2, y2, Tip ) { global QRadius, QFrameWidth, FontName, QFontWeight, NumChar, MY, MX, MaxQChar; ButtonColor = VarGet( "ButtonColor" + QBarCol ); TextColor = VarGet( "ButtonTextColor" + QBarCol ); Label = VarGetText( "ButtonLabel" + QBarCol ); Header = VarGetText( "ButtonHeader" + QBarCol ); GfxSetTextColor( TextColor ); GfxSetBkColor( ButtonColor ); QRadius = Min( ( X2 - X1 ) / 2, QRadius ); X1 = X1 + QFrameWidth; // Make button a little smaller that cell size Y1 = Y1 + QFrameWidth + 1; // so that group color can show X2 = X2 - QFrameWidth; Y2 = Y2 - QFrameWidth; GfxSelectSolidBrush( ButtonColor ); // Draw button GfxSelectPen( colorGrey50, 1 ); GfxRoundRect( x1 + 1, y1, x2, y2, QRadius, QRadius ); // Auto-size font wrt width and height of button F1 = ( Y2 - Y1 ) / 3; // Size font wrt button height and width F2 = ( X2 - X1 ) / ( MaxQChar ); FontSize = Min( F1, F2 ); StaticVarSet( "~QBarFontSize", FontSize ); GfxSetBkMode( 1 ); GfxSelectFont( FontName, FontSize, QFontWeight ); if ( Label == "" ) // Single label button GfxDrawText( Header, x1, y1 + 1, X2, Y2, 37 ); else // upper and lower label button { Ym = ( Y1 + Y2 ) / 2 + 1; GfxDrawText( Header, x1, y1, X2, Ym + 2, 37 ); GfxDrawText( Label, x1, Ym - 2, X2, Y2, 37 ); } if( MX >= X1 AND MY >= Y1 AND MX <= X2 AND MY <= Y2 ) VarSetText( "Tip", Tip ); } function AddQBarButton( Header, OffLabel, OnLabel, OffColor, OnColor, OffTextColor, OnTextColor, Col, QBarXOffset, Show, Active, Tip ) { global GroupSpacing, ButtonRadius, InCash, InShort, InLong, pxheight, QBarHeight, QBarWidth, QFrameWidth, FontName, QBarXOffset; global QRadius, MY, MX, QBarBkColor, LeftClick, LeftDown, HighLightColor, QBarXOffset, QAutoHide, NumChar, MArkerHeight; local QMY; GroupName = "QBar"; QBarCol = GroupName + "_" + Col; // Name for staticvariables associated with each QBar button MYs = MY; // prevent conflicts with use of MY in other functions if( StaticVarGet( "~TDashCount" ) == 1 ) StaticVarSet( "~LastMY", pxheight/2 ); // Startup QBar at centre height QBarType = StaticVarGetText( "~QBarType" ); // get QBar type asset in the ORDERS group if ( QBarType == "MKT" ) MYs = pxheight / 2; // for MKT, BID, and ASK freeze the QBar in the vertical centre of the window QBarButtonNum = Nz( VarGet( "QBarButtonNum" ) ); // Count horizontal position //X1 = MarkerWidth + QBarButtonNum * QBarWidth + 3 * MArkerHeight + 1 + GroupSpacing + MArkerXOffset; X1 = Max(QBarXOffset, MarkerWidth) + QBarButtonNum * QBarWidth + 3 * MArkerHeight + 1 + GroupSpacing + MArkerXOffset; X2 = X1 + QBarWidth; MaxQBarButtonNum = Nz( StaticVarGet( "~MaxQBarButtonNum" ) ); // count the number of buttons in the QBar QBarButtonNum = Nz( VarGet( "QBarButtonNum" ) ); // Count horizontal position VarSet( "QBarButtonNum", ++QBarButtonNum ); if ( QBarButtonNum > MaxQBarButtonNum ) StaticVarSet( "~MaxQBarButtonNum", MaxQBarButtonNum ); MaxQBarButtonNum = Nz( StaticVarGet( "~MaxQBarButtonNum" ) ); MaxQX2 = Nz( StaticVarGet( "~MaxQX2" ) ) + 1; // Recall first and last X-pixel positions covered by QBar, MinQX1 = Nz( StaticVarGet( "~MinQX1" ) ) - 1; // needed for rectangle-background coloring VarSet( "LastXPos", MaxQX2 + 1 ); // add 1 extra pixel to separate columns OnQBar = OnTDash AND MX < MaxQX2 AND MX > MinQX1; // Is cursor over QBar area? StaticVarSet( "~OnQBar", OnQBar ); if ( NOT OnQBar ) MYs = Nz(StaticVarGet( "~LastMY" )); // If not over QBar area recall last QBar position else StaticVarSet( "~LastMY", MYs ); // Save current QBar position for above use pxwidth = Status( "pxwidth" ); pxheight = Status( "pxheight" ); QMY = Max( QBarHeight / 2 + 2, MYs ); // Do not show partial buttons at top QMY = Min( pxheight - QBarHeight / 2 - 2, QMY ); // Same at bottom of window Y1 = QMY - QBarHeight / 2; // Top of QBar Y2 = QMY + QBarHeight / 2; // Bottome of QBar Y1m = Nz( QMY ) - QBarHeight / 2; // Track Qbar at vertical center of buttons if ( OnQBar OR !QAutoHide ) // Show QBar when cursor in QBar-width area, or Auto-Hide is off { StaticVarSet( "~QBarYPixel", QMY ); VarSetText( "ButtonHeader" + QBarCol, Header ); OnButton = MX >= X1 AND MX < X2 AND MY >= Y1 AND MY < Y2; if ( LeftClick AND OnButton ) // Flash color during a click { VarSet( "ButtonColor" + QBarCol, OnColor ); VarSet( "ButtonTextColor" + QBarCol, OnTextColor ); VarSetText( "ButtonLabel" + QBarCol, OnLabel ); } else { VarSet( "ButtonColor" + QBarCol, OffColor ); VarSet( "ButtonTextColor" + QBarCol, OffTextColor ); VarSetText( "ButtonLabel" + QBarCol, OffLabel ); } if ( Active == 0 ) // If a button is in-active grey-out the button { VarSet( "ButtonColor" + QBarCol, colorLightGrey ); VarSet( "ButtonTextColor" + QBarCol, colorGrey50 ); } OnButton = OnButton AND Active; if ( OnButton AND MY > Y1 AND MY < Y2 ) { Header = VarGet( "ButtonHeader" + QBarCol ); // recall button select information Label = VarGet( "ButtonLabel" + QBarCol ); if ( LeftClick ) VarSetText( "TDashAction", "~QBAR," + Header + "," + Label ); // Click else if ( LeftDown ) VarSetText( "TDashAction", "~~QBAR," + Header + "," + Label ); // Down else if ( LeftButtonRelease ) VarSetText( "TDashAction", "~~~QBAR," + Header + "," + Label ); // Release else VarSetText( "TDashAction", "QBAR," + Header + "," + Label ); // Hover StaticVarSet( "~ActionColor", OffColor ); // For main chart StaticVarSet( "~ActionTextColor", OffTextColor ); StaticVarSetText( "~QBarSelection", Header + " " + Label ); } if ( QBarButtonNum == 1 ) // only during drawing of the first button add surround background { StaticVarSet( "~MinQX1", X1 ); // find min max X for background rectangle QX2 = Nz( StaticVarGet( "~QX2" ) ); StaticVarSet( "~MaxQX2", QX2 ); F1 = ( Y2 - Y1 ) / 3; // Size font wrt button height and width F2 = ( X2 - X1 ) / NumChar; FontSize = Min( F1, F2 ); StaticVarSet( "~FontSize", FontSize ); if ( QBarType != "MKT" ) // Draw dashed price LMT priceline at left of QBar { ActionColor = Nz( StaticVarGet( "~ActionColor" ) ); GfxSelectPen( ActionColor, 1, 1 ); GfxMoveTo( 0, QMY ); GfxLineTo( X1, QMY ); } QX2 = Nz( StaticVarGet( "~QX2" ) ); // Draw QBar background and outline GfxSelectSolidBrush( colorGrey50 ); GfxSelectPen( colorGrey50, 1 ); GfxRoundRect( X1 - 1, Y1 - 1, QX2 + 2, Y2 + 2, QRadius, QRadius ); // Black outline GfxSelectSolidBrush( QBarBkColor ); // Bk color, overlay on outline GfxSelectPen( QBarBkColor, 1 ); GfxRoundRect( X1, Y1, QX2 + 1, Y2 + 1, QRadius, QRadius ); // warning msg above QBar AboveQBarMessage = StaticVarGetText( "~AboveQBarMessage" ); FontSize = StaticVarGet( "~QBarFontSize" ); gfxBlinkingMsg( AboveQBarMessage, x1, y1-2*FontSize-4, x1+3*QBarWidth, y1, colorWhite, colorBlack, FontSize+4 ); } if ( QBarButtonNum > MaxQBarButtonNum ) StaticVarSet( "~QX2", X2 ); // update max X if ( OnButton ) { GfxSelectSolidBrush( HighLightColor ); // Highlight outline of selected button GfxSelectPen( HighLightColor , 1 ); GfxRoundRect( x1, y1, x2 + 1, y2 + 1, QRadius, QRadius ); } DrawQBarButton( QBarCol, x1, y1, x2, y2, Tip ); StaticVarSet( "~LastMY", MYs ); QBarVisible = True; } else QBarVisible = False; TDashAction = VarGetText( "TDashAction" ); // For main Chart QBarSelection = StrExtract( TDashAction, -2 ) + " " + StrExtract( TDashAction, -1 ); StaticVarSet( "~QBarVisible", QBarVisible ); } function DrawTextBox( x1, y1, Text, Width, Height, BkColor, TextColor, FontSize, Format ) { global FontName, FontWeight, MY, MX, LeftClick, LeftDown; global EdgeWidth; Width = Min( pxwidth-X1 - 2, width-1 )-1; // Stay within pane Height = Min( pxheight-Y1 - 1, Height ); X1 = X1 + 1; // outside rectangle Y1 = Y1 + 1; X2 = X1 + Width; Y2 = Y1 + Height; X1a = X1 + EdgeWidth; // inside rectangle Y1a = Y1 + EdgeWidth + 1; X2a = X2 - EdgeWidth; Y2a = Y2 - EdgeWidth; GfxSelectSolidBrush( colorGrey50); // Draw button edge GfxSelectPen( colorBlack, 1 ); GfxRectangle( x1-1, y1, x2+1, y2+1 ); GfxSelectSolidBrush( BkColor ); // Draw button face GfxSelectPen( colorBlack, 1 ); GfxRectangle( x1a, y1a, x2a, y2a ); GfxSelectFont( FontName, FontSize, 500 ); GfxSetBkMode( 1 ); GfxSetTextColor( TextColor ); GfxDrawText( Text, x1a, y1a + 1, X2a, Y2a, format ); // only header available VarSet( "LastYPos", Y2 - 1 ); // To facilitate placing next module belwo this one TextboxWidth = X2 - X1; return TextBoxWidth+2; } function DrawGroupHeader( x1, y1, Width, HeaderSpace, Height, Header, Groupcolor, TextColor, Show ) { global FontName, FontWeight3D, MY, MX, LeftClick, LeftDown; global EdgeWidth, BackgroundColor, DividerFormat; local ShowGroupHeader; NumHeaders = Nz( VarGet( "NumHeaders" ) ); if( NumHeaders == 0 ) HeaderSpace = 0; if ( Show )// add space, except at top of window { Y1 = Y1 + HeaderSpace; SumSpace = Nz( VarGet( "SumSpace" ) ); SumSpace = SumSpace + Height + HeaderSpace; VarSet( "SumSpace", SumSpace ); VarSet( "NumHeaders", ++NumHeaders ); Y2 = Y1 + Height; Width = Min( pxwidth - X1, width ); // Stay within pane width Height = Min( pxheight - Y1 - 1, Height ); // Stay within pane height X2 = X1 + Width; GfxSelectSolidBrush( Groupcolor ); //Draw Divider GfxSelectPen( Groupcolor, 1 ); GfxRectangle( x1, Y1, x2, Y2 + 1 ); F1 = Max(1,( Y2 - Y1 ) / 2); // Size font wrt button height FontSize = F1; GfxSelectFont( FontName, FontSize, FontWeight3D ); GfxSetBkMode( 1 ); GfxSetTextColor( TextColor ); GfxDrawText( Header, x1, Y1+1, x2, y2+1, 37 ); } else Y2 = Y1; VarSet( "LastYPos", Y2 ); // To facilitate placing next group below this one } function PlaceOrderMarker( MArkername, Price, MArkerColor, MArkerTextColor, MArkerPenColor, Tip ) { if ( MArkername != "" ) { MArkername = StrToUpper( MArkername ); StaticVarSet( "~MainChartPrice_" + MArkername, Price ); PersistentVarSet( "MarkerPrice_" + MarkerName, Price ); StaticVarSet( "~ActiveMarker_" + MarkerName, True ); StaticVarSet( "~MarkerColor_" + MarkerName , MArkerColor ); StaticVarSet( "~MarkerTextColor_" + MarkerName , MArkerTextColor ); StaticVarSet( "~MarkerPenColor_" + MarkerName , MArkerPenColor ); StaticVarSetText( "~MarkerTip_" + MarkerName, Tip ); //_TRACE( "PlaceOrdermarker: " + MArkername ); } } function RemoveOrderMarker( MArkerName ) { if ( MArkername != "" ) { MArkername = StrToUpper( MArkername ); StaticVarRemove( "~MainChartPrice_" + MArkerName ); StaticVarSet( "~ActiveMarker_" + MarkerName, False ); PersistentVarRemove( "MarkerPrice_" + MarkerName ); StaticVarSet( "~ActiveMarker_" + MarkerName, Null ); //_TRACE( "RemoveOrderMarker: " + MArkername ); } } function ProcessGUI() { global TDashPosition, OnTDash; TDashAction = VarGetText( "TDashAction" ); StaticVarSetText( "~TDashAction", TDashAction ); // Needed in next pass, for code that precedes this statement. switch ( TDashAction ) { ///////////////////////////// SETUP case "~SETUP,TRACE,CLEAR": _TRACE( "!CLEAR!" ); _TRACE( TDashAction ); break; case "~SETUP,VOICE,TEST": Say( "", 1 ); // purge buffer xSay( "Voice Test" ); break; ///////////////////////////// TRADING case "~TRADING,TYPE,LMT": case "~TRADING,TYPE,LMTLAST": case "~TRADING,TYPE,LMTBID": case "~TRADING,TYPE,LMTASK": case "~TRADING,TYPE,MKT": Type = StrExtract( TDashAction, 2 ); StaticVarSetText( "~QBarType", Type ); // label for QBar buttons break; } return TDashAction; } // for debugging only RequestTimedRefresh( 0.1); //EnableTextOutput( True ); GfxSetOverlayMode( 2 ); StaticTDashAction = StaticVarGetText( "~TDashAction"); Msg1=Msg2=Msg3=""; T3 = StrFind( StaticTDashAction, "~~~" ); T2 = StrFind( StaticTDashAction, "~~" ); T1 = StrFind( StaticTDashAction, "~" ); if( !T3 AND !T2 AND !T1 ) Msg0 = StaticTDashAction; else Msg0 = ""; AddRowTogfxTitle( " Hover: "+Msg0, colorBlack, "LUCIDA CONSOLE", 12, 700 ); if( T3 ) Msg1 = StaticTDashAction; else if( T2 AND !T3 ) msg2 = StaticTDashAction; else if( T1 AND !T2 AND !T2 ) Msg3 = StaticTDashAction; AddRowTogfxTitle( " Click: "+Msg3, colorBlack, "LUCIDA CONSOLE", 12, 700 ); AddRowTogfxTitle( " Hold: "+Msg2, colorBlack, "LUCIDA CONSOLE", 12, 700 ); AddRowTogfxTitle( " Release: "+Msg1, colorBlack, "LUCIDA CONSOLE", 12, 700 ); SilentVoice = StaticVarGetText( "~SilentVoice" ); Msg = "LastVoice: "+SilentVoice; AddRowTogfxTitle( Msg, colorBlack, "LUCIDA CONSOLE", 12, 700 ); NumPendingOrders = Nz( StaticVarGet( "~NumPendingOrders" ) ); AddRowTogfxTitle( "#Pending: "+NumPendingOrders, colorBlack, "LUCIDA CONSOLE", 12, 700 ); TDashTicker = StaticVarGetText( "~TDashTicker" ); SignalArray = Nz( Foreign( TDashTicker + "~SignalArrays", "V", False ) ); NumTrades = LastValue(Cum( SignalArray>0 )); AddRowTogfxTitle( " #Trades: "+NumTrades, colorBlack, "LUCIDA CONSOLE", 12, 700 ); MainLastPrice = Nz( StaticVarGet( "~MainLastPrice" ) ); AddRowTogfxTitle( "MainLastPrice: "+MainLastPrice, colorBlack, "LUCIDA CONSOLE", 12, 700 ); CurrentPos = Nz( StaticVarGet( "~CurrentPosition" )); AddRowTogfxTitle( "CurrentPos: "+CurrentPos, colorBlack, "LUCIDA CONSOLE", 12, 700 ); GoingLongPrice = Nz(StaticVarGet( "~GoingLongPrice" )); AddRowTogfxTitle( "GoingLongPrice: "+GoingLongPrice, colorBlack, "LUCIDA CONSOLE", 12, 700 ); GoingShortPrice = Nz(StaticVarGet( "~GoingShortPrice" )); AddRowTogfxTitle( "GoingShortPrice: "+GoingShortPrice, colorBlack, "LUCIDA CONSOLE", 12, 700 ); //_TRACE( "Check" );