Scanner Help on finding assets

Hi,
I'm very new to programming, can you please guide on the below scanner.
I have managed to code the basics of the scanner,
basically, it needs to check the value of the past 1hour candle and If the conditions matched it needs to be added.
When I ran this, it runs for a long time and does not return any output.

_SECTION_BEGIN("ChannelScanner");

// INTRADAY TRADING HOURS AND CANDLE OPENING TIMES 
Candle1 = 091500;
// CHECK THE CHANNEL FORMATION 
Candle2= 101500;
Candle3 = 111500; 
Candle4 = 121500;
// Trading Window 
Candle5 = 011500;
Candle6 = 021500;
Candle7 = 031500;

// Scanner has to start checking only after 12.15 Candle Close. if run before returns no output as all the required intrday candles are not formed. 

Candle2High = TimeFrameGetPrice("H",inHourly,-3);
Candle2Low = TimeFrameGetPrice("L",inHourly,-3);
Candle2Close = TimeFrameGetPrice("C",inHourly,-3);

Candle3High = TimeFrameGetPrice("H",inHourly,-2);
Candle3Low = TimeFrameGetPrice("L",inHourly,-2);
Candle3Close = TimeFrameGetPrice("C",inHourly,-2);

Candle4High = TimeFrameGetPrice("H",inHourly,-1);
Candle4Low = TimeFrameGetPrice("L",inHourly,-1);
Candle4Close = TimeFrameGetPrice("C",inHourly,-1);

Candle5Open = TimeFrameGetPrice("O",inHourly,0);
Candle5Close_m5 = TimeFrameGetPrice("C",in5Minute,-1);
Candle5Close_m1 = TimeFrameGetPrice("C",in1Minute,-1);

//	101$ > 100$ > 97$ 
Condition1 = Candle2High > Candle3Close > Candle2Low;  // Condition1: 3rd Candle close is in between 2nd Candle High Low 

//101$ > 98.1$ >  97$
Condition2 = Candle2High > Candle4Close > Candle2Low;	// Condition2: 4th Candle Close is in  between 2nd Candle High Low 

Condition3 = Candle2High >= Candle3High AND Candle2Low <= Candle3Low;   // Condition3: 2nd Candle Sets the Channel Width for the 3rd and 4th Candle
Condition4 = Candle2High >= Candle4High AND Candle2Low <= Candle4Low;   // Condition4: 2nd Candle Sets the Channel Width for the 3rd and 4th Candle

Filter = Condition1 AND Condition2 AND Condition3 AND Condition4;

AddColumn(DateTime(), "Date", formatDateTime, colorBlack, colorDefault,150);
AddTextColumn(Name(), "Name", Null, colorBlack, colorDefault, 150);
AddColumn(GapDown(), "GapDown", Null, colorRed, 150);
AddColumn(GapUp(), "GapUp", Null, colorGreen,150);

_SECTION_END();

If the "Periodicity" in Analysis > Settings is set to "Daily" as is default,
You will n0t get Lower timeframes then that and "Hourly" will for sure fail.

Can you check what is set before proceeding further?

Periodicity is further limited by the resolution of your Data and base interval setting in DB..

1 Like

Hi Travick, Thanks, you are correct, the periodicity was set to daily, I have modified it to hourly in the database settings.

I will be running this scanner only in the middle of the market, let's say after 12 noon.
Can you please check, if I'm using the right coding approach to meet the requirement.

Main requirement is, Candle3 Close and Candle 4 Close Value has to be in between the Candle 2 High and Candle 2 low, Similarly, the Candle3, Candle 4 Hi/Low has to be in between the Candle2 High/Low.

I have reffered some AFL Scanner to find the value of the candle values and Made this below scanner, shall I request you to check on the same and suggest which one is the right approach.

_SECTION_BEGIN("ChannelScanner");

// INTRADAY TRADING HOURS AND CANDLE OPENING TIMES 
Candle1 = 091500;

// CHECK THE CHANNEL FORMATION 
Candle2= 101500;
Candle3 = 111500; 
Candle4 = 121500;

// TRADING WINDOW 
Candle5 = 011500;
Candle6 = 021500;
Candle7 = 031500;


