// Turtle minor and major trading signals - for AmiBroker - Use at your own risk
// CAUTION: Thrtles was originally designed to trade futures. Using it with stocks might pose many problems.
// Be sure to back test and optimize this with any stock you might use it with AND back test again.
// NOTE: This is a rudimentary implementation as it does not include the following:
// volitality share sizing
// stops
// Trade selection which only trades following a theoretical
// Two default periods are used 20/10 for short term trading and 65/30 for long term trading
// Try to optomize these valuess but be careful not curve fit. It must work across many stocks, etc. OR it is curve fitted.
// constants account = 5000.00; // set this to whatever you want to use per trade
tradeCount = 0;
price = 0.0;
PeriodSys1Buy = Param("Short bar entry", 20, 1, 100, 1);
// number of bars back to look for a short term buy breakvaout
PeriodSys1Sel1 = Param("Short bar exit", 10, 1, 100, 1);
// number of bars back to look for a sell
PeriodSys2Buy = Param("Long bar entry", 65, 1, 100, 1); // number of bars back to look for a long Buy breakvaout
PeriodSys2Sel1 = Param("Long bar exit", 30, 1, 100, 1); // number of bars back to look for a Sell
buyRangeSys1 = HHV(H, PeriodSys1Buy ); // buy or Short range for system 1
sellRangeSys1 = LLV(L, PeriodSys1Sel1 ); // Sell OR Cover range for system 1
shortRangeSys1 = LLV(L, Periodsys1Buy ); // Buy OR Short range for system 2
coverRangeSys1 = HHV(H, PeriodSys1Sel1 ); // Sell OR Cover range for system 2
// #####################
// System 1 rules
// #####################
// if the market sets a new system 1 day high then buy
myBuySys1 = IIf(C > Ref(buyRangeSys1, -1), 1, 0); // if todays Close is >= that the Highest value set Buy Signal
mySellSys1 = IIf(C < Ref(sellRangeSys1, -1), 1, 0); // if todays Close is <= that the Lowest value set Sell Signal
Sys1Buy = ExRem(myBuySys1 ,mySellSys1 ); // remove all the other buy signals from buy to Sell - only take one position
Sys1Sell = ExRem(mySellSys1 ,myBuySys1 ); // remove all the other Sell signals from Sell to Buy - only take one position
// short
myShortSys1 = IIf(C < Ref(shortRangeSys1, -1), 1, 0); // if todays Close is >= that the Highest value set Buy Signal
myCoverSys1 = IIf(C > Ref(coverRangeSys1, -1), 1, 0); // if todays Close is <= that the Lowest value set Sell Signal
Sys1Short = ExRem(myShortSys1 ,myCoverSys1 ); // remove all the other short signals from buy to Sell -only take one position
Sys1Cover = ExRem(myCoverSys1 ,myShortSys1 ); // remove all the other Cover signals from Sell to Buy -only take one position
// #####################
// System 2 rules
// #####################
buyRangeSys2 = HHV(H, PeriodSys2Buy ); // buy or Short range for system 1
sellRangeSys2 = LLV(L, PeriodSys2Sel1 ); // Sell OR Cover range for system 1
shortRangeSys2 = LLV(L, PeriodSys2Buy ); // Buy OR Short range for system 2
coverRangeSys2 = HHV(H, PeriodSys2Sel1 ); // Sell OR Cover range for system 2
// if the market sets a new system 1 day high then buy
myBuySys2 = IIf(C > Ref(buyRangeSys2, -1), 1, 0);
// if todays close is >= that the highest value set buy Signal
mySellSys2 = IIf(C < Ref(sellRangeSys2, -1), 1, 0); // if todays Close is <= that the Lowest value set Sell Signal
Sys2Buy = ExRem(myBuySys2 ,mySellSys2 ); // remove all the other buy signals from buy to Sell - only take one position
Sys2Sell = ExRem(mySellSys2 ,myBuySys2 ); // remove all the other sell signals from sell to Buy - only take one position
// short
myShortSys2 = IIf(C < Ref(shortRangeSys2, -1), 1, 0); // if todays Close is >= that the Highest value set Buy Signal
myCoverSys2 = IIf(C > Ref(coverRangeSys2, -1), 1, 0); // if todays Close is <= that the Lowest value set Sell Signal
Sys2Short = ExRem(myShortSys2 ,myCoverSys2 ); // remove all the other short signals from buy to sell - only take one position
Sys2Cover = ExRem(myCoverSys2 ,myShortSys2 ); // remove all the other Cover signals from Sell to Buy - only take one position
// #####################
// Combining the rules
// #####################
Buy = Sys1Buy OR Sys2Buy;
Sell = Sys1Sell OR Sys2Sell;
Short = Sys1Short OR Sys2Short;
Cover = Sys1Cover OR Sys2Cover;
// #####################
// Plotting the results
// #####################
// System 1 trades
Plot(Sys1Buy * C / 2, "Turtles - Sys1 Green = Buy", colorGreen);
Plot(-Sys1Sell * C / 2, "Blue = Sys1 Sell", colorBlue);
Plot(-Sys1Short * C / 2, "Red = Sys1 Short", colorRed);
Plot(Sys1Cover * C / 2, "Black = Sys1 Cover", colorBlack);
// System 2 trades
Plot(Sys2Buy * C, "\n Sys 2 - Green = Buy", colorGreen,
styleDashed );
Plot(-Sys2Sell * C, "Sys 2 Blue = Sell", colorBlue, styleDashed );
Plot(-Sys2Short * C, "Sys 2 Red = Short", colorRed, styleDashed );
Plot(Sys2Cover * C, "Sys 2 Black = Cover", colorBlack, styleDashed );
Filter = Sys1Buy OR Sys1Sell OR Sys1Short OR Sys1Cover OR Sys2Buy OR
Sys2Sell OR Sys2Short OR Sys2Cover ; // used for scan function
AddColumn(Sys1Buy , "Sys 1 Buy");
AddColumn(Sys1Sell , "Sys 1 Sell");
AddColumn(Sys1Short , "Sys 1 Short");
AddColumn(Sys1Cover , "Sys 1 Cover");
AddColumn(Sys2Buy , "Sys 2 Buy");
AddColumn(Sys2Sell , "Sys 2 Sell");
AddColumn(Sys2Short , "Sys 2 Short");
AddColumn(Sys2Cover , "Sys 2 Cover");
Mode = ParamToggle("Smoothing", "On|Off" );
MomPer = Param("Momentum Periods", 10, 1, 100, 1);
SmaPer = Param("Moving Average Periods", 7, 1, 1000, 1);
EmaPer = Param("Exponential Moving Average Periods", 7, 1, 1000, 1);
BaseLine = 0;
if( Mode == 1)
{
Mom = 100 * ((Close / MA(Close, (2 * MomPer) + 1) ) - 1);
}
else
{
Mom = 100 * ((EMA(Close, EmaPer) / MA(Close, (2 * MomPer) + 1) ) - 1);
}
Plot( Mom, "Anchored Momentum", ParamColor( "Color", colorBlue ), 1 );
Plot( BaseLine, "BaseLine", colorRed, styleNoTitle, 1 );
_SECTION_BEGIN("trendrider");
//------------------------------------------------------------------------------
//
// Formula Name: trendrider
// Author: sandeep
//
//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
/* Set Scaling to Automatic, Show dates On, Percent On, Middle On */
Title = "sunny trend Close - Ref(Close,-7)";
GraphXSpace = 5;
Graph0 = MA(Close - Ref(Close,-7),1);
Graph0Style = 5;
Graph0Color = 34;
Graph1 = MA(Graph0,5);
Graph1Style = 1;
Graph1Color = 32;
_SECTION_END();
_SECTION_BEGIN("trendrider");
//------------------------------------------------------------------------------
//
// Formula Name: trendrider
// Author: sandeep
//
//------------------------------------------------------------------------------
//
//
//
//------------------------------------------------------------------------------
/* Set Scaling to Automatic, Show dates On, Percent On, Middle On */
Title = "sunny trend Close - Ref(Close,-7)";
GraphXSpace = 5;
Graph0 = MA(Close - Ref(Close,-7),1);
Graph0Style = 5;
Graph0Color = 34;
Graph1 = MA(Graph0,5);
Graph1Style = 1;
Graph1Color = 32;
_SECTION_END();
_SECTION_BEGIN("INIT");
SetChartOptions(0,chartShowArrows|chartShowDates);
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
tchoice=Param("Title Selection ",2,1,2,1);
ZigLevel = Param("ZigLevel", 2, 1, 25 );
numbars = LastValue(Cum(Status("barvisible")));
hts = Param ("Text Shift", -33.5,-50,50,0.10);
dec = (Param("Decimals",2,0,7,1)/10)+1;
bi = BarIndex();
Lbi = LastValue(BarIndex());
sbi = SelectedValue(bi);
ScanLookBack = Param("Scan Lookback", 1, 1, 25 );
_SECTION_END();
_SECTION_BEGIN("Functions");
function Lastthursday() {
Daysinmonth=IIf(Month()==1 OR Month()==3 OR Month()==5 OR Month()==7 OR Month()==8 OR Month()==10 OR Month()==12,31,30);
Daysinmonthfeb=IIf(Year()%4 == 0 AND Year()%100!=0,29,28);
Daysinmonthfinal=IIf(Month()==2,Daysinmonthfeb,Daysinmonth);
returnvalue=IIf(Daysinmonthfinal-Day()<7 AND DayOfWeek()==4,1,0);
return returnvalue;
}
_SECTION_END();
_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",28,11,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor( ParamColor("Color",colorGreen) );
Hor=Param("Horizontal Position",750,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorViolet) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();
_SECTION_BEGIN("Price");
_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, _DEFAULT_NAME(), colorBlack , styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("Auto trend line Trendline");
percent = 0.01 * 1; /* Adjust this percent as necessary, */
firstpointL = 2;
firstpointH = 2;
y0=LastValue(Trough(L,percent,firstpointL));
y1=LastValue(Trough(Ref(L,-1),percent,1));
for( i = 1; i < BarCount AND y0 >= y1; i++ ){
firstpointL++;
y0=LastValue(Trough(L,percent,firstpointL));
}
x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL));
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1));
LineL = LineArray( x0, y0, x1, y1, 1 );
//Plot( LineL, "Support", colorGreen,styleLine | styleDots | styleNoTitle | styleNoRescale);
yt0=LastValue(Peak(H,percent,firstpointH));
yt1=LastValue(Peak(Ref(H,-1),percent,1));
for(i = 1; i < BarCount AND yt0 <= yt1; i++ ) {
firstpointH++;
yt0=LastValue(Peak(H,percent,firstpointH));
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH));
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1));
LineH = LineArray( xt0, yt0, xt1, yt1, 1 );
//Plot( LineH, "Resistance", colorBrown,styleLine | styleDots | styleNoTitle | styleNoRescale);
ATBuy = Cross(C,LineH);
ATShort = Cross(LineL,C);
//PlotShapes(ATBuy * shapeUpTriangle , colorBlue,0,L);
//PlotShapes(ATShort * shapeDownTriangle , colorRed,0,H);
_SECTION_END();
_SECTION_BEGIN("NW");
k = Param("K", 1.5, 1, 5, 0.1);
Per = Param("ATR", 14, 1, 30, 0.50);
j=Close;
f=ATR(Per );
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];
}
}
}
}
Plot(NW, "", IIf(Trend == 1, 27, 4), styleStaircase | styleNoRescale);
NMBuy = NMCover = Cross(j,nw);
NMSell = NMShort = Cross(nw,j);
baratnwbuy = LastValue(ValueWhen((NMBuy ) ,BarIndex())) ;
baratnwshort = LastValue(ValueWhen((NMShort ) ,BarIndex())) ;
shape = NMBuy * shapeSmallUpTriangle+ NMSell * shapeSmallDownTriangle;
PlotShapes( shape, IIf( NMBuy, colorBlue, colorRed ), 0, IIf( NMBuy, L, H));
_SECTION_END();
_SECTION_BEGIN("NAME");
GfxSetOverlayMode(0);
GfxSelectFont("Arial", Status("pxheight")/28 );
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorHSB( 42, 42, 42 ) );
GfxSetBkMode(0); // transparent
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 );
GfxSelectFont("Tahoma", Status("pxheight")/30 );
Title = EncodeColor(colorBlue)+""+EncodeColor(colorBlack)+Title ;
_SECTION_END();
GraphXSpace = 10 ;
_SECTION_BEGIN("Background_Setting");
SetChartBkGradientFill( ParamColor("BgTop", colorCustom14),
ParamColor("BgBottom", colorLightGrey),ParamColor("titleblock",colorYellow));
_SECTION_END();
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
My visual effect afl collection. | AmiBroker | 185 | ||
AFL Collection by Tamil Trader | AmiBroker | 10 | ||
P | AFL Collection without formula references FUTURE quotes | AmiBroker | 1 | |
My amibroker afl collections | AmiBroker | 18 | ||
The Grand AFL Collection Thread | AmiBroker | 20 |