[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] what are the best 5 formulae in amibroker for swing trading stocks?please help


  • To: amibroker@xxxxxxxxxxxxxxx
  • Subject: Re: [amibroker] what are the best 5 formulae in amibroker for swing trading stocks?please help
  • From: kin ford7 <ford7k@xxxxxxxxx>
  • Date: Wed, 2 May 2007 04:06:53 -0700 (PDT)

PureBytes Links

Trading Reference Links

Hi mohit
It is not a big deal. these formulae are readily
available in amibroker library.
Since you wanted, have them. I give them here
------------------------------------
1. support levels and resistance levels
----------------------------
//Support and resistance levels using RSI.
//graham Kavanagh May 2003
//Load into Indicator Builder
//Sensitivity of the levels can be changed with the
variables
//Can test different numbers live with the Param
function ctrl-R with open pane
RSIperiod	= 5;	// Param("RSI p",3,14,30,1);
Percent 		= 5;	//	Param("ZIG %",8,9,15,1);
EMAperiod 	= 5;	//Param("EMA p",4,5,10,1);
HHVperiod 	= 5;	//Param("HHV p",3,5,10,1);
NumLine 		= 1;	//Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;
Plot(C,"",colorBlack,styleCandle);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ),
"Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ),
"Support Level", colorGreen, styleLine);
}
Title = Name() + "; " + Date() + ": Support &
Resistance Levels using RSI:
 " + /*EncodeColor(colorGreen)+ "Support Levels are
Green; "+EncodeColor(colorRed)+
 "Resistance Levels are Red:
"+EncodeColor(colorBlack)+*/ "Num lines
="+WriteVal(numline,1) ; 
----------------------------------------------
relative strength
----------------------
/*
Simple Sector Rotation Model
bmitchell@xxxxxxxxx

This is a simple method for determining the strongest
sectors at any given time. Use daily
mode for intermediate term, and weekly for longer
term. The basis of it is Daryl Guppy's
Multiple Moving Averages (MMA) plot. Here, I seperate
the moving averages into short term
and long term averages, and give a point for each
moving average above all the long term averages.

I do this for every symbol in the watchlist except the
index being scanned, then I generally
sort the results based on the RS reading. To use this,
you need to create a watchlist of
symbols, and set WatchlistNum appropriately. Also, you
want to define a filter so that you only
scan this watchlist.

This is intended only for sector rotation, and
probably would not be terribly useful as a trading
system in and of itself. I use TC2000's MG* sector
indexes personally.
*/

EnableRotationalTrading();
SetOption("WorstRankHeld", 5);
PositionSize = -100;
PositionScore = 0;
WatchlistNum = 1;
Filter=1;
NumColumns=0;

function CalculatePosition(st, Lt1, Lt2, Lt3, Lt4,
Lt5, Lt6)
{
	score=0;

	if(st > Lt1) score++;
	if(st > Lt2) score++;
	if(st > Lt3) score++;
	if(st > Lt4) score++;
	if(st > Lt5) score++;
	if(st > Lt6) score++;
	return score;
}


// walk through the watchlist grabbing all the symbols
to calculate RS vs ourself.
List = CategoryGetSymbols(categoryWatchlist,
WatchlistNum);
for(i=0; (sym = StrExtract(List, i)) != "";i++)
{
	if(sym != Name())
	{
		f = RelStrength(sym);

		st3 = EMA(f, 3);
		st5 = EMA(f, 5);
		st8 = EMA(f, 8);
		st12 = EMA(f, 12);
		st15 = EMA(f, 15);

		Lt30 = EMA(f, 30);
		Lt35 = EMA(f, 35);
		Lt40 = EMA(f, 40);
		Lt45 = EMA(f, 45);
		Lt50 = EMA(f, 50);
		Lt60 = EMA(f, 60);

		z=BarCount - 1;
		// uncomment the following if you want to do some
backtesting or if you like waiting around
		// a long time for the exploration to complete
		//for(z=0;z < BarCount;z++)
		{

		PositionScore[z] = PositionScore[z] +
CalculatePosition(st3[z], Lt30[z], Lt35[z], Lt40[z],
Lt45[z], Lt50[z], Lt60[z]);

		PositionScore[z] = PositionScore[z] +
CalculatePosition(st5[z], Lt30[z], Lt35[z], Lt40[z],
Lt45[z], Lt50[z], Lt60[z]);

		PositionScore[z] = PositionScore[z] +
CalculatePosition(st8[z], Lt30[z], Lt35[z], Lt40[z],
Lt45[z], Lt50[z], Lt60[z]);

		PositionScore[z] = PositionScore[z] +
CalculatePosition(st12[z], Lt30[z], Lt35[z], Lt40[z],
Lt45[z], Lt50[z], Lt60[z]);

		PositionScore[z] = PositionScore[z] +
CalculatePosition(st15[z], Lt30[z], Lt35[z], Lt40[z],
Lt45[z], Lt50[z], Lt60[z]);

	}
}
}