c2 = Cross(TimeNum(),Candle2);  //detect the observation end time
c3 = Cross(TimeNum(),Candle3);   //detect the observation start time 
c4 = Cross(TimeNum(),Candle4);  


c2High = HighestSince(c2,H,1); //capture the 2 hour high
c2Low  = LowestSince(c2,L,1);  //capture the 2 hour low

c3High = HighestSince(c2,H,1); //capture the 3 hour high
c3Low  = LowestSince(c2,L,1);  //capture the 3 hour low

c4High = HighestSince(c2,H,1); //capture the 4 hour high
c4Low  = LowestSince(c2,L,1);  //capture the 4 hour low

Candle2High = ValueWhen(Candle3 ,c2High,1); 
Candle2Low = ValueWhen(Candle3 ,c2Low,1);  

Candle3High = ValueWhen(Candle4 ,c3High,1); 
Candle3Low = ValueWhen(Candle4 ,c3Low,1);  


Candle4High = ValueWhen(Candle5 ,c4High,1); 
Candle4Low = ValueWhen(Candle5 ,c4Low,1);  


//	101$ > 100$ > 97$ 
Condition1 = Candle2High > Candle3Close > Candle2Low;  // Condition1: 3rd Candle close is in between 2nd Candle High Low 

//101$ > 98.1$ >  97$
Condition2 = Candle2High > Candle4Close > Candle2Low;	// Condition2: 4th Candle Close is in  between 2nd Candle High Low 

Condition3 = Candle2High >= Candle3High AND Candle2Low <= Candle3Low;   // Condition3: 2nd Candle Sets the Channel Width for the 3rd and 4th Candle
Condition4 = Candle2High >= Candle4High AND Candle2Low <= Candle4Low;   // Condition4: 2nd Candle Sets the Channel Width for the 3rd and 4th Candle

Filter = Condition1 AND Condition2 AND Condition3 AND Condition4;

AddColumn(DateTime(), "Date", formatDateTime, colorBlack, colorDefault,150);
AddTextColumn(Name(), "Name", Null, colorBlack, colorDefault, 150);
AddColumn(GapDown(), "GapDown", Null, colorRed, 150);
AddColumn(GapUp(), "GapUp", Null, colorGreen,150);

_SECTION_END();

Before you get started, it is not clear whether you changed periodicity in Analysis window.
Can you elaborately explain what you have done, there are more under
Tools > Preferences > intraday
here you also need to select appropriate bar and ID settings.

All the Timeframes should be in correct correlation, a mismatch will just waste time.

What TF data do you get from data source?
I don't recall any instance where AB uses 12H time format implicitly.

and I doubt Candle 6 and 7 will work, because that afternoon time if it is, should be in 24H format or is it early morning?

Hi Travick,
Sure, I will try to provide as much as info I could explore and understand.

Datasource settings

Data Source: DDE Universal Data Plug-in
Base time Interval:1 Minute

Intrday Settings

  • Show day Session only
    Trading hours
    Start: 9:15
    End: 3:15

Tools -> Prefences -> Intraday Settings
This one has got the default custom time intervals
3,7,10,12,20

Backtester Settings
Periodicity: Hourly

Candle 6 and Candle 7 are near to the end of the Market.
1st Hourly Candle Opens at 9.15
2nd Opens at 10.15
..
..

Last Hourly Candle Opens at 3.15

These values aren't correct, convert the 12H time format to 24H.
so 3:15pm is 151500 instead.

These are intricacies you need to really focus on, otherwise you'll waste a lot of time for nothing.

Sure, Converted those timeframes into 24 hours.
Can you please assist me on the core logic.
is the values calculated using the AFL syntax and condition checking looks good ?

Whats the output you get?

You have still not posted enough info about your tests. What is the data range that and number of symbols u've defined for the scan?
If you're expecting someone to just run your code and say it works, it will work, but whether the logic is correct you have to decide.
Also read the manual and use _TRACE() and Debug so see whats going on in your code.

Thanks for the guidance, I got the exploration set correctly and it works fine.
I have set the periodicity to 5 min, the exploration happens on 5min chart time frame.
and in few places i use the TimeFrameSet function to switch to the required timeframe.

ok great, you can mark the thread as "Solved".