Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _SECTION_BEGIN("SymbolsToolgfx");
- /* SymbolsToolGFX.afl (Ver 7) By Panos Boufardeas 26/01/2015
- * This tool is used to easily draw symbols on a chart without having to use the default
- * AmiBroker Text tool. It can be useful for manually tracking elliott wave patterns, or otherwise.
- * this Afl runs for Amibroker Version 5.80 and above as we use the function PlotTextSetFont
- * How to use:
- * mouse Double-click to pick a color then choose a Symbol from a cell, then click once on the chart in desired location to draw.
- * In the lower right orner we have "R" and "D", these are symbol management tools.
- * Letter "R" This will release the current selected symbol so that it no longer plots when clicking on the chart.
- * Letter "D" Delete a single symbol on the chart by clicking it. Middle Mouse Button will also delete symbols.
- * Letter "L" The LazyBoy mode! This will automatically place characters in sequential order with each click.
- * Letter "+ -" will increase or decrease the symbol's size, You can also adjust this in parameters.
- * Default Front color is "colorAqua"
- * To edit or Add your favorite Symbols goto PART 4, PART 5, and PART 6
- * persistent static variables are:
- StaticVarSet( Yname + Position, y, 1 );
- StaticVarSet("st~Bar", Bar,1 );
- StaticVarSet("st~BarColor",BarColor,1);
- StaticVarSet("stf~Bar", fBar,1)
- */
- filename="<b>SymbolsTool Ver 7- \n 2x_FontSize, 2x_Delete, 1x_ColorId, LazyBoy </b>";
- Plot( C, "", colorWhite, styleBar, 0, 0, 0 );
- VarRemove = ParamTrigger("Static Var Remove", "Click here to Remove All");
- VarRemoveLazyBoy = ParamTrigger("Static Var Remove LazyBoy", "Click here to Remove LazyBoy");
- Fontsize = Param( " Font Size" ,14,1,600,1);
- DefaultSymbolSize =14; // <<<<<<<<<< Here edit the Default FontSize
- SetBarsRequired( -2, -2 );
- // Yname = "Y" + Name() + Interval() + GetChartID();
- Yname = "Y" + Name() + Interval();
- YLazyBoy = "YY" + Name() + Interval();
- CellHeight = 20;
- CellWidth = 20;
- GfxSelectPen( colorLightBlue );
- GfxGradientRect( 21,41,220, 220 , colorAqua, colorAqua ); // the Chassis Box
- /////// Static Var ////////////////////////////////////////
- Button_OnOFF = Nz(StaticVarGet("st~Button_OnOFF"),0);
- GetButtonRowPY = Nz(StaticVarGet("st~GetButtonRowPY"),0);
- GetButtonColPX = Nz(StaticVarGet("st~GetButtonColPx"),0);
- cellNumber = Nz(StaticVarGet("st~CellNumber"),0);
- colorID = Nz(StaticVarGet("st~ColorID"),36); // Default Front color is 36= "colorAqua"
- Bar = Nz( StaticVarGet( "st~Bar" ),0) ;
- BarColor = Nz( StaticVarGet( "st~BarColor" ),0) ;
- sCounter = Nz( StaticVarGet( "stf~Counter" ),0 ); printf( "\nLazyBoy-Counter : " + sCounter +"\n");
- fBar = Nz( StaticVarGet( "stf~Bar" ),0 );
- stepSize = 0.50; // GFX Symbol Size adjustment with +/- button
- SymbolSize = Nz( StaticVarGet( "st~SymbolSize"),DefaultSymbolSize ); printf( "\n Symbol Size =\t" + SymbolSize +"\n");
- for ( i = 2; i < 12; i++ ) // Horizontal Lines
- { // _TRACE("# cell = " + i);
- for ( Col = 0; Col < 12; Col++ ) // Vertical
- { // Horizontal
- GfxMoveTo( 20, i * CellHeight );
- GfxLineTo( 11 * CellWidth, i * CellHeight );
- // Vertical
- GfxMoveTo( Col * CellWidth, 41 );
- GfxLineTo( Col * CellWidth, 9 * CellHeight + 41 );
- }
- }
- function PrintInCell( string, row, Col )
- {
- GfxSetBkMode(1); // set transparent mode
- GfxSetTextColor( colorBlack );
- GfxDrawText( string, Col * CellWidth, row * CellHeight, (Col + 1 ) * CellWidth, (row + 1 ) * CellHeight, 1 );
- }
- function PrintInCellColor( string, row, Col, color )
- {
- GfxSetBkMode(1);
- GfxSetTextColor( color );
- GfxDrawText( string, Col * CellWidth, row * CellHeight, (Col + 1 ) * CellWidth, (row + 1 ) * CellHeight, 1 );
- }
- function DrawCircle(x,y,radius,BackColor)
- {
- GfxSelectSolidBrush( BackColor );
- GfxSelectPen( colorBlack );
- GfxCircle( x, y, radius );
- }
- /////////////////////////////////////////////////////////
- // Part 2: MOUSE BUTTON CALL BACKS
- function GetCellPosition( px, py )
- {
- // get Button Cell Position
- Col = floor( px / CellWidth );
- Row = floor( py / CellHeight );
- if ( Col >= 1 AND col <= 10 AND Row >= 2 AND row <= 10 ) // Button_OnOFF Only inside My cell area
- {
- StaticVarSet( "st~Button_OnOFF", 1 );
- StaticVarSet( "st~GetButtonRowPY", Row );
- StaticVarSet( "st~GetButtonColPx", Col );
- }
- ///////////// R = Reset Button_OnOFF ///////////////
- if (col == 10 AND Row == 10)
- { StaticVarSet( "st~Button_OnOFF",0 );
- StaticVarSet("st~ColorID",0);
- }
- ///////////// D = DeleteOnOFF ///////////////
- if ( NOT (col == 9 AND Row == 10) ) // DeleteOnOff
- {
- DeleteOnOff = StaticVarSet( "DeleteOnOff", 0 );
- }
- else if ( col == 9 AND Row == 10 )
- {
- DeleteOnOff = StaticVarSet( "DeleteOnOff", 1 );
- }
- }
- // Part 3://///////////////////////////////////////////////
- b = GetCursorMouseButtons();
- // retrieve co-ordinates in date/value units
- x = GetCursorXPosition(0);
- y = GetCursorYPosition(0);
- // retrieve co-ordinates in pixel units
- px = GetCursorXPosition(1);
- py = GetCursorYPosition(1);
- //////// return = 1, if mouse cursor is NOT in right blank bars and right scale
- dt = DateTime();
- Position = SelectedValue( BarIndex());
- NotRightScale= PX <=Status("pxchartright")-20 ;
- NotInRightBlankBars = IIf( x <= LastValue( DT ), 1, 0 );
- CursorOnBars= IIf(NotRightScale and NotInRightBlankBars ,1,0); // printf( "\n CursorOnBars "+CursorOnBars );
- //--------------------------------------------------
- Col = floor( px / CellWidth ); // printf("\n Col = floor( px / Cell " +col );
- Row = floor( py / CellHeight ); //printf("\n Row = floor( pY / Cell " +Row ) ;
- // iN_My_cell= ( Col >= 1 AND col <= 11 AND Row >= 2 AND row <= 10 ); // Only inside My cells
- iN_My_cell= ( GetButtonColPx >= 1 AND GetButtonColPx <= 11 AND GetButtonRowPY >= 2 AND GetButtonRowPY <= 10 );
- NOT_iN_My_cell_Area= ( Col > 11 );
- // NOT_iN_My_cell_Area= ( GetButtonColPx > 11 );
- if (Button_OnOFF )
- {
- GfxGradientRect( GetButtonColPX * CellWidth, GetButtonRowPY * CellHeight, ( GetButtonColPX + 1 ) * CellWidth, ( GetButtonRowPY + 1 ) * CellHeight, colorBrightGreen, colorGreen );
- }
- if( b & 8 ) // flag = 8 is set when window just received mouse click
- {
- if (b & 1 )
- {
- GetCellPosition( px, py ); /*Panos, retreves CellPosition Corectly*/
- if (Button_OnOFF)
- { CellNum=0; // Defines every row Number to start with ace
- if (GetButtonRowPY==2) {CellNum= 2- GetButtonRowPY + GetButtonColPX; } // =01
- if (GetButtonRowPY==3) {CellNum= GetButtonRowPY + 7 + GetButtonColPX; } // =11
- if (GetButtonRowPY==4) {CellNum= GetButtonRowPY + 16 + GetButtonColPX; } // =21
- if (GetButtonRowPY==5) {CellNum= GetButtonRowPY + 25 + GetButtonColPX; } // =31
- if (GetButtonRowPY==6) {CellNum= GetButtonRowPY + 34 + GetButtonColPX; } // =41
- if (GetButtonRowPY==7) {CellNum= GetButtonRowPY + 43 + GetButtonColPX; } // =51
- if (GetButtonRowPY==8) {CellNum= GetButtonRowPY + 52 + GetButtonColPX; } // =61
- if (GetButtonRowPY==9) {CellNum= GetButtonRowPY + 61 + GetButtonColPX; } // =71
- if (GetButtonRowPY==10) {CellNum= GetButtonRowPY + 70 + GetButtonColPX; } // =81
- StaticVarSet( "st~CellNumber",CellNum);
- }
- /////////////////////////////////////////////////////////
- // Pick a ColorID to Use from Row 9
- if (iN_My_cell)
- {
- if (cellNumber==71) {colorID =32;} //"colorRed";
- else if (cellNumber==72) {colorID =25;} //"colorOrange";
- else if (cellNumber==73) {colorID =42;} //"colorYellow";
- else if (cellNumber==74) {colorID =43;} //"colorBrightGreen";
- else if (cellNumber==75) {colorID =27;} //"colorGreen";
- else if (cellNumber==76) {colorID =29;} //"colorBlue"; colorLightBlue 37
- else if (cellNumber==77) {colorID =30;} //"colorBlueGrey";
- else if (cellNumber==78) {colorID =38;} //"colorViolet";
- StaticVarSet("st~ColorID",colorID);
- }
- // StaticVarSetText( "st~Symbol_"+i, Fonts ); θυμισου οτι το κομματι "Symbol runones" ανηκει εδω
- if ( Button_OnOFF AND NOT_iN_My_cell_Area AND CursorOnBars )
- {
- Position = SelectedValue( BarIndex() );
- // store Data Cursor Y Position,colorID,CellNumber + persistent for AmiBroker(5.90)
- if ( Bar[Position] == 0 AND NOT cellNumber == 88)
- StaticVarSet( Yname + Position, y, 1 );
- if ( Bar[Position] == 0 )
- {
- Bar[Position] = CellNum; //μεταφραση ειναι // bar[barIndex] = text
- StaticVarSet( "st~Bar", Bar, 1 );
- BarColor[Position] = colorID;
- StaticVarSet( "st~BarColor", BarColor, 1 );
- }
- }
- if ( cellNumber == 89 AND Button_OnOFF ) // "D" = DELETE ONE SYMBOL
- {
- if ( NOT_iN_My_cell_Area AND CursorOnBars )
- {
- Position = SelectedValue( BarIndex() );
- if ( Bar[Position] > 0 )
- {
- Say( "Symbol deleted" );
- StaticVarSet( Yname + Position, null, 1 );
- Bar[Position] = null; //μεταφραση ειναι // bar[barIndex] = text
- StaticVarSet( "st~Bar", Bar ); // _TRACE("#, Bar[Position] = " + Bar[Position]);
- BarColor[Position] = null;
- StaticVarSet( "st~BarColor", BarColor, 1 );
- }
- }
- }
- //--------Lazy Boy------------// Quick plotext Offering to Rensley--------------
- if ( cellNumber == 88 AND Button_OnOFF )
- {
- if ( NOT_iN_My_cell_Area AND CursorOnBars )
- {
- if ( sCounter < 10 )
- sCounter++;
- Position = SelectedValue(BarIndex());
- fBar[Position] = sCounter;
- StaticVarSet("stf~Counter", sCounter);
- StaticVarSet("stf~Bar", fBar,1);
- StaticVarSet( YLazyBoy+Position,Y,1 );
- if ( sCounter > 9 )
- StaticVarSet("stf~Counter",0);
- }
- }
- } //end if ( b & 1 )
- /////////////////////////////////////////////////////////
- // GFX Symbol Size adjustment with +/- button
- if ( Col<11 )
- {
- if ( cellNumber == 79 ) StaticVarSet( "st~SymbolSize", SymbolSize + stepSize );
- if ( cellNumber == 80 ) StaticVarSet( "st~SymbolSize", SymbolSize - stepSize );
- }
- } // end if ( b & 8 )
- for ( i = 0; i < BarCount; i++ ) //Quick plotext for Lazy Boy
- {
- if ( fBar[i] != 0 )
- { // shapePos[i] = StaticVarGet( Yname + i );
- shapePos[i] = StaticVarGet( YLazyBoy + i );
- PlotText("\n"+StaticVarGetText( "st~Elliot_" + fbar[i] ),i, shapePos[i], colorBlack,barcolor[i] );
- }
- }
- for ( i = 1; i < 10; i++ )
- {
- Text2 = StrExtract( "X,1,2,3,4,5,A,B,C", i - 1 );
- StaticVarSetText( "st~Elliot_" + i, Text2 );
- // _TRACE("#, st~Elliot_"+i +" = "+ Text2 );
- }
- //------end ----Lazy Boy----------------------------------
- // -2)-------- Display PlotText ( edit or Add your favorite Symbols here )
- FirstVisibleBar = Status( "FirstVisibleBar");
- Lastvisiblebar = Status("LastVisibleBar");
- bkcolor = colorDefault;
- shapePos = Null;
- /////////////////////////////////////////////////////////
- // PART 4: StaticVarSetText( "st~Symbol_"+i, Fonts );
- //for ( i = 0; i < BarCount; i++ )
- for ( i = FirstVisibleBar; i < Lastvisiblebar AND i < BarCount; i++ )
- {
- if ( b & 4 ) //------DELETE RED DOTS by pressing Middle mouse button
- {
- if ( x == dt[i])
- StaticVarSet( Yname + Position, null,1 );
- StaticVarSet( YLazyBoy+Position,null,1 );
- }
- shapePos[i] = StaticVarGet( Yname + i );
- if ( 0< bar[i] AND bar[i] <11 ) // 1st Row
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Wingdings 2",SymbolSize,i,shapePos[i],barcolor[i],bkcolor );
- // _TRACE("#,bar[i]= " + bar[i] + ", shapePos[i] = "+ shapePos[i]+", y = "+y +" I = "+ i );
- if ( 10< bar[i] AND bar[i] <31 ) //Row 2,3
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Arial",SymbolSize,i,shapePos[i],barcolor[i]);
- if ( 37< bar[i] AND bar[i] <41 ) //Row 4
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Arial",SymbolSize,i,shapePos[i],barcolor[i]);
- if ( 30< bar[i] AND bar[i] <38 ) //Row 4
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Wingdings 2",Fontsize,i,shapePos[i],barcolor[i]);
- if ( 40< bar[i] AND bar[i] <49 ) //Row 5
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Wingdings",Fontsize,i,shapePos[i],barcolor[i]);
- if ( 50< bar[i] AND bar[i] <53 ) //Row 6
- if (bar[i] ==51 ) // Down Triangle
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Wingdings 3",Fontsize,i,shapePos[i],colorRed);
- if (bar[i] ==52 ) // Up Triangle
- PlotTextSetFont(StaticVarGetText( "st~Symbol_" + bar[i] ),"Wingdings 3",Fontsize,i,shapePos[i],colorGreen);
- }
- PlotShapes( shapeSmallCircle, colorRed, 0, shapePos,0,0);
- // -1)---- SET a Number ID for every single Fonts and run Once -----( edit or Add your favorite Symbols here)
- Symbolvar=StaticVarGetText( "st~Symbol_RunOnce");
- if ( Symbolvar == "" )
- {
- for ( i = 1; i < 53; i++ )
- { // Array -- run from 1st to 7th row and SET a Number for every one Font
- Fonts = StrExtract( "j,k,l,m,n,o,p,q,r,i,A,B,C,W,X,Y,x,a,b,c,(i),(ii),(iii),(iv),(v),(a),(b),(c),(d),(e),D,E,<,=,N,R,T,?,!,+,J,L,O,M,N,U,R,T,,,q,p", i - 1 );
- StaticVarSetText( "st~Symbol_"+i, Fonts );
- // _TRACE("#, st~Symbol_"+i +" = "+ Fonts );
- }
- //_TRACE("#, StaticVarSetText Symbol are NOT Set: "+i );
- StaticVarSetText( "st~Symbol_RunOnce", "RunOnce" );
- }
- else
- {
- // _TRACE("#, StaticVarSetText Symbols are all Set - Once:" );
- }
- for ( i = 1; i < 10; i++ )
- {
- // Array -- run from 1st to 7th row and SET a Number for every one Font
- Fonts2 = StrExtract( "X,1,2,3,4,5,A,B,C", i - 1 );
- StaticVarSetText( "st~Elliot_" + i, Fonts2 );
- // _TRACE("#, st~Elliot_"+i +" = "+ Fonts2 );
- }
- /////-----/////-----/////-----/////-----/////-----/////-----/////-----
- // THE CODE BELOW HERE IS ONLY TO PRINT COLOR AND FONTS INSIDE TO CELLS (I DONT USE ANY MAIN CALCULATION)
- /////-----/////-----/////-----/////-----/////-----/////-----/////-----
- /////////////////////////////////////////////////////////
- // PART 5: Just ONLY Draw Round Button Color, in the cells -----( edit or Add your favorite Colors here)
- // part5 and part6 it is just to draw in the cells (there is not any calculation here)
- //////////////////////////////////////////////////////////
- // Row 8 = Draw Round Button Color
- DrawCircle(0.5 * CellWidth,9.5*CellHeight ,8,colorID); // Picked Color
- DrawCircle(1.5 * CellWidth,9.5*CellHeight ,8,colorRed);
- DrawCircle(2.5 * CellWidth,9.5*CellHeight ,8,colororange);
- DrawCircle(3.5 * CellWidth,9.5*CellHeight ,8,colorYellow);
- DrawCircle(4.5 * CellWidth,9.5*CellHeight ,8,colorBrightGreen);
- DrawCircle(5.5 * CellWidth,9.5*CellHeight ,8,colorGreen);
- DrawCircle(6.5 * CellWidth,9.5*CellHeight ,8,colorBlue);
- DrawCircle(7.5 * CellWidth,9.5*CellHeight ,8,colorBlueGrey);
- DrawCircle(8.5 * CellWidth,9.5*CellHeight ,8,colorViolet);
- /////////////////////////////////////////////////////////
- // PART 6: Just ONLY print FONTS / SYMBOLS in the cells ( edit or Add your favorite Symbols here)
- GfxSelectFont("Wingdings 2", CellHeight*0.75, 400 );
- for ( i = 1; i < 11; i++ )
- {
- Row1 = StrExtract( "j,k,l,m,n,o,p,q,r,i", i - 1 ); // 1st Row
- PrintInCell( Row1, 2, i );
- Row4 = StrExtract( "D,E,<,=,N,R,T", i - 1 ); // 4th Row
- if( i < 8 ) PrintInCell( Row4, 5, i );
- // _TRACE("#, Row4 i = " + i);
- }
- GfxSelectFont("Arial" , CellHeight*0.60, 400 );
- for ( i = 1; i < 11; i++ )
- {
- ROW2 = StrExtract( "A,B,C,W,X,Y,x,a,b,c", i - 1 ); // 2nd Row
- PrintInCell( ROW2, 3, i );
- ROW3 = StrExtract( "(i),(ii),(iii),(iv),(v),(a),(b),(c),(d),(e)", i - 1 ); // 3rd Row
- PrintInCell( ROW3, 4, i );
- }
- PrintInCell( "?", 5, 8 ); // 4th Row
- PrintInCell( "!", 5, 9 );
- PrintInCell( "+", 5, 10 ); // JUST an example
- PrintInCellcolor( "+", 9, 9,colorBlue ); // SymbolSize Increase
- PrintInCellcolor( "-", 9, 10,colorBlue ); // SymbolSize Decrease
- PrintInCellcolor( "L", 10, 8,colorBlue ); // LazyBoy
- PrintInCellcolor( "D", 10, 9,colorBlue ); // DeleteOnOff
- PrintInCellcolor( "R", 10, 10,colorBlue ); // Release selected symbol
- //-------------------------------------------------------------------------------------
- GfxSelectFont("Wingdings", CellHeight*0.75, 400 );
- for ( i = 1; i < 11; i++ )
- {
- Row5 = StrExtract( "J,L,O,M,N,U,R,T", i - 1 ); // 5th Row
- PrintInCell( Row5, 6, i );
- }
- GfxSelectFont("Wingdings 3" , CellHeight*0.8, 400 );
- PrintInCellColor( "q", 7, 1, colorRed );
- PrintInCellcolor( "p", 7, 2, colorGreen );
- // Remove All Static variable
- if ( VarRemove )
- {
- StaticVarRemove( "st~*" );
- StaticVarRemove( "stf~*" );
- for ( i = 0; i < BarCount; i++ ) { StaticVarRemove( Yname + i ); }
- }
- if (VarRemoveLazyBoy) StaticVarRemove( "stf~*" );
- RequestTimedRefresh( 0.1, True );
- // PART 7 Interpretation
- printf( "\n DeleteOnOff =\t" + StaticVarGet( "DeleteOnOff") );
- printf("\n<b> GetButtonCol-PX= "+StaticVarGet("st~GetButtonColPx")+ "\n GetButtonRow-PY = "+ StaticVarGet("st~GetButtonRowPY") );
- printf( "\n Button_OnOFF \t\t"+ StaticVarGet("st~Button_OnOFF"));
- printf( "\n CellNumber =\t" + cellNumber );
- printf( "\n <b> colorID =\t" + colorID+ "</b> ");
- TitlecolorID= writeif( colorID==32,"colorRed",Writeif( colorID==25,"ColorOrange", writeif( colorID==42,"ColorYellow", writeif( colorID==43,"ColorBrightGreen",
- writeif( colorID==27,"ColorGreen", writeif( colorID==29,"ColorBlue", writeif( colorID==30,"ColorBlueGrey", writeif( colorID==38,"ColorViolet",writeif( colorID==36,"colorAqua","No color Selected")))))))));
- _SECTION_END();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement