My afl collection

Status
Not open for further replies.

shivangi77

Well-Known Member
NMA Swing







Code:
_SECTION_BEGIN("NMA Swing");
SetBarsRequired(200,0);
 
GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k =  Optimize("K",Param("K",1,0.25,5,0.25),0.25,5,0.25);
Per= Optimize("atr",Param("atr",2,3,20,1),3,20,1);
HACLOSE=(O+H+L+C)/4;
HaOpen = AMA( Ref( HaClose,  -1 ),  1.0 );
HaHigh = Max( H,  Max( HaClose,  HaOpen ) );
HaLow = Min( L,  Min( HaClose,  HaOpen ) );
 
j=Haclose;
 
//=======================================================================================================================
//=========================Indicator==============================================================================================
f=ATR(10);
 
rfsctor = WMA(H-L, Per);
 
revers = k * rfsctor;
 
Trend = 1;  
NW[0] = 0;  
 
 
for(i = 1; i < BarCount; i++)
{
 if(Trend[i-1] == 1)                
 {
  if(j[i] < NW[i-1])                 
  {
   Trend[i] = -1;                   
   NW[i] = j[i] + Revers[i];        
  }
  else                             
  {
   Trend[i] = 1;
   if((j[i] - Revers[i]) > NW[i-1])
   {
    NW[i] = j[i] - Revers[i]; 
   }
   else
   {
    NW[i] = NW[i-1];
   }
  } 
 }
 if(Trend[i-1] == -1)               
 {
  if(j[i] > NW[i-1])                
  {
   Trend[i] = 1;                    
   NW[i] = j[i] - Revers[i];        
  }
  else                             
  {
   Trend[i] = -1;
   if((j[i] + Revers[i]) < NW[i-1]) 
   {
    NW[i] = j[i] + Revers[i]; 
   }
   else
   {
    NW[i] = NW[i-1];
   }
  }
 }
}
 
//===============system================
 
Plot(NW, "", IIf(Trend == 1, 27, 4), 4);
Buy=Cover=Cross(j,nw);
Sell=Short=Cross(nw,j);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
 
 
 
 
 
 
 
 
 
 
 
_SECTION_BEGIN("Elder Impulse Indicator");
/**************************************************************************
Name        :   Elder Impulse Indicator
Coded by    :   Lal
Date        :   28.10.2005
Note        :   Please refer to Elder's "Come Into my Trading Room"
                for full details 
******************************************************************************/
 
 
// User-defined parameter for EMA periods
EMA_prds = Param("EMA_periods", 6, 1, 30, 1);
 
 
// Compute EMA and MACD Histogram
DayEMA      = EMA(Close, EMA_prds);
Histogram   = MACD() - Signal();
 
// Determine if we have an Impulse UP, DOWN or None
Impulse_Up      =   DayEMA > Ref(DayEMA, -1) AND Histogram > Ref(Histogram, -1);
Impulse_Down    =   DayEMA < Ref(DayEMA, -1) AND Histogram < Ref(Histogram, -1);   
Impulse_None    =   (NOT Impulse_UP) AND (NOT Impulse_Down);
 
// Compute Weekly MACD and determine whether rising or falling
// Note: uses "non-standard"  parameters!
TimeFrameSet(inWeekly);
MACD_val    =   MACD(5, 8);
Signal_val  =   Signal(5, 8, 5);
Hist_in_w   =   MACD_val - Signal_val;
 
wh_rising   = Hist_in_w > Ref(Hist_in_w, -1);
wh_falling  = Hist_in_w < Ref(Hist_in_w, -1);
 
TimeFrameRestore();
 
// Now get Monthly MACD Histogram....
TimeFrameSet(inMonthly);
MACD_val        =   MACD(5, 8);
Signal_val      =   Signal(5, 8, 5);
Hist_in_m       =   MACD_val - Signal_val;
 
mh_rising = Hist_in_m > Ref(Hist_in_m, -1);
mh_falling = Hist_in_m < Ref(Hist_in_m, -1);
 
TimeFrameRestore();
 
wh_rising   = TimeFrameExpand( wh_rising, inWeekly ); 
wh_falling  = TimeFrameExpand( wh_falling, inWeekly ); 
mh_rising   = TimeFrameExpand(mh_rising, inMonthly);
mh_falling  = TimeFrameExpand(mh_falling, inMonthly);
 
kol     = IIf( wh_rising, colorGreen,  IIf(wh_falling, colorRed, colorLightGrey));
mkol    = IIf( mh_rising, colorCustom9,  IIf(mh_falling, colorOrange, colorLightGrey));
 
// Plot them all!
Plot(3, "R", kol, styleOwnScale|styleArea|styleNoLabel, -12, 156);  // Weekly trend
Plot(6, "R", mkol, styleOwnScale|styleArea|styleNoLabel, -0.5, 150);    // Monthly Trend
_SECTION_END();
 
 
 
 
 
 
 
_SECTION_BEGIN("J's SRI CHAKRA - PH: 9367151067");
//{J's SRI CHAKRA} 
//{Buy} 
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5; 
//{Lowest price stock <5} 
AA=IIf(C<5,Cross(C,ValueWhen(Peak(H,x1,1) !=Ref(Peak(H,x1,1),-1),H,1)), 
//{Price between 5 AND 20} 
IIf(C>5 AND C<20,Cross(C,ValueWhen(Peak(H,x2,1) !=Ref(Peak(H,x2,1),-1),H,1)), 
//{Price between 20 AND 70} 
IIf(C>20 AND C<70,Cross(C,ValueWhen(Peak(H,x3,1) !=Ref(Peak(H,x3,1),-1),H,1)), 
//{Price between 70 AND 150} 
IIf(C>70 AND C<150,Cross(C,ValueWhen(Peak(H,x4,1) !=Ref(Peak(H,x4,1),-1),H,1)), 
//{Price between 150 AND 300} 
IIf(C>150 AND C<300,Cross(C,ValueWhen(Peak(H,x5,1) !=Ref(Peak(H,x5,1),-1),H,1)), 
//{Price over 300} 
Cross(C,ValueWhen(Peak(H,x6,1)!=Ref(Peak(H,x6,1),-1),H,1))))))); 
 
//{Sell } 
x1=5; x2=4; x3=3; x4=2; x5=1; x6=.5; 
//{Lowest price stock <5} 
BB=IIf(C<5,Cross(ValueWhen(Trough(L,x1,1) !=Ref(Trough(L,x1,1),-1),L,1),C), 
//{Price between 5 AND 20} 
IIf(C>5 AND C<20,Cross(ValueWhen(Trough(L,x2,1) !=Ref(Trough(L,x2,1),-1),L,1),C), 
//{Price between 20 AND 70} 
IIf(C>20 AND C<70,Cross(ValueWhen(Trough(L,x3,1) !=Ref(Trough(L,x3,1),-1),L,1),C), 
//{Price between 70 AND 150} 
IIf(C>70 AND C<150,Cross(ValueWhen(Trough(L,x4,1) !=Ref(Trough(L,x4,1),-1),L,1),C), 
//{Price between 150 AND 300} 
IIf(C>150 AND C<300,Cross(ValueWhen(Trough(L,x5,1) !=Ref(Trough(L,x5,1),-1),L,1),C), 
//{Price over 300} 
Cross(ValueWhen(Trough(L,x6,1)!=Ref(Trough(L,x6,1),-1),L,1),C)))))); 
 
Color=IIf(BarsSince(AA)>BarsSince(BB),colorRed,IIf(RSI()>70,colorCustom11,colorDarkGreen)); 
  
///// Trailing Stop Module ///// 
 
P6=Param("Trailing Stop Risk",2.5,2,3.5,0.1); 
P7=Param("Trailing Stop LookBack",14,5,25,1); 
P8=Param("Trailing Stop PrevLow Switch",0,0,1,1); 
PrevLow=IIf(P8==1, Ref(C,-TroughBars(C,5,1)) ,Null); 
Plot(PrevLow,"",colorRed); 
 
//Position sizing// 
MyTotalPort = Param("MyTotalPort",1000000,10000,10000000,100000); 
AcceptableRisk = Param("AcceptableRisk",0.5,0.1,3,0.1); 
BarsFromStart = BarsSince(Cross(AA,BB)AND Ref(Color,-1)==colorRed) ; 
InitialStopLoss =Ref( H - P6*ATR(P7),-BarsFromStart); 
PositionSizing = 0.01*AcceptableRisk*MyTotalPort/( C - InitialStopLoss ); 
 
Plot(IIf( HHV(H - P6*ATR(P7),BarsFromStart+1) <C ,HHV(H - P6*ATR(P7),BarsFromStart+1),Null) ,"",colorBlue,1); 
PlotShapes(shapeHollowDownArrow*Cross(Ref(HHV(H - P6*ATR(P7),BarsFromStart+1),-1),C),colorRed,0,H,Offset=-43); 
Title=Name()+" "+Date()+" "+EncodeColor(colorWhite)+"J's SRI CHAKRA - Ph: 9367151067"+EncodeColor(colorCustom11)+" Vol="+NumToStr(Volume ,1.2)+" "+EncodeColor(1)+"Position Sizing ( " +AcceptableRisk+ "% Risk ) = " + WriteIf(color==colorLime,NumToStr(PositionSizing ,1.0),"0")+ 
EncodeColor(colorYellow)+"\nO="+O+EncodeColor(colorCustom3)+" Pk-Tgh Exit"+EncodeColor(colorCustom3)+" ATR Trailing Exit"+EncodeColor(colorOrange)+" RSI Exit"+EncodeColor(colorCustom9)+" ADX = "+ADX()+EncodeColor(colorWhite)+"\nH="+H+"\nL="+L+"\nClose="+ C+""+"\nchange= "+NumToStr((Ref(C,-1)-Close) ,1.2) + 
" "; 
PlotShapes( AA*shapeHollowUpTriangle,colorCustom9,0,L-0.2); 
PlotShapes( BB*shapeHollowDownTriangle,colorDarkRed,0,H+0.2); 
GraphXSpace=3;
_SECTION_END();
 
 
_SECTION_BEGIN("Plot Weekly and Daily Moving average");
//Plot Weekly and Daily Moving Average on Daily Price Chart
//Ver.1.01 revision
//3/02/02, coded by Anthony Faragasso
//e-mail: [email protected]
 
MaxGraph=7;
 
//Input Time periods for Weekly and Daily Moving Averages
WeeklyPds=20;//Weeks
DailyPds=1;//Days 
/***********************************/
//Input Price Variable ( open, high ,low, close);
Price=C;
 
WeeklyPrice=Price;
DailyPrice=Price;
/**********************************/
 
/***Colors***/
//Set to your Preference
Color=6;//Price chart
WklyAvgColor=5;//weekly AverageLine
DlyAvgColor=4;//Daily AverageLine
/**********************************/
 
Weekly=ValueWhen(DayOfWeek() > Ref( DayOfWeek(),1),WeeklyPrice);
 
WeeklyAvg=EMA(Weekly,WeeklyPds);
DailyAvg=EMA(DailyPrice,DailyPds);
 
 
 
Plot(EMA(C,200),"",colorCustom12,styleLine);
Plot(EMA(C,500),"",colorGold,styleLine);
 
 
 
 
Graph0=C;
Graph0Style=64;
Graph0Color=Color;
 
Graph1=WeeklyAvg;
Graph1Style=1+4;//Thick line
Graph1Color=WklyAvgColor;
 
Graph2=DailyAvg;
Graph2Style=1;
Graph2Color=DlyAvgColor;
 
 
 
_SECTION_END();
 
 
 
/****************************************
 
Name            :   Logic All In One for Intraday 
Date            :   10th JAN 2009
Author        : j
E-Mail ID     :  j
 
*****************************************/
 
 
 
EnableTextOutput(False);
 
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Title_X =   StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
  
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack), ParamColor("Title", colorBlack));
SetChartBkColor(ParamColor("Background", colorBlack));
_SECTION_END();
 
//Indicators
 
_SECTION_BEGIN("Indicators");
RSI_Periods     =   Param("RSI Periods", 2, 1, 100, 1);
MA_Periods      =   Param("Periods for MAV", 50, 1, 200, 1);
Daily_Trend_MA_Pds  =   Param("Periods for Trend EMA", 6, 1, 100, 1);
_SECTION_END();
 
SetBarsRequired(100000, 100000);
 
// Find nearest UP and DOWN bar before current bar
Up_Day  =   Close > Open;
Down_Day    =   Close < Open;
Reference_Low   =   ValueWhen(Up_Day, L, 1);
Reference_High  =   ValueWhen(Down_Day, H, 1);
Buy_Condition   =   C > O AND C > Reference_High;
Sell_Condition  =   C < O AND C < Reference_Low;
a= Buy_Condition;
b= Sell_Condition;
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Buy_Views = WriteIf(s,"EXIT ALL SHORT POSITIONS\n AND TRADE LONG WITH STOPLOSS="+EncodeColor(colorBrightGreen)+WriteVal(L,1.2)+",",""); 
Sell_Views =    WriteIf(ss,"EXIT ALL LONG POSITIONS \n AND TRADE SHORT WITH STOPLOSS="+EncodeColor(colorRed)+WriteVal(H,1.2)+",","");
 
 
// RSI and Vol ratio calculation
RSI_Value       =   RSI(RSI_Periods);
MAV_Value   =   V/EMA(V, MA_Periods);
 
//Percentage change
 
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
Percentage= t;
 
//Percentage Change in Volume 
 
w = V -Ref(V,-1);
x = (w/Ref(V,-1))*100;
Volume_Ratio = x;
//Volume_Ratio = V/EMA(V,50);
//Conditions
 
Condition1 = Percentage > 0.5 AND Volume_Ratio > 1.5;
Condition2 = Percentage > 1 AND Volume_Ratio < -1.5;
Condition3 = Percentage < 0 AND Volume_Ratio > -1.5;
Condition4 = Percentage < 1 AND Volume_Ratio < 1.5;
Condition5 = IIf(NOT Condition1 AND NOT Condition2 AND  NOT Condition3 AND  NOT Condition4, True,False);
 
 
Fresh_Buying = WriteIf(Condition1,"Fresh Buying", "");
Short_Covering = WriteIf(Condition2,"Short Covering", "");
Fresh_Short_Building = WriteIf(Condition3,"Fresh Short Building", "");
Possible_Bottom = WriteIf(Condition4,"Possible Bottom OR Top", "");
No_Major_Move = WriteIf(Condition5, "No_Major_Move","");
 
//interpretation output
 
EnableTextOutput(True);
"\nSell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2);
"Buy Above : " + WriteVal(Reference_High, 1.2);
"";
"Current RSI Value: " + WriteVal(RSI_Value, 1.2);
"Current Vol. Ratio: " + WriteVal(MAV_Value, 1.2);
"";
"Fresh Buying: " + WriteIf(Condition1,"Fresh Buying","");
 
EnableTextOutput(False);
 
Filter = Buy_Condition OR Sell_Condition;
 
// Trading System
PositionSize = BuyPrice * 1;
Buy     = Buy_condition;
Sell    = Sell_condition;
Buy     = ExRem( Buy, Sell );
Sell    = ExRem( Sell, Buy );
 
// Experimental Code BEGIN
Is_Last_Bar =   BarIndex()+1    == BarCount;
printf("Last Bar: %g\n", Is_Last_Bar);
Buy_Alert   =   Buy AND Is_Last_Bar;
Sell_Alert  =   Sell AND Is_Last_Bar;
Buy_Alert_Text  =   WriteIf(Buy_Alert, "BUY WARNING!!!", "");
Sell_Alert_Text =   WriteIf(Sell_Alert, "SELL WARNING!!!", "");
Buy_Alert_Text1 =   WriteIf(Buy_Alert, "BUY", "");
Sell_Alert_Text1    =   WriteIf(Sell_Alert, "SELL", "");
LastbarsignalCol        =   IIf(Buy_Alert, colorGreen, IIf(Sell_Alert, colorRed, colorLightGrey));
 
 
//Buy & Sell Arrows Signal
PlotShapes(shapeCircle  * Buy_Alert, colorBrightGreen, 0, L, -15);
PlotShapes(shapeCircle * Sell_Alert, colorRed, 0, H, 15);
 
 
 
 
// Check if previous day's close is above its 6-day EMA
DailyClose  =   TimeFrameCompress(Close, inDaily);
DailyEMA        =   EMA( DailyClose, Daily_Trend_MA_Pds); 
DailyClose      =   TimeFrameExpand(DailyClose, inDaily, expandFirst);
DailyEma        =   TimeFrameExpand(DailyEMA, inDaily, expandFirst);
 
// Trend detection based on 6EMA for Daily 
Daily_Trend_UP              =   DailyClose > DailyEMA;
Daily_Trend_DOWN            =   DailyClose < DailyEMA;
Trend_UP_Text       =   WriteIf(Daily_Trend_UP, "Daily Trend UP", "");
Trend_DOWN_Text =   WriteIf(Daily_Trend_DOWN, "Daily Trend DOWN", "");
Trend_Neutral_Text  =   WriteIf(NOT Daily_Trend_DOWN AND NOT Daily_Trend_UP, "Neutral", "");
TrendCol        =   IIf(Daily_Trend_UP, colorGreen, IIf(Daily_Trend_DOWN, colorRed, colorLightGrey));
 
 
/** Debug BEGIN  */
printf("\nDaily Close: %g ", DailyClose);
printf("\nDaily Trend: %g", (DailyEMA));
/*      Debug END ****/
 
//Inerpretation 
Title   =   Title_X + "\n"  +
 
            EncodeColor(colorCustom11) + "RSI(" + WriteVal(RSI_Periods, 1)  + "):  " +
            EncodeColor(colorBrightGreen) + WriteVal(RSI_Value, 1.2) + "\n" + 
            EncodeColor(colorCustom11) + "Vol. Ratio: " + EncodeColor(colorDarkGreen) + WriteVal(MAV_Value, 1.2) + "\n" +
            EncodeColor(colorRed) + Trend_Down_Text + EncodeColor(colorBrightGreen) + Trend_Up_Text +
            EncodeColor(colorWhite) + Trend_Neutral_Text +  "\n" + 
          EncodeColor(colorRed) + Sell_Alert_Text + EncodeColor(colorBrightGreen) + Buy_Alert_Text + "\n" +
          EncodeColor(colorRed) + Fresh_Short_Building + EncodeColor(colorBrightGreen) + Fresh_Buying + EncodeColor(colorWhite) + Short_Covering + EncodeColor(colorWhite) + Possible_Bottom +"\n" +
          EncodeColor(colorBrightGreen)+ "Buy Above : " + WriteVal(Reference_High, 1.2)+ "\n" +
          EncodeColor(colorCustom5) + "Sell Below: " + WriteVal(ValueWhen(Up_Day, L, 1), 1.2) + "\n" +
          EncodeColor(colorCustom12) + "Trend value: " + WriteVal(DailyEMA,1) +"\n"+
          EncodeColor(colorBlue)+ Buy_Views + EncodeColor(colorBlue)+ Sell_Views;
           
 
//M J Povit Point
 
DayH = TimeFrameGetPrice("H", inDaily, -1);     // yesterdays high
DayL = TimeFrameGetPrice("L", inDaily, -1);     //              low
DayC = TimeFrameGetPrice("C", inDaily, -1);     //              close
DayO = TimeFrameGetPrice("O", inDaily);         // current day open
Dayz = TimeFrameGetPrice("C", inDaily, -6);     //      six days close
if ( True )
{
PP = (Dayc + Dayc -6 )/2;
R1  =  Dayc + (DayH - DayL)/2;
S1  =  Dayc - (DayH - DayL)/2;
R2  =  Dayc + (DayH - DayL);
S2  =  Dayc - (DayH - DayL);
}
Plot(pp, "PP",colorYellow,styleDots+styleNoLine);
Plot(R1, "R1",colorCustom12,styleDots+styleNoLine);
Plot(S1, "S1",colorCustom9,styleDots+styleNoLine);
Plot(R2, "R2",colorRed,styleDots+styleNoLine);
Plot(S2, "S2",colorBlue,styleDots+styleNoLine);
 
 
//Average, Volitility & Percentage Scale.
av3=V/EMA(V,50);
V1= MA(V,50);
r = RSI(2); 
s=C-Ref(C,-1);
t=(s/Ref(C,-1))*100;
p=H-L;
q=(p/Ref(C,-1))*100;
 
//Explore Options
 
