Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Stress Indicator - Moddified for Amibroker (AFL)
MA5YK
over 6 years ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 4)
Tags:
oscillator, amibroker

Simple trade based on how a Stock is “Stressed” compared to it’s Index.

Option to display Stoch for both Stock & Index.

1. Wait for STRESS level to fall BELOW 10.
2. Three CONSECUTIVE LOWER CLOSE that forms a “Buy Zone”.
3. Exit trade when STRESS crosses 50.
4. All of the above is Buying a Stock and Selling the Index after checking correlation (between 30-70 percent to offset tracking).
5. Change the SETFOREIGN parameter if you want to use BANKNIFTY.

Screenshots

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Stress");
function PJKStress( High2, Low2, Close2, period )
{
  range1 = HHV( High, period ) - LLV( Low, period );
  range2 = HHV( High2, period ) - LLV( Low2, period );
  stoch1 = ( Close - LLV( Low, period ) )/range1;
  stoch2 = ( Close2 - LLV( Low2, period ) )/range2;

  VarSet("sstoch1", 100 * stoch1 );
  VarSet("sstoch2", 100 * stoch2 );

  diff = stoch1 - stoch2;

  range1 = HHV( diff, period ) - LLV( diff, period );
  
  return 100 * ( diff - LLV( diff, period ) )/range1;
}

Per = Param("Period", 60, 5, 100, 5); 
momper = Per;
Hedgeper = Per;

SetForeign("NIFTY"); 
// store index data in High2/Low2/Close2 variables
High2 = High;
Low2 = Low;
Close2 = Close;
RestorePriceArrays();

stress = PJKStress( High2, Low2, Close2, momper );

Stress_Buy_Level = Param("Buy Level", 10, 1, 49, 1) ;
Stress_Sell_Level = Param("Sell Level", 50, 50, 90, 1) ;
Stress_BuyWatch_Level = Stress_Buy_Level + 10;

Stress_Short_Level = Param("Short Level", 90, 50, 100, 1) ;
Stress_Cover_Level = Param("Cover Level", 50, 50, 89, 1) ;
Stress_ShortWatch_Level = Stress_Short_Level - 10;

Stress_Buy = Cross(Stress_Buy_Level, stress) ; //AND sstoch1 < 20 ;
Stress_Sell = Cross(stress, Stress_Sell_Level) ; //AND sstoch1 > 80 ;
Stress_buy = ExRem( Stress_buy, Stress_sell );
Stress_sell = ExRem( Stress_sell, Stress_buy ); 

Stress_Short = Cross(Stress, Stress_Short_Level) ;
Stress_Cover = Cross(Stress_Cover_Level, Stress) ; 
Stress_Cover = ExRem( Stress_Cover, Stress_Short );
Stress_Short = ExRem( Stress_Short, Stress_Cover ); 

shape_Buy = Stress_Buy * shapeUpArrow + Stress_Sell * shapesmallsquare; 
//PlotShapes( shape_Buy, IIf( Stress_Buy, colorTurquoise, colorTurquoise ), 0, 
//	IIf( Stress_Buy, Stress_Buy_Level, Stress_Sell_Level ) );
	
shape_Short = Stress_Short * shapeDownArrow + Stress_Cover * shapesmallsquare; 
//PlotShapes( shape_Short, IIf( Stress_Short, colorPink, colorPink ), 0, 
//	IIf( Stress_Cover, Stress_Cover_Level, Stress_Short_Level ) );

//SetGradientFill( colorIndigo /*top*/, colorDarkGrey /*bottom*/, 0 /*baseline level*/, GetChartBkColor() /*baseline color */ );
//PlotOHLC( stress, stress, 0, stress , "Stress Nifty("+Per+")", colorBluegrey, styleLine | styleGradient, Null, Null, 0, 0  );
Stress_Color = IIf(Cross(stress,Stress_Short_Level), colorRed, 
					IIf(Cross(Stress_Buy_Level,stress), colorRed,colorBlueGrey )); 
SetGradientFill( colorIndigo /*top*/, colorDarkGrey /*bottom*/, 0 /*baseline level*/, GetChartBkColor() /*baseline color */ );
PlotOHLC( stress, stress, 0, stress , "Stress Nifty("+Per+")", Stress_color, styleLine | styleGradient, Null, Null, 0, 0  );
//Plot( stress, "Stress Nifty("+Per+")", colorTan, ParamStyle("Style", styleGradient, maskHistogram), Null, Null, 0, 0, 1) ; //stylethick );

if (ParamToggle("Show Stoch","NO|YES",0))
{	
//Plot( stress, "Stress Nifty("+Per+")", colorTan, ParamStyle("Style", styleGradient, maskHistogram), Null, Null, 0, 0, 1) ; //stylethick );
Plot( sstoch1, "Stoch-"+Name(), colorGreen, Null, Null, 0, 0, 1) ;
Plot( sstoch2, "Stoch-Nifty", colorGold, Null, Null, 0, 0, 1) ;
}

