// translation in Amibroker AFL, Edward Pottasch, 9/29/2011
SetChartBkGradientFill( ParamColor("Inner panel upper",colorWhite),ParamColor("Inner panel lower",colorLightYellow));
Factor=Param("Factor",3,1,10,1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L+C)/3+(Factor*ATR(Pd));
Dn=(H+L+C)/3-(Factor*ATR(Pd));
aa=Cross(C,LLV(Up,13));
bb=Cross(HHV(Dn,13),C);
Td[0]=1;
for(i=1;i<BarCount;i++ )
{
prev=Td[i-1];
if(aa[i])
{
Td[i]=1;
}
else if(bb[i])
{
Td[i]=-1;
}
else
{
Td[i]=prev;
}
}
aa=Dn==HighestSince(Cross(Td,0),Dn);
Dnx=Dn[0];
for(i=1;i<BarCount;i++ )
{
prev=Dnx[i-1];
if(aa[i])
{
Dnx[i]=Dn[i];
}
else
{
Dnx[i]=prev;
}
}
aa=Up==LowestSince(Cross(0,Td),Up);
Upx=Up[0];
for(i=1;i<BarCount;i++ )
{
prev=Upx[i-1];
if(aa[i])
{
Upx[i]=Up[i];
}
else
{
Upx[i]=prev;
}
}
aa=Td==1;
bb=Td==-1;
ST[0]=1;
trend=Null;
for(i=1;i<BarCount;i++ )
{
prev=ST[i-1];
if(aa[i])
{
ST[i]=Dnx[i];
trend[i]=1;
}
else if(bb[i])
{
ST[i]=Upx[i];
trend[i]=-1;
}
else
{
ST[i]=prev;
trend[i]=trend[i-1];
}
}
Buy=Cover=aa;
Sell=Short=bb;
PositionSize = MarginDeposit = 1;
Buy = ExRem(Buy, Short);
Short = ExRem(Short, Buy);
PlotShapes( Buy * shapeUpArrow + Short * shapeDownArrow, IIf( Buy, colorBlack, colorBlack ) );
//r1=AmiTradingSA();
BuyBar = BarsSince ( Buy );
SellBar = BarsSince ( Sell );
//AlertIf( Buy , "EXEC D:\\Documents and Settings\\msa\\Desktop\\tr\\BuyOrderPlacer.exe", "Launching external application", 3 );
//AlertIf( Sell , "EXEC D:\\Documents and Settings\\msa\\Desktop\\tr\\SellOrderPlacer.exe", "Launching external application", 3 );
dist = 1.0*ATR(20);
for( i = 0; i < BarCount; i++ )
{
//if( Buy[i] ) PlotText( "Buy\n@" + C[ i ]+"\n sl :"+ValueWhen( supbase==Base, LLV(L,HHVperiod) ) , i, L[ i ]-dist[i], colorBlack,colorGreen );
//if( Short[i] ) PlotText( "Sell\n@" + C[ i ]+"\n sl :"+ ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), i, H[ i ]+dist[i], colorBlack, colorRed );
if( Buy[i] ) PlotText( "Buy\n@" + C[ i ] , i, L[ i ]-dist[i], colorBlack,colorWhite );
if( Short[i] ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist[i], colorBlack, colorWhite );
}
t1= Flip(Buy,Sell);
t2= Flip(Sell,Buy);
BPrice=ValueWhen(t1 AND Ref(t1,-1)==0,C,1);
SPrice=ValueWhen(t2 AND Ref(t2,-1)==0,C,1);
Buyplus1=(Bprice*1.008);
Buyplus2=(Bprice+80);
Buyminus=(Bprice*0.995);
//Plot(Buyplus1,"R1",colorGreen);
//Plot(Buyplus2,"R1",colorBlue,styleDots|styleThick|styleNoTitle);
//Plot(Buyminus,"R2",colorGreen);
Sellplus=(Sprice*1.005);
Sellminus1=(Sprice*0.992);
Sellminus2=(Sprice-80);
//Plot(Sellplus,"R3",colorRed);
//Plot(Sellminus1,"R4",colorRed);
//Plot(Sellminus2,"R4",colorBlack,styleDots|styleThick|styleNoTitle);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0,0)));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
Plot(IIf(trend==1,ST,Null),"\nUP",colorGreen,styleDashed);
Plot(IIf(trend==-1,ST,Null),"\nDN",colorRed,styleDashed);
GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink );
GfxRoundRect( 2, 15, 95, 35, 9, 9 ) ;
GfxSelectFont("romans", 9, 700 );
GfxTextOut("ST-7 6.0 2.5", 5, 18);
GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorPink );
GfxRoundRect( 100, 15, 200,42, 9, 9 ) ;
GfxSelectFont("romans", 18, 700 );
GfxTextOut( ""+C , 110, 13);
//GfxTextOut( ""+Buybar , 110, 13);
GfxSetBkMode(1);
GfxSelectPen( colorBlack, 1, 0) ;
GfxSelectSolidBrush( colorRed );
GfxRoundRect( 205, 15, 330, 35, 9, 9 ) ;
GfxSelectFont("romans", 9, 700 );
GfxTextOut("" +Date() , 210, 18);
//GfxTextOut("" +Sellbar , 210, 18);
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
bars = i;
i = 0;
}
if(Short[i] == 1)
{
sig = "SELL";
entry = C[i];
bars = i;
i = 0;
}
}
Offset = 20;
//Clr = IIf(sig == "BUY", colorLime, colorRed);
//ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
//sl = ssl[BarCount-1];
pxHeight = Status( "pxchartheight" ) ;
y = pxHeight;
x = 5;
x2 = 140;
GfxSelectPen( colorGreen, 1); // broader color
GfxRoundRect( x, y - 48, x2, y , 7, 7 ) ;
//GfxTextOut( ("Last " + sig + " appeared ") , 13, y-45) ; // The text format location
//GfxTextOut( (" BuyBar " + round((BarCount-bars-1) /55) + " Days ago") , 13, y-32) ; // The text format location
//GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 20, y-20);