Thursday, 29 September 2011

NAKSHATRA AFL

_SECTION_BEGIN("MA Diff");
T=26;
KMA=((C-MA(C,T))/MA(C,T))*100;
Graph0=KMA;
Graph0Style=2+4;
Graph0BarColor=IIf(KMA>0,5,4);
GraphXSpace=5;

_SECTION_END();

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", ParamColor("Color", colorRed ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//------------------------------------------------------------------------------

_SECTION_BEGIN("ZIG-ZAG");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();

_SECTION_BEGIN("MACD Exploration");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Z=Param("zig",1,0,10,0.1);


Cond1 = Cross(MACD(r1,r2),Signal(r1,r2,r3));

Cond3 = Zig(C,z)>Ref(Zig(C,z),-4);
Buy = Cond1 AND Cond3;

Cond4 = Cross(Signal(r1,r2,r3),MACD(r1,r2));

Cond6 = Zig(C,z)<Ref(Zig(C,z),-4);
Sell = Cond4 AND Cond6;
Trigger = WriteIf(Buy, "Buy", "") + WriteIf(Sell, "Sell", "");

_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}}: O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, V=%1.0f\n{{VALUES}}", O, H, L, C, V));

BG = IIf(Buy, colorPaleGreen, IIf(Sell, colorRose, colorDefault));
FG = IIf(Buy, colorDarkGreen, IIf(Sell, colorDarkRed, colorDefault));

if(Status("action") == actionIndicator)
{
Plot(C, "", colorGrey50, styleBar);
PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorBlue, 0,L, Offset=-60);
PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorWhite, 0,H, Offset=-30);
PlotShapes(shapeDownArrow*Sell,colorYellow,0,SellPrice,0);
PlotShapes(shapeUpArrow*Buy,colorYellow,0,BuyPrice,0);

}

//------------------------------------------------------------------------------------------------
if(Status("action") == actionExplore)

Filter = Buy OR Sell;
SetOption("NoDefaultColumns", True);

AddTextColumn(Name(), "Symbol", 77, FG, BG, 120);
AddColumn(DateTime(), "Date", formatDateTime, FG, BG, 100);
AddColumn(TimeNum() ,"Time",1);
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
AddColumn(V, "Volume");
AddColumn(Ref(V,-1),"P-Vol");
AddColumn(V/Ref(V,-1)*100,"Increase in Vol");
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );

shape = Buy * shapeHollowUpTriangle + Sell * shapeHollowDownTriangle;

PlotShapes( shape, IIf( Buy, colorBlue, colorWhite ), 0, IIf( Buy, Low, High ) );

GraphXSpace = 7;

GraphXSpace = 7;
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
_SECTION_END();


_SECTION_BEGIN("Background text");
C13=Param("fonts",20,10,30,1 );
C14=Param("left-right",2.1,1.0,5.0,0.1 );
C15=Param("up-down",12,1,20,1 );
Miny = Status("axisminy");
Maxy = Status("axismaxy");
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxwidth = Status("pxwidth");
pxheight = Status("pxheight");
GfxSetBkMode(transparent=1);
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/C13 );
GfxSetTextAlign( 6 );
GfxSetTextColor( ColorRGB (217,217,213));
GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "By", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
GfxSetTextColor( ColorRGB (103,103,103));
GfxTextOut( "Nakshatra", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
//Second phase starts Here
//File: BHS Chart
_SECTION_BEGIN("BHS1.02");
SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow));
SetChartBkColor(ParamColor("BackGround Color", colorDarkGrey));
pShowtradeLines = ParamToggle("Show Trade Lines", "No|Yes", 1);
pShowMarkers = ParamToggle("Show Markers", "No|Yes", 1);
synch=ParamToggle("Synchronize buy/short with foreign index", "No|Yes", 1);
Volmin=Param("Volume minimum",5000,0,10000000,50);
Volmax=Param("Volume maximum",1000000,0,10000000,50);
priceRL=Param("Price Range Min",150,1,20000,1);
priceRH=Param("Price Range Max",3000,1,20000,1);
PercChangemin=Param("Percentage Change Min set", -25, -100, 100, 0.1);
PercChangemax=Param("Percentage Change Max set", 25, -100, 100, 0.1);
PerctakeProfit=Param("Take Profit Percent Set",0.6,0.3,30,0.1);
PercStoploss=Param("StopLoss Percent Set",0.25,0.2,5,0.1);

//PlotOHLC(Open,High,Low,Close,"",colorWhite,styleCandle);
Bars = 0;
xpdh = 90;

{
Plot_Range = (TimeNum() >= 85500 AND TimeNum()<= 153500) AND (DateNum()==LastValue(DateNum()));
FH_Range = (TimeNum() >= 085500 AND TimeNum()<= 093000) AND (DateNum()==LastValue(DateNum()));

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

Num_Bars = 36000 / 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() >= 085400 AND TimeNum() <= 093000;
isdRth = TimeNum() >= 085400 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 );


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

