SELL Explore Output not working...Help Requested please

#1
Hello Members,
Below is a code which is a simple "Explore" to get the list of stocks which have gone into Buy / Sell zone, basis the EMA Crossover / Crossunder....

In this formulae, the BUY is working properly. However, SELL does not work. I even tried using CL_Sell (which is mentioned below as comments, in line7). But it just does not work.

Criteria :
Sell if Close < Min EMA AND crossover of EMA has happened i.e 200EMA > 100EMA > 50EMA (and close is below that) - NOT WORKING :confused:
Buy if Close > Max EMA AND crossover of EMA has happened. i.e. 50EMA > 100EMA > 200EMA (and Close is above that) - THIS IS WORKING...

Can someone please check and modify the code to correct the problem?

Thanking you in anticipation.

Warm Regards...RB



e1=EMA(C,50);
e2=EMA(C,100);
e3=EMA(C,200);

Maxema=Max(e3,Max(e2,e1));
Minema=Min(e1,Min(e2,e3));

//CL_Buy = e1>e1>e3;
//CL_Sell = e1<e2<e3;

EMA_buy=IIf((Close>Maxema) AND (C > (e1>e2>e3)),1,0);

EMA_sell=IIf((Close<Minema) AND (C < (e3>e2>e1)),1,0);


Filter = EMA_Buy OR EMA_Sell ;

AddColumn(EMA_buy,"EMA_Buy", format = 1.2, IIf(EMA_Buy == True, textColor = colorGreen, textColor = colorLightGrey));
AddColumn(EMA_sell,"EMA_Sell", format = 1.2, IIf(EMA_Sell == True, textColor = colorRed, textColor = colorLightGrey));
 
#2
try this one

Code:
e1=EMA(C,50);
e2=EMA(C,100);
e3=EMA(C,200);

Maxema=Max(e3,Max(e2,e1));
Minema=Min(e1,Min(e2,e3));

CL_Buy = ValueWhen(e1>e2 AND e2>e3, e1);
CL_Sell = ValueWhen(e1<e2 AND e2<e3, e1);

EMA_buy=IIf((Close>Maxema) AND (C > CL_Buy),1,0);
EMA_sell=IIf((Close<Minema) AND (C < CL_Sell),1,0);
EMA_sell = ExRem(EMA_sell, EMA_buy);
EMA_buy = ExRem(EMA_buy,EMA_sell);


Filter = EMA_Buy OR EMA_Sell ;

AddColumn(EMA_buy,"EMA_Buy", 1.2, IIf(EMA_Buy, colorGreen, colorLightGrey));
AddColumn(EMA_sell,"EMA_Sell", 1.2, IIf(EMA_Sell, colorRed, colorLightGrey));
 
#3
Dear Detwo,

Thanks for the reply wth code. But, the output is not coming correct. Atleast, this is not what I'm looking for...
C should be less than EMA1 < EMA2 < EMA3....
The code which I had posted was giving the BUY signals correctly. But SELL was not working...
Please help....
warm regards...RB
 
#4
This is what you want as per your sentences in first post.

Ema 50 is always min or max ema if it is above/below ema100 and ema100 is above/below ema 200. So you don't need max or min.

You can not write e1>e2>e3. that's wrong. Write e1 >e2 AND e2 >e3.

Code:
_SECTION_BEGIN("#Unnamed 1");
e1=EMA(C,50);
e2=EMA(C,100);
e3=EMA(C,200);

EMA_buy=IIf((Close>e1) AND (e1>e2 AND e2>e3), 1, 0);
EMA_sell=IIf((Close<e1) AND (e1<e2 AND e2<e3), 1, 0);

EMA_sell = ExRem(EMA_sell, EMA_buy);
EMA_buy = ExRem(EMA_buy,EMA_sell);
Buy = EMA_buy;
Sell = EMA_sell;

Filter = EMA_Buy OR EMA_Sell ;