Filter = 1; /* all symbols and quotes accepted */
//filer = Buy OR Sell ;
AddColumn(Open,"OPEN",1);
AddColumn(High,"HIGH",1);
AddColumn(Low,"LOW",1);
AddColumn(Close,"CLOSE",1); 
AddColumn(t,"Per",1.2);
AddColumn(V,"VOLUME",1);
AddColumn(V1,"AGV VOLUME",1);
AddColumn(av3,"RATIO50",1.2);
AddColumn(r,"RSI",2);
AddTextColumn(WriteVal(Reference_High, 1.2),"BUY ABOVE",colorWhite,colorGreen);
AddTextColumn(WriteVal(ValueWhen(Up_Day, L, 1), 1.2),"SELL BELOW",colorWhite,colorRed); 
AddTextColumn(Trend_Down_Text + Trend_Up_Text,"DAILY TREND",1,colorWhite,TrendCol); 
AddTextColumn(Buy_Alert_Text + Sell_Alert_Text,"LAST BAR SIGNAL",1,colorWhite,Lastbarsignalcol); 
 
 
 
 
//=====================================================================
//background stock name (works only on Amibroker version 5.00 onwards.
//=====================================================================
_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/10 );
GfxSetTextAlign( 6 );// center alignment
//GfxSetTextColor( ColorRGB( 200, 200, 200 ) );
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/12 );
GfxTextOut( "SRI CHAKRA", Status("pxwidth")/2, Status("pxheight")/3 );
GfxSelectFont("Tahoma", Status("pxheight")/20 );
GfxTextOut( "[email protected]", Status("pxwidth")/2, Status("pxheight")/2 );
_SECTION_END();
//======================================================================================
 
 
 
 
TimeFrameSet( in15Minute ); // switch to 5 minute frame 
_SECTION_BEGIN("display");
no=12;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-3),-1,0));
avn=ValueWhen(avd!=0,avd,1);
Hsupres=IIf(avn==1,sup,res);
 
//Plot(supres,"Alwa",colorTan,styleStaircase);
_SECTION_END();
 
TimeFrameRestore(); // restore time frame to original 
 
TimeFrameSet( inHourly ); // switch now to hourly 
_SECTION_BEGIN("display");
no=12;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-3),-1,0));
avn=ValueWhen(avd!=0,avd,1);
Hhsupres=IIf(avn==1,sup,res);
 
//Plot(supress,"Alwa",colorTan,styleStaircase);
_SECTION_END();
 
 
mah_9 = EMA( C, 9 ); // 9 bar moving average from hourly data 
//mah_9 = EMA( C, 9 ); // 9 bar moving average from hourly data 
 
TimeFrameRestore(); // restore time frame to original 
 
//Plot( Close, "Price", colorWhite, styleCandle ); 
 
// plot expanded average 
 
//Plot( TimeFrameExpand( Hsupres, in15Minute), "13 bar moving average from 5 min bars", colorGreen ); 
//Plot( TimeFrameExpand( Hhsupres, inHourly), "9 bar moving average from hourly bars", colorRed );
 
_SECTION_BEGIN("display");
no=12;
res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-3),-1,0));
avn=ValueWhen(avd!=0,avd,1);
supres=IIf(avn==1,sup,res);
 
Plot(supres,"",colorTan,styleStaircase);
_SECTION_END();
 
Hsig=TimeFrameExpand(Hsupres,in15Minute);
Hhsig=TimeFrameExpand(Hhsupres,inHourly);
 
Buy= C>hsig AND  C>supres AND C>Hhsig;
Sell=C<hsig AND C<supres AND C<Hhsig;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
 
PlotShapes(shapeUpArrow*Buy,colorCustom11, 0, L, -20 );
PlotShapes(shapeDownArrow*Sell,colorCustom12, 0, H, -20 );
 
 
//shape=Buy*shapeUpArrow + Sell*shapeDownArrow; PlotShapes(shape,IIf(Buy,colorBrightGreen,colorRed),0,IIf(Buy,Low,High)); 
_SECTION_END();
 
 
uptrend=C>hsig AND  C>supres AND C>Hhsig;
// downtrend=Sell=C<hsig AND C<supres AND C<Hhsig;
downtrend=C<hsig AND C<supres AND C<Hhsig;
 
//Buy=ExRem(Buy,Sell);
//Sell=ExRem(Sell,Buy);
//shape=Buy*shapeUpArrow + Sell*shapeDownArrow; PlotShapes(shape,IIf(Buy,colorBrightGreen,colorRed),0,IIf(Buy,Low,High)); _SECTION_END();
 
Plot( 5, /* defines the height of the ribbon in percent of pane width
*/"********",
IIf( uptrend, colorDarkOliveGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 200 );
 
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1); 
 
 
 
MinBars = 200;
MinBarsOK = IIf(BarCount >= MinBars, True, False);
 
if (MinBarsOK) { ;
 
 
  /* **********************************
 
Code to automatically identify pivots
 
********************************** */
// -- what will be our lookback range for the hh and ll?
farback=Param("How Far back to go",200,1,50,1);
nBars = Param("Number of bars", 100, 0, 50, 1);
 
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from the current bar, how many bars 
// back were the hhv and llv values of the previous 
// n bars, etc.?
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of 
// _Trace output will show a value of 0
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount-1);
curTrend = "";
if (aLLVBars[curBar] < 
aHHVBars[curBar]) {
curTrend = "D";
}
else {
curTrend = "U";
}
// -- Loop through bars. Search for 
// entirely array-based approach
// in future version
for (i=0; i<farback; i++) {
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars[curBar] < aHHVBars[curBar]) {
// ... and had been up, this is a trend change
if (curTrend == "U") {
curTrend = "D";
// -- Capture pivot information
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
// -- or current trend is up
} else {
if (curTrend == "D") {
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
// -- If curTrend is up...else...
} 
// -- loop through bars
} 
// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most 
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = (BarCount-1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx) {
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar]; 
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aHPivs[candIdx] = 1;
// ...and then rearrange elements in the 
// pivot information arrays
for (j=0; j<nHPivs; j++) {
aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-
(j+1)];
aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];
}
aHPivHighs[0] = candPrc ;
aHPivIdxs[0] = candIdx;
nHPivs++;
} 
} else {
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar]; 
if (
lastLPL > candPrc AND
candIdx > lastHPIdx AND
candIdx < curBar) {
// -- OK, we'll add this as a pivot...
aLPivs[candIdx] = 1;
// ...and then rearrange elements in the 
// pivot information arrays
for (j=0; j<nLPivs; j++) {
aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];
aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}
}
// -- Dump inventory of high pivots for debugging
/*
for (k=0; k<nHPivs; k++) {
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs[k] + ", " 
+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k], 
DateTime(), 1), formatDateTime)
+ ", " + aHPivHighs[k]);
}
*/
// -- OK, let's plot the pivots using arrows
PlotShapes(IIf(aHPivs==1, shapeDownTriangle, shapeNone), colorCustom12, 0, High, Offset=-20);
PlotShapes(IIf(aLPivs==1, shapeUpTriangle , shapeNone), colorCustom11, 0, Low, Offset=-20);
 
 
 
Sell = aHPivs == 1 ;
Buy = aLPivs == 1 ;
Filter=Buy OR Sell; 
Sell=ExRem(Sell,Buy); 
Buy=ExRem(Buy,Sell);
 
 
_SECTION_END();
 

shivangi77

Well-Known Member
Schaff Cycle






Best oscillator, I ever saw
It behaves best both in trending markets & side ways market.
It dont keeps on oscillates like stoch or RSI
If its below 10 then market is down & if above 90 then market is up
Dont trade otherwise.

Code:
MA1=23;
MA2=50;
TCLen=10;
MA1=Param("ShortMACDLen",23,5,36);
MA2=Param("LOngMACDLen",50,10,100);
TCLen=Param("TCLen(StochPeriod)",10,5,20);
Factor=.5;
//Calculate a MACD Line
XMac = MACD(MA1,MA2) ; // MACD in Amibroker always uses Close for MACD calculation
 
//1st Stochastic: Calculate Stochastic of a MACD
Value1 = LLV(XMac, TCLen);
Value2 = HHV(XMac, TCLen) - Value1;
 
//Frac1=1; // prime Frac1 to a default of 1
//Frac1 = IIf(Value2 > 0, ((XMac - Value1) / Value2) * 100, Ref(FRAC1,-1));
// have to "prime" first value so that reference to "i-1" does not result in subscript out of range
// since MACD for both periods is not defined until MA2 period, 0 seems to be mathematically correct priming value
frac1=0;
for (i = 1; i < BarCount; i++) {
if (Value2[i] > 0) {
    frac1[i] = ((XMac[i] - Value1[i])/Value2[i])*100;
    }
else {
    frac1[i]= frac1[i-1];
    }
}
 
//Smoothed calculation for %FastD of MACD
 
PF[0]=frac1[0]; 
PF[1]=frac1[1];
for (i = 2; i < BarCount; i++) {
    PF[i]=PF[i-1]+(Factor*(frac1[i]-PF[i-1]));
}
 
 
//2nd Stochastic: Calculate Stochastic of Smoothed Percent FastD, above.
Value3 = LLV(PF, TCLen);
Value4 = HHV(PF, TCLen) - Value3;
 
//%FastK of PF
/*
Frac2=1;
Frac2 = IIf(Value4 > 0, ((PF - Value3) / Value4) * 100, Ref(FRAC2,-1));
*/
 
frac2[0]=0;
for (i = 1; i < BarCount; i++) {
    if (Value4[i] > 0 ) {
        frac2[i]=((PF[i] - Value3[i])/Value4[i])*100;
    }
    else {
        frac2[i]=frac2[i-1];
    }
}
 
//Smoothed calculation for %FastD of PF
PFF[0]=frac2[0];
PFF[1]=frac2[1];
for (i = 2; i < BarCount; i++) {
    PFF[i]=PFF[i-1]+(Factor*(frac2[i]-PFF[i-1]));
}
 
Plot(pff,"STLC",colorRed,styleLine);
Plot(75,"",colorBlue,styleLine|styleDashed);
Plot(25,"",colorYellow,styleLine|styleDashed);
 

shivangi77

Well-Known Member
NIRVANA
(modified by amibrokerfans)







Code:
_SECTION_BEGIN("Nirvana_mrtq13");

a = Param("Average Pds", 5, 1, 10, 1 );
n = Param("Short Pds", 14, 5, 21, 1 );
m = Param("Long Pds", 60, 35, 90, 1 );

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 )) ));




Var4 =(Low+High+2*Close)/4; 
OP = EMA(Var4,a);
res1 = HHV(OP,n);

res2 =HHV(OP,m); 
sup2 =LLV(OP,m); 
sup1 =LLV(OP,n);

