Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar? - Aussie Stock Forums

# Thread: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar?

1. ## Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar?

Hi,
I want to scan stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar .

Can you please tell me AFL code to try ?

2. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

war1 = Cross(20,StochD(14,3,3));
//war1 = Ref(Cross(20,StochD(14,3,3)),-1);
Filter = war1;

3. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by Cor
war1 = Cross(20,StochD(14,3,3));
//war1 = Ref(Cross(20,StochD(14,3,3)),-1);
Filter = war1;
Code:
```Cross_ = Cross( 20, StochD( 14, 3, 3 ) );
war1 = Sum( Cross_, period = 2 ) == 1;

Filter = war1 AND Status( "lastbarinrange" );

AddColumn( C, "Price", format = 1.2 );
AddColumn( Ref( Cross_, -1 ), "Ref(Cross,-1)", 1.0 );```

4. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

None of these codes are working......Did you guys checked in your machine ?

I run the code with 1 year daily data ...no scrip found.....this is wrong ...because I find the same in other charting platform.

requirement is : Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar

5. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
None of these codes are working
The code works. Add this line to get a plot of the signals:

Plot(war1,"crosses",colorRed,styleLine);

A trading system based on these signals is profitable. Change the values to make the stochastic faster and the system becomes even more profitable.

Here is a complete listing:

//RecentStochDrop.afl

OptimizerSetEngine( "cmae" );

SetOption( "ExtraColumnsLocation", 1 );
SetOption( "InitialEquity", 100000 );
SetPositionSize( 10000, spsValue );
MaxPos = 1;
SetOption( "MaxOpenPositions", 1 );
SetTradeDelays( 0, 0, 0, 0 );

StochVar1 = Optimize("StochVar1",6,2,50,1);
StochVar2 = Optimize("StochVar2",1,1,10,1);
StochVar3 = Optimize("StochVar3",1,1,10,1);
SignalPeriod = Optimize("SignalPeriod",5,1,5,1);

Cross_ = Cross( BuyLevel, StochD( StochVar1, StochVar2, StochVar3 ) );
war1 = Sum( Cross_, period = SignalPeriod ) >= 1;

Plot(war1,"crosses",colorRed,styleLine);

Sell = !war1;

Filter = 1;

AddColumn( C, "Price", format = 1.2 );
AddColumn( Ref( Cross_, -1 ), "Ref(Cross,-1)", 1.0 );

//////////////// end ////////////////////

Best regards,
Howard

6. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

@howardbandy,

I run your code and I get this ..same scrips are repeated

2014-07-03_2143.png

By the way ...you provided a different code .....my objective was something else ..

I want to scan stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar

Can you provide a simple AFL which does this only ?

7. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
None of these codes are working......Did you guys checked in your machine ?
Did you check your very basic knowledge of Automatic Analysis? If you check the box "n last days .... n = 2" then the last 2 days will be scanned or explored.

Code:
```Buy = Cross(20, StochD(14, 3, 3));

Plot(Buy, "StochD Cross 20", colorBlack, styleArea);```

8. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
None of these codes are working......Did you guys checked in your machine ?

I run the code with 1 year daily data ...no scrip found.....this is wrong ...because I find the same in other charting platform.

requirement is : Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 bar

The code works. You just don't have much clue that's the problem.
Clueless guy from India again. What is a scrip?

9. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

This is what the code does!

If it is not what you want then explain it better without leaving questions.

Click it like Beckham

10. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Code:
```Cross_ = Cross( 20, StochD( 14, 3, 3 ) );
war1 = Sum( Cross_, period = 2 ) == 1;
dt = ValueWhen( war1, DateTime() );

Filter = Status( "lastbarinrange" );

AddColumn( dt, "DateTime of last cross", formatDateTime );
AddColumn( ValueWhen( war1, C ), "Price@Signal", format = 1.5 );
AddColumn( ValueWhen( war1, Cross_ ), "Cross", 1.0 );
AddColumn( ValueWhen( war1, Ref( Cross_, -1 ) ), "Ref(Cross,-1)", 1.0 );

Plot(StochD( 14, 3, 3 ),"StochD",colorWhite,styleLine);
Plot(war1,"crosses",colorRed,styleHistogram|styleownscale);
PlotGrid( 20, colorRed );```
And listen guy talking nonsense, don't press Scan but Explorer. Just saying.

11. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

my sincere apology if my language has hurt you in anyway....... I understand my language has probably gone into harsh way......This was not intentionally.

thanks for your time and help.

@Wysiwyg,

I did put check the box "n last days .... n = 2" in Automatic Analysis and explored.....but somehow its not giving me any resultset.

Could you please take a look at this video and let me know if I'm missing something here..

http://screencast.com/t/Mr3eY39gUr

@trash,
I'll give an update to your code soon after executing.

by the way ,could you please explain what this does Sum( Cross_, period = 2 ) == 1; ? why Sum has to be ==1 ? I'm confused at this part

once again....thanks for your time and help.

12. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
@trash,
I'll give an update to your code soon after executing.

by the way ,could you please explain what this does Sum( Cross_, period = 2 ) == 1; ? why Sum has to be ==1 ? I'm confused at this part

once again....thanks for your time and help.
Because both lines do the same.