A=IIf((FC4<=FC1+PDH*0.005),FC1,0);
B=IIf((FC4<=FC2+PDH*0.005 AND FC4>FC1+PDH*0.005),FC2,0);
Cl=IIf((FC4<=FC3 AND FC4>FC2+PDH*0.005),FC3,0);
AF=(A+B+Cl);

//foreign
_SECTION_BEGIN ("foreign Index bar graph");
Vr=ParamList("Index",List = "NIFTY_SPT,^NSEI,^NSEBANK,^CNXIT,^NSMIDCP,RELIANCE.NS,SBIN.N S",0);
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();

BuyPrice=(DayL+AF);
BuyTP1=(BuyPrice+(BuyPrice*(PerctakeProfit/100)));
BuyTP2=(C>=BuyTP1);
SellPrice=(DayH-AF);
SellTP1=(SellPrice-(SellPrice*(PerctakeProfit/100)));
SellTP2=(C<=SellTP1);
percchange=(((C-TOP)/TOP)*100);
Vol=(V>=Volmin AND V<=Volmax);
Percentage=(percchange>=PercChangemin AND percchange<=PercChangemax);
prc=(C>=priceRL AND C<=priceRH);
BuyStop1=(BuyPrice-(BuyPrice*(PercStoploss/100)));
BuyStop2=IIf((BuyStop1<=SellPrice) AND SellPrice<=BuyPrice,SellPrice,BuyStop1);
SellStop1=(SellPrice+(SellPrice*(PercStoploss/100)));
SellStop2=IIf((SellStop1>=BuyPrice) AND SellPrice<=BuyPrice, BuyPrice,SellStop1);

BuyStop=IIf((Buy AND NOT BuyTP2),BuyStop2,Null);
BuyTP=IIf(Buy AND NOT BuyStop,BuyTP2,Null);

Bars = BarsSince(TimeNum() >= 85400 AND TimeNum() < 092900);
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(BuyStop2),x1,LastValue(BuyStop2),0);
BuyTPline=LineArray(x0,LastValue(BuyTP1),x1,LastValue(BuyTP1),0);
SellPriceline=LineArray(x0,LastValue(SellPrice),x1 ,LastValue(SellPrice),0);
SellStopline=LineArray(x0,LastValue(SellStop2),x1, LastValue(SellStop2),0);
SellTPline=LineArray(x0,LastValue(SellTP1),x1,LastValue(SellTP1),0);
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0);


Plot(IIf(pShowtradeLines,BuyStopline,Null),"BuySto p",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(IIf(pShowtradeLines,SellPriceline,Null),"Shor t Here",colorRed,styleDots|styleNoRescale);
PlotShapes(IIf(pShowMarkers AND Buy, shapeHollowUpArrow, Null), colorDarkGreen, 0,L,Offset=-30);

if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ "Nakshatra Super " + " - " + Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
" - " + Date() +" - "+ EncodeColor(colorYellow) + "-Open="+WriteVal(O,1) + EncodeColor(colorYellow) + "- High= "+ WriteVal(H,1)+ EncodeColor(colorYellow) + "- Low= "+ WriteVal(L,1)+ EncodeColor(colorYellow) + "- Close= "+ WriteVal(C,1)+ EncodeColor(colorYellow) + "- Vol= "+ WriteVal(V,1)+("\n")
+WriteIf(Percchange, " % Change = "+(Percchange)+" ","")+" Previous DayHigh="+WriteVal(PDH,1)+", Previous DayLow="+WriteVal(PDL,1)+", Today High="+WriteVal(DayH,1)+", Todays Low="+WriteVal(DayL,1)+
WriteIf(Hac>BG3,EncodeColor(colorBrightGreen)+"+Up ",
WriteIf(Hac<BR3,EncodeColor(colorRed)+"-Down",EncodeColor(colorLightYellow)+"< Flat >")));
/*
GfxSetOverlayMode( mode = 0 );
GfxSelectPen( colorRed, 3 );
GfxSelectSolidBrush( colorPink );
GfxRoundRect( 20, 55, 180, 175, 15, 15 );
GfxSetBkMode(1);
GfxSelectFont( "Arial", 10, 700, False );
GfxSetTextColor( colorDarkBlue );
GfxSetTextAlign(0);
GfxTextOut( WriteIf(SellPrice, "TRP level: "+(SellPrice),""), 30, 60);
GfxTextOut( WriteIf(BuyPrice, "Buy Above: "+(BuyPrice),""), 30, 75);
GfxTextOut( WriteIf(BuyStop2, "Long SL: "+(BuyStop2),""), 30, 90);
GfxTextOut( WriteIf(BuyTP1 , "Long Target 1: "+(BuyTP1),""), 30, 105);
GfxTextOut( WriteIf(SellPrice, "Sell Below: "+(SellPrice),""), 30, 120);
GfxTextOut( WriteIf(SellStop2, "Short SL: "+(SellStop2),""), 30, 135);
GfxTextOut( WriteIf(SellTP1, "Short Target: "+(SellTP1),""), 30, 150);
*/
AddColumn(V,"Volume",1.0);
AddColumn(Percchange,"Change %",1.2);
AddColumn(BuyPrice,"Buy at",1.2);
AddColumn(BuyStop,"Buy Stop at",1.2);
AddColumn(BuyTP1,"Buy Profit at",1.2);
AddColumn(SellPrice,"Short at",1.2);
AddColumn(SellTP1,"Short profit at",1.2);

}

