Saturday, 13 September 2014

Volume is added for MACD Colored indicator. It gives further clarity on trend.

Volume is added for MACD Colored indicator. It gives further clarity on trend.






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

MACDstyle = ParamStyle("MACD style");
Signalstyle = ParamStyle("Signal style");
Histstyle = ParamStyle("Histogram style", styleHistogram | styleThick | styleNoLabel, maskHistogram );

MACDcolor = ParamColor( "Macd One Color", colorRed );
Signalcolor = ParamColor( "Signal Color", colorBlue );
Histcolor = ParamColor( "Histogram One Color", colorRed );

TitleText = StrFormat("MACD " + "(%g,%g)", r1, r2);
PlotGrid( 0 );
_SECTION_END(); _SECTION_END ();

_SECTION_BEGIN("MACD Color");
dyncolorswitch = ParamToggle("Macd Color","On,Off");
dynamic_color = IIf( MACD(r1, r2) > Ref(MACD(r1, r2),-1), ParamColor("Macd Up Color", colorGreen ), ParamColor("Macd Down Color", colorRed ));
Plot( ml = MACD(r1, r2), TitleText, IIf(dyncolorswitch, MACDcolor , dynamic_color), MACDstyle );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), Signalcolor, Signalstyle );
_SECTION_END(); _SECTION_END ();

_SECTION_BEGIN("Histogram Color");
Histogramswitch = ParamToggle("Histogram Color","On,Off");
Histogram_color = IIf( ml-sl > Ref(ml-sl,-1), ParamColor("Hist Up Color", ColorRGB(0,0,100) ), ParamColor("Hist Down Color", colorDarkRed ));
Plot( ml-sl, "MACD Histogram", IIf(Histogramswitch, Histcolor , Histogram_color), styleNoTitle | Histstyle );
_SECTION_END(); _SECTION_END ();

_SECTION_BEGIN("Buy Sell Arrows");
shapesSignalswitch = ParamToggle("Cross Signal Arrows","On,Off");
UPcolor = ParamColor( "UP Color", colorGreen );
DOWNcolor = ParamColor( "Down Color", colorRed );
Buy=Cross( MACD(), Signal() );
Sell=Cross( Signal(), MACD() );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( IIf(shapesSignalswitch,-1e10,shape), IIf( Buy, UPcolor, DOWNcolor ));
_SECTION_END();

_SECTION_BEGIN("Fill Color");
m = MACD(r1, r2);
s = Signal(r1,r2,r3);
Cloudswitch = ParamToggle("Fill Color","On,Off");
dynamic_color = IIf( m > s, ParamColor("Down Color", ColorRGB(0,0,100) ), ParamColor("Up Color", colorDarkRed ));
PlotOHLC( IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,m),IIf(Cloudswitch,-1e10,s),IIf(Cloudswitch,-1e10,m), "", dynamic_color, styleNoLabel | styleCloud );
_SECTION_END(); _SECTION_END ();

Buy=Cross( MACD(), Signal() );
Sell=Cross( Signal(), MACD() );



PlotShapes( IIf( Buy , shapeCircle, shapeNone ),            colorWhite, 0, Graph1 , 0  );
PlotShapes( IIf( Sell , shapeCircle, shapeNone ),            colorRed, 0, Graph1 , 0  );


_SECTION_BEGIN("VOLUME_Hight of Volume Bars Control");
PlotVOL = ParamToggle( "plot Volume?","No| Yes",1);
VolColor = (C>O OR (C==O AND (H-C)<=(C-L) ))*ParamColor( "VUpColor" ,colorGreen) +
(C<O OR (C==O AND
(H-C)>(C-L)) )*ParamColor( "VDnColor" ,colorRed) ;
VolScale = Param("1/Vol. Height (TimeBar chart)(fraction of
window) 5=1/5=20%",2, 1, 100, 1.0) ; // Timebars
if (PlotVOL >0)
{
Vheight = VolScale;
Plot(Prec(Volume ,0),"V",VolColor,styleNoTitle| styleOwnScale| styleNoLabel|styleThick| ParamStyle( "VStyle", styleHistogram,maskHistogram| styleNoLabel) ,Vheight ); }
_SECTION_END();

Tuesday, 9 September 2014

NMA Swing Explorer




_SECTION_BEGIN("NMA Swing Explorer");
SetBarsRequired(200,0);

GraphXSpace = 5;
SetChartOptions(0,chartShowArrows|chartShowDates);
k =  Optimize("K",Param("K",2,0.25,5,0.25),0.25,5,0.25);
Per= Optimize("atr",Param("atr",20,3,20,1),3,20,1);
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 ) );
if( ParamToggle("Plot Heikin-Ashi", "No,Yes", 1 ) )
   PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Heikin Ashi " + Name(), colorBlack, styleCandle );
else
 Plot( C, "Regular candles " + Name(), colorBlack, styleCandle );
j=Haclose;

//=======================================================================================================================
//=========================Indicator==============================================================================================
f=ATR(15);

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 );
NMAB= NW<HACLOSE;
NMAS= NW>HACLOSE;

NMA_status= WriteIf(NMAB, "BUY MODE", WriteIf(NMAS, "SELL MODE", "NEUTRAL"));
NMAS_Col=IIf(NMAB, colorGreen, IIf(NMAS, colorRed, colorLightGrey));
Filter=1;
AddColumn( NW[BarCount-1], "SAR", 1.2 );
AddColumn( HACLOSE, "HA Close", 1.2 );
AddColumn( C, "Close", 1.2 );
AddTextColumn(NMA_status, "MODE", 1, colorWhite, NMAS_Col);
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "NICK MA Swing System" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                    
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                    
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();

5-13 EMA Channel





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


A = EMA( H,5 );
B = EMA( L,5 );

 
x= Ref(A,-13);
y= Ref(B,-13);

D=.0009;
xt=x+x*D;
xb=x-x*D;

yt=y+y*D;
yb=y-y*D;

/* Buy or Sell Condition */
Buy = Cross(Close,xt);
Sell = Cross(yt,Close);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );

/* Plotting the Channel Cloud */

PlotOHLC( 0,xt,xb,xb ,"",colorBlue, styleCloud);
PlotOHLC( 0,yt,yb,yb ,"",colorBlue, styleCloud);
PlotOHLC( 0,xt,yb,yb ,"",colorRed, styleCloud);

Title = EncodeColor(colorWhite)+ "5-13 EMA Channel Trading System" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

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

SMV Trading System - An Intraday Trading Approach

 SMV Trading System - An Intraday Trading Approach





https://www.facebook.com/StocKanalysisBd?ref=hl

_SECTION_BEGIN("SMV Trading System v1.0");



Den = Param("Density", 1, 0.25, 100, 0.25);
IBBars = Param("Initial Balance Bars", 2, 0, 5, 1);
EnIB = Param("Show Initial Balance", 1, 0, 1, 1);
EnMP = Param("Show Market Profile", 1, 0, 2, 1);

PlotOHLC(O,H,L,C,"Price",IIf(C>O,colorGreen,colorRed),styleCandle);

BarsInDay = BarsSince(Day() != Ref(Day(), -1));
Bot = TimeFrameGetPrice("L", inDaily, 0);
Top = TimeFrameGetPrice("H", inDaily, 0);
Vol = TimeFrameGetPrice("V", inDaily, 0);
POC = H - H;
VAL = H - H;
VAH = H - H;
CurTop = HHV(H,BarsInDay+1);
Curbot = LLV(L,BarsInDay+1);
Range = Highest(Top-Bot);
TodayRange = Top - Bot;

AveRange = Sum(Top-Bot,30)/30;
LAveRange = AveRange[BarCount-1];
if (LAveRange < 1) {Den = 0.05;}
else if (LAveRange < 10) {Den = 0.25;}
else if (LAveRange < 20) {Den = 0.5;}
else if (LAveRange < 100) {Den = 1;}
else if (LAveRange < 500) {Den = 5;}
else {Den = 1;}

// Initialization
baseX = 0;
baseY = floor(Bot[0]/Den)*Den;
relTodayRange = 0;
firstVisBar = Status("firstvisiblebar");
lastVisBar = Status("lastvisiblebar");

D=.000125;

for (j=0; j <= 100; j++) {
  x[j] = 0;
}

i0 = 0;
i1 = 0;
for (i=0; i<BarCount; i++) {
  if (BarsInDay[i] == 0 AND i < firstVisBar) {
    i0 = i;
  }
  if (BarsInDay[i] == 0 AND i >= lastVisBar) {
    i1 = i;
  }
}

