My visual effect afl collection.

Seniors, could you please guide me where I am going wrong in the following afl code:

y = Year();
m = Month();
d = Day();
r=Hour();
e=Minute();
n=Second();
BuyDate=Null;
BuyTime=Null;
SellDate=Null;
SellTime=Null;

for(i=BarCount-1;i>1;i--)

{
if(Buy==1)
{
BuyDate=StrFormat("%02.0f-%02.0f-%02.0f", y[ i ], m[ i ], d[ i ] );

BuyTime=StrFormat("%02.0f:%02.0f:%02.0f", r[ i ],e[ i ],n[ i ] );


bars = i;
i = 0;
}
if( Sell==1)
{
SellDate=StrFormat("%02.0f-%02.0f-%02.0f", d[ i ], m[ i ], y[ i ] );

SellTime=StrFormat("%02.0f:%02.0f:%02.0f", r[ i ],e[ i ],n[ i ] );

bars = i;
i = 0;

}
}


GfxTextOut( " " + WriteIf (Buy, ""+BuyDate, ""), 40, 80 );

The above code gives {EMPTY} when GfxTextOut is used for output.

And :

GfxTextOut( " " + IIf (Buy, BuyDate, Null), 40, 80 );

produces result = 0


Also changing the for statement for loop gives afl error

for(i=0;i<BarCount;i++) gives endless loop error.

Any help will be highly appreciated.
Thanks for your kind assistance.
 
Sorry I should have used PHP code format:

Seniors, could you please guide me where I am going wrong in the following afl code:

PHP:
y = Year();
m = Month();
d = Day();
r=Hour(); 
e=Minute(); 
n=Second(); 
BuyDate=Null;
BuyTime=Null;
SellDate=Null;
SellTime=Null;

for(i=BarCount-1;i>1;i--)

{
if(Buy[i]==1)
{
BuyDate=StrFormat("%02.0f-%02.0f-%02.0f", y[ i ], m[ i ], d[ i ] );

BuyTime=StrFormat("%02.0f:%02.0f:%02.0f", r[ i ],e[ i ],n[ i ] );


bars = i;
i = 0;
}
if( Sell[i]==1)
{
SellDate=StrFormat("%02.0f-%02.0f-%02.0f", d[ i ], m[ i ], y[ i ] );

SellTime=StrFormat("%02.0f:%02.0f:%02.0f", r[ i ],e[ i ],n[ i ] );

bars = i;
i = 0;

}
}
GfxTextOut( " " + WriteIf (Buy, ""+BuyDate, ""), 40, 80 );

The above code gives {EMPTY} when GfxTextOut is used for output.

And :

GfxTextOut( " " + IIf (Buy, BuyDate, Null), 40, 80 );

produces result = 0


Also changing the for statement for loop gives afl error

for(i=0;i<BarCount;i++) gives endless loop error.

Any help will be highly appreciated.
Thanks for your kind assistance.
 

yasu222

Active Member
Spread

PHP:
//Spred Lines//
_SECTION_BEGIN("SPREAD LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid"); 
Ask = GetRTData("Ask"); 
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorLightOrange,styleDots,1) ;
Plot(ASK,"ASK",colorYellow,styleDots,1) ;
}
_SECTION_END(); 

_SECTION_BEGIN("SCORE BOARD");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
szBid = GetRTData("BidSize"); 
szAsk = GetRTData("AskSize");
Bid = GetRTData("Bid"); 
Ask = GetRTData("Ask"); 
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
x = 1000;
x2 =1090;
y = pxHeight-400;
GfxTextOut( ( "Bid Qty"),x-53,y-100);
GfxTextOut( (" "),x+13,y-100);
GfxTextOut( (""+szBid), x-20, y-80) ; // The text format location
GfxTextOut( ( "Ask Qty"),x+63+92,y-100);
GfxTextOut( (" "),x+13+92,y-100);
GfxTextOut( (""+szAsk), x+93+92, y-80) ; // The text format location
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location
}
_SECTION_END();
 