_SECTION_END();


_SECTION_BEGIN("short signal");
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 ) );
BG2=HHV(LLV(Low,4)+ATR(4),8);
BR2=LLV(HHV(High,4)-ATR(4),8);
SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=HaClose;
nm= (H-L);
rfsctor = WMA(nm, 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];
}
}
}
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
dist = 1.5*ATR(15);
for( i = 0; i < BarCount; i++ )
{
//if( Buy[i] ) PlotText( "Buy@" + O[ i ], i, L[ i ]-Trend[i], colorDarkBlue, colorYellow );
//if( Sell[i] ) PlotText( "Sell@" +H[ i ], i-4, L[ i ]+Trend[i], colorRed, colorYellow );
}

//PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,halow,-30);
//PlotShapes(IIf(Sell, shapeHollowDownTriangle, shapeNone),colorWhite, 0,hahigh,-15);
//PlotShapes(IIf(Cover, shapeHollowUpTriangle, shapeNone),colorWhite, 0,halow,-15);
//PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,hahigh,-30);

Wednesday, 28 September 2011

BUY - SELL afl(banknifty - positional)

//------------------------------------------------------------------------------
//
//  Kenzie SR System - 09/2010
//  Modified By Kenzie Sebastian (kenziesr@ * .co.id)
//  Shared for milis amibroker-4-bei@ * groups.com
//
//------------------------------------------------------------------------------

SetBarsRequired(200,0);

GraphXSpace = 7;
SetChartOptions(0,chartShowArrows|chartShowDates);


//---------------Color------------------------
per1=6;
per2=2;
Om=MA(O,per1);
hm=MA(H,per1);
lm=MA(L,per1);
Cm=MA(C,per1);

HACLOSE=(Om+Hm+Lm+Cm)/4;
HaOpen = AMA( Ref( HaClose,  -1 ),  0.5 );
HaHigh = Max( Hm,  Max( HaClose,  HaOpen ) );
HaLow = Min( Lm,  Min( HaClose,  HaOpen ) );

Of=MA(Haopen,per2);
Cf=MA(Haclose,per2);
Lf=IIf(haOpen<haClose,MA(Halow,per2),MA(Hahigh,per2));
Hf=IIf(haOpen<haClose,MA(Hahigh,per2),MA(Halow,per2));
//Color = IIf( Cf > Of, colorGreen, colorRed );


//----------------------------------------------------


TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);


  /* **********************************

Code to automatically identify pivots

********************************** */

// -- what will be our lookback range for the hh and ll?
farback=140; //How Far back to go
nBars = 12; //Number of bars

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

}

}


//============== EXPLORATION ==============
Buy=Cover=aLPivs==1;
Sell=Short=aHPivs==1;
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );

//============== Plot price ==============

n = 15;
a =  C > (MA(H,n)+MA(L,n))/2;// then Buy next bar at market;
b = C < (MA(H,n)+MA(L,n))/2;// then Sell Short next bar at market;

state=IIf(BarsSince(a)<BarsSince(b),1,0);

Longs=state==1;
shorts=state==0;

//Chart
Colorbar = IIf(Longs, colorGreen, IIf(Shorts, colorRed, colorGrey40));

Plot( C, "Close", colorbar, styleCandle = 64 | styleNoTitle );


//============== Plot Shape ==============

PlotShapes(

IIf(aHPivs==1, shapeDownArrow, shapeNone), colorOrange, 0,

High, Offset=-12);

PlotShapes(
IIf(aLPivs==1, shapeUpArrow , shapeNone), colorLime, 0,

Low, Offset=-12);

//============== EMA(13) ==============

//Plot(EMA(C, 8), "", colorWhite,
///        styleLine+styleNoRescale);

//============== TRENDING ==============

DTL=150; // DTL = Define Trend Long
DTM=70;    // DTM = Define Trend Medium
DTS=14;  // DTS = Define Trend Short

TL=LinRegSlope(MA(C, DTL),2);     // TL = Trend Long
TM=LinRegSlope(MA(C, DTM),2);  // TM = Trend Medium
TS=LinRegSlope(MA(C, DTS),2);  // TS = Trend Short

TLL=IIf(LinRegSlope(MA(C, DTL),2) > 0,True, False);      
TMM=IIf(LinRegSlope(MA(C, DTM),2) > 0,True, False);      
TSS=IIf(LinRegSlope(MA(C, DTS),2) > 0,True, False);      


//============== VOLUME ==============
Vlp=30; //Volume lookback period
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;

//============== WILLIAM'S %R ==============
WR = ((HHV(H,14) - C) /(HHV (H,14) -LLV (L,14))) *-100;