Linecolor = IIf(op>sup1 AND Ref(Op,-1)==Ref(sup1,-1), colorBrightGreen, IIf(op<res1 AND Ref(Op,-1)==Ref(res1,-1), colorRed, 3));
Plot(5, "",Linecolor, styleOwnScale|styleArea|styleNoLabel,-0.5, 350 );
Linecolor = IIf(Op==sup1,11,IIf(Op==res1,10,7));
Plot(OP, "OP", linecolor, 1+4); 
Plot(res1, "Resistance1", 11, 1); 
Plot(sup1, "Support1", 10, 1);
Plot(res2, "Resistance2", 4, 1);
Plot(sup2, "Support2", 5, 1);


_SECTION_BEGIN("Flower");
Show_color = ParamToggle("Display CandleColor", "No|Yes", 1);
r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );

Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);
flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);



m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, colorYellow,IIf(m1>0 AND 

m1>s1,colorWhite,IIf(m1>0 AND m1<s1,colorDarkYellow,colorRed)));
if(Show_color)
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
}

barColor=IIf(C>Green ,colorWhite,IIf(C < RED,colorRed,colorWhite));


PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, 

flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, 

flowerOpen), "Close", barColor, styleNoTitle | styleCandle);



_SECTION_END();


 



_SECTION_BEGIN("Bands");

SupResB =Param("Sup-Res Short",6,0,100,1);
nn=SupResB;



Bandlinecol=ParamColor("SupResLineColor",ColorRGB(82,82,82));
ParmCloud = ParamToggle("Cloud", "No|Yes", 0);
BoxCloudColor=ParamColor("BoxCloudColor",ColorRGB(27,27,27));


Line2=Param("ResLineLength",100,2,500,0.1);
Daysback1    = Line2; 
FirstBar1    = BarCount - DaysBack1; 
Hh=HHV(flowerHigh,nn);
LL=LLV(flowerLow,nn);

Res2=Hh;
Sup2=LL;

BandRes=IIf(BarIndex() >= Firstbar1,EndValue(Res2),Null);
BandSup=IIf(BarIndex() >= Firstbar1,EndValue(Sup2),Null);
Plot(BandRes,"",Bandlinecol,ParamStyle("ShortSupBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));
Plot(BandSup,"",Bandlinecol,ParamStyle("ShortResBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));




CS=BandRes;
CR=BandSup;


if(parmCloud == 1)
{
	PlotOHLC( CS, CS, CR,CR, "Band",BoxCloudColor, styleCloud | styleNoLabel|styleNoTitle); 
}

_SECTION_END();

_SECTION_BEGIN("Bands");

SupResB =Param("Sup-Res Short",6,0,100,1);
nn=SupResB;



Bandlinecol=ParamColor("SupResLineColor",ColorRGB(82,82,82));
ParmCloud = ParamToggle("Cloud", "No|Yes", 0);
BoxCloudColor=ParamColor("BoxCloudColor",ColorRGB(27,27,27));


Line2=Param("ResLineLength",100,2,500,0.1);
Daysback1    = Line2; 
FirstBar1    = BarCount - DaysBack1; 
Hh=HHV(flowerHigh,nn);
LL=LLV(flowerLow,nn);

Res2=Hh;
Sup2=LL;

BandRes=IIf(BarIndex() >= Firstbar1,EndValue(Res2),Null);
BandSup=IIf(BarIndex() >= Firstbar1,EndValue(Sup2),Null);
Plot(BandRes,"",Bandlinecol,ParamStyle("ShortSupBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));
Plot(BandSup,"",Bandlinecol,ParamStyle("ShortResBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));




CS=BandRes;
CR=BandSup;


if(parmCloud == 1)

PlotOHLC( CS, CS, CR,CR, "Band",BoxCloudColor, styleCloud | styleNoLabel|styleNoTitle); 

_SECTION_END();

_SECTION_BEGIN("Breakout Setting");
 Buyperiods=Param("Breakout periods best is usually 18",5,1,100,1,1);
 Sellperiods=Param("Exit Breakout",5,1,100,1,1);

 HaClose =EMA((O+H+L+C)/4,3); // Woodie 
 //HaClose =(O+H+L+C)/4; 
 HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
 HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
 HaLow = Min( L, Min( HaClose, HaOpen ) ); 
 Buy= C>Ref(HHV(High,Buyperiods),-1) ;
 Sell= C<Ref(LLV(Low,Sellperiods),-1);

 /* exrem is one method to remove surplus strade signals. It removes excessive signals of arrow */
 Buy = ExRem(Buy, Sell);
 Sell = ExRem(Sell, Buy);

 PlotShapes( IIf( Buy, shapeSmallUpTriangle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -30);
 //PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -8);

 PlotShapes( IIf( Sell, shapeSmallDownTriangle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -30);
 //PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -8);

 _SECTION_END();
_SECTION_BEGIN("Earth-2");

SetChartBkColor(16);
//Copyright 9Trading.com


trend = (5)*(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5))-
    (3)*(EMA(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5),3))-
    EMA(EMA(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5),3),2);
Buy1 = Cross(trend,5);
PlotShapes( IIf( Buy1, shapeHollowSmallCircle, shapeNone ), colorWhite, layer = 0, yposition = HaLow, offset = -10  ); 
 _SECTION_END();
_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
r4 = Param( "Wk slow", 17, 2, 200, 1 );
r5 = Param( "Wk fast", 8, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);


mycolor=IIf(m1<0 AND m1>s1, colorDarkGreen,IIf(m1>0 AND m1>s1,colorGreen,IIf(m1>0 AND m1<s1,colorDarkRed,colorRed)));

histcolor = IIf((m1-s1)-Ref((m1-s1),-1)> 0,colorLime,colorRed ); 

TimeFrameSet( inDaily );// weekly 
m1w=MACD(r4,r5);
s1w=Signal(r4,r5,r3);
kp=m1w-s1w;
kph=Ref(kp,-1);
TimeFrameRestore(); 

kw=TimeFrameExpand( kp, inDaily ); // expand for display 
khw=TimeFrameExpand( kph, inDaily ); // expand for display 
mw=TimeFrameExpand( m1w, inDaily ); // expand for display 
sw=TimeFrameExpand( s1w, inDaily ); // expand for display 

hcolor=IIf(mw<0 AND mw>sw, 51,IIf(mw>0 AND mw>sw,colorLime,IIf(mw>0 AND mw<sw,colorOrange,colorRed)));
gcolor=IIf(kw>khw,IIf(kw>0,colorDarkYellow,colorYellow),IIf(kw>0,colorSkyblue,colorBlue));

Plot(( m1 OR s1), "",  mycolor, styleHistogram|styleArea|styleThick|styleOwnScale|styleNoLabel,0,20 );
_SECTION_END();

_SECTION_BEGIN("Signals");


j1=Cross(m1,0);


PlotShapes( IIf( j1, shapeHollowSmallCircle, shapeNone ), colorWhite, layer = 0, yposition = HaLow, offset = -10  ); 

j3=Cross(s1,m1) AND m1>0;

PlotShapes( IIf( j3, shapeHollowSmallCircle, shapeNone ), colorRed, layer = 0, yposition = Hahigh, offset = 20  );


_SECTION_END();

_SECTION_BEGIN("Graphics");
GrpPrm=Param("Graphic Space",-5,-10,10);
GraphXSpace=GrpPrm;
_SECTION_END();
_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",28,11,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorWhite) );
Hor=Param("Horizontal Position",766,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut("CMP "+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorWhite) );
//GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );

_SECTION_END();




//#include <T3.AFL>;

_SECTION_BEGIN("PFE");

pds=10; 
x=sqrt((ROC(C,9)*ROC(C,9))+100);
y=Sum(sqrt((ROC(C,1)* ROC(C,1))+1),pds);
z=(x/y);
pfe=EMA(IIf(C>Ref(C,-9),z,-z)*100,5);

rsidn=pfe <-10 AND pfe<Ref(pfe,-1);
rsiup=pfe >10 AND pfe>Ref(pfe,-1);



 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,90,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(90,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,50 );
 _SECTION_END();



                                                                                            

//GfxRoundRect( 15,305,135,215, 5, 5 );
 GfxCircle( 70,90,70 );
 _SECTION_END();


_SECTION_BEGIN("STC");

_SECTION_BEGIN("Schaff Trend Cycle");
/*
Ported directly from original STC Tradestation code
results differ from other Amibroker versions that are not based directly on original EasyLanguage code
http://mediaserver.fxstreet.com/Reports/99afdb5f-d41d-4a2c-802c-f5d787df886c/ebfbf387-4b27-4a0f-848c-039f4ab77c00.pdf
*/
MA1=23;
MA2=50;
TCLen=10;
MA1=Param("ShortMACDLen",23,5,36);
MA2=Param("LOngMACDLen",50,10,100);
TCLen=Param("TCLen(StochPeriod)",10,5,20);
Factor=.5;
//Calculate a MACD Line
XMac = MACD(MA1,MA2) ; // MACD in Amibroker always uses Close for MACD calculation

//1st Stochastic: Calculate Stochastic of a MACD
Value1 = LLV(XMac, TCLen);
Value2 = HHV(XMac, TCLen) - Value1;

//Frac1=1; // prime Frac1 to a default of 1
//Frac1 = IIf(Value2 > 0, ((XMac - Value1) / Value2) * 100, Ref(FRAC1,-1));
// have to "prime" first value so that reference to "i-1" does not result in subscript out of range
// since MACD for both periods is not defined until MA2 period, 0 seems to be mathematically correct priming value
frac1=0;
for (i = 1; i < BarCount; i++) {
if (Value2[i] > 0) {
	frac1[i] = ((XMac[i] - Value1[i])/Value2[i])*100;
	}
else {
	frac1[i]= frac1[i-1];
	}
}

//Smoothed calculation for %FastD of MACD

PF[0]=frac1[0]; 
PF[1]=frac1[1];
for (i = 2; i < BarCount; i++) {
	PF[i]=PF[i-1]+(Factor*(frac1[i]-PF[i-1]));
}


//2nd Stochastic: Calculate Stochastic of Smoothed Percent FastD, above.
Value3 = LLV(PF, TCLen);
Value4 = HHV(PF, TCLen) - Value3;

//%FastK of PF
/*
Frac2=1;
Frac2 = IIf(Value4 > 0, ((PF - Value3) / Value4) * 100, Ref(FRAC2,-1));
*/

frac2[0]=0;
for (i = 1; i < BarCount; i++) {
	if (Value4[i] > 0 ) {
		frac2[i]=((PF[i] - Value3[i])/Value4[i])*100;
	}
	else {
		frac2[i]=frac2[i-1];
	}
}

//Smoothed calculation for %FastD of PF
PFF[0]=frac2[0];
PFF[1]=frac2[1];
for (i = 2; i < BarCount; i++) {
	PFF[i]=PFF[i-1]+(Factor*(frac2[i]-PFF[i-1]));
}

 //HT=ParamColor("HT", colorRed );

 rsidn=pff <2;
 rsiup=pff >98;


 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,120,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(120,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,60 );
 _SECTION_END();


 _SECTION_BEGIN("rsi");

 //HT=ParamColor("HT", colorRed );

 rsidn=RSI(7) <30;
 rsiup=RSI(7) >70;


 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,150,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(150,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,50 );
 _SECTION_END();








 _SECTION_BEGIN("Rays");

 //FT=ParamColor("FT", colorRed );

 Pp1=3;
 Pp2=2;

 CS33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),4); 
 CR33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),5);

 AtrupTrendCond1 = flowerClose> CS33 ;
 AtrdnTrendCond1 =CS33>flowerClose ;


 ATRup = WriteIf(AtrupTrendCond1,"atrup", "");
 ATRdown= WriteIf( AtrdnTrendCond1,"atrdn", "");

 if ( ATRup =="atrup")
 {
 GfxSelectSolidBrush( ColorRGB(0,180,0) ); 

 }
 else

 if (ATRdown =="atrdn")

 {
 GfxSelectSolidBrush( ColorRGB(180,0,0)); 

 }

 else

 if ( ATRdown =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,40 );

 _SECTION_END();


 _SECTION_BEGIN("Exit_Beast-3");

 //GT=ParamColor("GT", colorRed );

 EntrylookbackPeriod=10;
 EntryATRperiod=1.9;
 EntrySig = C > ( LLV( flowerLow, EntrylookbackPeriod ) + EntryATRperiod * ATR( 10 ) );
 ExitSig = C < ( HHV( flowerHigh, EntrylookbackPeriod ) -EntryATRperiod * ATR( 10 ) );


 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 EntryB = WriteIf( EntrySig,"eu", "");
 ExitB = WriteIf( ExitSig,"ed", "");

 if ( EntryB =="eu")
 {
 GfxSelectSolidBrush( ColorRGB(0,210,0) ); //

 }
 else

 if ( ExitB =="ed")

 {
 GfxSelectSolidBrush( ColorRGB(210,0,0)); //

 }

 else

 if ( ExitB =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,30 );// changing the value of x,y,rad x-70, y-90, rad-24

 _SECTION_END();



 _SECTION_BEGIN("CCI9-2");

 //HT=ParamColor("HT", colorRed );

 ccidn=CCI(8) < 0;
 cciup=CCI(9) > 0;


 ccresult1 = WriteIf( cciup,"cu", "");
 ccresult2 = WriteIf( ccidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( ccresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,240,0) ); 

 }
 else

 if ( ccresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(240,0,0)); 

 }

 else

 if ( ccresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,20);




 _SECTION_END();




 _SECTION_BEGIN("%BB7-1");

 //IT=ParamColor("IT", colorRed );
 p=7;
 x=((C+2*StDev(C,p)-MA(C,p))/(4*StDev(C,p)))*100;
 bbdown= x < 40;
 bbup= x > 40;

 bbresult1 = WriteIf( bbup,"bu", "");
 bbresult2 = WriteIf( bbdown,"bd", "");
 bbresult3 = WriteIf( C,"bearishrevers", "");



 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( bbresult1 =="bu")
 {
 GfxSelectSolidBrush( ColorRGB(62,255,62) ); 

 }
 else

 if ( bbresult2 =="bd")

 {
 GfxSelectSolidBrush( ColorRGB(255,62,62) ); 

 }

 else

 if ( bbresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,10 );


 _SECTION_END();



_SECTION_BEGIN("TSKPPIVOT4");
CHiPr = 0;
CLoPr = 9999999;
blsLong = 0;
PrevCOBar = 0;
NumBars = 0;
PrePP = 0;
PrevLowVal = 9999999;
BuySig = 0;
blsShort = 0;
PrevHiVal = 0;
blsNewCO = 0;
BarDif   = 0;

KPA900Val = E_TSKPA900(Close);
KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close);

// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
aHiVal = H - H;
aLoVal = L - L;


Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal  + IIf(tskp_colortmplcnd0 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd1 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd2 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd3 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd4 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd5 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd6 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd7 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd8 > 0, 1, -1); 


for (curBar=0; curBar < BarCount-1; curBar++)
{

	if ( curBar == 0 )
	{
		CHiPr = flowerHigh[curBar];
		CHiBar = curBar;
		CLoPr = flowerLow[curBar];
		CLoBar = curBar;
		blsLong = 0;
		blsShort = 0;
		blsNewCO = 0;
		PrePP = 0;
		PrevCOBar = 0;
		PrevHiVal =flowerHigh[curBar];
		PrevLowVal = flowerLow[curBar];
		BuySig = 0;
		SellSig = 0;
		blsLL  = 0;
	}

	if (flowerHigh[CurBar] >= CHiPr) {
		CHiPr = flowerHigh[CurBar];
		ChiBar = CurBar;
	}

	if (flowerLow[CurBar] <= CLoPr) {
		CLoPr = flowerLow[CurBar];
		CLoBar = CurBar;
	}

	if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){
		BarDif = CurBar - PrevCOBar;
		if (BarDif >= NumBars) {
			blsLong = 1;
			blsShort = 0;
			blsNewCO = 1;
			PrevCOBar = CurBar;
		}
	}

	if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){
		BarDif = CurBar - PrevCOBar;
		if (BarDif >= NumBars) {
			blsLong = 0;
			blsShort = 1;
			blsNewCO = 1;
			PrevCOBar = CurBar;
		}
	}

	if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) {
		LVal = CurBar - CLoBar;
		for (j= CLoBar-1; j <= CLoBar+1; j++)
		{
			if (j >=0) {
				aLPivs[j] = 1;
				aLoVal[j] = CLoPr;
			}
		}
		PrePP = -1;
		blsNewCO = 0;
		CHiPr = flowerHigh[CurBar];
		CHiBar = CurBar;
		CLoPr = flowerLow[Curbar];
		CLoBar = CurBar;
		} 
		else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) {
		HVal = CurBar - CHiBar;
		for (j= CHiBar-1; j <= CHiBar+1; j++)
		{		
			if (j >=0) {
				aHPivs[j] = 1;
				aHiVal[j] = CHiPr;
			}
		}
		PrePP = 1;
		blsNewCO = 0;
		CHiPr = flowerHigh[CurBar];
		CHiBar = CurBar;
		CLoPr = flowerLow[Curbar];
		CLoBar = CurBar;
		} 
}

PlotShapes(
IIf(aHPivs == 1,21,shapeNone),ColorRGB(255,0,145),0, aHiVal, offset = 5);
PlotShapes(IIf(aHPivs == 1, 15,shapeNone), ColorRGB(200,50,75),0,   aHiVal,Offset = 5);
PlotShapes(IIf(aLPivs == 1, 21,shapeNone), ColorRGB(0,125,225),0, aLoVal, Offset = -5);
PlotShapes(IIf(aLPivs == 1, 15,shapeNone), ColorRGB(0,125,255),0, aLoVal, Offset = -5);
_SECTION_END();

_SECTION_BEGIN("Spiker_Shadow");


C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;


green = 1; blue = 2; yellow = 3; red = 4; white = 5;
VType = IIf(ud,          
         IIf(uc, green, yellow),
       IIf(dd, 
         IIf(dc, red, blue), white));

/* green volume: up-day and up-close*/
gv = IIf(VType == green, V, 0); 
/* yellow volume: up-day but down-close */
yv = IIf(VType == yellow, V, 0); 
/* red volume: down-day and down-close */
rv = IIf(VType == red, V, 0); 
/* blue volume: down-day but up-close */
bv = IIf(VType == blue, V, 0); 


uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */


VolPer = Param("Adjust Vol. MA per.", 10, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 4, 1, 255, 1);


MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume




Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;


/*convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
Plot(Converge, "Bull/Bear Volume Convergence/Divergence", colorViolet,
1|styleLeftAxisScale|styleNoLabel|styleThick);
Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
}*/


upshadow=ParamColor("UpShadowColor",colorDarkTeal );
downshadow=ParamColor("DownShadowColor",colorDarkGrey );
riseFallColor = IIf(rising, upshadow,downshadow); 

riseFallShadows = Param("Show RiseFallShadows", 1, 0, 1, 1);
if(riseFallShadows){
Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,ParamStyle("ShadeStyle",styleHistogram|styleArea|styleThick|styleOwnScale|styleNoLabel,maskAll));

/*Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,
styleHistogram|styleArea|styleOwnScale|styleNoLabel);*/
}


//GraphXSpace =5;

//_N(Title="");
_SECTION_END();
_SECTION_END();
 

amibrokerfans

Well-Known Member
Schaff Cycle

Best oscillator, I ever saw
It behaves best both in trending markets & side ways market.
It dont keeps on oscillates like stoch or RSI
If its below 10 then market is down & if above 90 then market is up
Dont trade otherwise.
yes! its my personal fav also!
 
NIRVANA
(modified by amibrokerfans)







Code:
_SECTION_BEGIN("Nirvana_mrtq13");

a = Param("Average Pds", 5, 1, 10, 1 );
n = Param("Short Pds", 14, 5, 21, 1 );
m = Param("Long Pds", 60, 35, 90, 1 );

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 )) ));




Var4 =(Low+High+2*Close)/4; 
OP = EMA(Var4,a);
res1 = HHV(OP,n);

res2 =HHV(OP,m); 
sup2 =LLV(OP,m); 
sup1 =LLV(OP,n);

Linecolor = IIf(op>sup1 AND Ref(Op,-1)==Ref(sup1,-1), colorBrightGreen, IIf(op<res1 AND Ref(Op,-1)==Ref(res1,-1), colorRed, 3));
Plot(5, "",Linecolor, styleOwnScale|styleArea|styleNoLabel,-0.5, 350 );
Linecolor = IIf(Op==sup1,11,IIf(Op==res1,10,7));
Plot(OP, "OP", linecolor, 1+4); 
Plot(res1, "Resistance1", 11, 1); 
Plot(sup1, "Support1", 10, 1);
Plot(res2, "Resistance2", 4, 1);
Plot(sup2, "Support2", 5, 1);


_SECTION_BEGIN("Flower");
Show_color = ParamToggle("Display CandleColor", "No|Yes", 1);
r1 = Param( "ColorFast avg", 5, 2, 200, 1 );
r2 = Param( "ColorSlow avg", 10, 2, 200, 1 );
r3 = Param( "ColorSignal avg", 5, 2, 200, 1 );