i1 = BarCount-1;
for (i=i0; i<=i1; i++) {
  if (BarsInDay[i] == 0) {
    baseX = i;
    baseY = floor(Bot[i]/Den)*Den;
    maxY = floor(Top[i]/Den)*Den;
    relTodayRange = (maxY-baseY)/Den;

    for (j=0; j <= relTodayRange; j++) {
      x[j] = 0;
    }
  }

  if (EnMP == 2) {
    for (j=0; j<= relTodayRange; j++) {
      if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
PlotText(StrExtract("A,B,C,D,E,F,G,H,I,J,K,L,M,N",
                 BarsInDay[i]), baseX+x[j], baseY+j*Den, colorBlack);
        x[j]++;
      }
    }
  }
  else if (EnMP == 1) {
    for (j=0; j<= relTodayRange; j++) {
      if (L[i] <= baseY+j*Den AND H[i] >= baseY+j*Den) {
line = LineArray(baseX, baseY+j*Den, baseX+x[j]+1, baseY+j*Den);
Plot(line,"",ParamColor("Color", colorCustom13), styleLine+styleDots);
        x[j]++;
      }
    }
  }

 
  if (BarsInDay[i] == IBBars+1 AND EnIB == 1) {
    Line1 = LineArray(i-2, curtop[i-1],i+10, curtop[i-1],0,True);
    Line1a=Line1+d*Line1;
    Line1b=Line1-d*Line1;
    Plot(Line1,"",colorBlue,styleDots+styleThick);
    Plot(Line1a,"",colorBlue,styleDots+styleThick|styleNoLabel);
    Plot(Line1b,"",colorBlue,styleDots+styleThick|styleNoLabel);


    Line1 = LineArray(i-2, curbot[i-1],i+10, curbot[i-1],0,True);
    Line1a=Line1+d*Line1;
    Line1b=Line1-d*Line1;
    Plot(Line1,"",colorBlue,styleDots+styleThick);
    Plot(Line1a,"",colorBlue,styleDots+styleThick|styleNoLabel);
    Plot(Line1b,"",colorBlue,styleDots+styleThick|styleNoLabel);
  }

 
  if ((i < BarCount - 1 AND BarsInDay[i+1] == 0) OR i == BarCount-1) {
    maxXj = 0;
    for (j=0; j<= relTodayRange; j++) {
      if (maxXj < x[j]) {maxXj = x[j]; maxj = j;}
    }
    for (k=i-BarsInDay[i];k<=i;k++) {
      POC[k] = baseY+maxXj*Den;
    }
    Line1 = LineArray(baseX, baseY+maxXj*Den, i, baseY+maxXj*Den,0,True);
    Line1a=Line1+d*Line1;
    Line1b=Line1-d*Line1;
    //Plot(Line1,"",colorWhite,styleDots+styleThick);
    //Plot(Line1a,"",colorWhite,styleDots+styleThick|styleNoLabel);
    //Plot(Line1b,"",colorWhite,styleDots+styleThick|styleNoLabel);

  }
}

Plot(POC,"POC",colorYellow,styleDots);
_SECTION_END();


_SECTION_BEGIN("SDA2 Channel Trading System");
Derived=WMA(((H+L)/2)+(O-C),3);
i=WMA(Derived,3);
Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5;
Lower=(Derived-StDev(Derived,7))-ATR(2)/1;
color=IIf(BarsSince(Cross(Lower,C))>
BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed);
Plot(C,"",Color,64);
//Plot(Upper,"upper band",colorGreen);
//Plot(Lower,"lower band",colorDarkRed);




Buy = Cross(Close,Upper);
Sell = Cross(Lower,Close);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn( Lower, "Lower Band", 1.3 );
AddColumn( Upper, "Upper Band", 1.3 );

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


_SECTION_END();


_SECTION_BEGIN("Weekly MP");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color",colorTurquoise), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("Market Profile");
//Market Profile
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);

//===========================

Den = Param("Density", 200, 10, 300, 10);
ShowMP = ParamToggle("Show MP", "No|Yes");
ShowVP = ParamToggle("Show VP", "No|Yes");
StyleMP = ParamStyle("style MP", styleLine|styleDots, maskAll);
StyleVP = ParamStyle("style VP", styleLine|styleDots, maskAll);

//===========================

//===========================
BarsInDay =BarsSince(DayOfWeek() < Ref( DayOfWeek(), -1 ))+1;

//===========================
NewDay = DayOfWeek() > Ref( DayOfWeek(),1) OR Cum(1) == BarCount;

//===========================
Bot = TimeFrameGetPrice("L", inWeekly, 0);
Top = TimeFrameGetPrice("H", inWeekly, 0);
Vol = TimeFrameGetPrice("V", inWeekly, 0);

//===========================

Range = Highest(Top-Bot);
Box = Range/Den;
VolumeUnit = Vol/BarsInDay;

for (k = 0; k < Den; k++)            // loop through each line (price) starting at the Lowest price
{
Line = Bot + k*Box;
detect = Line >= L & Line <= H;

if(ShowMP == True)
{
CountMPString = IIf(NewDay, Sum(detect, BarsInDay), 0);
CountMPString = Ref(ValueWhen(NewDay, CountMPString, 0), -1);
MpLine = IIf(CountMPString >= BarsInDay, Line, Null);

Plot(MPLine, "", colorGreen , styleMP);
}

if(ShowVP == True)
{
CountVPString = IIf(NewDay, Sum(detect*V, BarsInDay)/VolumeUnit, 0);
CountVPString = Ref(ValueWhen(NewDay, CountVPString, 0), -1);
VpLine = IIf(CountVPString >= BarsInDay, Line + Box/4, Null);
// Plot()
Plot(VPLine, "", colorBlue, styleVP);
}
}

//Title = "{{NAME}} - {{INTERVAL}} {{DATE}} {{VALUES}} - \\c04 Market Profile  \\c06 Volume Profile";
_SECTION_END();

_SECTION_BEGIN("Price+VAP");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorOrange ), styleNoTitle | styleCandle );

////////////_SECTION_BEGIN("Volume At Price");
PlotVAPOverlay( Param("Lines", 300, 100, 1000, 1 ), Param("Width", 15, 1, 100, 1 ), ParamColor("Color", colorLightBlue ), ParamToggle("Side", "Left|Right" ) | 4*ParamToggle("Z-order", "On top|Behind", 1 ) );

_SECTION_END();

 _SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",990,1,1200,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+"  ("+xx+"%)", Hor , Ver+45 );
_SECTION_END();

Trading System for Amibroker (AFL)


System for Amibroker (AFL)



SetChartBkColor(ParamColor("BackGround Color", colorBlack));
pShowRangeLines = ParamToggle("Show Range Lines", "No|Yes", 0);
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch1=ParamToggle("Show NR,s", "No|Yes", 0);
Limit=Param(" Trade Till (Hour)(Min)(Sec)",142500,103000,153000,100);
AFfilter =Param("Factor Filter",2,2,3,1);

_SECTION_BEGIN ("foreign Index bar graph");
synch=ParamToggle("Synch with Index", "No|Yes", 0);
Vr=ParamList("Index to Synch",List = "^NSEI,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SBIN.NS",0);

_SECTION_BEGIN("P/L Settings");
PerctakeProfit=Param("Take Profit Percent",0.65,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent",0.8,0.2,5,0.1);
trades1=Param("Trade Above",1,1,10,1);
riskAmount=Param("Risk Amount",240,200,10000,100);

_SECTION_BEGIN("Trade Variables");
Volmin=Param("Volume Min",0,0,10000000,50);
Volmax=Param("Volume Max",10000000,0,10000000,50);
priceRL=Param("Price Range Min",15,1,20000,1);
priceRH=Param("Price Range Max",20000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -50, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 50, -100, 100, 0.1);


PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars  = 0;
xpdh  = 90;
_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "color",colorBlack), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
_SECTION_END();
_SECTION_BEGIN("SMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle("Style", styleThick) );
_SECTION_END();



//slopes
isSlopeUP=(MA( P, Periods )<L) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-2) AND Ref(MA( P, Periods ),-2)>Ref(MA( P, Periods ),-3) AND Ref(MA( P, Periods ),-3)>Ref(MA( P, Periods ),-4);// AND Ref(MA( P, Periods ),-4)>Ref(MA( P, Periods ),-5) AND Ref(MA( P, Periods ),-5)>Ref(MA( P, Periods ),-6);
isSlopeDN=(MA( P, Periods )>H) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-2) AND Ref(MA( P, Periods ),-2)<Ref(MA( P, Periods ),-3) AND Ref(MA( P, Periods ),-3)<Ref(MA( P, Periods ),-4);// AND Ref(MA( P, Periods ),-4)<Ref(MA( P, Periods ),-5) AND Ref(MA( P, Periods ),-5)<Ref(MA( P, Periods ),-6);
isSlpeUP=(MA( P, Periods )<C) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-2) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-3) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-4) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-5) AND Ref(MA( P, Periods ),-1)>Ref(MA( P, Periods ),-6);
isSlpeDN=(MA( P, Periods )>C) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-2) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-3) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-4) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-5) AND Ref(MA( P, Periods ),-1)<Ref(MA( P, Periods ),-6);

