Hi,
This started of as an exercise to mark the highs and lows of pivots using a click of the mouse button.
Added on GUI buttons and then I am trying to plot the wicks of candles ,
Seems to be an error in the "iif" function (method of selecting if the line is plotted at the "close or the open".
The relevant part of the code is lines 135 and 136,
OC[j] = IIf( shapePos ==H[i] AND C[i] > O[i], C[i], O[i] OR IIf(shapePos == L[i] AND C[i] < O[i], C[i], O[i] )); //THIS SELECTS OPEN OR CLOSE
OCcolor[j] = IIf( shapePos==H[i] AND C[i] > O[i], colorBlue, colorGrey40 ) OR IIf( shapePos==L[i] AND C[i] > O[i], colorBlue,colorGrey40) ;
full code posted below,
/*
This is with many thanks to PanoS, GUI code used from fxshrat,
modifications by Jeetu
*/
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates | chartHideQuoteMarker);
GraphLabelDecimals = 2;
GraphXSpace =10;
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
TC = IIf(C>Ref(C,-1),colorGreen,IIf(C<Ref(C,-1),colorRed,colorGold));
Plot( C, "Close", TC, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("wicks");
RequestTimedRefresh(0.1,True);
RequestMouseMoveRefresh();
//// Start Code for GuiButtons
numbuttons = 2; // number of toggle buttons
toggletext1 = "Disable Click,Enable Click";
toggletext2 = "Disable Remove,Remove slected";
//toggletext3 = " PROJ. ON , PROJ.OFF" ;
initial = 1;// intial toggle setting
persist = 1;// keep toggle state ON(1) / OFF(0)
ypos = 25;
width = 90;
height = 20;
// iterate number of toggle buttons
for ( toggleID = 1; toggleID <= numbuttons; toggleID++ )
{
toggletext = VarGetText( "toggletext" + toggleID );
GuiToggle( StrExtract(toggletext, 0), toggleID, x = 10, y = (toggleID-1)*(height+5) + ypos, width, height, notifyflag = 1 );
GuiSetColors(1,3,0, colorWhite, colorRed, 0, colorWhite, colorGreen, 0, colorWhite, colorGold, 0 );
staticname = StrFormat( "GuiParamToggle_%s_%g_%g", GetDatabaseName(), GetChartID(), toggleID );
staticget = Nz(StaticVarGet( staticname ), initial);
GuiSetCheck(toggleID, staticget);
togglecheck = GuiGetCheck(toggleID);
VarSet( "toggle" + toggleID, togglecheck );
if ( togglecheck ) GuiSetText( StrExtract(toggletext, 1), toggleID );
if ( GuiGetEvent( 0, 0 ) == toggleID && GuiGetEvent( 0, 1 ) == 1 ) {
StaticVarSet( staticname, 1-togglecheck, persist );
//Say( "Toggle " + StrExtract(toggletext, 1-togglecheck) );
RequestTimedRefresh(1);
}
}
// END Code for toggle buttons
//GuiTrigger for Removing All Tags
function xGuiTrigger( text1, idset, x, y, width, height, notifyflag )
{
local event, id, ONOFF; global GuiTriggerStaticName;
GuiButton( text1, idset, x, y, width, height, notifyflag );
id = GuiGetEvent( 0, 0 ); event = GuiGetEvent( 0, 1 );
GuiTriggerStaticName = StrFormat( "xGuiTrigger_%g_%g",GetChartID(), idset );
ONOFF = Nz( StaticVarGet( GuiTriggerStaticName ), 0 );
if( id == idset && event == 1 ) { StaticVarSet( GuiTriggerStaticName, 1 ); }
RequestMouseMoveRefresh();
return ONOFF;
}
ONOFF6 = xGuiTrigger( "Remove All", 6, 10 , 75, 90, 20, 1 );
GuiSetColors(6,6,0, colorWhite, colorRed, 0, colorWhite, colorDarkRed, 0, colorWhite, colorGold, 0 );
// END Code for trigger button
// a custom GFX Function to draw lines and text together
function GfxDrawOneLine( text1, text2, x1, y1, x2, y2 , color )
{
GfxSetBkMode(1);
GfxSelectPen( color );
GfxMoveTo( x1, y1 );
GfxLineTo( x2, y2 );
GfxSetTextColor(Color);
GfxTextOut( text1, x1, y1 );
GfxSelectFont( "Calibri", 12 );
GfxTextOut( text2, x2+1, y2+y2*0.001 );
}
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
bis = SelectedValue( bi );
SetBarsRequired(-2,-2);
symbol = Name();
tframe = Interval();
chartID = GetChartID(); // if you like this afl to share with other charts please Disable this line
XStaticName = "X" + chartID + symbol + tframe;
YStaticName = "Y" + chartID + symbol + tframe;
b = GetCursorMouseButtons();
//"Enable Click" button should be green
if( b & 8 ) // flag = 8 is set when window just received mouse click
{
if( toggle1 )
{
x = GetCursorXPosition( );
y = GetCursorYPosition( );
StaticVarSet( XStaticName + bis, x );
StaticVarSet( YStaticName + bis, y );
}
}
j = 0;
dt = DateTime();
shapePos = Null;
xx = yy = Null;
for ( i = 1; i <= lvb; i++ )
{
x = StaticVarGet( XStaticName + i );
y = StaticVarGet( YStaticName + i );
if ( x == dt[i] )
{
shapePos = IIf(abs(H[i]-y) < abs(L[i]-y), H[i], L[i]);
xx[j] = i;
yy[j] = IIf(abs(H[i]-y) < abs(L[i]-y), H[i], L[i]);
yyColor[j] = IIf(abs(H[i]-y) < abs(L[i]-y), colorGreen, colorRed) ;
OC[j] = IIf( shapePos ==H[i] AND C[i] > O[i], C[i], O[i] OR IIf(shapePos == L[i] AND C[i] < O[i], C[i], O[i] )); //THIS SELECTS OPEN OR CLOSE
OCcolor[j] = IIf( shapePos==H[i] AND C[i] > O[i], colorBlue, colorGrey40 ) OR IIf( shapePos==L[i] AND C[i] > O[i], colorBlue,colorGrey40) ;
j++;
}
}
GfxSetOverlayMode(1);
GfxSetCoordsMode(1);
for( i =1; i <= j ; i++ )
{
HLletter= writeif(yyColor[i - 1]==colorgreen,"H= ", "L= " ); // Letters of H or L
GfxDrawOneLine( "", StrFormat( HLletter+" %g",yy[i - 1]), xx[i - 1], yy[i - 1], BarCount - 1+5, yy[i - 1] , yyColor[i - 1] );
/*
HLletter= writeif(yyColor[i - 1]==colorgreen,"H= ", "L= " ); // Letters of H or L
GfxDrawOneLine( "", StrFormat( HLletter+" %g",yy[i - 1]), xx[i - 1], yy[i - 1], BarCount - 1+5, yy[i - 1] , yyColor[i - 1] );*/
OCletter= writeif(OCColor[i - 1]==colorBlue,"C= ", "O= " );
GfxDrawOneLine( "", StrFormat( OCletter+" %g",OC[i - 1]) , xx[i - 1], OC[i - 1], BarCount - 1+5,OC[i - 1] , OCColor[i - 1] );
}
// "Enable Click" should be green
// "Remove Selected" should be green, To remove any one tag, first select that tag (left click on that bar), then click the middle button
if( b & 8 )
{
if( b & 4 AND Toggle2 )
{
for( i = fvb ; i < BarCount; i++ )
{
x = StaticVarGet( XStaticName + i );
y = StaticVarGet( YStaticName + i );
if( x == dt[i] )
{
StaticVarRemove( XStaticName + bis);
StaticVarRemove( YStaticName + bis );
}
}
}
}
// Remove ALL Static Variable ---
if( ONOFF6 == 1 )
{
StaticVarRemove( XStaticName+"*" );
StaticVarRemove( YStaticName+"*" );
RequestMouseMoveRefresh();
StaticVarSet( GuiTriggerStaticName, 0 );
}
_SECTION_END();