//============== A/D ==============
TRH = IIf(Ref(C, -1) > H, Ref(C, -1), H);
TRL = IIf(Ref(C, -1) < L, Ref(C, -1), L);
ad = IIf(C > Ref(C, -1), C - TRL, IIf(C < Ref(C, -1), C - TRH, 0));
WAD = Cum(ad);
wu = wad > Ref(wad,-1);
wd = wad < Ref(wad,-1);

//============== MACD ==============
MB= Cross (MACD(), Signal());
MS = Cross( Signal(), MACD());
MB = ExRem(MB, MS);
MS = ExRem(MS, MB);
MB1= MACD() > Signal();
MS1= MACD() < Signal();

//============== STOCH ==============
StochKval = StochK(10,5);
StochDval = StochD(10,5,5);
StochBuy = Cross(StochK(10,5), StochD(10,5,5));
StochSell = Cross (StochD(10,5,5), StochK(10,5));
StBuy=StochK(10,5)>StochD(10,5,5);
StSell=StochK(10,5)<StochD(10,5,5);

//============== ADX ==============
adxBuy =  Cross(PDI(14), MDI(14));
adxSell = Cross(MDI(14), PDI(14));
adxBuy = ExRem(adxBuy, adxSell);
adxSell = ExRem(adxSell, adxBuy);
adxbuy1 = PDI(14) > MDI(14);
adxsell1 = MDI(14)> PDI(14);


//============== TMA ==============
function ZeroLagTEMA( array, period )
{
 TMA1 = TEMA( array, period );
 TMA2 = TEMA( TMA1, period );
 Diff = TMA1 - TMA2;
 return TMA1 + Diff ;
}
haClose = ( haClose + haOpen + haHigh + haLow )/4;
periodtm = 55;
ZLHa = ZeroLagTEMA( haClose, periodtm );
ZLTyp = ZeroLagTEMA( Avg, periodtm );
TMBuy = Cross( ZLTyp, ZLHa );
TMSell = Cross( ZLHa, ZLTyp );
TMBuy1= ZLTyp> ZLHa ;
TMSell1=ZLHa> ZLTyp ;

//============== ZLW ==============
R = ((HHV(H,14) - C) /(HHV (H,14) -LLV (L,14))) *-100;
MaxGraph=10;
PeriodZ= 10;
EMA1= EMA(R,PeriodZ);
EMA2= EMA(EMA1,5);
Difference= EMA1 - EMA2;
ZeroLagEMA= EMA1 + Difference;
PR=100-abs(ZeroLagEMA);
MoveAvg=MA(PR,5);
ZBuy = Cross(PR,moveAvg) AND PR<30;
ZSell = Cross(moveAvg,PR) AND PR>70;
ZBuy1= PR>= MoveAvg AND PR>= Ref(PR,-1) ;
ZSell1=(PR < MoveAvg) OR PR>= MoveAvg AND PR< Ref(PR,-1) ;

//============== RS ==============
p = (H+L+C)/3;
r1 = (2*p)-L;
s1 = (2*p)-H;
r2 = p +(r1 - s1);
s2 = p -(r2 - s1);
R3 = P + (R2 - S2);
S3 = P - (R3 - S2);

//============== IBUY ==============
Ibuy =  Cross(RSI(14), EMA(RSI(14),9));
Isell = Cross(EMA(RSI(14),9), RSI(14));
Ibuy = ExRem(Ibuy, ISell);
Isell = ExRem(ISell, Ibuy);
BlRSI = RSI(14) > EMA(RSI(14),9);
BrRSI = RSI(14) < EMA(RSI(14),9);


//============== TITLE ==============
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorGold)+ "Kenzie SR System" + EncodeColor(colorRose)+" (" +  Name() + ") " + EncodeColor(colorGold)+ Interval(2) +
 "  " + Date() +" " +" •  Open "+WriteVal(O,1.0)+"  •  "+"Hi "+WriteVal(H,1.0)+"  •  "+"Lo "+WriteVal(L,1.0)+"  •  "+
"Close "+WriteVal(C,1.0)+" ("+WriteVal(C-Ref(C,-1),1,0)+" "+WriteVal((C-Ref(C,-1))*100/Ref(C,-1),1.1)+ "%)  •  Vol= "+ WriteVal(V,1.0)
+" "+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(ColorRGB(255,0,128))+"(Less than Average)",WriteIf(V<Vn1,"(Low)","")))))+EncodeColor(colorGrey50)+"  •  "
+EncodeColor(colorGreen)+"EMA(Close,13) = "+WriteVal(EMA(C,13),1.2)


+"\n"+EncodeColor(47)+"• AccDist(): " + WriteIf(wu,EncodeColor(colorBrightGreen)+"Accumulation",WriteIf(wd,EncodeColor(colorRed)+"Distribution","Neutral"))

