Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › AFL Template & Looping Reference Library
- This topic is empty.
-
AuthorPosts
-
July 5, 2016 at 11:46 pm #104369Stephen JamesMember
Template for Stress Testing:-
Code://To engage / disengage blocks of code, highlight block > right click > Line Comment_SECTION_BEGIN (“Stress Testing Variables”);
//=================================================================================
//Stress Testing
//=================================================================================
//MCS Monte Carlo Part 1 of 2
Runs = Param(“Number of Runs”,100,0,100000,100);
Run = Optimize(“Run”,1,1,Runs,1);
MCP = Param(“Probability of Ignoring any Entry Signal %”,25,1,100,1);
//———————————————————————————
//Signal and Data Variance
function RandPercent(percent)
{
perc = percent/100;
rand = 1+(perc – mtRandom() * (perc*2));
return rand;
}
MCRP = Param(“Random Percent”,20,1,100,1);
Variant = RandPercent(MCRP);
//Apply ‘Variant’ to the variable being tested – e.g. Close * Variant
//———————————————————————————
//Rolling Window Analysis – disengage Monte Carlo code for test
Run = Optimize(“Run”,1,1,1,1);//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Index Filter”);
//=================================================================================
//Index Filter
//=================================================================================//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Optional Price & Volume Filters”);
//=================================================================================
//Optional Price & Volume Filters
//=================================================================================//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Universe Filter”);
//=================================================================================
//Universe Filter
//=================================================================================//=================================================================================
_SECTION_END();_SECTION_BEGIN(“Parameters”);
//=================================================================================
//System Parameters
//=================================================================================
//e.g. Moving average * Variant//=================================================================================
//Entry and Exit Signals
//=================================================================================
LE = //Long Entry//———————————————————————————
//MCS code part 2
if (MCP)
LE = LE && Random()*100 >= MCP;//=================================================================================
//Looping
//=================================================================================//=================================================================================
//Exploration
//=================================================================================
//Filter code for correlation analysis of index – run usual filter for system, then
//replace with this filter for the index
Filter = 1;
AddColumn(C,”Close”);//=================================================================================
//Interpretation Window
//=================================================================================//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Chart Plotting”);
//=================================================================================
//Chart Plotting
//=================================================================================
//Walk Forward Equity Plots replace all other plotting code
PlotForeign(“~~~ISEQUITY”,”In-Sample Equity”, colorRed, styleLine);
PlotForeign(“~~~OSEQUITY”,”Out-Of-Sample Equity”, colorGreen, styleLine);
Title = “{{NAME}} – {{INTERVAL}} {{DATE}} {{VALUES}}”;
//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Backtesting”);
//=================================================================================
//Backtesting Parameters & Position Sizing
//=================================================================================//=================================================================================
_SECTION_END();July 6, 2016 at 1:20 am #102786LeeDanelloParticipantThanks Craig,
Is the “engage / disengage blocks of code, highlight block > right click > Line Comment” a new feature of Amibroker? I haven’t noticed it before.
Just wondering whether the signal and data variance code should be run with the Monte Carlo code.
If you wanted to modify the closing price wouldn’t the code be Close = Close * Variant.
July 6, 2016 at 3:35 am #104693Stephen JamesMemberYes, I’ve only been alerted to the Line Comment recently so I gather it’s quite new.
Re MCS – depends on what you want to achieve.
The example of Variant is not full code – just an example to use the identifier ‘Variant’ instead of RandPercent(MCRP) as in the course notes – thought it might be easier.
An easier way to get the monthly data for an index when doing correlation analysis would be to use something like:-
MonthReturn = ROC(C,1);
Filter = MonthReturn;
AddColumn(MonthReturn,”Month ROC”);Once you have run the test on your system, replace the filter with the above, select the index on a chart, select ‘Current’ in the analyser filter, select Monthly in settings and run Explore. Then the monthly returns can be copied straight into excel.
July 6, 2016 at 5:15 am #104694LeeDanelloParticipantCraig Fisher wrote:Yes, I’ve only been alerted to the Line Comment recently so I gather it’s quite new.Re MCS – depends on what you want to achieve.
The example of Variant is not full code – just an example to use the identifier ‘Variant’ instead of RandPercent(MCRP) as in the course notes – thought it might be easier.
An easier way to get the monthly data for an index when doing correlation analysis would be to use something like:-
MonthReturn = ROC(C,1);
Filter = MonthReturn;
AddColumn(MonthReturn,”Month ROC”);Once you have run the test on your system, replace the filter with the above, select the index on a chart, select ‘Current’ in the analyser filter, select Monthly in settings and run Explore. Then the monthly returns can be copied straight into excel.
So if you want to use the variant code on it’s own, MCP should be MCRP in the following block.
Code://MCS code part 2
if (MCRP)
LE = LE && Random()*100 >= MCRP;If you wanted to use it in combination with trade skipping, the code given below is OK
Code://MCS code part 2
if (MCP)
LE = LE && Random()*100 >= MCP;July 6, 2016 at 5:59 am #104695Stephen JamesMemberSorry Maurice,
I was thinking more single run tests with the variance code – done without the MCS code active. However, you can still leave MCS code active in the code ready for an MCS test with variance as one is a backtest and the other an optimization. No need to change the code you alluded to.
July 6, 2016 at 6:55 am #104696LeeDanelloParticipantOK.
July 24, 2016 at 3:20 am #102787JulianCohenParticipantWould anyone have the code for entries exploration for the API on the ASX please? Is it the same as the US but just changing the currency to AUD?
Also I’m looking for the code to change the buy limit order for the Open auction please.
Thank you.
July 24, 2016 at 4:11 am #102788Nick RadgeKeymasterYes, its the same yet uses AUD
Code:SetOption(“NoDefaultColumns”,True);Filter = BO1;
Width = 65;
Width1 = 75;
if(Status(“action”)==4)
{
SetSortColumns(1);
}
AddTextColumn(WriteIf(BO1,”” + Name(),””),”Symbol”,1.3,29,55,90);
AddTextColumn(WriteIf(BO1,”STK”,””),”Type”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Expiry”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Strike”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”P/C”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Multiplier”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Trading Class”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”SMART”,””),”Exchange”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Primary Exchange”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”AUD”,””),”Currency”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Comb Legs”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Leave This Empty”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”Buy”,””),”Action”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””+STB1,””),”Quantity”,1.0,29,55,Width);
AddTextColumn(WriteIf(BO1,”LMT”,””),”Order Type”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””+BuyLim,””),”Lmt Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Aux Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Ctrl”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Status”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Filled”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Remaining”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Ave Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Last Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Parent Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”DAY”,””),”Time in Force”,1.3,29,55,Width1);Quote:Also I’m looking for the code to change the buy limit order for the Open auction please.The LMT order will participate in the open auction so long as the orders are placed prior the 10am open
July 24, 2016 at 4:23 am #104855JulianCohenParticipantNick Radge wrote:Yes, its the same yet uses AUDCode:SetOption(“NoDefaultColumns”,True);Filter = BO1;
Width = 65;
Width1 = 75;
if(Status(“action”)==4)
{
SetSortColumns(1);
}
AddTextColumn(WriteIf(BO1,”” + Name(),””),”Symbol”,1.3,29,55,90);
AddTextColumn(WriteIf(BO1,”STK”,””),”Type”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Expiry”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Strike”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”P/C”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Multiplier”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Trading Class”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”SMART”,””),”Exchange”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Primary Exchange”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”AUD”,””),”Currency”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Comb Legs”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Leave This Empty”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”Buy”,””),”Action”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””+STB1,””),”Quantity”,1.0,29,55,Width);
AddTextColumn(WriteIf(BO1,”LMT”,””),”Order Type”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””+BuyLim,””),”Lmt Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Aux Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Ctrl”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Status”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Filled”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Remaining”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Ave Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Last Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Parent Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”DAY”,””),”Time in Force”,1.3,29,55,Width1);Quote:Also I’m looking for the code to change the buy limit order for the Open auction please.The LMT order will participate in the open auction so long as the orders are placed prior the 10am open
Thanks a lot Nick. Didn’t you mention something about putting in the order + or – 3%?
July 24, 2016 at 6:08 am #104856LeeDanelloParticipantJulian Cohen wrote:Nick Radge wrote:Yes, its the same yet uses AUDCode:SetOption(“NoDefaultColumns”,True);Filter = BO1;
Width = 65;
Width1 = 75;
if(Status(“action”)==4)
{
SetSortColumns(1);
}
AddTextColumn(WriteIf(BO1,”” + Name(),””),”Symbol”,1.3,29,55,90);
AddTextColumn(WriteIf(BO1,”STK”,””),”Type”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Expiry”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Strike”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”P/C”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Multiplier”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Trading Class”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”SMART”,””),”Exchange”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Primary Exchange”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”AUD”,””),”Currency”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Comb Legs”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Leave This Empty”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”Buy”,””),”Action”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””+STB1,””),”Quantity”,1.0,29,55,Width);
AddTextColumn(WriteIf(BO1,”LMT”,””),”Order Type”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””+BuyLim,””),”Lmt Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Aux Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Ctrl”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Status”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Filled”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Remaining”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Ave Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Last Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Parent Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”DAY”,””),”Time in Force”,1.3,29,55,Width1);Quote:Also I’m looking for the code to change the buy limit order for the Open auction please.The LMT order will participate in the open auction so long as the orders are placed prior the 10am open
Thanks a lot Nick. Didn’t you mention something about putting in the order + or – 3%?
I understand that it’s only for exits so that you get filled if gaps occur against you.
July 24, 2016 at 11:23 pm #102789Nick RadgeKeymasterJulian – If you want to participate at the official opening price then you need to be filled in the opening auction. The best way to do this is using some kind of buffer like 3% or so.
I recently did a Chartist member training session which discusses this better:
[video width=425 height=344 type=vimeo]171858892[/video]
July 28, 2016 at 9:47 am #104859SaidBitarMemberhere is the code for the DDE for the API for the AUS stocks
Code:AddTextColumn(WriteIf(BO1,”” + StrReplace(Name(), “.asx”, “” ),””),”Symbol”,1.3,29,55,90);
AddTextColumn(WriteIf(BO1,”STK”,””),”Type”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Expiry”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Strike”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”P/C”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Multiplier”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Trading Class”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”SMART”,””),”Exchange”,1.3,29,55,80);
AddTextColumn(WriteIf(BO1,””,””),”Primary Exchange”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,”AUD”,””),”Currency”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Comb Legs”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Leave This Empty”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,BO2,””),”Action”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””+BO3,””),”Quantity”,1.0,29,55,Width);
AddTextColumn(WriteIf(BO1,”LMT”,””),”Order Type”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””+BO4,””),”Lmt Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Aux Price”,1.3,29,55,Width);
AddTextColumn(WriteIf(BO1,””,””),”Ctrl”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Status”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Filled”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Remaining”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Ave Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Last Fill Price”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,””,””),”Parent Id”,1.3,29,55,Width1);
AddTextColumn(WriteIf(BO1,”DAY”,””),”Time in Force”,1.3,29,55,Width1);July 30, 2016 at 5:47 am #104860JulianCohenParticipantSorry Nick I have been trying for days to find a computer that will play this flash movie but can’t find one.
So to sum it up, I want to enter market on open orders in the ASX Monday for my rotational system. Do I do the following:
1. Run my system to create the entries
2. Add 3% to the price
3. Enter them as LMT orders manually an hour before the open
4. Monitor and any that aren’t filled after 30 mins use a MKT order for themJuly 30, 2016 at 5:51 am #102790Nick RadgeKeymasterUsually 3% will fill everything. Else use 5%.
November 12, 2018 at 8:30 pm #102791AnonymousInactiveHi everyone, I noticed in some other parts of the forum that others are able to generate a report that shows the number of days to wait before a new high. If anyone is willing to share the AFL it would be appreciated. I assume this is saved in the “Report Charts” folder and then it appears automatically?
Thanks! -
AuthorPosts
- You must be logged in to reply to this topic.