{
//Convert data to daily
Plot_Range = (TimeNum() >= 95500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range   = (TimeNum() >= 095500 AND TimeNum()<= 101459) AND (DateNum()==LastValue(DateNum()));

FH_Prices  = High * FH_Range;
FH_Marker  = BarsSince(FH_Range>0);

//Find number of bars in 60 minutes
Num_Bars   = 3600 / Interval(1); 

TimeFrameSet(inDaily);
TOP_        = Open;
PDH_        = Ref(High,-1);
PDL_        = Ref(Low,-1);
PDO_        = Ref(Open,-1);
PDC_        = Ref(Close,-1);
PDM_        = (PDH_+PDL_)/2;
TimeFrameRestore();
//
isAll = True;
isRth =  TimeNum() >= 095400 AND TimeNum() <= 101459;
isdRth =  TimeNum() >= 095400 AND TimeNum() <= 160000;

aRthL = IIf(isRth, L, 1000000);
aRthH = IIf(isdRth, H, Null);
aRthLd = IIf(isdRth, L, 1000000);

TOP         = TimeFrameExpand(TOP_,inDaily,expandFirst);
PDH         = TimeFrameExpand(PDH_,inDaily,expandFirst);
PDL         = TimeFrameExpand(PDL_,inDaily,expandFirst);
PDO         = TimeFrameExpand(PDO_,inDaily,expandFirst);
PDC         = TimeFrameExpand(PDC_,inDaily,expandFirst);
PDM         = TimeFrameExpand(PDM_,inDaily,expandFirst);
FHH        = Ref(HHV(High*FH_Range,Num_Bars),-FH_Marker);
FHL = TimeFrameCompress( aRthL, inDaily, compressLow );
FHL = TimeFrameExpand( FHL, inDaily, expandFirst );
DayH = TimeFrameCompress( aRthH, inDaily, compressHigh );
DayH = TimeFrameExpand( DayH, inDaily, expandFirst );
DayL = TimeFrameCompress( aRthLd, inDaily, compressLow );
DayL = TimeFrameExpand( DayL, inDaily, expandFirst );

//find factor
FC1=((PDH-PDL)*0.433);
FC2=((PDH-PDL)*0.7666);
FC3=((PDH-PDL)*1.355);
FC4=(FHH-FHL);

//NOW FILTER TO FIND THE APPLICABLE FACTOR
F11=IIf((FC4<=FC1+PDH*0.005),FC1,0);
F22=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
F33=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
element1=IIf(F11>0,F11,0);
element2=IIf(F22>0,F22,0);
element3=IIf(F33>0,F33,0);
AF=(F11+F22+F33);
since=(TimeNum() >= 101459 AND TimeNum()<= Limit) AND (DateNum()==LastValue(DateNum()));

//nr7 / nr1 /nr8

rang=High-Low;
nr7s=IIf(rang==LLV(rang,7) ,shapeDigit7+shapePositionAbove,shapeNone);
nr8s=IIf(Ref(nr7s,-1)  AND rang==LLV(rang,8) ,shapeDigit8+shapePositionAbove,shapeNone);
nr7=IIf(synch1,nr7s,0);
nr8=IIf(synch1,nr8s,0);
InsideBar = Inside() ;
nr1=IIf(nr7 AND InsideBar, shapeDigit1,shapeNone);

//foreign
SetForeign(Vr);
HaC =(O+H+L+C)/4;
HaO = AMA( Ref( HaC, -1 ), 0.5 );
HaH = Max( H, Max( HaC, HaO) );
HaL = Min( L, Min( HaC, HaO) );
BG3=HHV(LLV(HaL,4)+ATR(4),8);
BR3=LLV(HHV(HaH ,4)-ATR(4),8);
co = IIf(Hac>BG3 ,colorBrightGreen,IIf(Hac < BR3,colorRed,colorGrey50));
Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
RestorePriceArrays();
_SECTION_END();

GLong=(TOP==FHL);// AND TimeNum()<= 101600;
Gshort=(TOP==FHH);// AND TimeNum()<= 101600;
GLS=(AF<=(FHH-FHL));
advance=Foreign("NSE_Advancing","H");
decline=Foreign("NSE_Declining","H");

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1 OR H>=BuyTP1 );
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1 OR L<=SellTP1);
TSB= IIf(SAR(acc,accm)>BuyTP1 AND SAR(acc,accm)<L,SAR(acc,accm),BuyTP1);
TSB1=Cross(TSB,C);
TSS= IIf(SAR(acc,accm)<SellTP1 AND SAR(acc,accm)>H,SAR(acc,accm),SellTP1);
TSS1=Cross(C,TSS);
percchange=(((C-PDC)/PDC)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
Buy1=(Vol AND Percentage AND prc  AND since AND (Hac>BG3) AND advance>=Decline AND (Cross(C,BuyPrice)));
Buy2=(Vol AND Percentage AND prc  AND since AND advance>=Decline AND (Cross(C,BuyPrice)));
Short1= (Vol AND Percentage AND prc AND  since AND advance<=Decline AND (Hac<BR3) AND (Cross(SellPrice,C)));
Short2= (Vol AND Percentage AND prc AND  since AND advance<=Decline AND (Cross(SellPrice,C)));
Buy3 =  IIf(synch,Buy1,Buy2);
Short3= IIf(synch,Short1,Short2);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
//BuyStop1=IIf(BuyStop1<= SellPrice, SellPrice, BuyStop1 );
BuyStop2=(L<=BuyStop1 OR C<=BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
//SellStop1=IIf(SellStop1 >= BuyPrice, BuyPrice, SellStop1);
SellStop2=(H>=SellStop1 OR C>=SellStop1);


tradebase=(Buy3 OR Short3 AND since);
trades=Cum(tradebase);
trades2=(trades>=trades1);


Buy=(Buy3 AND trades2 AND isSlopeUP AND (NOT Ref(Buy3,-1) AND NOT Ref(Buy3,-2) AND NOT Ref(Buy3,-3) AND NOT Ref(Buy3,-4) AND NOT Ref(Buy3,-5))) ;
Short=(Short3  AND trades2 AND isSlopeDN AND (NOT Ref(Short3,-1) AND NOT Ref(Short3,-2) AND NOT Ref(Short3,-3)  AND NOT Ref(Short3,-4) AND NOT Ref(Short3,-5))) ;
BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop1,Null);
SellStop=IIf(Short AND NOT SellTP2,SellStop1,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);
SellTP=IIf(Short AND NOT SellStop,SellTP2,Null);


//experiment
tradebaseB=(Buy);
tradesB=Cum(tradebaseB);

BuyTP3=BuyTP2 AND TradesB>=1;
tradebaseBTP=(BuyTP3);
tradesBTP=Cum(tradebaseBTP);

Buystop3=Buystop2 AND TradesB>=1;
tradebaseBSL=(Buystop3 AND since);
tradesBSL=Cum(tradebaseBSL);

tradebaseS=(Short);
tradesS=Cum(tradebaseS);

SellTP3=SellTP2 AND TradesS>=1;
tradebaseSTP=(SellTP3);
tradesSTP=Cum(tradebaseSTP);

Sellstop3=Sellstop2 AND TradesS>=1;
tradebaseSSL=(Sellstop3 AND since);
tradesSSL=Cum(tradebaseSSL);

buyTriggered = (TradesB==1);
buyTargetHit= (TradesBTP>=1);
buyStoplossHit= (TradesBSL>=1);

shortTriggered = TradesS==1;
shortTargetHit= (TradesSTP>=1);
shortStoplossHit= (TradesSSL>=1);
//end



//line plot basics
Bars       = BarsSince(TimeNum() >= 95400 AND TimeNum() < 101459);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum());
x0         = BarCount-LastValue(Bars);
x1         = BarCount-1;
TOP_Line   = LineArray(x0,LastValue(TOP),x1,LastValue(TOP),0);
PDH_Line   = LineArray(x0,LastValue(PDH),x1,LastValue(PDH),0);
PDL_Line   = LineArray(x0,LastValue(PDL),x1,LastValue(PDL),0);
PDC_Line   = LineArray(x0,LastValue(PDC),x1,LastValue(PDC),0);
PDM_Line   = LineArray(x0,LastValue(PDM),x1,LastValue(PDM),0);
FHH_Line   = LineArray(x0,LastValue(FHH),x1,LastValue(FHH),0);
FHL_Line   = LineArray(x0,LastValue(FHL),x1,LastValue(FHL),0);
BuyPriceline=LineArray(x0,LastValue(BuyPrice),x1,LastValue(BuyPrice),0);
BuyStopline=LineArray(x0,LastValue(BuyStop1),x1,LastValue(BuyStop1),0);
BuyTPline=LineArray(x0,SelectedValue(TSB),x1,SelectedValue(TSB),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop1),x1,LastValue(SellStop1),0);
SellTPline=LineArray(x0,SelectedValue(TSS),x1,SelectedValue(TSS),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue(DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue(DayL),0);

//Ready codes
//Cshavebuy1=IIf((C>=((BuyStopline)) AND H<=BuyPriceline) AND NOT Short,Buystopline+(2*((Ref(High,-1)-Ref(Low,-1))*factor/100)),0);
//Cshavesell1=IIf((C<=((Sellstopline)) AND L>=SellPriceline) AND NOT Buy,SellStopline-(2*((Ref(High,-1)-Ref(Low,-1))*factor/100)),0);
Cshavebuy1=IIf((C>BuyStopline AND H<=BuyPriceline AND H > BuyPriceline*0.997) AND NOT Short AND since,(BuyPriceline*0.997),0);
Cshavesell1=IIf((C<Sellstopline AND L>=SellPriceline AND L<SellPriceLine*1.002) AND NOT Buy AND since,(SellPriceLine*1.002),0);
Cshavebuy2=Cshavebuy1 AND (NOT Ref(Cshavebuy1,1) AND isSlopeUP);
Cshavebuy3=Cshavebuy1 AND (NOT Ref(Cshavebuy1,1) AND ((Hac>BG3) OR (NOT (Hac>BG3) AND NOT (Hac<BR3))) AND isSlopeUP);
Cshavesell2=CshaveSell1  AND (NOT Ref(Cshavesell1,1) AND isSlopeDN);
Cshavesell3=CshaveSell1  AND (NOT Ref(Cshavesell1,1) AND ((Hac<BR3) OR (NOT (Hac>BG3) AND NOT (Hac<BR3))) AND isSlopeDN);
Cshavebuy= IIf(Synch,Cshavebuy3,Cshavebuy2);
Cshavesell=IIf(synch,Cshavesell3,Cshavesell2);



lotSize = round((riskAmount/(BuyPrice-BuyStop1)));

//PLOT LINES
Plot(IIf(pShowtradeLines,BuyPriceline,Null),"Buy Here",colorBrightGreen,styleDots|styleNoRescale);
Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuyStop",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,BuyTPline,Null),"Buy Take profit",colorBrightGreen,styleDashed|styleNoRescale);
//Plot(IIf(pShowtradeLines,Cshavebuyline,Null),"Ready Long",colorLime,styleDashed|styleNoRescale);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Short Here",colorRed,styleDots|styleNoRescale);
Plot(IIf(pShowtradeLines,SellStopline,Null),"ShortStop",colorRed,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellTPline,Null),"Short Take Profit",colorRed,styleDashed|styleNoRescale);
//Plot(IIf(pShowtradeLines,Cshavesellline,Null),"Ready Short",colorOrange,styleDashed|styleNoRescale);
Plot(IIf(pShowRangeLines,TOP_Line,Null),"Open",colorGreen,styleDashed|styleNoRescale);
Plot(IIf(pShowRangeLines,PDH_Line,Null),"PDH",colorPlum,styleLine|styleNoRescale);
Plot(IIf(pShowRangeLines,PDL_Line,Null),"PDL",colorPlum,styleLine|styleNoRescale);
Plot(IIf(pShowRangeLines,DayHline,Null),"DayH",colorYellow,styleLine|styleNoRescale);
Plot(IIf(pShowRangeLines,DayLline,Null),"DayL",colorYellow,styleLine|styleNoRescale);
Plot(IIf(pShowRangeLines,FHH_Line,Null),"1015H",IIf(FH_Range==1,Null,colorBlue),styleLine|styleNoRescale);
Plot(IIf(pShowRangeLines,FHL_Line,Null),"1015L",IIf(FH_Range==1,Null,colorBlue),styleLine|styleNoRescale);