Prd1=Param("ATR Period",4,1,20,1);
Prd2=Param("Look Back",7,1,20,1);
green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2);
red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2);
flowerClose = EMA((Open+High+Low+Close)/4,3) ;
flowerOpen = EMA((Ref(Open,-1) + Ref(flowerClose,-1))/2,3);
Temp = Max(High, flowerOpen);
flowerHigh = EMA(Max(Temp, flowerClose),3);
Temp = Min(Low,flowerOpen);
flowerLow = EMA(Min(Temp, flowerClose),3);



m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);
mycolor=IIf(m1<0 AND m1>s1, colorYellow,IIf(m1>0 AND 

m1>s1,colorWhite,IIf(m1>0 AND m1<s1,colorDarkYellow,colorRed)));
if(Show_color)
{
ColorHighliter = myColor;
SetBarFillColor( ColorHighliter );
}

barColor=IIf(C>Green ,colorWhite,IIf(C < RED,colorRed,colorWhite));


PlotOHLC( IIf(flowerOpen<flowerClose, flowerOpen, 

flowerClose),flowerHigh,flowerLow,IIf(flowerOpen<flowerClose, flowerClose, 

flowerOpen), "Close", barColor, styleNoTitle | styleCandle);



_SECTION_END();


 



_SECTION_BEGIN("Bands");

SupResB =Param("Sup-Res Short",6,0,100,1);
nn=SupResB;



Bandlinecol=ParamColor("SupResLineColor",ColorRGB(82,82,82));
ParmCloud = ParamToggle("Cloud", "No|Yes", 0);
BoxCloudColor=ParamColor("BoxCloudColor",ColorRGB(27,27,27));


Line2=Param("ResLineLength",100,2,500,0.1);
Daysback1    = Line2; 
FirstBar1    = BarCount - DaysBack1; 
Hh=HHV(flowerHigh,nn);
LL=LLV(flowerLow,nn);

Res2=Hh;
Sup2=LL;

BandRes=IIf(BarIndex() >= Firstbar1,EndValue(Res2),Null);
BandSup=IIf(BarIndex() >= Firstbar1,EndValue(Sup2),Null);
Plot(BandRes,"",Bandlinecol,ParamStyle("ShortSupBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));
Plot(BandSup,"",Bandlinecol,ParamStyle("ShortResBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));




CS=BandRes;
CR=BandSup;


if(parmCloud == 1)
{
	PlotOHLC( CS, CS, CR,CR, "Band",BoxCloudColor, styleCloud | styleNoLabel|styleNoTitle); 
}

_SECTION_END();

_SECTION_BEGIN("Bands");

SupResB =Param("Sup-Res Short",6,0,100,1);
nn=SupResB;



Bandlinecol=ParamColor("SupResLineColor",ColorRGB(82,82,82));
ParmCloud = ParamToggle("Cloud", "No|Yes", 0);
BoxCloudColor=ParamColor("BoxCloudColor",ColorRGB(27,27,27));


Line2=Param("ResLineLength",100,2,500,0.1);
Daysback1    = Line2; 
FirstBar1    = BarCount - DaysBack1; 
Hh=HHV(flowerHigh,nn);
LL=LLV(flowerLow,nn);

Res2=Hh;
Sup2=LL;

BandRes=IIf(BarIndex() >= Firstbar1,EndValue(Res2),Null);
BandSup=IIf(BarIndex() >= Firstbar1,EndValue(Sup2),Null);
Plot(BandRes,"",Bandlinecol,ParamStyle("ShortSupBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));
Plot(BandSup,"",Bandlinecol,ParamStyle("ShortResBand",styleLine|styleDashed|stylehidden|styleNoTitle|styleNoLabel|styleThick,maskAll));




CS=BandRes;
CR=BandSup;


if(parmCloud == 1)

PlotOHLC( CS, CS, CR,CR, "Band",BoxCloudColor, styleCloud | styleNoLabel|styleNoTitle); 

_SECTION_END();

_SECTION_BEGIN("Breakout Setting");
 Buyperiods=Param("Breakout periods best is usually 18",5,1,100,1,1);
 Sellperiods=Param("Exit Breakout",5,1,100,1,1);

 HaClose =EMA((O+H+L+C)/4,3); // Woodie 
 //HaClose =(O+H+L+C)/4; 
 HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
 HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
 HaLow = Min( L, Min( HaClose, HaOpen ) ); 
 Buy= C>Ref(HHV(High,Buyperiods),-1) ;
 Sell= C<Ref(LLV(Low,Sellperiods),-1);

 /* exrem is one method to remove surplus strade signals. It removes excessive signals of arrow */
 Buy = ExRem(Buy, Sell);
 Sell = ExRem(Sell, Buy);

 PlotShapes( IIf( Buy, shapeSmallUpTriangle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -30);
 //PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, layer = 0,yposition = HaLow, offset = -8);

 PlotShapes( IIf( Sell, shapeSmallDownTriangle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -30);
 //PlotShapes( IIf( Sell, shapeSmallCircle, shapeNone ), colorRed, layer = 0, yposition = HaHigh, offset = -8);

 _SECTION_END();
_SECTION_BEGIN("Earth-2");

SetChartBkColor(16);
//Copyright 9Trading.com


trend = (5)*(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5))-
    (3)*(EMA(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5),3))-
    EMA(EMA(EMA(((Close-LLV(Low,27))/(HHV(High,27)-LLV(Low,27)))*(100),5),3),2);
Buy1 = Cross(trend,5);
PlotShapes( IIf( Buy1, shapeHollowSmallCircle, shapeNone ), colorWhite, layer = 0, yposition = HaLow, offset = -10  ); 
 _SECTION_END();
_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
r4 = Param( "Wk slow", 17, 2, 200, 1 );
r5 = Param( "Wk fast", 8, 2, 200, 1 );
m1=MACD(r1,r2);
s1=Signal(r1,r2,r3);


mycolor=IIf(m1<0 AND m1>s1, colorDarkGreen,IIf(m1>0 AND m1>s1,colorGreen,IIf(m1>0 AND m1<s1,colorDarkRed,colorRed)));

histcolor = IIf((m1-s1)-Ref((m1-s1),-1)> 0,colorLime,colorRed ); 

TimeFrameSet( inDaily );// weekly 
m1w=MACD(r4,r5);
s1w=Signal(r4,r5,r3);
kp=m1w-s1w;
kph=Ref(kp,-1);
TimeFrameRestore(); 

kw=TimeFrameExpand( kp, inDaily ); // expand for display 
khw=TimeFrameExpand( kph, inDaily ); // expand for display 
mw=TimeFrameExpand( m1w, inDaily ); // expand for display 
sw=TimeFrameExpand( s1w, inDaily ); // expand for display 

hcolor=IIf(mw<0 AND mw>sw, 51,IIf(mw>0 AND mw>sw,colorLime,IIf(mw>0 AND mw<sw,colorOrange,colorRed)));
gcolor=IIf(kw>khw,IIf(kw>0,colorDarkYellow,colorYellow),IIf(kw>0,colorSkyblue,colorBlue));

Plot(( m1 OR s1), "",  mycolor, styleHistogram|styleArea|styleThick|styleOwnScale|styleNoLabel,0,20 );
_SECTION_END();

_SECTION_BEGIN("Signals");


j1=Cross(m1,0);


PlotShapes( IIf( j1, shapeHollowSmallCircle, shapeNone ), colorWhite, layer = 0, yposition = HaLow, offset = -10  ); 

j3=Cross(s1,m1) AND m1>0;

PlotShapes( IIf( j3, shapeHollowSmallCircle, shapeNone ), colorRed, layer = 0, yposition = Hahigh, offset = 20  );


_SECTION_END();

_SECTION_BEGIN("Graphics");
GrpPrm=Param("Graphic Space",-5,-10,10);
GraphXSpace=GrpPrm;
_SECTION_END();
_SECTION_BEGIN("Magnified Market Price");
//by Vidyasagar, [email protected]//
FS=Param("Font Size",28,11,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorWhite) );
Hor=Param("Horizontal Position",766,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut("CMP "+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorWhite) );
//GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );

_SECTION_END();




//#include <T3.AFL>;

_SECTION_BEGIN("PFE");

pds=10; 
x=sqrt((ROC(C,9)*ROC(C,9))+100);
y=Sum(sqrt((ROC(C,1)* ROC(C,1))+1),pds);
z=(x/y);
pfe=EMA(IIf(C>Ref(C,-9),z,-z)*100,5);

rsidn=pfe <-10 AND pfe<Ref(pfe,-1);
rsiup=pfe >10 AND pfe>Ref(pfe,-1);



 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,90,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(90,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,50 );
 _SECTION_END();



                                                                                            

//GfxRoundRect( 15,305,135,215, 5, 5 );
 GfxCircle( 70,90,70 );
 _SECTION_END();


_SECTION_BEGIN("STC");

_SECTION_BEGIN("Schaff Trend Cycle");
/*
Ported directly from original STC Tradestation code
results differ from other Amibroker versions that are not based directly on original EasyLanguage code
http://mediaserver.fxstreet.com/Reports/99afdb5f-d41d-4a2c-802c-f5d787df886c/ebfbf387-4b27-4a0f-848c-039f4ab77c00.pdf
*/
MA1=23;
MA2=50;
TCLen=10;
MA1=Param("ShortMACDLen",23,5,36);
MA2=Param("LOngMACDLen",50,10,100);
TCLen=Param("TCLen(StochPeriod)",10,5,20);
Factor=.5;
//Calculate a MACD Line
XMac = MACD(MA1,MA2) ; // MACD in Amibroker always uses Close for MACD calculation

//1st Stochastic: Calculate Stochastic of a MACD
Value1 = LLV(XMac, TCLen);
Value2 = HHV(XMac, TCLen) - Value1;

//Frac1=1; // prime Frac1 to a default of 1
//Frac1 = IIf(Value2 > 0, ((XMac - Value1) / Value2) * 100, Ref(FRAC1,-1));
// have to "prime" first value so that reference to "i-1" does not result in subscript out of range
// since MACD for both periods is not defined until MA2 period, 0 seems to be mathematically correct priming value
frac1=0;
for (i = 1; i < BarCount; i++) {
if (Value2[i] > 0) {
	frac1[i] = ((XMac[i] - Value1[i])/Value2[i])*100;
	}
else {
	frac1[i]= frac1[i-1];
	}
}

//Smoothed calculation for %FastD of MACD

PF[0]=frac1[0]; 
PF[1]=frac1[1];
for (i = 2; i < BarCount; i++) {
	PF[i]=PF[i-1]+(Factor*(frac1[i]-PF[i-1]));
}


//2nd Stochastic: Calculate Stochastic of Smoothed Percent FastD, above.
Value3 = LLV(PF, TCLen);
Value4 = HHV(PF, TCLen) - Value3;

//%FastK of PF
/*
Frac2=1;
Frac2 = IIf(Value4 > 0, ((PF - Value3) / Value4) * 100, Ref(FRAC2,-1));
*/

frac2[0]=0;
for (i = 1; i < BarCount; i++) {
	if (Value4[i] > 0 ) {
		frac2[i]=((PF[i] - Value3[i])/Value4[i])*100;
	}
	else {
		frac2[i]=frac2[i-1];
	}
}

//Smoothed calculation for %FastD of PF
PFF[0]=frac2[0];
PFF[1]=frac2[1];
for (i = 2; i < BarCount; i++) {
	PFF[i]=PFF[i-1]+(Factor*(frac2[i]-PFF[i-1]));
}

 //HT=ParamColor("HT", colorRed );

 rsidn=pff <2;
 rsiup=pff >98;


 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,120,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(120,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,60 );
 _SECTION_END();


 _SECTION_BEGIN("rsi");

 //HT=ParamColor("HT", colorRed );

 rsidn=RSI(7) <30;
 rsiup=RSI(7) >70;


 rsiresult1 = WriteIf( rsiup,"cu", "");
 rsiresult2 = WriteIf( rsidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 120 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( rsiresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,150,0) ); 

 }
 else

 if ( rsiresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(150,0,0)); 

 }

 else

 if ( rsiresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );


 GfxCircle( 70,90,50 );
 _SECTION_END();








 _SECTION_BEGIN("Rays");

 //FT=ParamColor("FT", colorRed );

 Pp1=3;
 Pp2=2;

 CS33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),4); 
 CR33=HHV(LLV(flowerHigh,Pp1)-ATR(Pp2),5);

 AtrupTrendCond1 = flowerClose> CS33 ;
 AtrdnTrendCond1 =CS33>flowerClose ;


 ATRup = WriteIf(AtrupTrendCond1,"atrup", "");
 ATRdown= WriteIf( AtrdnTrendCond1,"atrdn", "");

 if ( ATRup =="atrup")
 {
 GfxSelectSolidBrush( ColorRGB(0,180,0) ); 

 }
 else

 if (ATRdown =="atrdn")

 {
 GfxSelectSolidBrush( ColorRGB(180,0,0)); 

 }

 else

 if ( ATRdown =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,40 );

 _SECTION_END();


 _SECTION_BEGIN("Exit_Beast-3");

 //GT=ParamColor("GT", colorRed );

 EntrylookbackPeriod=10;
 EntryATRperiod=1.9;
 EntrySig = C > ( LLV( flowerLow, EntrylookbackPeriod ) + EntryATRperiod * ATR( 10 ) );
 ExitSig = C < ( HHV( flowerHigh, EntrylookbackPeriod ) -EntryATRperiod * ATR( 10 ) );


 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 EntryB = WriteIf( EntrySig,"eu", "");
 ExitB = WriteIf( ExitSig,"ed", "");

 if ( EntryB =="eu")
 {
 GfxSelectSolidBrush( ColorRGB(0,210,0) ); //

 }
 else

 if ( ExitB =="ed")

 {
 GfxSelectSolidBrush( ColorRGB(210,0,0)); //

 }

 else

 if ( ExitB =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,30 );// changing the value of x,y,rad x-70, y-90, rad-24

 _SECTION_END();



 _SECTION_BEGIN("CCI9-2");

 //HT=ParamColor("HT", colorRed );

 ccidn=CCI(8) < 0;
 cciup=CCI(9) > 0;


 ccresult1 = WriteIf( cciup,"cu", "");
 ccresult2 = WriteIf( ccidn,"cd", "");




 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( ccresult1 =="cu")
 {
 GfxSelectSolidBrush( ColorRGB(0,240,0) ); 

 }
 else

 if ( ccresult2 =="cd")

 {
 GfxSelectSolidBrush( ColorRGB(240,0,0)); 

 }

 else

 if ( ccresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,20);




 _SECTION_END();




 _SECTION_BEGIN("%BB7-1");

 //IT=ParamColor("IT", colorRed );
 p=7;
 x=((C+2*StDev(C,p)-MA(C,p))/(4*StDev(C,p)))*100;
 bbdown= x < 40;
 bbup= x > 40;

 bbresult1 = WriteIf( bbup,"bu", "");
 bbresult2 = WriteIf( bbdown,"bd", "");
 bbresult3 = WriteIf( C,"bearishrevers", "");



 RequestTimedRefresh( 0 );
 GfxSelectFont( "Tahoma", 12, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorWhite );

 if ( bbresult1 =="bu")
 {
 GfxSelectSolidBrush( ColorRGB(62,255,62) ); 

 }
 else

 if ( bbresult2 =="bd")

 {
 GfxSelectSolidBrush( ColorRGB(255,62,62) ); 

 }

 else

 if ( bbresult2 =="")

 {
 GfxSelectSolidBrush( colorGrey40 ); 

 }

 GfxSelectFont( "Arial", 10, 100 );
 GfxSetBkMode( 1 );
 GfxSetTextColor( colorBlack );

 GfxSelectPen( colorBlack, 1 ); // broader color 
 GfxCircle( 70,90,10 );


 _SECTION_END();



_SECTION_BEGIN("TSKPPIVOT4");
CHiPr = 0;
CLoPr = 9999999;
blsLong = 0;
PrevCOBar = 0;
NumBars = 0;
PrePP = 0;
PrevLowVal = 9999999;
BuySig = 0;
blsShort = 0;
PrevHiVal = 0;
blsNewCO = 0;
BarDif   = 0;

KPA900Val = E_TSKPA900(Close);
KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close);

// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
aHiVal = H - H;
aLoVal = L - L;


Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume);
sctotal = 0;
sctotal = sctotal  + IIf(tskp_colortmplcnd0 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd1 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd2 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd3 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd4 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd5 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd6 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd7 > 0, 1, -1); 
sctotal = sctotal  + IIf(tskp_colortmplcnd8 > 0, 1, -1); 


for (curBar=0; curBar < BarCount-1; curBar++)
{

	if ( curBar == 0 )
	{
		CHiPr = flowerHigh[curBar];
		CHiBar = curBar;
		CLoPr = flowerLow[curBar];
		CLoBar = curBar;
		blsLong = 0;
		blsShort = 0;
		blsNewCO = 0;
		PrePP = 0;
		PrevCOBar = 0;
		PrevHiVal =flowerHigh[curBar];
		PrevLowVal = flowerLow[curBar];
		BuySig = 0;
		SellSig = 0;
		blsLL  = 0;
	}

	if (flowerHigh[CurBar] >= CHiPr) {
		CHiPr = flowerHigh[CurBar];
		ChiBar = CurBar;
	}

	if (flowerLow[CurBar] <= CLoPr) {
		CLoPr = flowerLow[CurBar];
		CLoBar = CurBar;
	}

	if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){
		BarDif = CurBar - PrevCOBar;
		if (BarDif >= NumBars) {
			blsLong = 1;
			blsShort = 0;
			blsNewCO = 1;
			PrevCOBar = CurBar;
		}
	}

	if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){
		BarDif = CurBar - PrevCOBar;
		if (BarDif >= NumBars) {
			blsLong = 0;
			blsShort = 1;
			blsNewCO = 1;
			PrevCOBar = CurBar;
		}
	}

	if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) {
		LVal = CurBar - CLoBar;
		for (j= CLoBar-1; j <= CLoBar+1; j++)
		{
			if (j >=0) {
				aLPivs[j] = 1;
				aLoVal[j] = CLoPr;
			}
		}
		PrePP = -1;
		blsNewCO = 0;
		CHiPr = flowerHigh[CurBar];
		CHiBar = CurBar;
		CLoPr = flowerLow[Curbar];
		CLoBar = CurBar;
		} 
		else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) {
		HVal = CurBar - CHiBar;
		for (j= CHiBar-1; j <= CHiBar+1; j++)
		{		
			if (j >=0) {
				aHPivs[j] = 1;
				aHiVal[j] = CHiPr;
			}
		}
		PrePP = 1;
		blsNewCO = 0;
		CHiPr = flowerHigh[CurBar];
		CHiBar = CurBar;
		CLoPr = flowerLow[Curbar];
		CLoBar = CurBar;
		} 
}

PlotShapes(
IIf(aHPivs == 1,21,shapeNone),ColorRGB(255,0,145),0, aHiVal, offset = 5);
PlotShapes(IIf(aHPivs == 1, 15,shapeNone), ColorRGB(200,50,75),0,   aHiVal,Offset = 5);
PlotShapes(IIf(aLPivs == 1, 21,shapeNone), ColorRGB(0,125,225),0, aLoVal, Offset = -5);
PlotShapes(IIf(aLPivs == 1, 15,shapeNone), ColorRGB(0,125,255),0, aLoVal, Offset = -5);
_SECTION_END();

_SECTION_BEGIN("Spiker_Shadow");


C1 = Ref(C, -1);
uc = C > C1; dc = C <= C1;
ud = C > O; dd = C <= O;


green = 1; blue = 2; yellow = 3; red = 4; white = 5;
VType = IIf(ud,          
         IIf(uc, green, yellow),
       IIf(dd, 
         IIf(dc, red, blue), white));

/* green volume: up-day and up-close*/
gv = IIf(VType == green, V, 0); 
/* yellow volume: up-day but down-close */
yv = IIf(VType == yellow, V, 0); 
/* red volume: down-day and down-close */
rv = IIf(VType == red, V, 0); 
/* blue volume: down-day but up-close */
bv = IIf(VType == blue, V, 0); 


uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */


VolPer = Param("Adjust Vol. MA per.", 10, 1, 255, 1);
ConvPer = Param("Adjust Conv. MA per.", 4, 1, 255, 1);


MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
MAtv = TEMA(V, VolPer );//total volume




Converge = (TEMA(MAuv - MAdv, ConvPer));
Converge1 = Ref(Converge, -1);
ConvergeUp = Converge > Converge1;
ConvergeOver = Converge > 0;
rising = ConvergeUp AND ConvergeOver;
falling = !ConvergeUp AND ConvergeOver;