+"\n"+ EncodeColor(47) +"• RSI(14): " +WriteIf(RSI(14)>10 AND RSI(14)<90,EncodeColor(colorBrightGreen),WriteIf(RSI(14)<10 ,EncodeColor(07),EncodeColor(colorRed))) + WriteVal(RSI(14),format=1.1)
 +WriteIf(RSI(14)>10 AND RSI(14)<90," Range"+EncodeColor(colorBrightGreen),WriteIf(RSI(14)<10 ," OverSold"+EncodeColor(07)," OverBought"+EncodeColor(colorRed)))

+"\n"+ EncodeColor(47) +"• CCI(14): " +WriteIf(CCI(14)>-100 AND CCI(14)<100,EncodeColor(colorBrightGreen),WriteIf(CCI(14)<-100 ,EncodeColor(07),EncodeColor(colorRed))) + WriteVal(CCI(14),format=1.1)
 +WriteIf(CCI(14)>-100 AND CCI(14)<100," Range"+EncodeColor(colorBrightGreen),WriteIf(CCI(14)<-100 ," OverSold"+EncodeColor(07)," OverBought"+EncodeColor(colorRed)))

+"\n"+ EncodeColor(47) +"• ROC(C,14): " +WriteIf(ROC(C,14)>-10 AND ROC(C,14)<10,EncodeColor(colorBrightGreen),WriteIf(ROC(C,14)<-10 ,EncodeColor(07),EncodeColor(colorRed))) + WriteVal(ROC(C,14),format=1.1)
 +WriteIf(ROC(C,14)>-10 AND ROC(C,14)<10," Range"+EncodeColor(colorBrightGreen),WriteIf(ROC(C,14)<-10 ," OverSold"+EncodeColor(07)," OverBought"+EncodeColor(colorRed)))

+"\n"+ EncodeColor(47) +"• Wm%R(14): " +WriteIf(WR>-80 AND WR<-20,EncodeColor(colorBrightGreen),WriteIf(WR<-80 ,EncodeColor(07),EncodeColor(colorRed))) + WriteVal(WR,format=1.1)
 +WriteIf(WR>-80 AND WR<-20," Range"+EncodeColor(colorBrightGreen),WriteIf(WR<-80 ," OverSold"+EncodeColor(07)," OverBought"+EncodeColor(colorRed)))



+"\n"+EncodeColor(colorGold)+"• Signal(IBuy): " + WriteIf(Ibuy,EncodeColor(colorBrightGreen)+"BuyWarning",WriteIf(Isell,EncodeColor(colorRed)+"SellWarning",WriteIf(BlRSI,EncodeColor(colorBrightGreen)+"BullishZone",WriteIf(BrRSI,EncodeColor(colorRed)+"BearishZone","Neutral"))))

+"\n"+EncodeColor(colorGold)+"• Signal(TMA): " + WriteIf(TMBuy,EncodeColor(colorBrightGreen)+"Buy",WriteIf(TMSell,EncodeColor(colorRed)+"Sell",WriteIf(TMBuy1,EncodeColor(colorBrightGreen)+"Bullish",WriteIf(TMSell1,EncodeColor(colorRed)+"Bearish","Neutral"))))

+"\n"+EncodeColor(colorGold)+"• Signal(MACD): " + WriteIf(MB,EncodeColor(colorBrightGreen)+"Buy",WriteIf(MS,EncodeColor(colorRed)+"Sell",WriteIf(MB1,EncodeColor(colorBrightGreen)+"Bullish",WriteIf(MS1,EncodeColor(colorRed)+"Bearish","Neutral"))))

+"\n"+EncodeColor(colorGold)+"• Signal(Stoch): " + WriteIf(StochBuy,EncodeColor(colorBrightGreen)+"Buy",WriteIf(StochSell,EncodeColor(colorRed)+"Sell",WriteIf(StBuy,EncodeColor(colorBrightGreen)+"Bullish",WriteIf(StSell,EncodeColor(colorRed)+"Bearish","Neutral"))))

+"\n"+EncodeColor(colorGold)+"• Signal(ADX): " + WriteIf(adxBuy,EncodeColor(colorBrightGreen)+"Buy",WriteIf(adxSell,EncodeColor(colorRed)+"Sell",WriteIf(adxBuy1,EncodeColor(colorBrightGreen)+"Bullish",WriteIf(adxSell1,EncodeColor(colorRed)+"Bearish","Neutral"))))



);


//============== BACKGROUND NAME ==============

pxwidth = Status("pxwidth");
pxheight = Status("pxheight");

GfxSetOverlayMode(1);
GfxSetBkMode(0); // transparent
GfxSelectFont("Amienne", Status("pxheight")/15);
GfxSetTextColor( colorGrey40 );
//GfxTextOut( "Kenzie Sebastian", Status("pxwidth")/5.3, Status("pxheight")/5 );

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

////BACKGROUND COLOR////////////////////////////////////////////////////////
SetChartBkColor(ColorRGB(255,200,255));
SetChartBkGradientFill( colorPlum, colorPlum);
/////////////////////////////////////////////////////////////////////////////////////



_SECTION_END();

_SECTION_BEGIN("NMA ");  
k =  Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
j=(O+H+L+C)/4;
nm= (H-L);
rfsctor = WMA(nm, 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];
   }
  }
 }
}

Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

