Simple Coding Help - No Promise.

Refer

http://www.traderji.com/amibroker/9...rthiks-315-pullback-strategy.html#post1098781

Also found one on the net.Remember this is not perfect.Don't keep searching for the Holy Grail.

Source:http://algoji.com/mean-reversion-strategy/


Code:
_SECTION_BEGIN("AlgoJi.com Mean_Revert");
SetPositionSize(1,spsShares);
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

SetBarsRequired(10000,0);
FastEMAPeriod = Param("FastEMAPeriod",15,1,100,1);
SlowEMAPeriod =Param("SlowEMAPeriod",180,1,200,1);

per1= 15;
per2= 2;

EMA1= EMA(C,FastEMAPeriod);
EMA2= EMA(C,SlowEMAPeriod);

uptrend= EMA1>EMA2; dwntrend= EMA1<EMA2;
bbtop= BBandTop(C,per1,per2);
bbot= BBandBot(C,per1,per2);
supp= Cross(C,bbot); ress= Cross(bbtop,C);

Ll= LLV(L,5); Hh= HHV(H,5);

Buy=Sell=Short=Cover=Null;

sl=sls=tgt=tgts=0;
for(i=200; i<BarCount; i++)
{
	if(sl==0 AND uptrend[i] AND supp[i])
	{ Buy[i]=1; sl= Ll[i]; tgt= H[i];}
	if((L[i]<sl OR ress[i]) AND sl>0)
	{ if(L[i]<sl)SellPrice[i]= sl; Sell[i]= 1; sl=tgt=0;}

	if(sls==0 AND dwntrend[i] AND ress[i])
	{ Short[i]=1; sls= Hh[i]; tgts= L[i];}
	if( (H[i]>sls OR supp[i]) AND sls>0)
	{ if(H[i]>sls)CoverPrice[i]=sls; Cover[i]=1; sls=tgts=0; }
}



Plot( EMA1, "EMA Fast", colorRed, styleLine | styleNoRescale ); 
Plot( EMA2, "EMA Slow", colorBlue, styleLine | styleNoRescale ); 
Plot(bbtop, "Band Top", colorBlack, styleLine);
Plot(bbot, "Band Bottom", colorBlack, styleLine);

PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );

PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );


_SECTION_END();


Thanx amit ji for ur help...

its a strategy to be plotted in scanner or exploration..

not finding any holy Grail...
 

amitrandive

Well-Known Member
Thanx amit ji for ur help...

its a strategy to be plotted in scanner or exploration..

not finding any holy Grail...
Add this at the end of the code.
Code:
Filter=Buy OR Sell OR Short OR Cover; 
 
AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Short,ShortPrice,Null)," Short Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Cover,CoverPrice,Null)," Cover Signal ",6.2,1.2,colorGreen);
 
Add this at the end of the code.
Code:
Filter=Buy OR Sell OR Short OR Cover; 
 
AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Short,ShortPrice,Null)," Short Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Cover,CoverPrice,Null)," Cover Signal ",6.2,1.2,colorGreen);


showing errors
 

amitrandive

Well-Known Member
Add this at the end of the code.
Code:
Filter=Buy OR Sell OR Short OR Cover; 
 
AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Short,ShortPrice,Null)," Short Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Cover,CoverPrice,Null)," Cover Signal ",6.2,1.2,colorGreen);
Will check later , am outside.
Code working correctly , check your version of Amibroker.



Complete code(if you have not pasted correctly)

Code:
_SECTION_BEGIN("AlgoJi.com Mean_Revert");
SetPositionSize(1,spsShares);
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

SetBarsRequired(10000,0);
FastEMAPeriod = Param("FastEMAPeriod",15,1,100,1);
SlowEMAPeriod =Param("SlowEMAPeriod",180,1,200,1);

per1= 15;
per2= 2;

EMA1= EMA(C,FastEMAPeriod);
EMA2= EMA(C,SlowEMAPeriod);

uptrend= EMA1>EMA2; dwntrend= EMA1<EMA2;
bbtop= BBandTop(C,per1,per2);
bbot= BBandBot(C,per1,per2);
supp= Cross(C,bbot); ress= Cross(bbtop,C);

Ll= LLV(L,5); Hh= HHV(H,5);

Buy=Sell=Short=Cover=Null;

sl=sls=tgt=tgts=0;
for(i=200; i<BarCount; i++)
{
	if(sl==0 AND uptrend[i] AND supp[i])
	{ Buy[i]=1; sl= Ll[i]; tgt= H[i];}
	if((L[i]<sl OR ress[i]) AND sl>0)
	{ if(L[i]<sl)SellPrice[i]= sl; Sell[i]= 1; sl=tgt=0;}

	if(sls==0 AND dwntrend[i] AND ress[i])
	{ Short[i]=1; sls= Hh[i]; tgts= L[i];}
	if( (H[i]>sls OR supp[i]) AND sls>0)
	{ if(H[i]>sls)CoverPrice[i]=sls; Cover[i]=1; sls=tgts=0; }
}