/*convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
if(convergenceOscillator OR OscillatorOnly){
Plot(Converge, "Bull/Bear Volume Convergence/Divergence", colorViolet,
1|styleLeftAxisScale|styleNoLabel|styleThick);
Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
}*/


upshadow=ParamColor("UpShadowColor",colorDarkTeal );
downshadow=ParamColor("DownShadowColor",colorDarkGrey );
riseFallColor = IIf(rising, upshadow,downshadow); 

riseFallShadows = Param("Show RiseFallShadows", 1, 0, 1, 1);
if(riseFallShadows){
Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,ParamStyle("ShadeStyle",styleHistogram|styleArea|styleThick|styleOwnScale|styleNoLabel,maskAll));

/*Plot(IIf(rising OR falling, 1, 0), "", riseFallColor,
styleHistogram|styleArea|styleOwnScale|styleNoLabel);*/
}


//GraphXSpace =5;

//_N(Title="");
_SECTION_END();
_SECTION_END();
AF,
Can you explain how to enter long and short for intraday and then lond or short in eod.. hope your explanation with your experience will help to understand this afl.

Regards,
Paresh
 

shivangi77

Well-Known Member
How to take profits in bull and bear markets



1. Check market indicators for overall direction
2. Scan the industry groups to know which one to zero in.
3. Cut out the stocks with the most potentially profitable formation within the favourable groups
4. Concentrate majority of buying in continuation-type buy patterns that are already in Stage 2, and reverse for bear markets
5. Know where protective stop will be (ALWAYS use it) set before entering the order if its too far away, look for other stock or wait to purchase when safer level forms
6. Never sell a stock in Stages 1 or (especially) 2, AND never buy a stock in Stages 3 or (especially) 4 stage analysis can be applied to any investments that are governed by supply and demand
7. Never guess a bottom (and go long)
8. Dont feel that one has to be 100% invested all the times. Differentiate when charts and indicators point to fully invested and when to extreme caution
9. Always be in harmony with the market buy Stage 2 strength; sell Stage 4 weakness
10. In case of conflict between price volume action and the earnings, always go with objective message being supplied by technical approach
11. Always be consistent. Keep a diary and analyze actions

READING CHARTS:

Daily for very short traders, weekly for intermediate (several months) traders. Below specifically on weekly charts:
1. Look at each high-low-close spike forming pattern with insight into next major move
2. Look at volume plot very important that volume is large and expanding on breakout
3. Look at 30 week MA never long if P below declining 30-week MA; never short if P above rising 30 week MA
4. Be aware of its long-range background (yearly high-low, long-term support/resistance)
5. Look at its relative-strength line long on up trend, short on downtrend; watch those situations where it shifts direction


Stage 1: basing area. After several months decline, start sideways trend. Volume lessens (often starts expanding towards end stage 1). 30 week MA begins to flatten out.

Stage 2: advancing phase. Ideal time to go long when stock swinging out of its base into this more dynamic stage. Breakout above resistance zone and 30-week MA should occur on impressive volume. Usually after initial rally at least one pullback (the less the pullback the stronger the stock).

30 week MA usually starts moving up shortly after breakout. Expect price to move two steps forward and one sharp step back ok as long as above 30 week MA.

When angle of ascent of MA slows down considerably and prices closer and closer to MA, stock becomes a hold.

Stage 3: top area. Upward advance loses momentum and stock starts trending sideways. Volume usually heavy and moves sharp and choppy.Prices tiptoes below and above MA on declines and rallies. Keep emotions in check.

Stage 4: declining phase. Stock breaks below bottom of support zone.


WHEN TO BUY

Stock initially moves out of Stage 1 base and enters Stage 2. Risk extremely low (support just beneath purchase price) and excellent upside potential (entire Stage 2 advance lies ahead), but need patience (it can take time for solid Stage 2 momentum to build).

After Stage 2 is well underway, when stock drops back close to its MA and consolidates. MA should still be clearly trending higher. Then it breaks out anew on top of resistance zone this is continuation buy.

Early in bull market plenty of stocks breaking out for the first time, later very few but still plenty of continuation variety buys.

Rule of thumb: 80% continuation buys, 20% early stage 2 variety.

Use buy stops, within set limits, good-til-cancelled (GTC):
A. Dont have to watch market closely frees attention
B. Better, less emotional decision (not involved in market energy)
The more mechanical the system and the less subject to judgements and emotions, the more profitable.

Buying/Selling patterns
4 Year presidential cycle: first year bear, second year bear until midway then bullish, third year most bullish, fourth year choppy usually first half weak, then strong
Months - bullish: Nov-Jan, April. Bearish: Feb, May, June, September
Day of week: Monday worse, Friday strongest.
Day preceding holidays usually bullish.

Selecting the sector
Use same criteria than stocks, most important criteria that group be healthy (not in Stage 3 or 4), breaking into Stage 2 with a minimum of resistance overhead. One difference: if group well in Stage 2 far above support and one stock just breaking out of Stage 1 basis its ok to buy; same if group just moved in Stage 2 but one stock as continuation pattern, ok to buy.
For trader, ideal is a continuation breakout within a dynamic group exhibiting the very same sort of pattern.
If several sectors are well, best will be one with best individual top chart patterns.

REFINING BUYING PROCESS

ResistanceAlways check where and how much overhead resistance there is on any stock, first on 2-4 years, then on 10 years chart.

VolumeNever trust a breakout that isnt accompanied by a significant increase in volume. Either:
a. a one-week volume spike that is at least twice the average volume of the past few weeks, or
b. a volume build-up over the past 3-4 weeks that is at least twice the average volume of the past several weeks, coupled with at least some increase in the breakout week

Relative strengthMeasure of how strong a stock is in relation to the overall market. Never buy a stock if its relative strength is in poor shape.

Buying checklistCheck overall direction of market
Scan the industry groups that look best technically
List stocks in favourable groups that have bullish patterns but are in trading range. Write down price they need to break out.
Narrow down the list discarding ones with overhead resistance nearby.
Narrow list further by checking relative strength
Set what stop loss level should be discard unacceptable ones
Put in buy-stop orders for half of position on stocks that meet buying criteria
If volume is favourable on breakout and contracts on decline, but other half position on a pullback near the initial breakout
If volume pattern is not high enough on breakout, sell stock on first rally. If it fails to rally and falls back below the breakout point, immediately dump it.

Further tips on buying
Some chart patterns one needs to be familiar. Do not anticipate their completion.
1. head-and-shoulder (easier on daily than weekly charts) most powerful and reliable of all bottom formations. Important indicators: 30 week MA not declining and crossed by prices at breakout; there must be a significant increase in volume on the breakout. Head-and-shoulder can also be indicator for a group or overall market, if several similar patterns in same time span.
2. double bottom very profitable formation when it occurs in conjunction with impressive volume, favourable relative strength and minimal overhead resistance (frequent, so look for confirmation signals).

The bigger the base, the bigger the move.

Diversify stocks and groups.

WHEN TO SELL

Dont average down in a negative situation
Dont refuse to sell because the overall market trend is bullish
Dont wait for the next rally to sell

Always have protective stop-loss. When set initial stop, pay less attention to 30 week MA and more to prior correction low. Place it below round number.
After buy on breakout, place stop-loss below lower end of base.
When trending, give it plenty of room and raise it after each substantial correction have stopped.
At stage 3, become more aggressive with stoploss. Do not wait for 30 week MA to be violated before selling.

Using trendlines
Way of locking in even more of the profits. Sell at least part position when trendline (connecting at least 3 points) violated. Either whole position stoploss just under trendline, or half there and half under last correction low.

Swing rule
Does not appear often, but very accurate. When there is an important decline, subtract new low price from previous peak, then double it: this gives potential near term price area for upswing.

Losing
Taking a loss on some positions is just a cost of doing business.

SELLING SHORT
Stocks fall much faster than they rise, because fear causes a panic reaction while greed takes a while to simmer.
Dont short a stock that is too thin or covering position will raise the price.
Dont short a stock in Stage 2 (above 30 week MA)
Dont short a stock that is part of a strong group.
Always set a buy stop.

Sequence
1. Market. Check that market is bearish
2. Group. Isolate market sectors that are potentially vulnerable. In group chart: below its 30 week MA, relative-strength is trending lower, possible negative chart pattern, several chart from that sector are technically weak
3. Individual chart pattern. Stock should have had significant runup before top was formed. Far from significant support areas.
4. Relative strength. Indicator must be trending lower.
5. Volume. Not a major priority on the short side.

Ideal to short at breakout, but ok to short well into Stage 4. However, make sure a consolidation pattern forms beneath the declining MA and then a new breakdown occurs.

MARKET LONG TERM INDICATORS
Stage analysis
30-week MA
Advance-Decline lineAs long as AD line and index are moving in gear its ok. When AD line starts losing upside momentum and the index charges higher, thats a negative divergence signalling market trouble ahead also negative divergence if the index is rallying to new high and the AD line refuses to confirm. If the divergence takes place over a short period of time (several weeks) the decline is likely to turn out to be a correction within an ongoing bull market. If the divergence continues to take shape over a long period of time (several months), then the market advance is becoming dangerously selective, with money out of the broad market and into blue chips. Sign of a problem.
When a major bottom is forming, the index will reach the ultimate low and then refuse to drop further, while the AD line continues to move lower and lower, this is a positive divergence.
Whether top or bottom, the longer a divergence lasts, the more significant the eventual reversal will be.
Graph the NYSE AD line on the same page as the DJ Industrial. Can also use point and figure on a daily basis.

Momentum index 200 day moving average of AD line. Its most important signal is the cross of the zero line (the longer it was above or below, the more significant the cross).
Its more helpful at spotting tops than bottoms. At the bottom, it acts more as a confirming signal. In a bull market, it peaks before the DJ.

New hi new lo On a weekly basis. It offers very early warning.
When consistently positive or negative, its a long term indication. When an important divergence takes shape, a reversal in the trend is starting to form.

REDUCING RISK

To increase probability of success when trading options
1. Buy a call option only on a stock that is in Stage 2 or is moving into Stage 2. Buy a put option only on a stock that is in Stage 4 or is first entering that phase
2. Buy only an option that has big potential you are going to be wrong more often with options than with stocks. Selectivity is absolutely crucial!
3. Give a reasonable amount of time before expiration 40/50 days to 3 months
4. Buy an option that is close to the striking price and, if possible, in the money. Or if its out of the money, make sure its very close to the striking price.
5. Use a very tight protective stop (mental) on option positions any sign of weakness is a reason to say goodbye to a position..
 
Status
Not open for further replies.

Similar threads