Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › generating signal/order plots
- This topic is empty.
-
AuthorPosts
-
June 7, 2016 at 3:19 pm #101534AnonymousInactive
I have put together some code for graphing signals generated by the setup trigger (ie: the number of buy limit orders I will be placing) in my MRV system. Perhaps others can improve/modify it more.
I include the following in my MCS code:Code:// calculate the number of buy limit orders we will be making and potential buy orders (depends on maxPositions)
AddToComposite(longEntrySetup == 1,”~SetupSignals_V15″,”X”,atcFlagDeleteValues|atcFlagEnableInBacktest|atcFlagEnableInBacktest);
AddToComposite(buy == 1,”~BuySignals_V15″,”X”,atcFlagDeleteValues|atcFlagEnableInBacktest|atcFlagEnableInBacktest);
setupSignals = Foreign(“~SetupSignals_V15″,”C”);
buySignals = Foreign(“~BuySignals_V15″,”C”);Once the MCS code has been backtested in the normal way two tickers are generated: ~SetupSignals_V15 and ~BuySignals_V15 (use any name your like).
Then its just a matter of plotting them.Code:Graph0 = Foreign(“~SetupSignals_V15″,”C”);
Graph1 = Foreign(“~BuySignals_V15″,”C”);I put the following in Basic Charts folder for easily comparing between different versions of systems (hence the _V15) and running a MA :
Code://———————————————————
// System signals_V02
//
// Generate Buy and buySetup signal plots. Taken from tickers:
// ~SetupSignals_V?? and ~BuySignals_V?? generated in backtests
//———————————————————// paramaters to select system verion and MA period
sysVersion = ParamList(“System Version”,”V14|V15″,0);
avPeriod = Param(“MA period”,100,1,200,1);
maxScale = Param(“Chart Max”,300,20,400,20);// select the system tickers and averages
setupSignals = Foreign(“~SetupSignals_” + sysVersion,”C”);
buySignals = Foreign(“~BuySignals_” + sysVersion,”C”);
setupSignalsAv = MA(setupSignals,avPeriod);
buySignalsAv = MA(buySignals,avPeriod);// setup a nice chart title
SetChartOptions(1,chartShowArrows|chartShowDates,chartGridMiddle,0,maxScale);
_N(Title = encodecolor(colorlime) + “~MR-system Operating V14 Test: ” + encodecolor(colordefault) + StrFormat(“{{INTERVAL}} {{DATE}} {{VALUES}}”) );// plot everthing
Plot(setupSignals,”# Buy orders placed”,colorGrey40,styleLine|styleOwnScale,0,maxScale);
Plot(buySignals,”# Buy orders hit”,colorGold,styleLine|styleOwnScale,0,maxScale);
Plot(setupSignalsAv,”Avg (” + NumToStr(avPeriod,1.0) + ” days) ” + “buy orders placed”,colorWhite,styleLine|styleOwnScale,0,maxScale);
Plot(buySignalsAv,”Avg (” + NumToStr(avPeriod,1.0) + ” days) ” + “buy orders hit”,colorBrown,styleLine|styleOwnScale,0,maxScale);reference on AddToComposite here
June 7, 2016 at 3:48 pm #104300AnonymousInactiveOutput from MRV system:
June 8, 2016 at 4:05 am #104304JulianCohenParticipantDarryl would you mind explaining what this is as you lost me after the first sentence
June 8, 2016 at 6:41 am #104310AnonymousInactiveJulian Cohen wrote:Darryl would you mind explaining what this is as you lost me after the first sentenceno probs julian. its just a way of gaphing the number of setup signals ie: the number of buy limit orders that you would have to place each day (not necessarily filled)
hope that makes senseJune 8, 2016 at 7:18 am #104311JulianCohenParticipantAh OK… I was thinking it was some new fangled indicator
June 8, 2016 at 11:56 am #104312AnonymousInactiveJulian Cohen wrote:Ah OK… I was thinking it was some new fangled indicatorno nothing that is going to make money unfortunately :dry: but… its nice to know how hard your API may have to work for you
June 16, 2016 at 9:05 am #104317ChrisViridesMemberDarryl,
I edited the Graph file so that the setups are on the same date as the buys.
Plot(Ref(setupSignals,-1),”# Buy orders placed”,colorGrey40,styleHistogram|styleOwnScale,0,maxScale);
This code is top stuff, thanks
November 23, 2016 at 2:35 pm #104301LeeDanelloParticipantSaid Bitar wrote:Brent Hause wrote:Quote:I liked the Idea and wanted to try it, so i modified the codes to check the number of signals per day and to adjust the number of positions accordingly. then i ran 4000 MCs to compare with my previous MCs.
i was expecting to find the STDEV tighter but the result was almost the same at leas the stdev for CAR and DD.Said – curious how you coded this…what function did you use to count the number of setups on a given day?
i added all the signals to a new ticker and run a scan after than i used the values of that ticker in position sizing
hint:
Code:AddToComposite(BuySignal, “~~~SystemSignals”, “X”);Code:AddToComposite(Buy,”~Buys”,”X”);
AddToComposite(Sell,”~Sells”,”X”);
Buys = Foreign(“~Buys”,”C”);
Sells = Foreign(“~Sells”,”C”);
Plot(Buys,”Buys”,5,1);
Plot(Sells,”Sells”,4,1);November 24, 2016 at 2:11 am #105842AnonymousInactiveSo far so good, but how do you get the daily data for the new security in a workable format (as opposed to a chart, which is great for a visual check, but not helpful for programming rules)? For instance, I am looking to compare the number of buy signals I have on a daily basis (“~Signals”) to the number of trades taken to get an approximate “hit rate”.
Once I run the scan, next I do an exploration. While the data is correct, it is a bit cumbersome to deal with…you get the same value across all signals that met the filter.
E.g. – Here is a screenshot of exploration results. Each stock that meets the criteria “BuySetUp” is shown, along with the ~Signals value (Signals column). The ~Signals value is rightly the same across all tickers for a given date (as it is the count of all tickers meeting the criteria BuySetUp). Other than running the exploration across all the symbols and then manually culling the data set in excel, does anyone know of a way that we can run an exploration and just get the date and the ~Signals value?
I’ve attached two screenshots for clarification…the first is a shot of what the explorer is spitting out, the second is what I am looking for…
November 24, 2016 at 2:25 am #105845AnonymousInactiveIt always seems the answer comes to me after I finally ask the question…
Code:AddToComposite(Ref(BuySetUp,1) == 1,”~Signals”,”C”,atcFlagDeleteValues|atcFlagEnableInBacktest|atcFlagEnableInExplore);
Filter = C > 1;
AddColumn(Foreign(“~Signals”,”C”),”~Signals”,1);Step 1 – Create the custom index and add the signals
Step 2 – Create the filter
Step 3 – Run the scan
Step 4 – In the exploration window, change the “Apply to” field to “current” and type in the custom index into the security field
Step 5 – Run the explorationNovember 24, 2016 at 7:18 am #105846AnonymousInactivePSA – I spent a good part of today working on an adaptive position sizing model for my MOC strategy – standard stuff that increases the allocation if there are fewer than the max signals allowed by the system on a given day. Unfortunately, there was no change in performance on either an absolute or risk-adjusted basis. When looking at the whole of the results, I didn’t see any discernable difference at all. The theme of simplicity reigning supreme is recurs!
November 24, 2016 at 7:38 am #105851JulianCohenParticipantIt’s a worthwhile excercise none the less. Test test test.
November 25, 2016 at 1:27 am #105852AnonymousInactiveIndeed…the brain is already starting to think of new applications for the coding I worked with…
November 29, 2016 at 7:20 am #104302AnonymousInactiveThought I’d post a quick update on how I ended up incorporating the ~Signals index in my MOC strategy. In my system, the ~Signals index is a synthetic index that I created to track the number of signals on a given day.
Initially, I tried using a “light” position size scaling algorithm depending on the ~Signals index. My system allows for up to 40 positions, so the position size varied between 5% of equity and 10% of equity depending on how many signals were given (~Signals <= 20, position size = 10%; as ~Signals scaled to 40, position size works its way to 5% of equity). This didn’t do much to improve performance, so I got a bit more aggressive with it. I’ve seen people throw around a cap of 10% of equity for a position size, but the metrics over the long term were such that I was comfortable with up to 15% position size for days with very few signals. The new position scaling scheme looks like this:
Code:{
if(SignalCount[i] <= 13) {FPAmt[i] = 15;} if(SignalCount[i] == 14) {FPAmt[i] = 14.5;} if(SignalCount[i] == 15) {FPAmt[i] = 13.5;} if(SignalCount[i] == 16) {FPAmt[i] = 12.5;} if(SignalCount[i] == 17) {FPAmt[i] = 11.5;} if(SignalCount[i] == 18) {FPAmt[i] = 11;} if(SignalCount[i] == 19) {FPAmt[i] = 10.5;} if(SignalCount[i] == 20) {FPAmt[i] = 10;} if(SignalCount[i] == 21) {FPAmt[i] = 9.5;} if(SignalCount[i] == 22) {FPAmt[i] = 9.1;} if(SignalCount[i] == 23) {FPAmt[i] = 8.7;} if(SignalCount[i] == 24) {FPAmt[i] = 8.3;} if(SignalCount[i] == 25) {FPAmt[i] = 8.0;} if(SignalCount[i] == 26) {FPAmt[i] = 7.7;} if(SignalCount[i] == 27) {FPAmt[i] = 7.4;} if(SignalCount[i] == 28) {FPAmt[i] = 7.1;} if(SignalCount[i] == 29) {FPAmt[i] = 6.9;} if(SignalCount[i] == 30) {FPAmt[i] = 6.7;} if(SignalCount[i] == 31) {FPAmt[i] = 6.5;} if(SignalCount[i] == 32) {FPAmt[i] = 6.3;} if(SignalCount[i] == 33) {FPAmt[i] = 6.1;} if(SignalCount[i] == 34) {FPAmt[i] = 5.9;} if(SignalCount[i] == 35) {FPAmt[i] = 5.7;} if(SignalCount[i] == 36) {FPAmt[i] = 5.5;} if(SignalCount[i] == 37) {FPAmt[i] = 5.4;} if(SignalCount[i] == 38) {FPAmt[i] = 5.2;} if(SignalCount[i] == 39) {FPAmt[i] = 5.1;} if(SignalCount[i] >= 40) {FPAmt[i] = 5.0;}
}Another thing I did with the ~Signals index was allowed it to influence the stretch. In my system, I code the stretch level as ATRM (ATR Multiple) where my limit = C – ATR(n)*ATRM. I was using a static ATRM (1.5) but now I allow for a lower ATRM if the signal count is <40.
Code:ATRM = 1.5;
for(m=1; mI played with more complex schemes, but further complexity did not add value.
In summary, on days with fewer signals the position size will be bigger and the stretch smaller.These changes added to performance on both an absolute and risk-adjusted basis across time frames without increasing selection bias. The increase in performance isn’t huge, but worth the extra effort IMO. I am about to start live trading again, so yet to know if these results are truly achievable, but I figured I’d share how I incorporated the signal count index with the group.
Below is a metrics comparison across different time frames (average of 20 run MCS). Version 2 includes the incorporation of the ~Signals index, version 1 is the base strategy. Results below are compounded.
November 29, 2016 at 9:43 am #105869ScottMcNabParticipantThank you for sharing Brent.
I too was using a static stretch initially. I found it beneficial to have a different stretch based on a number of conditions relating to the individual stock and the index…boosted metrics quite a bit so may be worth playing around with;
ATRM = IIf (insert stock or index condition here,1.7,1.0);
If it worked ok on the SPX then I would test it on other markets (NDX, XAO, SEHK) as there is a real risk of curve fitting down this track
AuthorPosts- You must be logged in to reply to this topic.