war1 = Sum( Cross_, 2) == 1;
war1 = Cross_ OR Ref( Cross, -1 );

using Sum is just a more clever/shorter way.

Both (Cross_ and Ref( Cross_, -1) ) are not true at the same time. So the Sum of both is always 1 but not 2. 0 + 1 = 1 and 1 + 0 = 1 also. Right? Basic math.

13. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
Could you please take a look at this video and let me know if I'm missing something here..

http://screencast.com/t/Mr3eY39gUr
Why do you use Old Analysis?? You can set 2 bars range in New Analysis too. Old Analysis is obsolete and has been left in by TJ for old codes using OLE stuff the old way.

Anyway all codes do what your sentence in first post is telling us.
Reporting a cross signal during last 1 or 2 bars.

Now this code

Code:
```Cross_ = Cross( 20, StochD( 14, 3, 3 ) );
war1 = Sum( Cross_, period = 2 ) == 1;

Filter = war1 AND Status( "lastbarinrange" );

AddColumn( C, "Price", format = 1.5 );
AddTextColumn( WriteIf( Cross_, "TRUE", "" ), "Cross", 1.0 );
AddTextColumn( WriteIf( Ref( Cross_, -1 ), "TRUE", "" ), "Ref(Cross,-1)", 1.0 );```
reports only realtime signals if one of both conditions is true at most recent bar.

So let's take a look. I mean it's pretty simple. Last bar is at 09:46 so it reports signals on that bar only.

The other code reports most recent occurrence not just on most recent bar. That's why DateTime@Signal column was added to output the time of most recent signal occurrence. Pretty simple again.

Code:
```Cross_ = Cross( 20, StochD( 14, 3, 3 ) );
war1 = Sum( Cross_, period = 2 ) == 1;
dt = ValueWhen( war1, DateTime() );

Filter = Status( "lastbarinrange" );

SetSortColumns( 3 );
AddColumn( dt, "DateTime@Signal", formatDateTime, colorDefault, colorDefault, 130 );
AddColumn( ValueWhen( war1, C ), "Price@Signal", format = 1.5 );
AddTextColumn( WriteIf( ValueWhen( war1, Cross_ ), "TRUE", "" ), "Cross", 1.0 );
AddTextColumn( WriteIf( ValueWhen( war1, Ref( Cross_, -1 ) ), "TRUE", "" ), "Ref(Cross,-1)", 1.0 );

Plot(StochD( 14, 3, 3 ),"StochD",colorWhite,styleLine);
Plot(war1,"crosses",colorRed,styleHistogram|styleownscale);
PlotGrid( 20, colorRed );```

14. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

The code by Wysiwyg does the same thing as my first code if applied on last 2 bars set in "Range:"

His code reports price and datetime at Cross signal. That's the only difference.

15. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Originally Posted by amiuser
@Wysiwyg,

I did put check the box "n last days .... n = 2" in Automatic Analysis and explored.....but somehow its not giving me any resultset.

Could you please take a look at this video and let me know if I'm missing something here..

http://screencast.com/t/Mr3eY39gUr
You didn't check the "from: - to:" box for date range. You still had the "n last days" box checked. If you are exploring a list of securities and there are no results then that is because the conditions have not been met. Trash is better versed in Amibroker than me so follow his directions.

16. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Thanks ... that helped a lot.

You know ....I have EOD data ...and I may like to explore the same in weekly time frame ? Is there any settings in New Analysis window where I may mention time frame before exploration.

17. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Go to backtester settings General tab and there set Periodicity.

You can visually check set timeframe via Column output.

Code:
```Cross_ = Cross( 20, StochD( 14, 3, 3 ) );
war1 = Sum( Cross_, period = 2 ) == 1;
dt = ValueWhen( war1, DateTime() );

Filter = Status( "lastbarinrange" );

SetSortColumns( 4 );

AddTextColumn( Interval( 2 ), "Time Frame", 1.0 );
AddColumn( dt, "DateTime@Signal", formatDateTime, colorDefault, colorDefault, 130 );
AddColumn( ValueWhen( war1, C ), "Price@Signal", format = 1.5 );
AddTextColumn( WriteIf( ValueWhen( war1, Cross_ ), "TRUE", "" ), "Cross", 1.0 );
AddTextColumn( WriteIf( ValueWhen( war1, Ref( Cross_, -1 ) ), "TRUE", "" ), "Ref(Cross,-1)", 1.0 );

Plot(StochD( 14, 3, 3 ),"StochD",colorWhite,styleLine);
Plot(war1,"crosses",colorRed,styleHistogram|styleownscale);
PlotGrid( 20, colorRed );```

18. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

Besides I apologize for calling you "clueless guy". I was just annoyed (again) because most of the time people jump to the some conclusion too early. Anyway it wasn't fair from my side too.

19. ## Re: Scanning stocks whose slow stochastic (14,3,3) has gone below 20 in last 1 or 2 b

How to add volume in AFL code ?

I want to add volume >50000 like this ..

Buy = Cross(20, StochD(14, 3, 3)) and volume >50000 ;

Plot(Buy, "StochD Cross 20", colorBlack, styleArea);

I am not sure about the syntax . Can you please correct me.

Thanks