//---------------trading  -------------

Buy=Cross(j,nw);
Short=Cross(nw,j);
Sell=Cross(nw,j);
Cover=Cross(j,nw);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
PlotShapes(IIf(Cover, shapeHollowCircle, shapeNone),colorTan, 0,Close,0);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
//-----------end--------------
Long=Flip(Buy,Sell OR Cover);
Shrt=Flip(Sell,Buy OR Cover);
NOTrade= NOT (Long OR shrt);
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
_SECTION_END();

Saturday, 24 September 2011

GANN Signals

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C,
SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorOrange ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );
//gann breakout formula
YH=HHV(Close,365);
YEL=LLV(Close,365);
YCENTRE=(YH+YEL)/2;
yhov=IIf(Close>ycentre,yEL,yel);
g1=sqrt(yEL);
x1=Param("GANN MULTIPLIER",2,0.5,5,0.5);
L0=floor((g1-1*X1)^2);
L1=floor((g1-0*x1)^2);
L2=floor((g1+1*x1)^2);
L3=floor((g1+3*x1)^2);
L4=floor((g1+4*x1)^2);
L5=floor((g1+5*x1)^2);
L6=floor((g1+6*x1)^2);
L7=floor((g1+7*x1)^2);
L8=floor((g1+8*x1)^2);
L9=floor((g1+9*x1)^2);
L10=floor((g1+10*x1)^2);
L11=floor((g1+11*x1)^2);
L12=floor((g1+12*x1)^2);
L13=floor((g1+13*X1)^2);
L14=floor((g1+14*X1)^2);
L15=floor((g1+15*X1)^2);
L16=floor((g1+16*X1)^2);
L17=floor((g1+17*X1)^2);
L18=floor((g1+18*X1)^2);
L19=floor((g1+19*X1)^2);
L20=floor((g1+20*X1)^2);
Cx=C+0.12345;
//choosing the current levels//
x=IIf(Cx>L0 AND cx<L1,L0,IIf(cx>L1 AND cx<L2,L1,IIf(cx>L2 AND
cx<L3,L2,IIf(cx>L3 AND cx<L4,L3,IIf(cx>L4 AND cx<L5,L4,IIf(cx>L5 AND
cx<L6,L5,IIf(cx>L5 AND cx<L7,L6,IIf(cx>L7 AND cx<L8,L7,IIf(cx>L8 AND
cx<L9,L8,IIf(cx>L9 AND cx<L10,L9,IIf(cx>L10 AND cx<L11,L10,IIf(cx>L11 AND
cx<L12,L11,IIf(cx>L12 AND cx<L13,L12,IIf(cx>L13 AND cx<L14,L13,IIf(cx>L14 AND
cx<L15,L14,IIf(cx>L15 AND cx<L16,L15,IIf(cx>L16 AND cx<L17,L16,IIf(cx>L17 AND
cx<L18,L17,IIf(cx>L18 AND cx<L19,L18,IIf(cx>L19 AND
cx<L20,L19,L20))))))))))))))))))));
p=IIf(x==L0,L0,IIf(x==L1,L1,IIf(x==L2,L2,
IIf(x==L3,L3,IIf(x==L4,L4,IIf(x==L5,L5, IIf(x==L6,L6 ,IIf(x==L6,L6 ,
IIf(x==L7,L7 ,IIf(x==L8,L8 ,IIf(x==L9,l9,IIf(x==L10,L10
,IIf(x==L11,L11,IIf(x==L12,L12,IIf(x==L13,L13,IIf(x==L14,L14,IIf(x==L15,L15,IIf(x==L16,L16,IIf(x==L17,L17,IIf(x==L18,L18,IIf(x==L19,L19,IIf(x==L20,L20,L20))))))))))))))))))))));
q=IIf(x==L0,L1,IIf(x==L1,L2,IIf(x==L2,L3,
IIf(x==L3,L4,IIf(x==L4,L5,IIf(x==L5,L6, IIf(x==L6,L7 ,IIf(x==L6,L8 ,
IIf(x==L7,L8 ,IIf(x==L8,L9 ,IIf(x==L9,L10,IIf(x==L10,L11
,IIf(x==L11,L12,IIf(x==L12,L13,IIf(x==L13,L14,IIf(x==L14,L15,IIf(x==L15,L16,IIf(x==L16,L17,IIf(x==L17,L18,IIf(x==L18,L19,IIf(x==L19,L20,IIf(x==L20,L20,L20))))))))))))))))))))));
r=IIf(x==L0,L2,IIf(x==L1,L3,IIf(x==L2,L4,
IIf(x==L3,L5,IIf(x==L4,L6,IIf(x==L5,L7, IIf(x==L6,L8 ,IIf(x==L6,L9 ,
IIf(x==L7,L9 ,IIf(x==L8,L10 ,IIf(x==L9,L11,IIf(x==L10,L12
,IIf(x==L11,L13,IIf(x==L12,L14,IIf(x==L13,L15,IIf(x==L14,L16,IIf(x==L15,L17,IIf(x==L16,L18,IIf(x==L17,L19,IIf(x==L18,L20,IIf(x==L19,L20,IIf(x==L20,L20,L20))))))))))))))))))))));
//plotting section//
Plot(p,"support if falls below",colorBlack,styleDots);
Plot(q,"crucial if crosses this",colorBlue,styleDots);
Plot(r,"target or resistance",colorRed,styleDots);
//Plot((r-((r-q)/2)),"intermediatelevel",colorLightGrey,styleDots);
//Plot((p+((q-p)/2)),"intermediatelevel2",colorLightGrey,styleDots);

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ),
styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick
| styleNoLabel, maskHistogram  ), 2 );
_SECTION_END();

