Tuesday 9 September 2014

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

No comments:

Post a Comment

Thanks