AddColumn(EMA_buy,"EMA_Buy", 1.2, IIf(EMA_Buy, colorGreen, colorLightGrey));
AddColumn(EMA_sell,"EMA_Sell", 1.2, IIf(EMA_Sell, colorRed, colorLightGrey));

PlotShapes(Buy*shapeUpArrow, colorGreen);
PlotShapes(Sell*shapeDownArrow, colorRed);
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Plot( EMA( P, 50), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Plot( EMA( P, 100 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, 200), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();
 

Attachments

#5
Chief,
At the outset, THANKS A TONNE....i realised what mistake i was making, which was sort of stupid one....All the same, next time, I will surely remember the same and avoid such mistakes.

Additionally, Just troubling you for 2 more things in this AFL modification, as follows (ref to the diag attached herewith - AA Explore O/p)
1) if the condition is BUY, the char is Green. Instead, can I have the cell backgnd green colored / red colored? I tried the bkdngcolor option, which did not work.Here's the syntax which i used:
AddColumn(BollUpTrendBegin,"BollUpTrnd", format = 1.2, bkgndcolor=IIf(BollUpTrendBegin==True,colorGreen,colorWhite));

2) And, wanted to know how can I get the CURRENT timeframes Explore o/p only. Say for example, in the attachd snapshot, (scanning done on 14/3 @ 1445hrs; timeframe-5Min) the earlier day's signals were also coming and it becomes too tedious to bifurcate.
Wud it be possible to code the "scrip NAME" satisying the criteria to have some different colorbackgnd on the scrip name column - mapped with Sys time ?
I know the 2nd condition sounds tedious, but to sort out things, it becomes tedious, hence this query please

thanking you in anticipation.....

warm regards...RB
 
#7
1) if the condition is BUY, the char is Green. Instead, can I have the cell backgnd green colored / red colored? I tried the bkdngcolor option, which did not work.Here's the syntax which i used:
AddColumn(BollUpTrendBegin,"BollUpTrnd", format = 1.2, bkgndcolor=IIf(BollUpTrendBegin==True,colorGreen,colorWhite));
simply change the two addcolumn lines of my code with these ones. Read the help file of Amibroker! It's all explained there what each function is doing and what components are included in those functions.

Code:
AddColumn(EMA_buy,"EMA_Buy", 1, colorWhite, IIf(EMA_Buy, colorDarkGreen,colorWhite));
AddColumn(EMA_sell,"EMA_Sell", 1, colorWhite, IIf(EMA_Sell, colorDarkRed, colorWhite));
I don't quite understand your second problem. And I can't see a picture.
 
Last edited:

karthik_sri

Well-Known Member
#8
try this one

Code:
e1=EMA(C,50);
e2=EMA(C,100);
e3=EMA(C,200);

Maxema=Max(e3,Max(e2,e1));
Minema=Min(e1,Min(e2,e3));

CL_Buy = ValueWhen(e1>e2 AND e2>e3, e1);
CL_Sell = ValueWhen(e1<e2 AND e2<e3, e1);

EMA_buy=IIf((Close>Maxema) AND (C > CL_Buy),1,0);
EMA_sell=IIf((Close<Minema) AND (C < CL_Sell),1,0);
EMA_sell = ExRem(EMA_sell, EMA_buy);
EMA_buy = ExRem(EMA_buy,EMA_sell);


Filter = EMA_Buy OR EMA_Sell ;

AddColumn(EMA_buy,"EMA_Buy", 1.2, IIf(EMA_Buy, colorGreen, colorLightGrey));
AddColumn(EMA_sell,"EMA_Sell", 1.2, IIf(EMA_Sell, colorRed, colorLightGrey));
Dear Detwo,
Please help and give me AFL for the condition like we plot EMA's viz 15,25,35,45 & 55...the conditions are mentioned below...

Buy when there is a crossover of EMA and all EMA's are above the respective EMA's

Sell when there is a crossover of EMA and all EMA's are below the respective EMA's

The crossover can be like 15EMA will cross EMA25 & EMA35 and bounce back in the trend.

Cheers,
Karthik
 

Similar threads