MTF timeframe scan output (Scanning Timeframe not Pattern with single timeframe)

Status
Not open for further replies.

cheap

Active Member
#1
Hi,
I get this script afl from other forum,
Kindly look at it.
Code:
_SECTION_BEGIN("gang");
fh=fopen("scanner.txt","w");
fputs(" TIcker Bullish Hammer(In Min) Bearish Hammer (In Min) \n",fh);
fputs(" ================================================== ===================================== \n",fh);
fputs("\n",fh);


list = CategoryGetSymbols( categoryAll,0,0 );

for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{

for(j=1;j<51;j++)
{
TimeFrameSet(j*in1Minute);

blh=(LastValue(Foreign(sym,"Close"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
brh=(LastValue(Foreign(sym,"Close"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;

TimeFrameRestore();

if(blh==1)
{

fputs(sym+" "+NumToStr((j*in1Minute)/60)+"\n",fh);
}
if(brh==1)
{
fputs(sym+" "+NumToStr((j*in1Minute)/60)+"\n",fh);
} 

}

}


fclose(fh);


//RequestTimedRefresh(1);
_SECTION_END();
Kindly tell me whether this code is working right for you?

If you want to change bullish and bearish hammer code to Bullish Engulfing .
How will you accomplish this task ?
Bullish engulfing code
((O1 > C1) AND (C > O) AND (C >= O1) AND (C1 >= O) AND ((C - O) > (O1 - C1)))
 
Last edited:

trash

Well-Known Member
#2
I'm sorry to say but the code is awful.

Also why exporting to text file if you can do the output in AB explorer?

I know where the code comes from. It is from some other Indian forum. There the guy who made that code wrote that "it is not possible to output in Explorer". You may tell him that he has no idea of AmiBroker (yet).

The proof can be found in this my post, just look below. There as an example I used three simple candle patterns and output for 20 min to 30 min bar times.
Both explorer versions do output the same results but just with different view.

Either use Addcolumn() then bar times are column headers and cell input are patterns being comma separated.



Or use AddRow() function to get vertical output with patterns being column header.


BTW: candle patterns are a waste of time.

Don't ask for the codes. I'm just telling you guys what is awful and what is possible. You have to find out yourself.
 

cheap

Active Member
#3
I'm sorry to say but the code is awful.

Also why exporting to text file if you can do the output in AB explorer?

I know where the code comes from. It is from some other Indian forum. There the guy who made that code wrote that "it is not possible to output in Explorer". You may tell him that he has no idea of AmiBroker (yet).

The proof can be found in this my post, just look below. There as an example I used three simple candle patterns and output for 20 min to 30 min bar times.
Both explorer versions do output the same results but just with different view.

Either use Addcolumn() then bar times are column headers and cell input are patterns being comma separated.



Or use AddRow() function to get vertical output with patterns being column header.


BTW: candle patterns are a waste of time.

Don't ask for the codes. I'm just telling you guys what is awful and what is possible. You have to find out yourself.
Hi,
these patterns are single candlestick pattern, Can you do two candlestick pattern Bullish or bearish engulfing pattern?
it's scanning last bar only so , Can you scan more than 10 bars and give output in scanner?
thanks for input.
 

trash

Well-Known Member
#4
Can you do two candlestick pattern Bullish or bearish engulfing pattern?
...
Can you scan more than 10 bars and give output in scanner?
Yes, both are possible.

You may add any pattern or other output you like to.
But you have to keep in mind that

1. you are iterating trough multiple symbols
2. you are iterating trough multiple time frames
3. you are iterating trough multiple bars backward
4. on multiple patterns

So the more iterations and variables you add the slower the processing will become to get your desired output.



Code for bullish bearish engulfing

Code:
O1 = Ref(O,-1); C1 = Ref(C,-1);
bullengulfing = ((O1>C1) AND (C>O) AND (C>=O1) AND (C1>=O) AND ((C-O)>(O1-C1)));
bearengulfing = ((C1>O1) AND (O>C) AND (O>=C1) AND (O1>=C) AND ((O-C)>(C1-O1)));
 

cheap

Active Member
#5
ello,
When i try to add bullish engulfing in upper code, i can't see output value,
it's showing error. Why is it ?
do i need to write bullishengulfing outside of loop?



Code:
_SECTION_BEGIN("gang");
fh=fopen("scanner.txt","w");
fputs(" TIcker Bullish Hammer(In Min)              Bearish Hammer (In Min)    bullengulfing(In Min) \n",fh);
fputs(" ============================================  ====================================  =================\n",fh);
fputs("\n",fh);


list = CategoryGetSymbols( categoryAll,0,0 );

for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{

for(j=1;j<51;j++)
{
TimeFrameSet(j*in1Minute);

blh=(LastValue(Foreign(sym,"Close"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
brh=(LastValue(Foreign(sym,"Close"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
O1 = Ref(O,-1); C1 = Ref(C,-1);
bullengulfing = ((O1>C1) AND (C>O) AND (C>=O1) AND (C1>=O) AND ((C-O)>(O1-C1)));
bearengulfing = ((C1>O1) AND (O>C) AND (O>=C1) AND (O1>=C) AND ((O-C)>(C1-O1)));

TimeFrameRestore();

if(blh==1)
{

fputs(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}
if(brh==1)
{
fputs(sym+"                                                            "+NumToStr((j*in1Minute)/60)+"\n",fh);
} 
if(bullengulfing==1)
{

fputs(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}

}

}


fclose(fh);


//RequestTimedRefresh(1);
_SECTION_END();
To code this in explorer do i need to add , addcolumn() only , or do i need to change anything different in upper code?
Is same timeframe code will work in explorer? do i need to change it?
 

KelvinHand

Well-Known Member
#6
ello,
When i try to add bullish engulfing in upper code, i can't see output value,
it's showing error. Why is it ?
do i need to write bullishengulfing outside of loop?



Code:
_SECTION_BEGIN("gang");
fh=fopen("scanner.txt","w");
fputs(" TIcker Bullish Hammer(In Min)              Bearish Hammer (In Min)    bullengulfing(In Min) \n",fh);
fputs(" ============================================  ====================================  =================\n",fh);
fputs("\n",fh);


list = CategoryGetSymbols( categoryAll,0,0 );

for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{

for(j=1;j<51;j++)
{
TimeFrameSet(j*in1Minute);

blh=(LastValue(Foreign(sym,"Close"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
brh=(LastValue(Foreign(sym,"Close"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
O1 = Ref(O,-1); C1 = Ref(C,-1);
bullengulfing = ((O1>C1) AND (C>O) AND (C>=O1) AND (C1>=O) AND ((C-O)>(O1-C1)));
bearengulfing = ((C1>O1) AND (O>C) AND (O>=C1) AND (O1>=C) AND ((O-C)>(C1-O1)));

TimeFrameRestore();

if(blh==1)
{

fputs(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}
if(brh==1)
{
fputs(sym+"                                                            "+NumToStr((j*in1Minute)/60)+"\n",fh);
} 
if(bullengulfing==1)
{

fputs(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}

}

}


fclose(fh);


//RequestTimedRefresh(1);
_SECTION_END();
To code this in explorer do i need to add , addcolumn() only , or do i need to change anything different in upper code?
Is same timeframe code will work in explorer? do i need to change it?

To use the explorer, remove all the file output command.
Do the simple task first - just 1 condition, multiple condition try it later when everything work fine.
Try the addcolumn that trash's method 1.
Read guide & research examples for explorer.

do the addrow later after you gain experience.
 

cheap

Active Member
#7
To use the explorer, remove all the file output command.
Do the simple task first - just 1 condition, multiple condition try it later when everything work fine.
Try the addcolumn that trash's method 1.
Read guide & research examples for explorer.

do the addrow later after you gain experience.
Do you mean removing all fputs commands only? how to add
addcolumns() in timeframe screening?
ci.e. How to add timeframe Addcolumn("Bull Bar"), How to add timeframe in that column?
So it can output timeframe
 

KelvinHand

Well-Known Member
#8
Do you mean removing all fputs commands only? how to add
addcolumns() in timeframe screening?
ci.e. How to add timeframe Addcolumn("Bull Bar"), How to add timeframe in that column?
So it can output timeframe
Yes. removing all fopen, fputs fclose commands. The rest remain.
try out.
Read the guide on filter and addcolumns
 

cheap

Active Member
#9
Yes. removing all fopen, fputs fclose commands. The rest remain.
try out.
Read the guide on filter and addcolumns
I removed all fopen , fputs, fclose

Code:
_SECTION_BEGIN("gang");

(" TIcker Bullish Hammer(In Min)              Bearish Hammer (In Min)    bullengulfing(In Min) \n",fh);
(" ============================================  ====================================  =================\n",fh);
("\n",fh);


list = CategoryGetSymbols( categoryAll,0,0 );

for( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ )
{

for(j=1;j<51;j++)
{
TimeFrameSet(j*in1Minute);

blh=(LastValue(Foreign(sym,"Close"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))>(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
brh=(LastValue(Foreign(sym,"Close"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low")))/2) AND(LastValue(Foreign(sym,"Open"))<(LastValue(Foreign(sym,"High"))+LastValue(Foreign(sym,"Low") ))/2) ;
O1 = Ref(O,-1); C1 = Ref(C,-1);
bullengulfing = ((O1>C1) AND (C>O) AND (C>=O1) AND (C1>=O) AND ((C-O)>(O1-C1)));
bearengulfing = ((C1>O1) AND (O>C) AND (O>=C1) AND (O1>=C) AND ((O-C)>(C1-O1)));

TimeFrameRestore();

if(blh==1)
{

(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}
if(brh==1)
{
(sym+"                                                            "+NumToStr((j*in1Minute)/60)+"\n",fh);
} 
if(bullengulfing==1)
{

(sym+"                 "+NumToStr((j*in1Minute)/60)+"\n",fh);
}

}

}


(fh);


//RequestTimedRefresh(1);
_SECTION_END();
where to add filter =1;
which variable do i need to add on Addcolumn for i.e. bull bar
 

KelvinHand

Well-Known Member
#10
where to add filter =1;
which variable do i need to add on Addcolumn for i.e. bull bar
[/Quote]


Here the sample. play yourself.
note:I not working on Minutes.

Apply to *Filter, Range: 1 recent day(s)/ 1 recent bar(s)
PHP:
SetOption("NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker",1, colorDefault,colorDefault, 50);
AddTextColumn( FullName(), "Company",1, colorDefault,colorDefault,250);
AddColumn( DateTime(), "Date", formatDateTime, colorDefault,colorDefault, 80 );


for ( i = 20; i <= 50; i++ ) // 1minute to 30minute
{
	TimeFrameSet( i * in1Minute );

		O1 = Ref(O,-1); 
		C1 = Ref(C,-1);
		MP = (H+L)/2;
        R = H-L;
        
        
        //-- Condition 
		blBar=C>MP AND O>MP;
		brBar=C<MP AND O<MP;

		blEngulf = ((O1>C1) AND (C>O) AND (C>=O1) AND (C1>=O) AND ((C-O)>(O1-C1)));
		brEngulf = ((C1>O1) AND (O>C) AND (O>=C1) AND (O1>=C) AND ((O-C)>(C1-O1)));
		
		ss = ((R>4*(O-C)) AND ((H-C)/(.001+R)>= 0.75) AND ((H-O)/(.001+R)>= 0.75));
		
		filter = blBar OR brBar or	ss OR blEngulf OR brEngulf;  	

		str  =  WriteIf(blBar, "BullBar,", "")+
		        WriteIf(brBar, "BearBar,", "")+
		        WriteIf(blEngulf, "Bull Engulfing,","")+ 
		        WriteIf(brEngulf, "Bear Engulfing,", "") +
		        WriteIf(ss,       "Shooting Star,", "");
 		str = StrLeft( str, StrLen(str)-1);      
		
		AddTextColumn(str,  ""+NumToStr(i, 1.0)+"-Min"); 
	TimeFrameRestore();


}
 
Last edited:
Status
Not open for further replies.

Similar threads