//Shapes
PlotShapes(nr1,colorGreen,0,L);
PlotShapes(nr7,colorGreen,0,H);
PlotShapes(nr8,colorRed,0,(L-(H-L)/4));
PlotShapes(IIf(pShowMarkers AND Short, shapeDownArrow, Null), colorOrange, 0,H,Offset=-15);
PlotShapes(IIf(pShowMarkers AND Buy, shapeUpArrow, Null), colorWhite, 0,L,Offset=-15);
PlotShapes(IIf(pShowMarkers AND Cshavesell, shapeHollowSmallDownTriangle, Null), colorOrange, 0,H,Offset=-35);
PlotShapes(IIf(pShowMarkers AND Cshavebuy, shapeHollowSmallUpTriangle, Null), colorWhite, 0,L,Offset=-35);



AlertIf( Buy, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Buy",2);
AlertIf( Short, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Short", 2 );
AlertIf( BuyStop, "SOUND C:\\Windows\\Media\\Ringin.wav", "BuyStop Hit", 2 );
AlertIf( TSB1, "SOUND C:\\Windows\\Media\\Ringin.wav", "Buy Take Profit", 2 );
AlertIf( SellStop, "SOUND C:\\Windows\\Media\\Ringin.wav", "Short Stop Hit", 2 );
AlertIf( TSS1, "SOUND C:\\Windows\\Media\\Ringin.wav", "Short Take Profit", 2 );
AlertIf( Cshavebuy, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Get Ready to Buy", 2 );
AlertIf( Cshavesell, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Get Ready to Short", 2 );


if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite) + " - " +  Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - " +EncodeColor(colorYellow) + "Vol= "+ WriteVal(V)+" - "+ WriteIf(Percchange, "% Change =  "+(Percchange)+"  ","")+
WriteIf(GLS, "   -  FactorFriendlyBothSides  "+(GLS)+"  ","")+
WriteIf(trades, "   -Trade #:   "+(Trades)+"  ","")+
WriteIf(AF, "   -   AF:   "+(AF)+"  ","")+
WriteIf((lotSize) AND since, " -  Position Size :  "+( lotSize )+"  ","")+
"\n"+"\n"+

WriteIf(F11, "F1:     Best "+"  ","")+
WriteIf(F22, "F2:     Medium "+"  ","")+
WriteIf(F33, "F3:     No Good"+"  ","")+
WriteIf(F33, "F3:     No Good"+"  ","")+
Comm2=("\n"+"Slope:      ")+
WriteIf(isSlopeUP,EncodeColor(colorBrightGreen)+"+Up",
WriteIf(isSlopeDN,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >"))+
Comm2=("\n"+Vr+" :   Phase:    ")+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >"))+

"\n"+"\n"+
EncodeColor(colorBrightGreen) +
WriteIf(BuyPrice, "BUY:  "+(BuyPrice)+"  ","")+
WriteIf(BuyStop1, " - BUY SL:  "+(BuyStop1),"")+
WriteIf(TSB , "  -  BUY TP:  "+(TSB)+" ","")+
"\n"+
EncodeColor(colorRed) +
WriteIf(SellPrice, "SHORT:  "+(SellPrice)+"  ","")+
WriteIf(SellStop1, "-  SHORT SL:  "+(SellStop1)+"  ","")+
WriteIf(TSS, "   -  SHORT TP:  "+(TSS)+"  ","")+"\n"+
"\n"+
EncodeColor(colorBrightGreen) +
WriteIf(GLong, "Open=1015L Bullish:  "+(GLong)+"  ","")+
EncodeColor(colorRed) +
WriteIf(Gshort, "Open=1015H Bearish:  "+(Gshort)+"  ","")+
"\n"+
EncodeColor(colorBrightGreen) +
WriteIf(advance, "Advance:  "+(advance)+"  ","")+
EncodeColor(colorRed) +
WriteIf(decline, "   -  Decline:  "+(Decline)+"  ",""));




AddColumn( IIf(Cshavebuy, 82, IIf(Cshavesell, 82,01 )), "READY", formatChar, IIf(Cshavesell,colorDarkRed,colorGreen) );
AddColumn( IIf(Buy, 66, IIf(Short, 83,01 )), "ACTION ", formatChar, IIf(Short,colorDarkRed,colorGreen) );
AddTextColumn(
WriteIf(element1,"F1",
WriteIf(element2,"F2",
WriteIf(element3,"F3",
""))),"ELEMENT",1.0,
IIf((element1 OR element2),colorDarkGreen,colorDarkRed));

AddColumn(BuyPrice,"Buy",1.2);
AddColumn(BuyStop1,"Buy SL",1.2);
AddColumn(TSB,"Buy TP",1.2);
AddColumn(SellPrice,"Short",1.2);
AddColumn(SellStop1,"Short SL",1.2);
AddColumn(TSS,"Short TP",1.2);
Filter= IIf(AFfilter==2,Buy OR  Short OR Cshavebuy OR Cshavesell AND (element1 OR element2),Buy OR  Short OR Cshavebuy OR Cshavesell AND (element1 OR element2 OR element3));// OR  GLong OR Gshort);// AND trades2 AND GLS;
}

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

Volume Price Analysis (VPA) v1.1 for Amibroker (AFL)

Volume Price Analysis (VPA) v1.1 for Amibroker (AFL)





//====================================================================================
_SECTION_BEGIN("Volume Price Analysis - V.1.0");
SetChartOptions(0,chartShowArrows|chartShowDates);
//=======================================================================================
DTL=Param("Linear regression period",60,10,100,10);
wbf=Param("WRB factor",1.5,1.3,2.5,.1);
nbf=Param("NRB factor",0.7,0.3,0.9,0.1);
TL=LinRegSlope(MA(C, DTL),2);
 Vlp=Param("Volume lookback period",30,20,300,10);
Vrg=MA(V,Vlp);
St = StDev(Vrg,Vlp);
Vp3 = Vrg + 3*st;
Vp2 = Vrg + 2*st;;
Vp1 = Vrg + 1*st;;
Vn1 = Vrg -1*st;
Vn2 = Vrg -2*st;
rg=(H-L);
arg=Wilders(rg,30);
wrb=rg>(wbf*arg);
nrb=rg<(nbf*arg);
Vl=V<Ref(V,-1) AND V<Ref(V,-2);
upbar=C>Ref(C,-1);
dnbar=C<Ref(C,-1);
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2);
Cloc=C-L;
x=rg/Cloc;
x1=IIf(Cloc=0,arg,x);
Vb=V>Vrg OR V>Ref(V,-1);
ucls=x1<2;
dcls=x1>2;
mcls=x1<2.2 AND x1>1.8 ;
Vlcls=x1>4;
Vhcls=x1<1.35;
j=MA(C,5);
TLL=LinRegSlope(j,40) ;
Tlm=LinRegSlope(j,15) ;
tls=LinRegSlope(j,5);
mp=(H+L)/2;
_SECTION_END();
//==========================================================================================
_SECTION_BEGIN("VSA");
utbar=wrb AND dcls AND tls>0 ;
utcond1=Ref(utbar,-1) AND dnbar ;
utcond2=Ref(utbar,-1) AND dnbar AND V>Ref(V,-1);
utcond3=utbar AND V> 2*Vrg;
trbar=Ref(V,-1)>Vrg  AND Ref(upbar,-1) AND Ref(wrb,-1) AND dnbar AND dcls AND wrb AND tll>0 AND H==HHV(H,10);
Hutbar=Ref(upbar,-1) AND Ref(V,-1)>1.5*Vrg AND dnbar AND dcls AND NOT wrb AND NOT utbar;
Hutcond=Ref(Hutbar,-1) AND dnbar AND dcls AND NOT utbar;
tcbar=Ref(upbar,-1) AND H==HHV(H,5)AND dnbar AND (dcls OR mcls) AND V>vrg AND NOT wrb AND NOT Hutbar ;
Scond1=(utcond1 OR utcond2 OR utcond3) ;
Scond2=Ref(scond1,-1)==0;
scond=scond1 AND scond2;
stdn0= tll<0 AND V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn= V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0;
stdn1= tll<0 AND V>(vrg*1.5) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls)AND tls<0 AND tlm<0;
stdn2=tls<0 AND Ref(V,-1)<Vrg  AND upbar AND vhcls AND V>Vrg;
bycond1= stdn OR stdn1;
bycond= upbar  AND Ref(bycond1,-1);
stvol= L==LLV(L,5)  AND (ucls OR mcls) AND V>1.5*Vrg AND tll<0;
ndbar=upbar AND nrb AND Vl  AND dcls ;
nsbar=dnbar AND nrb AND Vl  AND dcls ;
nbbar= C>Ref(C,-1) AND Vl AND nrb AND x1<2;
nbbar= IIf(C>Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND x1<1.1,1,0);
lvtbar= vl AND L<Ref(L,-1) AND ucls;
lvtbar1= V<Vrg AND L<Ref(L,-1) AND ucls AND tll>0 AND tlm>0 AND wrb;
lvtbar2= Ref(Lvtbar,-1) AND upbar AND ucls;
dbar= V>2*Vrg AND dcls AND upbar AND tls>0 AND tlm>0 AND NOT Scond1 AND NOT utbar;
eftup=H>Ref(H,-1) AND L>Ref(L,-1) AND C>Ref(C,-1) AND C>=((H-L)*0.7+L) AND rg>arg AND V>Ref(V,-1);
eftupfl=Ref(eftup,-1) AND (utbar OR utcond1 OR utcond2 OR utcond3);
eftdn=H<Ref(H,-1) AND L<Ref(L,-1) AND C<Ref(C,-1) AND  C<=((H-L)*0.25+L) AND rg>arg AND V>Ref(V,-1);
_SECTION_END();
//=======================================================================================================================
_SECTION_BEGIN("Chart");
Vcolor=IIf(tls>0 AND tlm>0 AND tll>0,colorLime,IIf(tls>0 AND tlm>0 AND tll<0,colorGreen,
IIf(tls>0 AND tlm<0 AND tll<0,colorPaleGreen,IIf(tls<0 AND tlm<0 AND tll<0,colorRed,IIf(tls<0 AND tlm>0 AND tll>0,colorPaleGreen,
IIf(tls<0 AND tlm<0 AND tll>0,colorOrange,colorBlue))))));
GraphXSpace = 5;
PlotOHLC( Open,  High,  Low,  Close, "", vcolor, styleBar | styleThick  );
_SECTION_END();
//============================================================================================================================
// commentary
_SECTION_BEGIN("Commentary");
Vpc= utbar OR utcond1 OR utcond2 OR utcond3 OR stdn0 OR stdn1 OR stdn2 OR stdn OR lvtbar1 OR Lvtbar OR Lvtbar2 OR Hutbar OR Hutcond OR ndbar OR stvol OR tcbar;

if( Status("action") == actionCommentary )
(
printf ( "=========================" +"\n"));
printf ( "VOLUME PRICE ANALYSIS" +"\n");
printf ( "www.vpanalysis.blogspot.com" +"\n");
printf ( "=========================" +"\n");
printf ( Name() + " - " +Interval(2) +  "  - " + Date() +" - " +"\n"+"High-"+H+"\n"+"Low-"+L+"\n"+"Open-"+O+"\n"+
"Close-"+C+"\n"+ "Volume= "+ WriteVal(V)+"\n");
WriteIf(Vpc,"=======================","");
WriteIf(Vpc,"VOLUME ANALYSIS COMMENTARY:\n","");

WriteIf(utbar , "Up-thrusts are designed to catch stops and to mislead as many traders as possible. 
They are normally seen after there has been weakness in the background. The market makers know that the
market is weak, so the price is marked up to catch stops, encourage traders to go long in a weak market,
AND panic traders that are already Short into covering their very good position.","")+
WriteIf(utcond3,"This upthrust bar is at high volume.This is a sure sign of weakness. One may even seriously
consider ending the Longs AND be ready to reverse","")+WriteIf(utbar OR utcond3," Also note that A wide spread
down-bar that appears immediately after any up-thrust, tends to confirm the weakness (the market makers are
locking in traders into poor positions).
With the appearance of an upthrust you should
certainly be paying attention to your trade AND your stops. On many upthrusts you will find that the market will
'test' almost immediately.","")+WriteIf(utcond1 , "A wide spread down bar following a Upthrust Bar.
This confirms weakness. The Smart Money is locking in Traders into poor positions","");
WriteIf(utcond2 , "Also here the volume is high( Above Average).This is a sure sign of weakness. The Smart Money is
locking in Traders into poor positions","")+WriteIf(stdn, "Strength Bar. The stock has been in a down Trend. An upbar
with higher Volume closing near the High is a sign of strength returning. The downtrend is likely to reverse soon. ","")+
WriteIf(stdn1,"Here the volume is very much above average. This makes this indication more stronger. ","")+
WriteIf(bycond,"The previous bar saw strength coming back. This upbar confirms strength. ","")+
WriteIf(Hutbar," A pseudo Upthrust. This normally appears after an Up Bar with above average volume. This looks like an upthrust bar
closing down near the Low. But the Volume is normally Lower than average. this is a sign of weakness.If the Volume is High then weakness
increases. Smart Money is trying to trap the retailers into bad position. ","")+
WriteIf(Hutcond, "A downbar after a pseudo Upthrust Confirms weakness. If the volume is above average the weakness is increased. ","")+
WriteIf(Lvtbar2,"The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength","")+
WriteIf(dbar,"A wide range, high volume bar in a up trend closing down is an indication the Distribution is in progress. The smart money
is Selling the stock to the late Comers rushing to Buy the stock NOT to be Left Out Of a Bullish move. ","")+
WriteIf(Lvtbar2,"The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength","")+
WriteIf(tcbar,"The stock has been moving up on high volume. The current bar is a Downbar with high volume. Indicates weakness and probably end of the up move","")+
WriteIf(eftup,"Effort to Rise bar. This normally found in the beginning of a Markup Phase and is bullish sign.These may be found at the top of an Upmove as the Smart money makes a
last effort to move the price to the maximum","")+
WriteIf(eftdn,"Effort to Fall bar. This normally found in the beginning of a Markdown phase.","")+

WriteIf(nsbar,"No Supply. A no supply bar indicates supply has been removed and the Smart money can markup the price. It is better to wait for confirmation","")+
WriteIf(stvol,"Stopping Volume. This will be an downbar during a bearish period closing towards the Top accompanied by High volume.
A stopping Volume normally indicates that smart money is absorbing the supply which is a Indication that they are Bullishon the MArket.
Hence we Can expect a reversal in the down trend. ","")+
WriteIf(ndbar, "No Demand
Brief Description:
Any up bar which closes in the middle OR Low, especially if the Volume has fallen off,
is a potential sign of weakness.

Things to Look Out for:
if the market is still strong, you will normally see signs of strength in the next few bars,
which will most probably show itself as a:
* Down bar with a narrow spread, closing in the middle OR High.
* Down bar on Low Volume.","");
_SECTION_END();
_SECTION_BEGIN("Advanced Trend Lines");
ShowSR   = ParamToggle("Show Vert S/R","No|Yes", 0);
SRPer    = Param("S/R Percentage", 3, 1);
SRBack   = Param("S/R Back", 5, 1);
function GetXSupport(Lo, Percentage, Back)
{
 return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back)));
}
function GetYSupport(Lo, Percentage, Back)
{
 return (LastValue(Trough(Lo, Percentage, back)));
}

function GetXResistance(Hi, Percentage, Back)
{
 return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back)));
}
function GetYResistance(Hi, Percentage, Back)
{
 return (LastValue(Peak(Hi, Percentage, Back)));
}

if(ShowSR)
{
    for(i=1; i<=SRBack; i++)
    {
        x0 = GetXSupport(L, SRPer, i);
        x1 = BarCount-1;
        y0 = GetYSupport(L, SRPer, i);
        x = LineArray(x0, y0, x1, y0, 0);
        Plot(x, "", IIf(LastValue(C) > x, colorGreen, colorRed), styleLine|styleDashed|styleThick);
        x0 = GetXResistance(H, SRPer, i);
        y0 = GetYResistance(H, SRPer, i);
        x = LineArray(x0, y0, x1, y0, 0);
        Plot(x, "", IIf(LastValue(C) > x, colorGreen, colorRed), styleLine|styleDashed|styleThick);

    }
}


//=========================================================================================
//ploting the chart shapes
_SECTION_BEGIN("Indications");
PlotShapes( shapeSmallSquare*(utbar AND NOT scond) , colorRed, 0, H, 10 );
PlotShapes(shapeSmallCircle*trbar, colorBlue, 0, H, 20 );
PlotShapes(shapeSmallDownTriangle*scond, colorRed, 0, H,-20);
PlotShapes(shapeSmallSquare*stdn, colorLime, 0, L, -20 );
PlotShapes(shapeSmallSquare*stdn1, colorLime, 0, L, -20 );
PlotShapes(shapeSmallSquare*lvtbar1, colorLime, 0, L, -20 );
PlotShapes(shapeSmallUpTriangle*lvtbar2, colorYellow, 0, L, -20 );
PlotShapes(shapeHollowSmallCircle*stvol, colorLime, 0, L, -10 );
PlotShapes(shapeSmallUpTriangle*bycond, colorLime, 0, L, -20 );
PlotShapes(shapeSmallSquare*(Hutbar) , colorBlue, 0, H, 10 );
PlotShapes(shapeSmallDownTriangle*(Hutcond) , colorBlue, 0, H, -20 );
PlotShapes(shapeSmallDownTriangle*tcbar , colorYellow, 0, H, -20 );
PlotShapes(shapeSmallUpTriangle*stdn2, colorAqua, 0, L, -20 );
PlotShapes(shapeSmallSquare*(dbar) , colorBlue, 0, H, 10 );
PlotShapes(shapeSmallSquare*lvtbar, colorCustom12, 0, L, -20);
PlotShapes(shapeSmallSquare*(ndbar) , colorBlue, 0, H, 10 );
PlotShapes(shapeSmallCircle*nsbar, colorLime, 0, L, -20 );
PlotShapes(shapeSmallCircle*eftup, colorTurquoise, 0, mp, 0 );
PlotShapes(shapeSmallCircle*eftdn, colorYellow, 0, mp, 0 );

_SECTION_END();
//======================================================================================================================================================================================
//TITLE
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Volume Price Analysis" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - " +EncodeColor(colorLime)+ "Volume= "+WriteVal(V)+"--"+EncodeColor(colorYellow)+
WriteIf (utbar, " An Upthrust Bar. A sign of weakness. ","")+
WriteIf (utcond1, " A downbar after an Upthrust. Confirm weakness. ","")+
WriteIf (utcond2 AND NOT utcond1, " A High Volume downbar after an Upthrust. Confirm weakness.","")+
WriteIf (utcond3, "This upthrust at very High Voume, Confirms weakness","")+
WriteIf (stdn1, "Strength seen returning after a down trend. High volume adds to strength. ","")+
WriteIf (stdn0 AND NOT stdn, "Strength seen returning after a down trend. ","")+
WriteIf (stdn AND NOT stdn1, "Strength seen returning after a long down trend. ","")+
WriteIf (Lvtbar, "Test for supply. ","")+
WriteIf (Lvtbar2, "An Upbar closing near High after a Test confirms strength. ","")+
WriteIf (bycond, "An Upbar closing near High. Confirms return of Strength. ","")+
WriteIf (dbar, "A High Volume Up Bar closing down in a uptrend shows Distribution. ","")+
WriteIf (Hutbar, "Psuedo UpThrust.   A Sign of Weakness. ","")+
WriteIf (Hutcond, "A Down Bar closing down after a Pseudo Upthrust confirms weakness. ","")+
WriteIf (Lvtbar1, "Test for supply in a uptrend. Sign of Strength. ","")+
WriteIf (stdn2, "High volume upbar closing on the high indicates strength. ","")+
WriteIf (Tcbar, "High volume Downbar after an upmove on high volume indicates weakness. ","")+
WriteIf (ndbar, "No Demand. A sign of Weakness. ","")+
WriteIf (nsbar, "No Supply. A sign of Strength. ","")+
WriteIf (eftup, "Effort to Rise. Bullish sign ","")+
WriteIf (eftdn, "Effort to Fall. Bearish sign ","")+
WriteIf (eftupfl, "Effort to Move up has failed. Bearish sign ","")+
WriteIf (stvol, "Stopping volume. Normally indicates end of bearishness is nearing. ","")+
("\n Volume: ")+WriteIf(V>Vp2,EncodeColor(colorLime)+"Very High",WriteIf(V>Vp1,EncodeColor(colorLime)+" High",WriteIf(V>Vrg,EncodeColor(colorLime)+"Above Average",
WriteIf(V<Vrg AND V>Vn1,EncodeColor(colorRed)+"Less than Average",WriteIf(V<Vn1,"Low","")))))+
(EncodeColor(colorYellow)+"      Spread: ")+WriteIf(rg >(arg*2),EncodeColor(colorLime)+" Wide",WriteIf(rg>arg,EncodeColor(colorLime)+" Above Average",EncodeColor(colorRed)+" Narrow"))+
(EncodeColor(colorYellow)+"      Close:  ")+WriteIf(Vhcls,EncodeColor(colorLime)+"Very High",WriteIf(ucls,EncodeColor(colorLime)+"High",WriteIf(mcls,EncodeColor(colorYellow)+"Mid",
WriteIf(dcls,EncodeColor(colorRed)+"Down","Very Low"))))+
("\n Trend: ")+WriteIf(tls>0,EncodeColor(colorLime)+"  Short Term-UP",EncodeColor(colorRed)+"  Short Term-Down")+
WriteIf(tlm>0,EncodeColor(colorLime)+"         MID Term-UP",EncodeColor(colorRed)+"        Mid Term-Down")+
WriteIf(tll>0,EncodeColor(colorLime)+"       Long Term-Up",EncodeColor(colorRed)+"         Long term-Down"));
_SECTION_END();
//============================================================================================================================================================================================
_SECTION_BEGIN("Exploration");


lqok=V>Vrg;
Cond=stdn1 OR bycond  OR stdn2 OR ndbar OR tcbar OR utbar OR utcond1 OR trbar;
color = IIf(stdn1, colorPaleGreen,IIf(bycond , colorGreen,IIf(stdn2, colorBrightGreen,
        IIf(ndbar, colorYellow,IIf(Tcbar, colorOrange,IIf(utbar OR  utcond1, colorRed,IIf(trbar,colorCustom12,colorWhite)))))));
Filter = (cond AND lqok) ;

AddTextColumn(
WriteIf(stdn1,"Strenth Seen",
WriteIf(bycond ,"STR + ",
WriteIf(stdn2,"Strength Pronouced",
WriteIf(ndbar,"Weakness seen",
WriteIf(Tcbar,"WEAK",
WriteIf(utbar OR  utcond1,"Weakness pronounced",
WriteIf(trbar,"Reversal Likely",""))))))),"Strength Meter",1,colorDefault,color);


_SECTION_BEGIN("Name");
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/6 );
GfxSetTextAlign( 6 );// center alignment

GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/12 );