//Plot( Stress_Buy_Level, "", colorViolet, stylenolabel) ;
//Plot( Stress_Sell_Level, "", colorGrey50, styleDots | stylenolabel) ;
//Plot( Stress_BuyWatch_Level, "", colorViolet, styleDashed | styleNoLabel) ;

//Plot( Stress_Short_Level, "", colorViolet, stylenolabel) ;
//Plot( Stress_Cover_Level, "", colorgrey50, styleDots | stylenolabel) ;
//Plot( Stress_ShortWatch_Level, "", colorViolet, styleDashed | styleNoLabel) ;
_SECTION_END();

13 comments

1. satish1b

AFL not working

2. nyoman.ardana

Great job. Thanks for sharing.

3. mrofka

AFL not working, AmiBroker 5.50.5

Ln:62, Col:16: Error 32. Syntax error, unexpected’(‘.Is there semicolon missing at the end of the previous line?
Ln:63, Col:103: Error 29. Variable ’stylegradient’ used without having been initialized.

4. MA5YK

I’m using in latest Amibroker 5.9 but I don’t think there is anything in the AFL that should not work with older versions.

Try using the “Copy & Paste friendly” link.

5. davidalan

If you wanted to use S&P 500 as the index would you replace Nifty with ^GSPC or what thanks

6. Divyesh

Dear MA5YK,
can you suggest which is the best TF for trade ?
and which are the Best Script for trade….!

7. MA5YK

@davidalan: Yes, just replace NIFTY with any Market-Index you trade in.

@Divyesh: I don’t trade intraday so no idea how it performs there. Rising or Falling Stress shows Stock is going to move. Just create a simple exploration from the Buy/Sell conditions and run it on NSE Futures to get ideas. It’s one more tool to help us find an Entry point.

8. davidalan

Thank You

9. k726

NOT WORKING

10. kv_maligi

Following Error

Ln:62, Col:16: Error 32. Syntax error, unexpected’(‘.Is there semicolon missing at the end of the previous line?
Ln:63, Col:103: Error 29. Variable ’stylegradient’ used without having been initialized.

11. hoierman

Masyk,
Interesting AFL.
I have attempted to add an Exploration (see below) to this fine code but but when implemented get zilch(0) Buys… all sells on a 3700 database. Your help in letting me know changes necessary to make the BUY work. Your help will be most appreciated

Dick

Buy = Stress_Buy; 
Sell = Stress_Sell;

Filter = C <35 AND C >2 AND Volume > 80000 AND C> Ref(C,-1)AND PDI (14)> MDI(14);
ADR = ( (H-L) + Ref(H-L,-1) +  Ref(H-L,-2) +  Ref(H-L,-3) +  Ref(H-L,-4) + Ref(H-L,-5) +  Ref(H-L,-6) + Ref(H-L,-7) +  Ref(H-L,-8)+  Ref(H-L,-9) )/10;
ADRX = (ADR)/C *100;

AddTextColumn( WriteIf(Buy, "Buy" , "Sell" ) ,   "TRADE" , 2 ,   IIf(Buy,colorYellow, colorWhite), IIf(Buy, colorDarkGreen, colorDarkRed) );
AddTextColumn(IndustryID(1) ,"     Industry Sector      ", 25.0, colorWhite, colorBlue);
AddColumn( Close, "Close", 1.2, IIf( ROC(C, 1 ) >= 0, colorDarkGreen,colorRed ),50 );
AddColumn(Ref(Close,-1),"Y-Close",1.2, IIf(ROC(Ref(C,-1),1)>=0,colorDarkGreen, colorRed ),50 );
AddColumn( Volume, "Volume", 10.0, IIf( ROC(V, 1 ) >=0,colorDarkGreen, colorRed ) );
AddColumn( ROC(Close, 1 ),"ROC(1)", 1.2, IIf( ROC(C, 1 ) >= 0,colorDarkGreen, colorRed));
//AddColumn( LongStochD, "StochD", 2.1, colorDarkBlue,37 );
AddColumn((adr/C)*100, "AvDayRg%of C", 2.2, colorDarkGreen, colorGold); 
AddColumn( ADR, "ADR (10)", 2.2, colorWhite,colorBlue);
AddColumn( ADRX, "ADRX (10)", 2.2, colorWhite,colorBlue);
AddColumn(Ref(MA(V,10),-1), "10dAvgVOL", 8.0, colorWhite, colorBlue);
AddColumn( (V/Ref(MA(V,10),-1))*100,"V>of10dMA" ,3.0, colorLightYellow, colorDarkGrey);
12. MA5YK

Dick,

If I’m not mistaken you may need to add Buy/Sell to the filter.

Filter = BUY OR SELL

I’m also going to assume you’ve changed the Index in the SETFOREIGN parameter to the market you are trading in.

This site needs some sort of comment notification system.

13. tgbssk

Hi,

I need some help from you about C/C++

if I am not wrong you have written AmibrokerFeeder.

Leave Comment

Please login here to leave a comment.

Back