Simple Coding Help - No Promise.

amsin21

Well-Known Member
Hi,

I was trying to use Amibroker Say() as below. It triggers and says...but keeps on repeating till the trigger gets voided or candle changes or time frame changes. Please someone help to get this fixed, so that only onetime it says.

x = EMA(Close,5);
C1 = ParamColor("EMA5", colorTeal);
y = EMA(Close,13);
C2 = ParamColor("EMA13", colorRed);

Plot(x, "EMA(5)", C1, styleLine);
Plot(y, "EMA(13)", C2, styleLine);
Plot( C, "Close", ParamColor("Color", colorGreen ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

Buy=Cross(x,y);
Sell=Cross(y,x);

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = Sell;
Cover = Buy;
Cover = ExRem(Cover,Short);
Short = ExRem(Short,Cover);
Filter = Cover OR Short;

AlertIf( Buy, "SOUND c:/alert.wav", "Audio alert",0,1+2+4+8);
AlertIf( Sell, "SOUND c:/alert.wav", "Audio alert",0,1+2+4+8);

if(LastValue(Buy)) Say(Name()+Interval(2)+"Buy");
if(LastValue(Sell)) Say(Name()+Interval(2)+"Sell");


PlotShapes(shapeUpArrow*Buy,colorBrightGreen);
PlotShapes(shapeDownArrow*Sell,colorLightOrange);
 
Hi,

Can anyone help me with the following:

I am trying to backtest an afl and for debugging, I am printing the Buy and Sell value in the interpretation window. I want to print the Date & Time of the candle with the Buy and Sell also. Unfortunately, I am unable to get the correct method to do so.

Regards,
This is one way in which I got this working


Code:
Dates = DateTime(); // This global date array is used in function dtString
function [B]dtString[/B](flag)
{
	return WriteVal(ValueWhen(flag, Dates, 1), formatDateTime);
}
Place above 5 lines somewhere in start
....

Then you can use this as follows

Code:
Plot(BuyPrice, [B]dtString[/B](Buy), colorBlue, styleNoLabel);
Plot(ShortPrice, [B]dtString[/B](Short), colorRed, styleNoLabel);
 

toocool

Well-Known Member
Senior coders please help

Pivot =h+l+c /3

Same way high lo close of any time frame is needed to plot moving average of pivot, for example on 15 minutes chart high lo close of every 15 minutes bar will be taken to calculate pivot value and plot it as a moving average, from 1 period moving average to unlimited period moving average.

Kindly provide AFL for same, thanks
 

trash

Well-Known Member
Hi,

Can anyone help me with the following:

I am trying to backtest an afl and for debugging, I am printing the Buy and Sell value in the interpretation window. I want to print the Date & Time of the candle with the Buy and Sell also. Unfortunately, I am unable to get the correct method to do so.

Regards,
If you wanna plot datetime on chart then use Loop and DatetimeToStr() within loop. For 90 degree orientation of text use GfX functions like GFXSelectFont


So ... code snippet

Code:
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 ] );
    }
}
Picture:
 

Attachments

If you wanna plot datetime on chart then use Loop and DatetimeToStr() within loop. For 90 degree orientation of text use GfX functions like GFXSelectFont


So ... code snippet

Code:
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 ] );
    }
}
Picture:


Hi Trash,
Please see the image, i am getting an error.. please advise how to correct this..
 

toocool

Well-Known Member
Senior coders please help

Pivot =h+l+c /3

Same way high lo close of any time frame is needed to plot moving average of pivot, for example on 15 minutes chart high lo close of every 15 minutes bar will be taken to calculate pivot value and plot it as a moving average, from 1 period moving average to unlimited period moving average.

Kindly provide AFL for same, thanks
i tried this formula but in this formula the pivot calculation formula is not written so it must not be plotting moving average correctly .......right?

pd = Param("Period",5,1,200);
PMA = MA(Avg, pd);
PEMA = EMA(Avg, pd);
Plot(PMA, "Pivot MA", paramColor("PMA color", colorRed));
Plot(PEMA, "Pivot EMA", paramColor("PEMA color", colorBlue));

i have no knowledge of coding please correct this code .......thanks:thumb:
 

KelvinHand

Well-Known Member
i tried this formula but in this formula the pivot calculation formula is not written so it must not be plotting moving average correctly .......right?

pd = Param("Period",5,1,200);
PMA = MA(Avg, pd);
PEMA = EMA(Avg, pd);
Plot(PMA, "Pivot MA", paramColor("PMA color", colorRed));
Plot(PEMA, "Pivot EMA", paramColor("PEMA color", colorBlue));

i have no knowledge of coding please correct this code .......thanks:thumb:
Avg is an internal representation of (H+L+C)/3;

if you not sure, modified the PEMA = MA((H+L+C)/3, pd); and they should superimpose nicely.
 

toocool

Well-Known Member
@KelvinHand

so the new code should be like this ? am i right?


pd = Param("Period",5,1,200);
PMA = MA((H+L+C)/3, pd);
PEMA = MA((H+L+C)/3, pd);
Plot(PMA, "Pivot MA", paramColor("PMA color", colorRed));
Plot(PEMA, "Pivot EMA", paramColor("PEMA color", colorBlue));
 

Similar threads