GfxSelectFont("Tahoma", Status("pxheight")/36 );

_SECTION_END();
//======================================================================================

Trend Manager- Translated by karthikmarar




//Trend Manager- Translated by karthikmarar from MT4 code for inditraders.com forum
//AFL works on amibroker version 5.20 and above
SetChartBkColor(colorBlack);
p=Param("period",7,3,20,1);
pl1=ParamToggle("Plot Stoploss line","No,Yes",0);
pl2=ParamToggle("Plot Setup signals","No,Yes",0);


Hx=IIf(H<Ref(H,-p),Ref(H,-p),H);
Lx=IIf(L>Ref(L,-p),Ref(L,-p),L);

Hxl=IIf(H<Ref(H,-p),Ref(H,-p),H);
Lxl=IIf(L>Ref(L,-p),Ref(L,-p),L);
spana=(Hx+Lx)/2;
spanb=Ref(spana,-2);
for( i = p; i < BarCount; i++ )
{
if (spana[i]>spanb[i])
   {
    H1[i]=spana[i]; 
    L1[i]=spanb[i];
    O1[i]=L1[i];
    C1[i]=H1[i];
    }
else
   {
    H1[i]=spanb[i]; 
    L1[i]=spana[i];
    O1[i]=H1[i];
    C1[i]=L1[i];
    }
}