Thanks all for your good-wishes.

I have been able to dig in this forum http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-205.html post #2042 and able to find my answer for printing Datetime on chart. Thanks to "trash" for his efforts in posting code snippet.

This was to get a small GfxText windows with BuyDate, BuyTime, BuyRate & MTM so that it helps in positional Buy a view at a glance for the portfolio.

I am posting below just the code, for the benefit of member in case they want to refer.

PHP:
dist = 1.20 * ATR( 10 );
bi = BarIndex();
dt = DateTime();
firstbar = FirstVisibleValue( bi );
lastbar = LastVisibleValue( bi );

GfxSetCoordsMode( 1 );
GfxSelectFont( "Arial", 9, weight = 500, italic = False, underline = False, orientation = 900 );
GfxSetBkMode( 1 );
GfxSetTextColor( BuyColor );

for ( i = firstbar; i <= lastbar; i++ )
{
    if ( Buycond[ i ] )
    {
        PlotText( "Buy\n@" + BuyPrice[ i ], i, L[ i ] - dist[ i ], Buycolor );
        GfxTextOut( datetimetostr( dt[ i ] ), i - 1, H[ i ] + dist[ i ] );
    }
}

GfxSetTextColor( SellColor );
GfxSelectFont( "Arial", 9, weight = 500, italic = False, underline = False, orientation = -900 );

for ( i = firstbar; i <= lastbar; i++ )
{
    if ( Sellcond[ i ]  )
    {
        PlotText( "Sell\n@" + SellPrice[ i ], i, H[ i ] + dist[ i ], Sellcolor );
        GfxTextOut( datetimetostr( dt[ i ] ), i + 1, L[ i ] - dist[ i ] );
    }
}
Thanks all again for your kind support.
Regards,
 

ocil

Well-Known Member
Re: Spread

Thanks Yasu. One request how to reduce the size of the bid and ask line? i want short line.

PHP:
//Spred Lines//
_SECTION_BEGIN("SPREAD LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid"); 
Ask = GetRTData("Ask"); 
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorLightOrange,styleDots,1) ;
Plot(ASK,"ASK",colorYellow,styleDots,1) ;
}
_SECTION_END(); 

_SECTION_BEGIN("SCORE BOARD");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
szBid = GetRTData("BidSize"); 
szAsk = GetRTData("AskSize");
Bid = GetRTData("Bid"); 
Ask = GetRTData("Ask"); 
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
x = 1000;
x2 =1090;
y = pxHeight-400;
GfxTextOut( ( "Bid Qty"),x-53,y-100);
GfxTextOut( (" "),x+13,y-100);
GfxTextOut( (""+szBid), x-20, y-80) ; // The text format location
GfxTextOut( ( "Ask Qty"),x+63+92,y-100);
GfxTextOut( (" "),x+13+92,y-100);
GfxTextOut( (""+szAsk), x+93+92, y-80) ; // The text format location
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location
}
_SECTION_END();
 

yasu222

Active Member
TWAP or Time Weighted Average Price

PHP:
_SECTION_BEGIN("TWAP");
/*
The TWAP for a stock is calculated by 
Averaging OHLC in each bar then averaging the whole previous bars
*/
 
P11   = Param("Start Time",091500, 0 , 235959, 1 ) ; 
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == P11, BarIndex());
TodayClose = Sum(C,Bars_so_far_today);
TodayHigh = Sum(H,Bars_so_far_today);
TodayLow = Sum(L,Bars_so_far_today);
TodayOpen = Sum(O,Bars_so_far_today);
TWAP = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP = TWAP / Bars_so_far_today,0);
Plot (ATWAP,"TWAP",colorYellow, styleThick);
_SECTION_END();
 
Last edited:
hi sir....
i have register my self for pushbullet...i also have afl for it ....but whenever buy or signal generates it doent show message or not sending the message... can u please help mi out in this.....please
It is perfectly working. You can get the activation code from Pushbullet and enter in your afl in the line given below

