Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › Handy CBT code
- This topic is empty.
-
AuthorPosts
-
May 2, 2020 at 8:32 am #111384GlenPeakeParticipant
An Explore example below of checking whether the Index Filter is Up/Down using the “AddMultiTextColumn” option. I hadn’t used this option before.
Code:_SECTION_BEGIN (“Normal MA Index Filter”);
//=================================================================================
// SPX Index Filter
//=================================================================================IndexTog = ParamToggle(“Index Filter”,”Off|On”,1);
“”;
“Normal MA Index Filter”;
//IndexCode = ParamStr(“Index Symbol”,”$NDX”);
IndexCode = ParamStr(“Index Symbol”,”$SPX”);
//IndexCode = ParamStr(“Index Symbol”,”$DJI”);Index = Foreign(IndexCode,”C”);
IndMA = Param(“Index MA”,200,10,300,10);
IndFiltUp = Index > MA(Index,IndMA);
IndFiltDown = Index < MA(Index,IndMA); IndFilt = IIf(IndexTog,IndFiltUp,1); //================================================================================= _SECTION_END(); Filter = 1; IndexUP = IndFiltUp; IndexDOWN = IndFiltDown; TextList = "No signalnIndex UPnIndex DownnIndexUP and IndexDown"; TextSelector = 1 * IndexUP + 2 * IndexDown; AddMultiTextColumn(TextSelector,TextList, "Index Filter Status ", 1.0,IIf(TextSelector == IndexUP, colorGreen, colorRed)); // ------------------------------------------------------------------ // https://www.amibroker.com/guide/afl/addmultitextcolumn.html
// ------------------------------------------------------------------May 2, 2020 at 8:50 am #111390GlenPeakeParticipantUsing the StaticVAR option to merge Indicators of dissimilar values and RANK accordingly…
Handy if you want to build a Rotational system using multiple indicators with dissimilar values.
You can then manipulate how you want to calculate the rank….E.g. ‘Average’ rank shown below.
Code:// https://forum.amibroker.com/t/exploration-ranks/14285/2
//
// ———————————————————-
// choose WL in Analysis window
wlnum = GetOption( “FilterIncludeWatchlist” );
List = CategoryGetSymbols( categoryWatchlist, wlnum ) ;if( Status( “stocknum” ) == 0 )
{
StaticVarRemove( “ShortTermValues*” );
StaticVarRemove( “LongTermValues*” );for( n = 0; ( Symbol = StrExtract( List, n ) ) != “”; n++ )
{
SetForeign( symbol );ShortTermValues = RSI( 15 );
LongTermValues = ROC( C, 200 );RestorePriceArrays();
StaticVarSet( “ShortTermValues” + symbol, ShortTermValues );
StaticVarSet( “LongTermValues” + symbol, LongTermValues );
}StaticVarGenerateRanks( “rank”, “ShortTermValues”, 0, 1224 );
StaticVarGenerateRanks( “rank”, “LongTermValues”, 0, 1224 );
}symbol = Name();
svShortTermValues = StaticVarGet( “ShortTermValues” + symbol );
svLongTermValues = StaticVarGet( “LongTermValues” + symbol );ShortTermRank = StaticVarGet( “rankShortTermValues” + symbol );
LongTermRank = StaticVarGet( “rankLongTermValues” + symbol );// from here you can choose whatever manipulation of the two rankings you desire
// example below is to average the two rankings
AverageRank = ( ShortTermRank + LongTermRank ) / 2;// Exploration of calculations //
Filter = 1;
AddtextColumn(FullName(), “Name”);
AddColumn( svShortTermValues, “Short Term Values” );
AddColumn( svLongTermValues, “Long Term Values” );
AddColumn( ShortTermRank, “Short Term Rank”, 1.0 );
AddColumn( LongTermRank, “Long Term Rank”, 1.0 );
AddColumn( AverageRank, “Average Rank”, 1.1 );SetSortColumns( 8 );
May 2, 2020 at 2:56 pm #111391JulianCohenParticipantGlen I get an “error 701 Missing Buy/Sell variable assignments” when I use this with my rotational code.
Any idea what I’m doing wrong?
I’m placing it just before the line for SetBacktestMode(backtestRotational)May 2, 2020 at 11:55 pm #111393GlenPeakeParticipantHi Julian,
I would put all this code above the rank criteria and then edit the Rank = accordingly as below, where AverageRank is the calculation output of the StaticVar code, with the 1000 – AverageRank bit so that it ranks from the biggest number to lowest number etc when running the ranking calc through the backtest etc etc…..
Code://=================================================================================
//Entry & Exit
//=================================================================================
Rank = 1000 – AverageRank; //Criteria for rotationLet me know if you want a full sample Rotational system code posted and I can throw one up if you still get stuck.
January 13, 2021 at 3:26 pm #111273AnonymousInactiveDoes anyones’ Amibroker crash when trying to run most of these snippets of code? Seem to be having issues on my end
January 13, 2021 at 8:27 pm #112873Nick RadgeKeymasterWhat version are you running? Might be worth upgrading to latest version.
January 13, 2021 at 9:59 pm #112874AnonymousInactiveUpgraded from 6.30.5 to 6.38.0 to no avail. My knowledge of this CBT is pretty limited, but did some tinkering though and the issue seemed to be with duplicating:
if (Status (“action”) == actionPortfolio )
Fixed – now I realize you cant just bolt on those snippets together, need to include them under the same if statement and also delete duplicate objects
June 24, 2021 at 10:14 am #111274ChrisThongParticipantHi All,
I found the following codes from Cesar’s Blog, which is relating to exploration of ~~~Equity for drawdown percentage and new equity high.
To explore, please select symbol “~~~Equity” and the date that you wanted to explore.
Code://=================================================================================
//Equity exploration parameters
//=================================================================================
Filter = True;
{
eq = C;
drPerc = -100*(eq/Highest(eq) – 1);
barSinNewHigh = BarsSince(drPerc == 0);
dd1 = IIf((barSinNewHigh == 0 AND Ref(barSinNewHigh,-1) != 0) OR (Status(“lastbarinrange”)), 1, 0);
dd1 = IIf(Status(“firstbarinrange”), 1, dd1);
dd2 = IIf(barSinNewHigh == 0 AND Ref(barSinNewHigh,-1) != 0 OR (Status(“lastbarinrange”)), HHV(drPerc, barSinNewHigh) , 0);
ddSort = Sort(dd2);
dn = DateNum();
barsToMdd = IIf(dd1 != 0, HighestSinceBars(Ref(dd1, -1) != 0, drPerc), 0);
}//=================================================================================
// Equity exploration code
//================================================================================={
AddColumn(C,”Equity”);
AddColumn(drPerc,”Draw Down Percent”);
AddColumn(barSinNewHigh,”barSinNewHigh”);
AddColumn(dd1,”dd1″);
AddColumn(dd2,”dd2″);
AddColumn(ddSort,”ddSort”);
AddColumn(barsToMdd,”barsToMdd”);
AddColumn(IIf(dd1==1, Ref(dn, -barsToMdd), 0), “DN MDD”);
AddColumn(BarIndex(), “Bar Index”, 1.0);
}Code: -
AuthorPosts
- You must be logged in to reply to this topic.