SetBarFillColor( IIf(C>spanb,colorBlue,colorRed) );
PlotOHLC(O1,H1,L1,C1,"",IIf(H>spana,colorBlack,colorBlack),ParamStyle("Plot Style",styleBar,maskPrice));
Plot(C,"",ParamColor("Bar Color",colorLime),128+4);
pd=(C>spanb AND Ref(C,-1)>Ref(spanb,-1));
nd=(C<spana AND Ref(C,-1)<Ref(spana,-1));
Buysetup= PD;
Shortsetup=nd;
Buysetupvalid=Flip (Buysetup, Shortsetup);
Shortsetupvalid=Flip (Shortsetup, Buysetup);
Buy=Cover= Ref (Buysetupvalid, - 1) ==1 AND H>ValueWhen (buysetup, H) +0.01;
Short=Sell=Ref (Shortsetupvalid, - 1) ==1 AND L<ValueWhen (Shortsetup, L) - 0.01;
Buy=ExRem (Buy, Sell);
Sell=ExRem (Sell, Buy);
Short=ExRem (Short, Cover);
Cover=ExRem (Cover, Short);
inlong=Flip(Buy,Sell);
inshort=Flip(Sell,Buy);
Plot(IIf(Buysetup AND pl1,spanb,Null),"",colorRed,styleDashed);
Plot(IIf(shortsetup AND pl1,spanb,Null),"",colorRed,styleDashed);
shortsetupvalid=ExRem (shortsetupvalid, buysetupvalid);
buysetupvalid=ExRem (buysetupvalid, shortsetupvalid);
PlotShapes (IIf (shortsetupvalid AND pl2,shapeDownTriangle, shapeNone), colorRed, 0, H, - 40);
PlotShapes (IIf (buysetupvalid AND pl2,shapeUpTriangle, shapeNone), colorGreen, 0, L, - 40);


SetChartOptions(0,chartShowArrows|chartShowDates);
Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )+
 "\n"+"tm High = "+WriteVal(spana,1.4)
 + "\n"+"tm Low = "+WriteVal(spanb,1.4);

KAMA SYSTEM--AMA System by Karthikmarar









_SECTION_BEGIN("KAMA System");

