Simple Coding Help - No Promise.

KelvinHand

Well-Known Member
pd = Param("Period",5,1,200);

//--KH: Check the superimpose to get confident yourself,
// this is to prove to you that Avg <=> (H+L+C)/3

PMA = MA(Avg, pd);
PEMA = MA((H+L+C)/3, pd);

Plot(PMA, "Pivot MA", paramColor("PMA color", colorRed));
Plot(PEMA, "Pivot EMA", paramColor("PEMA color", colorBlue));
 

trash

Well-Known Member


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

GfxSetCoordsmode is a new function added to AB 5.80!

But if applying that code snippet in that version you are still not there since I have written "snippet" in bold letters. How much more clearly do you think it has to be pointed out? So it means it is code part of a larger code. Using that snippet you need to add a system code at the top yourself with buycond and sellcond variables as well as buy and sell color variables.
 

toocool

Well-Known Member
pd = Param("Period",5,1,200);

//--KH: Check the superimpose to get confident yourself,
// this is to prove to you that Avg <=> (H+L+C)/3

PMA = MA(Avg, pd);
PEMA = MA((H+L+C)/3, pd);

Plot(PMA, "Pivot MA", paramColor("PMA color", colorRed));
Plot(PEMA, "Pivot EMA", paramColor("PEMA color", colorBlue));
i am sorry bro , i do not understand how to check superimpose :confused:
 

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);
Awaiting ... help from any experts :sos:
 

humble

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,
Hi,

@mastermind007 & @trash thanks for the help. I am doing the following:

dt = DateTime();

And in the iteration of the bars, doing a "datetimetostr( dt))", and it is working as expected.

Regards,
 
Hi frnds,

Say I have two buy conditions b1 and b2 and i use it as buy=b1 or b2. Trailing stop loss logic for both the conditions is different.

I have used this. SL= iif(b1, logic of b1, logic of b2);
This doesn't work maybe because the bar next to the signal bar may not satisfy b1 hence stoploss is not according to logic of b1.

I want is if a trade is triggered according to b1 then apply logic of b1 on all subsequent bars, same for b2.



plz see the image, in top frame a signal is generated according to b1, and in the lower frame is the tsl according to b1.

Hope someone helps.

Thanks,
Purusharth

Not able to c the attachements, do i need to use a diff browser....
 

cellclinic

Well-Known Member
Hello Friends :)

Again with a humble request ... Need to get an buy sell signal with sound alert or a pop up with the name & price of the particular stock ...

AFL formulla as folllows ...

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("DONCHAIN2");
// Plots a 20 period Donchian channel

pds=144;
DonchianUpper =HHV(Ref(C,-1),pds);
DonchianLower = LLV(Ref(C,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorGreen,styleLine);
Plot(DonchianMiddle,"DM",colorViolet,styleNoDraw);
Plot(DonchianLower,"DL",colorRed,styleLine);

_SECTION_BEGIN("DONCHAIN2");
// Plots a 20 period Donchian channel

pds=720;
DonchianUpper =HHV(Ref(C,-1),pds);
DonchianLower = LLV(Ref(C,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorDarkRed,styleThick);
Plot(DonchianMiddle,"DM",colorWhite,styleNoDraw);
Plot(DonchianLower,"DL",colorRed,styleThick);
 

amitrandive

Well-Known Member
Hello Friends :)

Again with a humble request ... Need to get an buy sell signal with sound alert or a pop up with the name & price of the particular stock ...

AFL formulla as folllows ...

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Price");
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", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("DONCHAIN2");
// Plots a 20 period Donchian channel

pds=144;
DonchianUpper =HHV(Ref(C,-1),pds);
DonchianLower = LLV(Ref(C,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorGreen,styleLine);
Plot(DonchianMiddle,"DM",colorViolet,styleNoDraw);
Plot(DonchianLower,"DL",colorRed,styleLine);

_SECTION_BEGIN("DONCHAIN2");
// Plots a 20 period Donchian channel

pds=720;
DonchianUpper =HHV(Ref(C,-1),pds);
DonchianLower = LLV(Ref(C,-1),pds);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;


Plot(DonchianUpper,"DU",colorDarkRed,styleThick);
Plot(DonchianMiddle,"DM",colorWhite,styleNoDraw);
Plot(DonchianLower,"DL",colorRed,styleThick);
You have not defined what is a Buy/Sell in the code.
First define a BUY/SELL and then,
Add these two lines to the end of the code to get a pop up.But pop up has issues to be sorted,maybe an expert can help.

Code:
PopupWindow("Buy : " + FullName(),"Alert", 5, 640*mtRandom(), 480*mtRandom());
PopupWindow("Sell : " + FullName(),"Alert", 5, 640*mtRandom(), 480*mtRandom());
A common problem is that if you call PopupWindow() from a loop or if one gets generated on every AFL pass, you can get hundreds or even thousands of pop-ups piling up on your screen. Tomasz posted a simple work-around on the AmiBroker Feedback Center that took care of the problem in some cases (Suggestion 1528):

http://www.amibroker.org/userkb/2008/08/30/popup-window-preventing-pile-ups/
 
Last edited:

cellclinic

Well-Known Member
Thanks Amit for supporting once again ..

sorry for not providing buy & sell conditions as it skipped from mind .;)

If Possible :- 2 Buy Signal ( Differently Colored )

Buy 1 if price closed & trade above Donchian 144 upper band .

Buy 2 if price closed & trade above Donchian 720 upper band .

Sell1 if price closed & trade below Donchian 144 lower band .

Sell2 if price closed & trade below Donchian 720 lower band .

Addition With alert :)

You have not defined what is a Buy/Sell in the code.
First define a BUY/SELL and then,
Add these two lines to the end of the code to get a pop up.But pop up has issues to be sorted,maybe an expert can help.

Code:
PopupWindow("Buy : " + FullName(),"Alert", 5, 640*mtRandom(), 480*mtRandom());
PopupWindow("Sell : " + FullName(),"Alert", 5, 640*mtRandom(), 480*mtRandom());
 

Similar threads