Wednesday, 7 September 2011

36 EMA afl(with buy sell signal)

TimeFrameSet(in15Minute);
Limit=Param(" Trade Till (Hour)(Min)(Sec)",144500,103000,153000,100);
since=(TimeNum() >= 091500 AND TimeNum()<= Limit) AND (DateNum()==LastValue(DateNum())); inv=Param("INVEST CAPITAL", 28000,1000, 1000000, 500 ); SetChartOptions(0,chartShowArrows|chartShowDates|chartWrapTitle|chartHideQuoteMarker); PlotOHLC(Open,High,Low,Close,"", IIf(CCI(14) > ((Ref(CCI(14),-1)+Ref(CCI(14),-2))/2),colorAqua,colorBrown) , styleCandle|styleThick);


_SECTION_BEGIN("Stochastic %D");
Plot( StochD( 8 , 4, 3 ), _DEFAULT_NAME(), colorYellow, styleDashed| styleOwnScale | styleThick | styleNoLabel );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Plot( EMA( P, 3), _DEFAULT_NAME(), colorBrightGreen, styleLine| styleOwnScale | styleThick | styleNoLabel );

_SECTION_END();

_SECTION_BEGIN("EMA1");
Plot( EMA( P, 6 ), _DEFAULT_NAME(), colorRed, styleLine| styleOwnScale | styleThick | styleNoLabel );

_SECTION_END();
st=StochD( 8 , 4, 3 );
EMA3= EMA( P, 3);
EMA6= EMA( P, 6);

Buyr=IIf(since & (st<=50 & (Cross(EMA3,EMA6) | EMA3>EMA6)),1,0);
Buy=IIf(Ref(Buyr,-1),H>=Ref(H,-1),0);
Dayl=TimeFrameGetPrice("L",inDaily,0);
BuyPrice=(round(ValueWhen(Buyr,H)*10))/10;
Buystop1=(round((ValueWhen(Buyr,dayL) | ValueWhen(Cross(EMA6,EMA3),H))*10))/10;
Buytp1= (round((BuyPrice + (BuyPrice-Buystop1))*10))/10;
Buytp2=IIf(Cross(H,Buytp1) | Cross(C,Buytp1) |Cross(Buystop1,L) | Cross(EMA6,EMA3) , 1,0);
Buystop2=(Cross(buystop1,L) | Cross(H,buystop1) | Cross(EMA6,EMA3));
shortr=IIf(since & (st>=45 & (Cross(EMA6,EMA3) | EMA6>EMA3)),1,0);
Short=IIf(Ref(shortr,-1),L<=Ref(L,-1),0); Dayh=TimeFrameGetPrice("H",inDaily,0); SellPrice=(round(ValueWhen(shortr,L)*10))/10; sellstop1=(round((ValueWhen(Shortr,Dayh) | ValueWhen(Cross(EMA3,EMA6),L))*10))/10; Sellstop2=(Cross(H,sellstop1) | Cross(sellstop1,L) | Cross(EMA3,EMA6)); Lotsize=IIf(buyr|shortr,round((inv*5.5)/H),0); Selltp1= (round((ShortPrice - (sellstop1-SellPrice))*10))/10; Selltp2=IIf(Cross(selltp1,L) | Cross(selltp1,C) |Cross(H,sellstop1) | Cross(EMA6,EMA3) , 1,0); TSB=BuyTP1; TSS=SellTP1; Buy=ExRem(Buy,Short); Short=ExRem(Short,Buy); //cumulative trades total trades1=Param("Trade Above",1,1,10,1); tradebase=(Buy OR Short ); trades=Cum(tradebase); trades2=(trades>=trades1);
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);
//cumulative trades individual