SetChartOptions(0,chartShowArrows|chartShowDates);
Title = ("KAMA SYSTEM - " + Name()+"  " + Date() +"  "+Interval(2) +"  "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");



bs=Param("BUY Sensitivity",3,2,20,1);
bf=Param("BUY Finetune",2,0.1,20,0.1);
// Sell Adjustments
ss=Param("SELL Sensitivity",3,2,20,1);
sf=Param("SELL Finetune",1,0.1,20,0.1);
//stock selection parameters
MyCL = Param( "CL", 10, 10, 100, 10 );
MyVK = Param( "VK", 30, 10, 100, 10 );
MyTL = Param( "TL", 300, 100, 1000, 100 );

fast = 2/(2+1);
slow = 2/(30+1);
//BUY part
dirb=abs(Close-Ref(Close,-bs));
volb=Sum(abs(Close-Ref(Close,-1)),bs);
ERb=dirb/volb;
scb =( ERb*(fast-slow)+slow)^2;
xb = AMA( C, scb );
flb=bf*StDev(xb-Ref(xb,-1),20);
j=xb-Ref(xb,-3);


//SELL part
dirs=abs(Close-Ref(Close,-ss));
vols=Sum(abs(Close-Ref(Close,-1)),ss);
ERs=dirs/vols;
scs =( ERs*(fast-slow)+slow)^2;
xs = AMA( C, scs );
fls=sf*StDev(xs-Ref(xs,-1),20);
k=Ref(Xs,-3)-Xs;

Buy=Cross(j,flb) ;
Sell=Cross(k,fls);
mycolor=IIf(C>xb,colorLime,colorRed);
Plot( C, "Close", mycolor,styleNoTitle | styleBar|styleThick   );
Plot(xb,"KAMA-BUY",colorYellow,1);
Plot(xs,"KAMA-SELL",colorOrange,1);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

shape = Buy * shapeUpArrow +Sell * shapeDownArrow ;

PlotShapes( shape, IIf( Buy, colorGreen, colorYellow ),0, IIf( Buy, Low, High ) );

GraphXSpace = 5;
dist = 1.5*ATR(20);

for( i = 0; i < BarCount; i++ )
{
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorLime );
if( Sell[i] ) PlotText( "sell\n@" + C[ i ], i, L[ i ]+dist[i], colorYellow );
}
Filter= Buy OR Sell;

PositionScore=100/C;
PositionSize = - 20;
SetBarsRequired(10000, 10000);
SetFormulaName("KAMA System");

_SECTION_END();

_SECTION_BEGIN("IIR2");

function IIR2( input, f0, f1, f2 )
// the function body
{
result[ 0 ] = input[ 0 ];
result[ 1 ] = input[ 1 ];
for( i = 2; i < BarCount; i++ )
{
result[i] = f0 * input[i] + f1 * result[i-1] + f2 * result[i-2];
}

return result;
}

SmoothedClose = IIR2(Close, 0.2, 1.4, -0.6 );

Plot( SmoothedClose, "function example", colorRed );

_SECTION_END();

_SECTION_BEGIN("GSMA");
SetBarsRequired(100000,0);
PI = 3.1415926;

function jIIR2( input, f0, f1, f2 )
{
    result[ 0 ] = input[ 0 ];
    result[ 1 ] = input[ 1 ];

    for( i = 2; i < BarCount; i++ )
    {
       result[ i ] = f0 * input[ i ] +
                     f1 * result[ i - 1 ] +
                     f2 * result[ i - 2 ];
    }

   return result;
}

function GSMA( input, Period )
{
  N = 0;
  an = 2 * PI / Period;
  c0 = b0 = 1;
  c1 = b1 = b2 = a1 = a2 = gamma1 = 0;
  beta1 = 2.415 * ( 1- cos( an ) );
  alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 );
  alpha1 = ( cos( an ) + sin( an ) - 1 )/cos( an );
   {
    fo = alpha ^ 2;
    f1 = 2 * ( 1- alpha ); f2 = -( 1 - alpha )*( 1 - alpha );
  }
 

  return jIIR2( input, fo,f1,f2);
}
period=Param("period",13,1,40,1);


Plot( GSMA( C,period), "GSMA", colorLime );


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



x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );




LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");

LRLine =  IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); //  styleDots );


SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;

width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;

SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");

Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );


SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;

width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );  
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;

SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");

Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );


CROSS OVER BUY AND SELL VER 2 for Amibroker (AFL)

CROSS OVER BUY AND SELL   for Amibroker (AFL)





https://www.facebook.com/StocKanalysisBd?ref=hl



trendup = IIf(MACD(12,26) > 0 AND MACD(12,26) > Signal(12,26,9), colorBlue, colorWhite);
trendcolor = IIf(MACD(12,26) < 0 AND MACD(12,26) < Signal(12,26,9), colorRed, trendup);
Plot( C, "Close", trendcolor, styleBar | styleThick );



sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
RSIup = r > 70;
RSIdown = r < 30;

shape = RSIup * shapeNone + RSIdown * shapeNone;
PlotShapes(shape, IIf( RSIup, colorBrightGreen, colorRed ), 0, IIf( RSIup, Low, High ) );

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

SetChartBkColor(ParamColor("Panel color ",colorBlack));

PlotOHLC( Open,  High,  Low,  Close, "", colorLime, styleBar| styleThick   );



_SECTION_BEGIN("trailstops");
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( TrailStop, "Trailing stop", colorGold, styleThick | styleLine  );
Plot( C, "Price", color, styleBar  );

Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );


_SECTION_BEGIN("GFX EMA");
procedure Plotlinewidth(pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,pshowdate)
{
local pvalue,ptitle,pcolor,pstyle,pmin,pmax,pxshift,plinewidth,ppenstyle,pshowdate;
local Miny,Maxy; local Lvb,fvb; local pxwidth,pxheight; local TotalBars,axisarea; local i,x,y;
if(plinewidth>0 && Status("action") == 1 && (pstyle & styleLine==styleLine)){
GfxSetOverlayMode(0);
Miny=Status("axisminy"); Maxy=Status("axismaxy");
lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar");
pxwidth=Status("pxwidth"); pxheight=Status("pxheight");
TotalBars=Lvb-fvb; xaxisarea=56;
if(pshowdate)yaxisarea=10;
else
yaxisarea=0; i=0;
x=5+i*(pxwidth-xaxisarea-10)/( TotalBars+1);
y=5+yaxisarea+(pvalue[i+fvb]-Miny)*(pxheight-yaxisarea-10)/(Maxy-Miny);
GfxMoveTo(x,pxheight - y);
for(i=1; i<TotalBars AND i<(BarCount-fvb); i++)
{
GfxSelectPen(pcolor[i + fvb],plinewidth,0);
x=5+i*(pxwidth-xaxisarea-10)/(TotalBars+1);
y=5+yaxisarea+(pvalue[i+fvb]-Miny)*(pxheight-yaxisarea-10)/(Maxy-Miny);
GfxLineTo(x,pxheight - y);
}}}
RequestTimedRefresh(2);
_SECTION_END();



_SECTION_BEGIN("Small Triggers");
p1 = Param("TL 1 Periods", 20, 5, 50, 1);
p2 = Param("TL 2 Periods", 5, 3, 25, 1);
TL1 = LinearReg(C, p1);
TL2 = EMA(TL1, p2);
Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12));
Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("Large Triggers");
p3 = Param("TL 3 Periods", 80, 5, 100, 1);
p4 = Param("TL 4 Periods", 20, 3, 100, 1);
TL3 = LinearReg(C, p3);
TL4 = EMA(TL3, p4);
Col1 = IIf(TL3 > TL4, ParamColor("TLL Up Colour", colorBlue), ParamColor("TLL Dn Colour", colorRed));
Plot(TL3, "TriggerLine 3", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL4, "TriggerLine 4", Col1, styleLine|styleThick|styleNoLabel);
_SECTION_END();

_SECTION_BEGIN("Fibo Retrace and Extensions");
fibs = ParamToggle("Plot Fibs","Off|On",1);
pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
Back = Param ("Extend Left = 2",1,1,500,1);
Fwd  = Param("Plot Forward", 0, 0, 500, 1);
text = ParamToggle("Plot Text","Off|On",1);
hts  = Param ("Text Shift", -33.5,-50,50,0.10);
style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp  = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp  = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;

function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
AND xSp0 > xRp0, ySp0 + retval, Null))));
return FibVal;
}

x0 = Min(xSp0,xRp0)-Back;
x1 = (BarCount -1);

r236 = fib(0.236); r236I = LastValue (r236,1);
r382 = fib(0.382); r382I = LastValue (r382,1);
r050 = fib(0.50); r050I = LastValue (r050,1);
r618 = fib(0.618); r618I = LastValue (r618,1);
r786 = fib(0.786); r786I = LastValue (r786,1);
e127 = fib(1.27); e127I = LastValue (e127,1);
e162 = fib(1.62); e162I = LastValue (e162,1);
e200 = fib(2.00); e200I = LastValue (e200,1);
e262 = fib(2.62); e262I = LastValue (e262,1);
e424 = fib(4.24); e424I = LastValue (e424,1);

p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
color100 =IIf(xSp0 < xRp0,colorLime,colorRed);

numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);

if(fibs==1)
{
Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
}

if(text==1)
{
PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I  + 0.05, color00);
PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
}
_SECTION_END();


farback=Param("How Far back to go",100,50,5000,10);
nBars = Param("Number of bars", 12, 5, 40);



Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",

H: " + High + ", L: " + Low + ", C: " + Close;



PlotOHLC(Open, High, Low, Close,

"BIdx = " + BarIndex() +

"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L

+ "\n"+"C ",

colorBlack, styleBar);

GraphXSpace=7;

aHPivs = H - H;

aLPivs = L - L;



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;



aHHVBars = HHVBars(H, nBars);

aLLVBars = LLVBars(L, nBars);

aHHV = HHV(H, nBars);

aLLV = LLV(L, nBars);



aVisBars = Status("barvisible");

nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));

_TRACE("Last visible bar: " + nLastVisBar);



curBar = (BarCount-1);

curTrend = "";

if (aLLVBars[curBar] <

aHHVBars[curBar]) {

curTrend = "D";

}

else {

curTrend = "U";

}