AddTextColumn(FullName(), "Name");
AddColumn(PositionScore[BarCount - 1], "RS");


-----------------------------------------------
3.modified darvas box
//////////begin/////////

box1=0;
box2=0;
SetBarsRequired(10000,10000);
procedure fillDarvas(start,end,swap,top, bottom )
{
   for ( j = start; j < end; j++)
   {
       if( box1[j] == swap)
  box1[j]= top ;
else
box1[j]= bottom;

       if(box2[j] == swap)
  box2[j]= bottom ;
else
box2[j]= top;
   }
}

BoxArr1 = 0;
BoxArr2 = 0;
StateArray = 0;
DBuy = 0;
DSell = 0;
TopArray = 0;
BotArray = 0;
tick=0;

BoxTop = High[0];
BoxBot = Low[0];
swap=0;
state = 0;
BoxStart = 0;

for (i=0; i<BarCount; i++)
{
 if (state==5)
 {
  TopArray[i]=BoxTop;
  BotArray[i]=BoxBot;
  if (Low[i]<(BoxBot*(1-tick/100)) ||
High[i]>(BoxTop*(1+tick/100)))
  {
fillDarvas(BoxStart,i,swap,BoxTop,BoxBot);

  state = 1;
  swap =  !swap;
  BoxTop = High[i];
  BoxStart = i;
  }
 }
 else
 {
  if (High[i]<BoxTop)
  {
      if ((state<3) || (Low[i]>BoxBot))
      {
   state++;
   }
      else
   {
      state=3;
   }
      if (state==3)
      BoxBot=Low[i];
  }
  else
  {
      state=1;
      BoxTop=High[i];
  }
 }
 StateArray[i] = state;
}

fillDarvas(BoxStart,BarCount,swap,BoxTop,BoxBot);


Buyrule=H>Ref(box1,-1) AND H>Ref(box2,-1) AND
Ref(statearray,-1)==5;
Sellrule=L<Ref(box1,-1) AND L<Ref(box2,-1) AND
Ref(statearray,-1)==5;



_SECTION_BEGIN("Darvas box");
Plot(C,"",1,64);
Plot( box2, "" , 1 + statearray , styleLine );
Plot( box1, " Status = "+WriteVal(statearray,1.0) , 1
+ statearray, styleLine );
_SECTION_END();


Buy = Buyrule;
statopt = Optimize("statopt var", 3, 1, 5, 1 ); 
lossopt= Optimize("lossopt var", 5, 3, 10, 1 ); 
//statopt=5;
//lossopt=7;

topvalue=IIf(box1>box2,box1,box2);
Sellrule2 = (((topvalue-Close)*100/topvalue) >
lossopt) AND (statearray == statopt);
Sell = Sellrule OR Sellrule2;

Short = Sell;
Cover = Buy;
---------------------------------------
4.n bar reversal system

