- Joined
- 21 August 2008
- Posts
- 2,832
- Reactions
- 8,776
Don't know if this is any help but a quick google I located this https://www.marketcalls.in/amibroker/profit-table-afl-code-yearly-max-drawdown.htmlDoes any one have or seen any code for a rolling 12 month returns profit table?
i.e instead of each month displaying that months return it would display a rolling 12 month CAR
This would be a great tool for looking into a systems consistency. I've tried to build my own no luck as yet.
No problems mate, starting to get above my level, but I will keep an eye out for you.
Don't know if this is any help but a quick google I located this https://www.marketcalls.in/amibroker/profit-table-afl-code-yearly-max-drawdown.html
It might lead you along the path you wanted, hope it helps.
Edit: Sorry @Roller_1 after re-reading I misunderstood what you were after. Sorry mate
@Roller_1 well there goes my Friday night....googling some more AmiBroker stuff.
Yes I lead an exciting life
It might lead you along the path you wanted, hope it helps.
They had a rolling returns graph but I couldn't find a table like @Roller_1 wanted. This is the link to the graph https://www.marketcalls.in/amibroker/amibroker-afl-code-compute-10-year-rolling-returns.html@debtfree I was checking out that link which led me to the profit table AFL file.
That's pretty interesting and definitely opens up some options when wanting to customise. Good find mate!
I couldn't find a table like @Roller_1 wanted
I am the point of setting my trailing stops:
1. Since buy, if index filter continues true, Stop loss at 70% of high, until
2. Index filter has become not true, change stop loss of 90% of high since buy, until
3. Index filter returns true, then 70% of high subject to this stop loss being above stop loss in Condition 2
I have created some rudimentary rules, but these I know are way off. I would welcome some guidance on writing the AFL to implement the above trailing stop
Code:SetForeign( "XAO" ); Filter1 = C> MA( C, 10 ); Filter3 = Ref(MA( C, 10 ),-1)> Filter1; RestorePriceArrays(); Filter = Filter1; _SECTION_BEGIN("Buy_sell"); Hh = Ref(HHV(H,20),-1); Buy = Iif(Filter,Cross(C,Hh),0); //Trailing Stops: // 1. Since buy, if index filter continues true, Stop loss at 70% of high, until // 2. Index filter has become not true, change stop loss of 90% of high since buy, until // 3. Index filter returns true, then 70% of high subject to this stop loss being above stop loss in Condition 2 Stop1 = IIf(Filter1,C<= Hh*.7,0); //stop condition1 Stop2 = IIf(Filter3, C<= Hh*.9,0); //stop condition2 Stop3 = IIf(Ref(filter3,-1), C<= Hh*.9,0); //stop condition3 Sell = C<Stop1 OR C<Stop2 OR C<Stop3; _SECTION_END();
Hi CNH, did you ever have any luck with this?
SetForeign("$xao"); // Replaces current stock code with XAO
IndexFilter = Close > MA(Close,10); // Basic moving average test
Plot( Close, "$XAO", colorGrey40, styleLine | styleOwnScale ); // Plot XAO close price
Plot( MA(Close,10), "$XAO MA", colorPink, styleLine | styleOwnScale ); // Plot XAO Moving Average
IndexFilterHealthy = IIf( IndexFilter == 1 , colorGreen, Null );
Plot( 1, "Index Healthy", IndexFilterHealthy, styleOwnScale| styleArea| styleNoLabel,-.5, 100);
RestorePriceArrays();
maxpos = 10; // maximum number of open positions
SetOption("InitialEquity", 100000 ); // set initial equity = 100K
SetOption( "MaxOpenPositions", maxpos );
SetPositionSize( 100 / maxpos, spsPercentOfEquity );
// Standard buy / sell system
period = 20; // number of averaging periods
m = EMA( Close, period ); // exponential moving average
Buy = Sell = 0;
Short = Cover = 0;
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
// Trailing Stop loop
TrailStopPercent = 1 - 30/100; // Normal Trail Stop set @ 30 % nice and loose
IndexStopPercent = 1 - 10/100; // Index Trail Stop set @ 10 % now tighter due to index filter mood change
StopLevel = IIf( IndexFilter == 0, IndexStopPercent, TrailStopPercent); // Selects which value to use in trailing stop
trailARRAY = Null;
trailstop = 0;
TrailStopSell = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * StopLevel [ i ] ;
}
else Buy[ i ] = 0;
if( trailstop > 0 AND Close[ i ] < trailstop)
{
TrailStopSell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 AND TrailStopSell [i] == 0)
{
trailstop = Max( High[ i ] * StopLevel [ i ], trailstop );
trailARRAY[ i ] = trailstop;
}
}
Sell = TrailStopSell OR Cross( m, Close ); // sell when closes crosses BELOW moving average
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
// plots price chart and trail stop
Plot( C, "Price", colorDefault, styleBar );
Plot( m, "MA 20", colorAqua, styleLine );
InTrade = Flip(Buy,Sell); // used to turn off trail stop plot
Plot( IIf(InTrade, trailARRAY, Null),"trailing stop level", IIf( IndexFilter == 0, colorRed, colorYellow ), styleLine, Null, Null, 0, -1, 1);
// Plots buy and sell signals
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, L, Offset=-60);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
Filter = Buy;
AddColumn(Close,"Close",1.2); // current bar close
AddColumn(High,"High",1.2); // Current bar high
AddColumn(trailARRAY,"TS Value",1.2); // Based on % of High ( high select )
AddColumn(100*(1-StopLevel),"Stop %",1.2); // displays which % value we are using depending on index filter
AddColumn(IndexFilter, "Index Filter Active",1,
IIf( IndexFilter, colorGreen, colorRed),
IIf( IndexFilter, colorGreen, colorRed), 80);
I can't figure out how to have a trailing stop stay at 10% after the market turns up again (which is what the WTT does).
Hi, no I did not get to an answer on this Trailing Stop. I did get an index filter to work as a caution working with a second filter.Hi CNH, did you ever have any luck with this?
- Index Filter using $XAO
- $XAO (Grey) plotted against $XAO Moving Average (10 period) (Pink)
- Test is Close > MA == Healthy
- Ribbon on bottom Green for Healthy ** note scaling appears to be out for some reason
Plot( Close, "$XAO", colorGrey40, styleLine | styleLeftAxisScale ); // Plot XAO close price
Plot( MA(Close,10), "$XAO MA", colorPink, styleLine | styleLeftAxisScale ); // Plot XAO Moving Average
@wasp maye look at GapUp to detect spike
View attachment 104426
or by some code like this
GapUp = ( L > 1.10*Ref(H, -1) ); // today's Low 10% above yesterday's high
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?