for (i=0; i<farback; i++) {

curBar = (BarCount - 1) - i;



if (aLLVBars[curBar] < aHHVBars[curBar]) {



if (curTrend == "U") {

curTrend = "D";



curPivBarIdx = curBar - aLLVBars[curBar];

aLPivs[curPivBarIdx] = 1;

aLPivLows[nLPivs] = L[curPivBarIdx];

aLPivIdxs[nLPivs] = curPivBarIdx;

nLPivs++;

}


} else {

if (curTrend == "D") {

curTrend = "U";

curPivBarIdx = curBar - aHHVBars[curBar];

aHPivs[curPivBarIdx] = 1;

aHPivHighs[nHPivs] = H[curPivBarIdx];

aHPivIdxs[nHPivs] = curPivBarIdx;

nHPivs++;

}



}



}



curBar = (BarCount-1);

candIdx = 0;

candPrc = 0;

lastLPIdx = aLPivIdxs[0];

lastLPL = aLPivLows[0];

lastHPIdx = aHPivIdxs[0];

lastHPH = aHPivHighs[0];

if (lastLPIdx > lastHPIdx) {



candIdx = curBar - aHHVBars[curBar];

candPrc = aHHV[curBar];

if (

lastHPH < candPrc AND

candIdx > lastLPIdx AND

candIdx < curBar) {



aHPivs[candIdx] = 1;



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 {




candIdx = curBar - aLLVBars[curBar];

candPrc = aLLV[curBar];

if (

lastLPL > candPrc AND

candIdx > lastHPIdx AND

candIdx < curBar) {




aLPivs[candIdx] = 1;



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

}

}





PlotShapes(

IIf(aHPivs==1, shapeHollowDownArrow, shapeNone), colorRed, 0,

High, Offset=-15);

PlotShapes(

IIf(aLPivs==1, shapeHollowUpArrow , shapeNone), colorBrightGreen, 0,

Low, Offset=-15);
_SECTION_END();

_SECTION_BEGIN("Dots Color");
acc = Param("Acceleration", 0.01, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.1, 0, 1, 0.001 );
myColor = IIf (C > SAR( acc, accm ) , colorTurquoise , colorRed);
Plot( SAR( acc, accm ), _DEFAULT_NAME(), myColor , ParamStyle("Style", styleDots |styleThick | styleNoLine, maskDefault | styleDots | styleThick | styleNoLine ) );
_SECTION_END();

SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));

Monday, 8 September 2014

Explorer for Amibroker (AFL)


Explorer for Amibroker (AFL)




_SECTION_BEGIN("All in One Explorer - Otithi");
i=0;

High52 = HHV(High,250);
Low52 = LLV(Low,250);


BB1=C>BBandTop(C,20,2) AND Ref(C,-1)<Ref(BBandTop(C,20,2),-1);
BB2=C<BBandBot(C,20,2) AND Ref(C,-1)>Ref(BBandBot(C,20,2),-1);
BBStatus=WriteIf(BB1,"Above Top",WriteIf(BB2,"Below Bottom",WriteIf(IsNull(MA(C,20)),"N/A","Neutral")));
BBColor=IIf(BB1,colorRed,IIf(BB2,colorGreen,colorLightGrey));
IIf(BB2,i+1,i);


MAShort = C>MA(C,15);
IIf(MAShort,i+1,i);
MAMid = C>MA(C,45);
IIf(MAMid,i+1,i);
MALong = C>MA(C,100);
IIf(MALong,i+1,i);
ShortStatus = WriteIf(MAShort,"Bullish",WriteIf(IsNull(MA(C,15)) ,"N/A","Bearish"));
ShortColor = IIf(MAShort,colorGreen,colorRed);
MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,45))," N/A","Bearish"));
MidColor = IIf(MAMid,colorGreen,colorRed);
LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
LongColor = IIf(MALong,colorGreen,colorRed);


MACDBull=MACD(12,26)>Signal(12,26,9);
IIf(MACDBull,i+1,i);
MACDStatus=WriteIf(MACDBull,"Bullish",WriteIf(IsNull(MACD(12,26)),"N/A","Bearish"));
MACDColor=IIf(MACDBull,colorGreen,colorRed);


Period=14;
LLVBarsSince=LLVBars(L,Period)+1;
HHVBarsSince=HHVBars(H,Period)+1;
AroonDown=100*(Period-LLVBarsSince)/(Period-1);
AroonUp=100*(Period-HHVBarsSince)/(Period-1);
AroonOsc=AroonUp-AroonDown;
Aroon=AroonOsc>0;
IIf(Aroon,i+1,i);
AroonStatus=WriteIf(Aroon,"Bullish",WriteIf(IsNull (RSI(14)),"N/A","Bearish"));
AroonColor=IIf(Aroon,colorGreen,IIf(IsNull(RSI(14) ),colorLightGrey,colorRed));


StochKBull=StochK(14,3)>StochD(14,3,3);
IIf(StochKBull,i+1,i);
StochKStatus=WriteIf(StochKBull,"Bullish",WriteIf( IsNull(StochK(14,3)),"N/A","Bearish"));
StochKColor=IIf(StochKBull,colorGreen,colorRed);

R1=RSI(14)>30 AND Ref(RSI(14),-1)<30 AND Ref(RSI(14),-2)<30;
R2=RSI(14)<70 AND Ref(RSI(14),-1)>70 AND Ref(RSI(14),-2)>70;
IIf(R1,i+1,i);
RSIStatus=WriteIf(R1,"Improving",WriteIf(R2,"Decli ning",WriteIf(IsNull(RSI(14)),"N/A","Neutral")));
RSIColor=IIf(R1,colorGreen,IIf(R2,colorRed,colorLightGrey));

M1=MFI(14)>80;
M2=MFI(14)<20;
IIf(M2,i+1,i);
MFIStatus=WriteIf(M1,"Overbought",WriteIf(M2,"Over sold",WriteIf(IsNull(MFI(14)),"N/A","Neutral")));
MFIColor=IIf(M1,colorRed,IIf(M2,colorGreen,colorLightGrey));


 TrendScore =

 IIf(BB2,1,0)+
 IIf(MAShort,1,0)+
 IIf(MAMid,1,0) +
 IIf(MAMid,1,0) +
 IIf(MALong,1,0)+
 IIf(MACDBull,1,0) +
 IIf(Aroon,1,0) +
 IIf(StochKBull,1,0)+
 IIf(R1,1,0) +
 IIf(M2,1,0) ;







Filter = 1;

AddColumn(High52,"52 Week High");
AddColumn(Low52,"52 Week Low");
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddTextColumn(BBStatus,"BBand",1,colorWhite,BBColor);
AddTextColumn(ShortStatus,"Short MA(15)",1,colorWhite,ShortColor);
AddTextColumn(MidStatus,"Mid MA(45)",1,colorWhite,MidColor);
AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
AddTextColumn(MACDStatus,"MACD",1,colorWhite,MACDColor);
AddTextColumn(AroonStatus,"Aroon",1,colorWhite,AroonColor);
AddTextColumn(StochKStatus,"Stochastic",1,colorWhite,StochKColor);
AddTextColumn(RSIStatus,"RSI(14)",1,colorWhite,RSIColor);
AddTextColumn(MFIStatus,"MFI(14)",1,colorWhite,MFIColor);
AddColumn(TrendScore,"Score");
_SECTION_END();

Profit Trading system with Target and Stoploss for Amibroker (AFL)




Profit Trading system with Target and Stop-loss for Amibroker (AFL)

https://www.facebook.com/StocKanalysisBd?ref=hl


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

SD = StochD(8, 3, 3);
MH = MACD(8, 21) - Signal(8, 21, 5);
trendup = IIf(MH > 0 OR (MH > 0 AND MH > Ref(MH, -1)) AND RSI(3) >50 AND SD < 80 AND SD > Ref(SD, -1) AND ValueWhen(C,O<C), colorBlue, colorWhite);
trendcolor = IIf(MH < 0 OR (MH < 0 AND MH < Ref(MH, -1)) AND RSI(3) <50 AND SD > 20 AND SD < Ref(SD, -1) AND ValueWhen(C,O>C), colorRed, trendup);
Plot( C, "Close", trendcolor, styleCandle | styleThick );

_SECTION_END();

no=Param( "Swing", 5, 1, 55 );
res=HHV(H,no);
sup=LLV(L,no);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);
Plot(tsl, _DEFAULT_NAME(), colorBlue, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C)  ;
_SECTION_END();

a=C;
g=(EMA(Close,3) * (2 / 4 - 1)-EMA(Close,5) * (2 / 6 - 1)) / (2 /4- 2 /6);
e=Ref(tsl,-1);
Buy = Cross(C,tsl) ;
Sell = Cross(tsl,C)  ;
SellPrice=ValueWhen(Sell,e,1);
BuyPrice=ValueWhen(Buy,e,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
Filter=Buy OR Sell;
Buy = Cross(C,tsl) ;
Sell = Cross(tsl,C)  ;
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
a1=Ref(tsl,-1);

dist = 0.8*ATR(1); //0.8
dist1 = 1.8*ATR(1); //1.2
for( i = 0; i < BarCount; i++ )
{
 if( Buy[i] )
 {
  PlotText( "Buy:" + L[ i ] + "\nTgt: " + (a1[i]*1.005) + "\nSL: " + (tsl[i]*0.9975), i, L[ i ]-dist[i], colorLime);
 }
 if( Sell[i] )
 {
  PlotText( "Sell:" + H[ i ] + "\nT: " + (a1[i]*0.995) + "\nSL: " + (tsl[i]*1.0025), i, H[ i ]+dist1[i], colorBlack);
 }
}