Simple Coding Help - No Promise.

hello sir i want a afl that scan all nse stocks above 100 only which fullfill the below criteria.

BUY CONDITION: A 15min. bullish candle close above day range high only after 10.15am and scan only till 1.30pm.
SELL CONDITION: A 15min. bearish candle close below day range low only after 10.15am and scan only till 1.30pm.

I am attaching some screenshots of sell condition criteria hope you will understand.

Simple.

Thanks in advance.
 

Attachments

Romeo1998

Well-Known Member
Dear friend houmansat,
thank u for your kind words :happy:
but i m not an expert, my knowledge of amibroker is less than 0.1 % :D
in the above code, many variables r not defined, means it seems like an incomplete code, hence i cannot modify or alter it much :)
u were right abt the previous code, i had forgotten to change rsi in the rest of the code :D
here is the modified code :happy:
Code:
_SECTION_BEGIN("RSI Trendlines and Wedges");
SetChartOptions(0,0,chartGrid30|chartGrid70);
periods = Param( "Periods", 14, 1, 200, 1 );
a = RSI(periods);
Plot( a, _DEFAULT_NAME(), ParamColor( "Color", colorlightblue ), ParamStyle("Style",styleThick)  );

/*RSI Trendlines and Wedges*/
G=0;// set G=1, 2, 3, ... to see previous Resistance trendlines
GG=0;// set G=1, 2, 3, ... to see previous Support trendlines
x = Cum(1);
per = Param("Sensitivity",1,1,100,1); // sensitivity calibration
s1=a;
s11=a;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1+GG ));
startt=LastValue(ValueWhen( pS, x, 2+GG ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1+GG ) );
startS = LastValue( ValueWhen( pS, s1, 2+GG ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;// the Support trendline equation
Plot(IIf(x>startt-6 AND TRENDLINES>0 AND TRENDLINES<100,trendlineS,-1e10),"Support",IIf(as>0,5,4),8);
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1+G ));
startt1=LastValue(ValueWhen( pR, x, 2+G ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1+G ) );
startR = LastValue( ValueWhen( pR, s11, 2 +G ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;// the Resistance trendline equation
Plot(IIf(x>startT1-6 AND TRENDLINER>0 AND TRENDLINER<100,trendlineR,-1e10),"Resistance",IIf(Ar>0,5,4),8);
Ascwedge=Ar>0.5 AND As>sqrt(2)*Ar AND trendlineR>trendlineS;
Descwedge= As<-0.5 AND As>Ar/sqrt(2) AND trendlineR>trendlineS;
Filter=1;
AddColumn(Ascwedge,"AscWedge",1.0);
AddColumn(DescWedge,"DesWedge",1.0);
AddColumn(Ascwedge AND trendlineS>50 AND a>50,"Probable Bearish Breakout",1.0);
AddColumn(Descwedge AND trendlineR<50 AND a<50,"Probable Bullish Breakout",1.0);
/* END of code */
_SECTION_END();
 
Last edited:

Romeo1998

Well-Known Member
Dear friend houmansat,
After searching in google, i found the remaining code of that incomplete formula
u only need to replace this code
Code:
Filter=Cond_buy OR Cond_sell;
AddColumn(IIf(Cond_buy,Close,Null)," Buy ", 6.2,1.2,colorGreen);
AddColumn(IIf(Cond_sell,Close,Null)," Sell ",6.2,1.2,colorOrange);
with this one :happy:
Code:
Buy = Cover = cond_buy;
Sell = Short = cond_sell;
Filter = Buy OR Sell;
AddColumn( IIf( Buy, Close, Null ), " Buy ", 1.2, colorGreen, colorDefault );
AddColumn( IIf( Sell, Close, Null ), " Sell ", 1.2, colorRed, colordefault );
now scan, exploration n backtest will work fine :happy:
 
Last edited:
thanks romeo.but have error.in which line i should add your code??will you plz added for me in your code and complete afl?thanxx.best wishes
error 29:variable cond_buy used without having been initialized. it seems cond_buy cond_sell not initialized befor!
 
Last edited:

Romeo1998

Well-Known Member
Dear friend houmansat,
i think this is the code u r looking for :happy:
Code:
// RSI TRENDLINE formula ver 1.0

                                                        
TP = Param("Trend Per", 100,2,1000,1);                                                               
per_RSI= Param("RSI Per", 14, 2, 100,1);
IND =  RSI(per_RSI);                                                                                                     
Center = 50 ;


Plot( RSI(per_RSI), "", 4, 4);     
Plot(50,"",1,1) ;


// CALCULATE  UPTREND

startvalue = LastValue( LLV( IND, TP ) );                                                                         
startbar =  LastValue( ValueWhen( IND == startvalue, BarIndex(), 1) );                     
BP = BarCount - Startbar;                                                                                           

secondvalue =  LastValue( LLV( IND, BP - 5  ) );                                                       
secondbar =  LastValue( ValueWhen( IND == secondvalue, BarIndex(), 1) );           
BP2 = BarCount - secondbar; 

thirdvalue =  LastValue( LLV( IND, BP2 - 5 ) );                                                   
thirdbar =  LastValue( ValueWhen( IND == thirdvalue, BarIndex(), 1) );             
BP3 = BarCount - thirdbar; 

fourthvalue =  LastValue( LLV( IND, BP3 - 5 ) );                                                       
fourthbar =  LastValue( ValueWhen( IND ==fourthvalue, BarIndex(), 1) );         
BP4 = BarCount - fourthbar; 

fifthvalue =  LastValue( LLV( IND, BP4 - 5 ) );                                                   
fifthbar =  LastValue( ValueWhen( IND ==fifthvalue, BarIndex(), 1) );       
BP5 = BarCount - fifthbar; 

sixthvalue =  LastValue( LLV( IND, BP5 - 5 ) );                                             
sixthbar =  LastValue( ValueWhen( IND ==sixthvalue, BarIndex(), 1) );         

Low_1= IIf( BarIndex() == startbar, 80, Null);
Low_2= IIf( BarIndex() == secondbar, 80, Null);
Low_3= IIf( BarIndex() == thirdbar, 80, Null);
Low_4= IIf( BarIndex() == fourthbar, 80, Null);
Low_5= IIf( BarIndex() == fifthbar, 80, Null);
Low_6= IIf( BarIndex() == sixthbar, 80, Null);

b = startvalue ;   
FirstSlope = (secondvalue - b) / (secondbar - startbar) ;
FirstTrendline = FirstSlope * ( BarIndex() - startbar ) + b;                                                             
//Plot(  IIf(  BarIndex() >= startbar  AND FirstTrendline <= 90 , FirstTrendline, Null ) , "FirstTrendline", colorGreen, styleThick +2048 );       

SecondSlope = (thirdvalue - b) / (thirdbar - startbar) ;
SecondTrendline = SecondSlope * ( BarIndex() - startbar ) + b;

ThirdSlope = (fourthvalue - b) / (fourthbar - startbar) ;
ThirdTrendline = ThirdSlope * ( BarIndex() - startbar ) + b;

FourthSlope = (fifthvalue - b) / (fifthbar - startbar) ;
FourthTrendline = FourthSlope * ( BarIndex() - startbar ) + b;   

FifthSlope = (sixthvalue - b) / (sixthbar - startbar) ;
FifthTrendline = FifthSlope * ( BarIndex() - startbar ) + b; 

MainSlope = IIf( FirstSlope > SecondSlope,  IIf( SecondSlope > ThirdSlope,  IIf( ThirdSlope > FourthSlope,
IIf( FourthSlope >  FifthSlope,  FifthSlope, FourthSlope),ThirdSlope), SecondSlope), FirstSlope) ;

MainLine = MainSlope * ( BarIndex() - startbar ) + b;   
Plot(  IIf(  BarIndex() >= startbar, MainLine, Null ) , "MainLine", colorDarkGreen, styleThick ) ;   


IND_Diff = IIf(  BarIndex() >= startbar, abs( IND - MainLine), Null) ;
MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 2.5, 0.5,5,  0.5);

Cond_Buy = IIf( BarIndex() >= Thirdbar AND  IND_Diff  <= MainTrendLine_Diff, IND, 0)  AND  MainLine < 55 ;

PlotShapes( IIf( Cond_Buy, shapeUpArrow , shapeNone ), colorGreen );



/////////////////////////////////////////////

// CALCULATE  DOWNTREND

starthigh = LastValue( HHV( IND, TP ) );                                                                         
starthighbar =  LastValue( ValueWhen( IND == starthigh, BarIndex(), 1) );               
HBP = BarCount - starthighbar;                                                                                   

secondhigh =  LastValue( HHV( IND, HBP - 5  ) );                                                   
secondhighbar =  LastValue( ValueWhen( IND == secondhigh, BarIndex(), 1) );     
HBP2 = BarCount - secondhighbar; 

thirdhigh =  LastValue( HHV( IND, HBP2 - 5 ) );                                                   
thirdhighbar =  LastValue( ValueWhen( IND == thirdhigh, BarIndex(), 1) );           
HBP3 = BarCount - thirdhighbar; 

fourthhigh =  LastValue( HHV( IND, HBP3 - 5 ) );                                                         
fourthhighbar =  LastValue( ValueWhen( IND ==fourthhigh, BarIndex(), 1) );           
HBP4 = BarCount - fourthhighbar; 

fifthhigh =  LastValue( HHV( IND, HBP4 - 5 ) );                                                   
fifthhighbar =  LastValue( ValueWhen( IND ==fifthhigh, BarIndex(), 1) );         
HBP5 = BarCount - fifthhighbar; 

sixthhigh =  LastValue( HHV( IND, HBP5 - 5 ) );                                               
sixthhighbar =  LastValue( ValueWhen( IND ==sixthhigh, BarIndex(), 1) );           

High_1= IIf( BarIndex() == starthighbar, 90, Null);
High_2= IIf( BarIndex() == secondhighbar, 90, Null);
High_3= IIf( BarIndex() == thirdhighbar, 90, Null);
High_4= IIf( BarIndex() == fourthhighbar, 90, Null);
High_5= IIf( BarIndex() == fifthhighbar, 90, Null);
High_6= IIf( BarIndex() == sixthhighbar, 90, Null);

MainTrendLine_Diff = Param("Difference IND from MainTrendLine", 1, 100,1);

d = starthigh ;   
FirstDownSlope = (secondhigh - d) / (secondhighbar - starthighbar) ;
FirstDownTrendline = FirstDownSlope * ( BarIndex() - starthighbar ) + d;                                                               

SecondDownSlope = (thirdhigh - d) / (thirdhighbar - starthighbar) ;
SecondDownTrendline = SecondDownSlope * ( BarIndex() -  starthighbar ) + d;                                                         

ThirdDownSlope = (fourthhigh - d) / (fourthhighbar - starthighbar) ;
ThirdDownTrendline = ThirdDownSlope * ( BarIndex() - starthighbar ) + d; 

FourthDownSlope = (fifthhigh - d) / (fifthhighbar - starthighbar) ;
FourthDownTrendline = FourthDownSlope * ( BarIndex() - starthighbar ) + d; 

FifthDownSlope = (sixthhigh - d) / (sixthhighbar - starthighbar) ;
FifthDownTrendline = FifthDownSlope * ( BarIndex() - starthighbar ) + d; 

MainDownSlope = IIf( FirstDownSlope < SecondDownSlope,  IIf( SecondDownSlope < ThirdDownSlope, 
IIf( ThirdDownSlope < FourthDownSlope,  IIf( FourthDownSlope <  FifthDownSlope, FifthDownSlope, FourthDownSlope),ThirdDownSlope), SecondDownSlope), FirstDownSlope) ;

MainDownLine =  IIf( MainDownSlope == 0, Null, MainDownSlope * ( BarIndex() - starthighbar ) + d ) ;   
Plot(  IIf(  BarIndex() >=  starthighbar, MainDownLine, Null ) , "Main_DOWN_Line", colorViolet, styleThick ) ;   

IND_Diff = IIf(  BarIndex() >=  starthighbar, abs( IND - MainDownLine), Null) ;

Cond_Sell = IIf( BarIndex() >= Thirdbar AND  IND_Diff  <= MainTrendLine_Diff, IND, 0)  AND  MainDownLine > 45 ;

PlotShapes( IIf( Cond_Sell, shapeDownArrow , shapeNone ), colorRed );


Title =  StrFormat(  Name()  + "     " + "RSI" +  " " + per_RSI ) ;

Buy = Cover = cond_buy;
Sell = Short = cond_sell;
Filter = Buy OR Sell;
AddColumn( IIf( Buy, Close, Null ), " Buy ", 1.2, colorGreen, colorDefault );
AddColumn( IIf( Sell, Close, Null ), " Sell ", 1.2, colorRed, colordefault );
:happy:
 
thanks remeo.VERY NICE INDICATOR exactly. and also want to add scan /explorer to your AFL it is possible??some difference they have.your ind is better for me trend line has more condition and more sensitive.thanks
 

Similar threads