Need help to code rate-of-change filter and price filter

Hai All,
Good Day

Kindly help to edit below code,

1, I need to limit percentage of price change from 1.5% to 3%.

2, Also need to remove stocks which have price value below 300.

_SECTION_BEGIN("All in One Explorer - Manish");
i=0;
//52 Week High Low
High52 = HHV(High,250);
Low52 = LLV(Low,250);

Filter=1;
AddColumn(ROC(V,1),"% Volume change",1.2);
AddColumn(ROC(C,1),"% Price change",1.2);
minChange = Param("Minimum Change", 1.5, 0.01, 100, 0.01);
maxChange = Param("Maximum Change", 2.8, 0.01, 100, 0.01);

//Moving Average (Short, Mid & Long Term)
MAShort = C>MA(C,5);
IIf(MAShort,i+1,i);
MAMid = C>MA(C,20);
IIf(MAMid,i+1,i);
MALong = C>MA(C,100);
IIf(MALong,i+1,i);
ShortStatus = WriteIf(MAShort,"Bullish",WriteIf(IsNull(MA(C,5)) ,"N/A","Bearish"));
ShortColor = IIf(MAShort,colorGreen,colorRed);
MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,20))," N/A","Bearish"));
MidColor = IIf(MAMid,colorGreen,colorRed);
LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
LongColor = IIf(MALong,colorGreen,colorRed);

//MACD
MACDBull=MACD(12,26)>Signal(12,26,9);
IIf(MACDBull,i+1,i);
MACDStatus=WriteIf(MACDBull,"Bullish",WriteIf(IsNull(MACD(12,26)),"N/A","Bearish"));
MACDColor=IIf(MACDBull,colorGreen,colorRed);

//Stochastic
StochKBull=StochK(14,3)>StochD(14,3,3);
IIf(StochKBull,i+1,i);
StochKStatus=WriteIf(StochKBull,"Bullish",WriteIf( IsNull(StochK(14,3)),"N/A","Bearish"));
StochKColor=IIf(StochKBull,colorGreen,colorRed);


 TrendScore =

 IIf(MAShort,1,0)+
 IIf(MAMid,1,0) +
 IIf(MAMid,1,0) +
 IIf(MALong,1,0)+
 IIf(MACDBull,1,0) +
 IIf(StochKBull,1,0)+





/*
TrendScore =

IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
*/





Filter = 1;

//AddColumn(High52,"52 Week High");
//AddColumn(Low52,"52 Week Low");
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddTextColumn(ShortStatus,"Short MA(5)",1,colorWhite,ShortColor);
AddTextColumn(MidStatus,"Mid MA(20)",1,colorWhite,MidColor);
AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
AddTextColumn(MACDStatus,"MACD",1,colorWhite,MACDColor);
AddTextColumn(StochKStatus,"Stochastic",1,colorWhite,StochKColor);
AddColumn(TrendScore,"Score");
_SECTION_END();

http://www.amibroker.com/guide/afl/param.html

3 Likes

@amal.kalapurayil your code has many lines that are unnecessary and make no sense. It also appears as if you copied and pasted bits of different codes into this one afl so again it appears disorganized.

Your original questions,

Potentially can be reviewed with some code like this,

PriceCondition = ROC(C, 1) >= 1.5 AND ROC(C, 1) <= 3.0;
LowPriceFilter = C > 300;

Filter = PriceCondition AND LowPriceFilter;

image

There are several lines that are not doing anything as they are currently written,

IIf(MAShort,i+1,i);

and again,

IIf(MAMid,i+1,i);

and again,

IIf(MALong,i+1,i);

If you insist on using the Immediate If function then I suggest a review of what it does and how to use it,
https://www.amibroker.com/guide/afl/iif.html

If your variables are properly coded then this section

 TrendScore =

 IIf(MAShort,1,0)+
 IIf(MAMid,1,0) +
 IIf(MAMid,1,0) +  // hmm, looks like more copy and paste mistake having this twice??
 IIf(MALong,1,0)+
 IIf(MACDBull,1,0) +
 IIf(StochKBull,1,0)+

Compare the results if it was written this way

TrendScore = MAShort + MAMid + MALong + MACDBull + StochKBull;

Good luck!

5 Likes

Hi,
Good day to you

Thanks for your support.

i have applied below code and run exploration but still didn't get stocks with below condition.

below screenshot fyr.

Requesting you to please assist if there any other changes required.!

PriceCondition = ROC(C, 1) >= 1.5 AND ROC(C, 1) <= 3.0;
LowPriceFilter = C > 300;

Filter = PriceCondition AND LowPriceFilter;

Screenshot (283)

Are you running your exploration over a watchlist?
Does your watchlist contain multiple symbols?
Maybe there is no true results to show?