Plot( EMA1, "EMA Fast", colorRed, styleLine | styleNoRescale ); 
Plot( EMA2, "EMA Slow", colorBlue, styleLine | styleNoRescale ); 
Plot(bbtop, "Band Top", colorBlack, styleLine);
Plot(bbot, "Band Bottom", colorBlack, styleLine);

PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );

PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );


_SECTION_END();
Filter=Buy OR Sell OR Short OR Cover; 
 
AddColumn(IIf(Buy,BuyPrice,Null)," Buy Signal ", 6.2,1.2,colorGreen); 
AddColumn(IIf(Sell,SellPrice,Null)," Sell Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Short,ShortPrice,Null)," Short Signal ",6.2,1.2,colorOrange);
AddColumn(IIf(Cover,CoverPrice,Null)," Cover Signal ",6.2,1.2,colorGreen);
 
Hi,
Kindly see
http://www.traderji.com/amibroker/101561-mtf-timeframe-scan-output-scanning-timeframe-not-pattern-single-timeframe-p2-3.html#post1150226

Code:
Version(6.0);
SetOption("NoDefaultColumns", True );
AddTextColumn( Name(), "Ticker",1, colorDefault,colorDefault, 80);
AddColumn( DateTime() , "Date", formatDateTime, colorDefault,colorDefault, 80 ); 
//[ its col in the row to hold the date val]

AddTextColumn("#", "BullBar"); 
AddTextColumn("#", "BearBar"); 
AddTextColumn("#", "Bull Engulfing"); 
AddTextColumn("#", "Bear Engulfing"); 
AddTextColumn("$", "Shorting Star"); 

for ( i = 1; i <=15; i++ ) 
{
    TimeFrameSet( i * in1Minute );

        O1 = Ref(O,-1); 
        C1 = Ref(C,-1);
        MP = (H+L)/2;
        R = H-L;
        
        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 blEngulf OR brEngulf;
        if ( NOT LastValue(Filter) ) break;
        
        x= StrFormat("%02g-min", i);
        str = "";
        str = str + WriteIf(blBar,    x, "\t");
        str = str + WriteIf(brBar,    x, "\t");
        str = str + WriteIf(blEngulf, x, "\t");  //removed + sign ,the bug is here
        str = str + WriteIf(brEngulf, x, "\t");  //removed + sign ,the bug is here
        str = str + WriteIf(ss,       x, "");
                     
        AddRow(Name()+"\t\t\t"+str);

    TimeFrameRestore();
}  

SetSortColumns(1, -2, 3,4,5,6,7);
Kindly use this afl, and kindly post screenshot, what is it showing ?

Kindly give your input
 
Last edited:
Hi my friends .i asked many times to add buy sell scanner to this RSI indicator .will you plz help me
buy= rsi in support
sell=rsi in resis
and will you plz possible change RSI time frame.
Code:
// RSI TRENDLINE formula ver 1.0

SetBarsRequired(sbrAll, sbrAll);                                                        
TP = Param("Trend Per", 300,2,1000);                                                                
per_RSI= Param("RSI Per", 9, 7, 35,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", 2.5, 0.5,7,  0.5);

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 =  Name() + "\\c17" +   "  " +"\\c12" + "RSI" +  " " + per_RSI   ;
 

amitrandive

Well-Known Member
Hi my friends .i asked many times to add buy sell scanner to this RSI indicator .will you plz help me
buy= rsi in support
sell=rsi in resis
and will you plz possible change RSI time frame.
Code:
// RSI TRENDLINE formula ver 1.0

SetBarsRequired(sbrAll, sbrAll);                                                        
TP = Param("Trend Per", 300,2,1000);                                                                
per_RSI= Param("RSI Per", 9, 7, 35,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", 2.5, 0.5,7,  0.5);

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 =  Name() + "\\c17" +   "  " +"\\c12" + "RSI" +  " " + per_RSI   ;
You have to define your own buy and sell conditions.

As per the buy and sell conditions in the AFL,add these lines to the end of your 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);
 
Could someone pls help me how to do an afl code when we need buy signal Sell Signal at the line as breakout point we just have to name it as Support ressistance Line can be anykind such as horizontal Line ,Triangle, trendline just name it and wait till breaks or touch the line
and the buy sell signal opens only one time when latest price crosses the line on current bar immidiately not next bar , and should not open again when the latest price comeback to touch the line as it creates multiple orders and to display entry price with buy sell arrow on each entry .Thanks
 

Similar threads