---------------------
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}}
Open %g, Hi %g, Lo %g, Close %g (%.1f%%) 
Vol"+
WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C,
SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorBlack ),
styleNoTitle | ParamStyle("Style") | GetPriceStyle()
); 
if( ParamToggle("Tooltip shows", "All Values|Only
Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:  
%g\nClose:  %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ),
O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();





//An n Bar Reversal Program
//The theory says that this indicator gives reliable
signals of strong trends.
//Its disadvantage is that the signal can be a little
late, but is offset by its reliability.
// An uptrend is assumed to be in place if todays high
is higher than those
// of the previous n days,and a downtrend is in place
when todays low is lower 
//than those of the previous n days. Otherwise the
existing trend persists.
//n is commonly set at 3 but can be any value.
//The implementation here simply shows arrows at trend
reversals.

n= Param("No. of Bars",3,2,8,1);
TrendUp = H > Ref(HHV(H,n),-1);
TrendDn = L < Ref(LLV(L,n),-1);
TrendUp = ExRem(TrendUp,TrendDn);
TrendDn = ExRem(TrendDn,TrendUp);
PlotShapes(TrendUp*shapeUpArrow,colorGreen);
PlotShapes(TrendDn*shapeDownArrow,colorRed);

5.jim berg volatility

----------------------------
_SECTION_BEGIN("jim berg volatility ATR STOP SYSTEM");
//AMIBROKER, VOLATILITY SYSTEM. Here is a sample
AmiBroker chart 
//demonstrating the techniques from Jim Berg's article
in this issue.


//In "The Truth About Volatility," Jim Berg presents
how to use several well-known volatility measures such
as average True range (ATR) to calculate entry,
trailing stop, AND profit-taking levels. Implementing
techniques presented in the article is very simple
using the AmiBroker Formula Language (Afl), AND takes
just a few lines of code. 

//Listing 1 shows the formula that the plots
color-coded price chart, trailing stop, AND
profit-taking lines, as well as a colored ribbon
showing volatility-based entry AND exit signals. The
relative strength index (RSI) used by Berg is a
built-in indicator in AmiBroker, so no additional code
is necessary. See Figure 3 for an example. 



//LISTING 1 
EntrySignal = C > ( LLV( L, 20 ) + 2 * ATR( 10 ) ); 
ExitSignal = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ); 
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal,
colorOrange, colorGrey50 )); 
TrailStop = HHV( C - 2 * ATR(10), 15 ); 
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10); 
/* plot price chart and stops */ 
Plot( TrailStop, "Trailing stop", colorBrown,
styleThick | styleLine ); 
Plot( ProfitTaker, "Profit taker", colorLime,
styleThick ); 
Plot( C, "Price", Color, styleBar | styleThick ); 

/* plot color ribbon */ 
Plot( 1, "", Color, styleArea | styleOwnScale |
styleNoLabel, -0.1, 50 ); 

//--Tomasz Janeczko, AmiBroker.com 

//http://www.traders.com/Documentation/FEEDbk_docs/Archive/022005/TradersTips/TradersTips.html
_SECTION_END();

---------------------------------------
enjoy!!!!!!!!!!!

regards
ford



--- Mohit Gupta <mohitgupta_2001@xxxxxxxxxxx> wrote:

> Can anyone send me code afl's for all these
> mentioned formulaes.
> I would be highly thankful.If anyone can provide me
> the need.
> 
> Thanks in advance.
> 
> Regards
> Mohit Gupta
> Delhi
> India
> 
>   ----- Original Message ----- 
>   From: ford7k 
>   To: amibroker@xxxxxxxxxxxxxxx 
>   Sent: Tuesday, May 01, 2007 10:59 AM
>   Subject: [amibroker] what are the best 5 formulae
> in amibroker for swing trading stocks?please help
> 
> 
>   Gents,
>   please guide me about the best 5 formulae to be
> used for swing 
>   trading stocks.
>   ---------------------
>   to begin I know 
>   1)the support-resistance formula from
>   //Support and resistance levels using RSI.
>   //graham Kavanagh May 2003
>   -----------------------
>   just try to catch the stock at best support levels
> 
>   2)relative strength by brian
>   Simple Sector Rotation Model
>   bmitchell@xxxxxxxxx
> 
>   3)modified darvas box
>   this also gives good support and resistance levels
>   ---------------
>   //LISTING 1//
>   Periods = 100;
>   function DarvasHigh( Periods )
>   {
>   HHVtemp = HHV( High, Periods );
>   result = HHVTemp;
>   for( i = Periods + 4; i < BarCount; i++ ) etc
>   -----------------------------
> 
>   4)n bar reversal
>   ------------------------------
>   //An n Bar Reversal Program
>   //The theory says that this indicator gives
> reliable signals of 
>   strong trends.
>   //Its disadvantage is that the signal can be a
> little late, but is 
>   offset by its reliability.
>   // An uptrend is assumed to be in place if todays
> high is higher 
>   than those
>   // of the previous n days,and a downtrend is in
> place when todays 
>   low is lower 
>   //than those of the previous n days. Otherwise the
> existing trend 
>   persists.
>   //n is commonly set at 3 but can be any value.
>   //The implementation here simply shows arrows at
> trend reversals.
>   --------------------------
>   BUT FOR SOME REASON THIS THING I CANT USE
>   HELP ME TO USE IT BY GUIDANCE
> 
>   REGARDS
>   FORD
> 
> 
> 
>    


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/