tradesB=Cum(Buy);
TSB1=IIf(tradesB>=1,(Cross(H,TSB) OR Cross(C,TSB)) AND since,0);
BSL1=IIf(tradesB>=1,(Cross(Buystop1,L) OR Cross(BuyStop1,C)) AND since,0);
tradesBTP=Cum(TSB1);
tradesBSL=Cum(BSL1);
tradesS=Cum(Short);
TSS1=IIf(tradesS>=1,(Cross(TSS,L) OR Cross(TSS,C)) AND since,0);
SSL1=IIf(tradesS>=1,(Cross(H,SellStop1) OR Cross(C,SellStop1)) AND since,0);
tradesSTP=Cum(TSS1);
tradesSSL=Cum(SSL1);
Sell1=IIf(TradesBTP==1,TSB1,0);
Sell2=IIf(TradesBTP>=1,Hold(Sell1==1,Limit),0);
Cover1=IIf(tradesSTP==1,TSS1,0);
Cover2=IIf(tradesSTP>=1,Hold(Cover1==1,Limit),0);
bstop1=IIf(tradesBSL==1,BSL1,0);
bstop2=IIf(tradesBSL>=1 AND (Sell2==0 OR Cover2==0),Hold(bstop1==1,Limit),0);
sstop1=IIf(tradesSSL==1,SSL1,0);
sstop2=IIf(tradesSSL>=1 AND (Cover2==0 OR Sell2==0),Hold(sstop1==1,Limit),0);
Sell=IIf(bstop2==1,0,Sell1);
bstop=IIf(Sell2==1,0,bstop1);
Cover=IIf(sstop2==1,0,Cover1);
sstop=IIf(Cover2==1,0,sstop1);

FH_Range = (TimeNum() >= 085959 AND TimeNum()<= 090459) 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);

isAll = True;
isRth = TimeNum() >= 085959 AND TimeNum() <= 090459; isdRth = TimeNum() >= 085959 AND TimeNum() <= 160000; aRthL = IIf(isRth, L, 1000000); aRthH = IIf(isdRth, H, Null); aRthLd = IIf(isdRth, L, 1000000); DayH = TimeFrameCompress( aRthH, inDaily, compressHigh ); DayH = TimeFrameExpand( DayH, inDaily, expandFirst ); DayL = TimeFrameCompress( aRthLd, inDaily, compressLow ); DayL = TimeFrameExpand( DayL, inDaily, expandFirst ); //line plot basics Bars = BarsSince(TimeNum() >= 085959 AND TimeNum() < 090459) ;// AND DateNum()==LastValue(DateNum());
x0 = BarCount-LastValue(Bars);
x1 = BarCount-1;
DayHline=LineArray(x0,LastValue(DayH),x1,LastValue(DayH),0);
DayLline=LineArray(x0,LastValue(DayL),x1,LastValue(DayL),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);


Plot(DayHline,"",colorYellow,styleLine|styleNoRescale);
Plot(DayLline,"",colorYellow,styleLine|styleNoRescale);
//PLOT LINES
Plot(BuyPriceline,"Buy Here",colorBrightGreen,styleDots|styleNoRescale);
//Plot(BuyStopline,"BuyStop",colorBrightGreen,styleDots|styleNoRescale| styleNoLine);
Plot(BuyTPline,"Buy Take profit",colorBrightGreen,styleDashed|styleNoRescale);
Plot(SellPriceline,"Short Here",colorRed,styleDots|styleNoRescale);
//Plot(SellStopline,"ShortStop",colorRed,styleDots|styleNoRescale| styleNoLine);
Plot(SellTPline,"Short Take Profit",colorRed,styleDashed|styleNoRescale);

//shapes
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-25 );
PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,H,-25 );
AddColumn( IIf(Buyr, 82, IIf(Shortr, 82,01 )), "READY", formatChar, colorWhite, bkcolor= IIf(Shortr,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(Buy, 66, IIf(Short, 83,01 )), "GO", formatChar, colorWhite, bkcolor= IIf(Short,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(Sell, 80, IIf(Cover, 80,01 )), "PR", formatChar, colorWhite, bkcolor= IIf(Cover ,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(bstop, 76, IIf(sstop, 76,01 )), "SL", formatChar, colorWhite, bkcolor= IIf(sstop ,colorDarkRed,colorDarkGreen) );

AddColumn( IIf(Buy OR bstop OR Sell | Buyr , BuyPrice, IIf(Short OR sstop OR Cover |Shortr , SellPrice,01 )), "ENTRY@", 1.2, colorWhite, bkcolor= IIf(Short OR sstop OR Cover | Shortr,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(Buy OR bstop OR Sell| Buyr , BuyStop1, IIf(Short OR sstop OR Cover |Shortr , SellStop1,01 )), "STPLS@", 1.2, colorWhite, bkcolor= IIf(Short OR sstop OR Cover |Shortr ,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(Buy OR bstop OR Sell| Buyr , TSB, IIf(Short OR sstop OR Cover |Shortr , TSS,01 )), "PROFIT@", 1.2, colorWhite, bkcolor= IIf(Short OR sstop OR Cover |Shortr ,colorDarkRed,colorDarkGreen) );
AddColumn( IIf(Buy OR bstop OR Sell| Buyr , Lotsize, IIf(Short OR sstop OR Cover |Shortr , Lotsize,01 )), "QTY", 1.0, colorWhite, bkcolor= IIf(Short OR sstop OR Cover|Shortr ,colorDarkRed,colorDarkGreen) );
Filter=Buyr | Shortr | Buy OR Short OR Sell OR Cover OR bstop OR sstop ;