objXmlHttpMain.setRequestHeader "Authorization", "Bearer 7d4Pi7sfFnXm4CAASQtGyULcrY0Th3L9"
 
Spread

PHP:
//Spred Lines//
_SECTION_BEGIN("SPREAD LINES");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
Plot(BID,"BID",colorLightOrange,styleDots,1) ;
Plot(ASK,"ASK",colorYellow,styleDots,1) ;
}
_SECTION_END();

_SECTION_BEGIN("SCORE BOARD");
messageboard = ParamToggle("Message Board","Show|Hide",1);
if (messageboard == 1 )
{
szBid = GetRTData("BidSize");
szAsk = GetRTData("AskSize");
Bid = GetRTData("Bid");
Ask = GetRTData("Ask");
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor( colorWhite );
GfxSelectSolidBrush( colorBlue ); // this is the box background color
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
x = 1000;
x2 =1090;
y = pxHeight-400;
GfxTextOut( ( "Bid Qty"),x-53,y-100);
GfxTextOut( (" "),x+13,y-100);
GfxTextOut( (""+szBid), x-20, y-80) ; // The text format location
GfxTextOut( ( "Ask Qty"),x+63+92,y-100);
GfxTextOut( (" "),x+13+92,y-100);
GfxTextOut( (""+szAsk), x+93+92, y-80) ; // The text format location
GfxTextOut( ( "Bid"),x+13,y-100);
GfxTextOut( (" "),x+27,y-100);
GfxTextOut( (""+Bid), x+13, y-80) ; // The text format location
GfxTextOut( ( "Ask"),x+13+92,y-100);
GfxTextOut( (" "),x+27+92,y-100);
GfxTextOut( (""+Ask), x+13+92, y-80) ; // The text format location
}
_SECTION_END();
yasu sir
first of all i am very thankful to you for this wonderful collection of AFLs
now i want LinTRA AFL
for both intraday and positional trading
if you can help me in this please tell me how can i get this AFL
for refrence m giving you one link where these AFL is live running on scripts
i.e.
http://www.marketcalls.in/lintra/crudeoilm
waiting for your reply
tanmay
 

yasu222

Active Member
_SECTION_BEGIN("!BABY_BANDS");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorLightGrey, styleNoTitle+styleCandle);
SetBarsRequired( 10000, 10000);
SetChartOptions(2, chartWrapTitle|chartHideQuoteMarker);
grid_day = Day()!=Ref(Day(),-1);
Plot(grid_day,"",colorLightGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);

NO1 = Param("BAND VALUE",7,2,50,1,1);
NO2 = Param("Standard Deviation",2,0.1,5,0.3,0.3);

TB1 = BBandTop(C,NO1,NO2);
LB1 = BBandBot(C,NO1,NO2);
TB2 = BBandTop(LB1,NO1,NO2);
LB2 = BBandBot(TB1,NO1,NO2);
TB3 = BBandTop(LB2,NO1,NO2);
LB3 = BBandBot(TB2,NO1,NO2);
TB = Ref(TB3,-NO1);
LB = Ref(LB3,-NO1);

BSell1 = Cross(C,TB);
BBuy1 = Cross(LB,C);

BSell = ExRem(BSell1,BBuy1);
BBuy = ExRem(BBuy1,BSell1);

PlotShapes(Bsell*shapeStar,colorBrightGreen,0,L,-10);
PlotShapes(Bbuy*shapeStar,colorPink,0,H,10);
Plot( TB, "BBTop" + _PARAM_VALUES(), colorSkyblue, styleDashed );
Plot( LB, "BBBot" + _PARAM_VALUES(), colorTan, styleDashed );
//Plot( MA(C,no1), "Mid Line" + _PARAM_VALUES(), colorTan, styleDashed );
AlertIf( BBUY , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( BSELL , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );
 

Similar threads