You are using multiple 'Filter' variable - only use one.

Do not post screenshot of code - post the actual (full) code instead.

You are using 'IIF' incorrectly in your MACD section.

5 Likes

Hi,

I'm using exploration over a watchlist having 100+ symbols.

Please find the below revised code which i have edited,

Requesting you to please check and advise if there is any error and help to correct.

Still exploration don't filter below points,

""" 1, I need to limit percentage of price change from 1.5% to 3%.

2, Also need to remove stocks which have price value below 300. """

_SECTION_BEGIN("All in One Explorer");
i=0;
//52 Week High Low
High52 = HHV(High,250);
Low52 = LLV(Low,250);

Filter=1;
AddColumn(ROC(V,1),"% Volume change",1.2);
AddColumn(ROC(C,1),"% Price change",1.2);
minChange = Param("Minimum Change", 1, 0.01, 100, 0.01);
maxChange = Param("Maximum Change", 3, 0.01, 100, 0.01);

PriceCondition = ROC(C, 1) >= 1.5 AND ROC(C, 1) <= 3.0;
LowPriceFilter = C > 300;

Filter = PriceCondition AND LowPriceFilter;


//Moving Average (Short, Mid & Long Term)
MAShort = C>MA(C,5);
MAMid = C>MA(C,20);
MALong = C>MA(C,100);
ShortStatus = WriteIf(MAShort,"Bullish",WriteIf(IsNull(MA(C,5)) ,"N/A","Bearish"));
ShortColor = IIf(MAShort,colorGreen,colorRed);
MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,20))," N/A","Bearish"));
MidColor = IIf(MAMid,colorGreen,colorRed);
LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
LongColor = IIf(MALong,colorGreen,colorRed);




 TrendScore =

TrendScore = MAShort + MAMid + MALong;





/*
TrendScore =

IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
*/





Filter = 1;

//AddColumn(High52,"52 Week High");
//AddColumn(Low52,"52 Week Low");
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddTextColumn(ShortStatus,"Short MA(5)",1,colorWhite,ShortColor);
AddTextColumn(MidStatus,"Mid MA(20)",1,colorWhite,MidColor);
AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
AddColumn(TrendScore,"Score");
_SECTION_END();

Did you not see this! You are currently using 'Filter' x 3!

2 Likes

Just use this on it's own and see what you get. Divide and conquer.

PriceCondition = ROC(C, 1) >= 1.5 AND ROC(C, 1) <= 3.0;
LowPriceFilter = C < 300;

Filter = PriceCondition AND LowPriceFilter;
3 Likes

Hi,

Thank you so much. Its okay now. :slight_smile:

1 Like

Hi,

Can i ask you one more doubt,

If i required negative side ( Means losers details ) percentage of price change from ' -1.5%' to '-3%' , How i can edit below formula,

PriceCondition = ROC(C, 1) >= 1.5 AND ROC(C, 1) <= 3.0;
LowPriceFilter = C < 300;

Filter = PriceCondition AND LowPriceFilter;

You really should at least attempt these adjustments yourself to heighten your learning.

PriceCondition = ROC(C, 1) <= -1.5 AND ROC(C, 1) >= -3.0;
LowPriceFilter = C < 300;

Filter = PriceCondition AND LowPriceFilter;
3 Likes

Thank You so much.. :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

Dear All,

Please help me to add below 2 condition in my code as I'm tried and failed to add the same.

Column 1 : Last 74 bar average volume ( 5 minute candles )
Column 2 : Shows that how much % of volume increased or decreased in current 5
minute candle compared to last 74 bar average volume
( Compare ' Column 2 with Column 4' )

_SECTION_BEGIN("All in One Explorer");
//52 Week High Low
High52 = HHV(High,250);
Low52 = LLV(Low,250);

Filter=1;
AddColumn(ROC(V,1),"% Volume change",1.2);
AddColumn(ROC(C,1),"% Price change",1.2);
minChange = Param("Minimum Change", 1, 0.01, 100, 0.01);
maxChange = Param("Maximum Change", 3, 0.01, 100, 0.01);

PriceCondition = ROC(C, 1) <= -1.2 AND ROC(C, 1) >= -3.0;
LowPriceFilter = C > 300;

Filter = PriceCondition AND LowPriceFilter;

AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));

_SECTION_END();

Where in your code do you refer to a 74 Bar Volume average?

MA_V_74_previous = Ref(MA(Volume, 74), -1);
pctDiff_volume = ((Volume - MA_V_74_previous) / MA_V_74_previous) * 100;
1 Like

Hi,

I need to add volume average as per below. ( First 2 columns in exploration)

First Column : Last 74 bar average volume ( 5 minute candles )
Second Column : Shows that how much % of volume increased or decreased in
current 5 minute candle compared to last 74 bar average volume

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.