Australian (ASX) Stock Market Forum

Developing a mechanical system from scratch

Same breakout system with Slippage and commision and only trading the first 4 hours of the European session....Basic Breakout time limited slipp and comm.PNG
 
Nah tech, it's fresh outta the language editor....every time I open tradestation I have a look at it recently.
 
As I learn to code different filters I try it out....
 
BP ATR SWitch.PNG CD ATR SWitch.PNG EC ATR SWitch.PNG JY ATR SWitch.PNG Had lunch with a mate today and we were talking about ATR. I mentioned that as a regime filter i sometimes use two ATRs of differing lengths as a switch. I then pondered if it might be a good signal....Turns out it is....here's the stats on the currencies and the EL Code. I used a simple moving average cross for a stop and the ATR cross for the signal. More likely a good idea of a regime filter than a system though.
Code:
//ATR Crossover woth SMA cross trailing stop_use on daily TF_by CanOz
if marketposition <1 and AvgTrueRange(20) crosses above AvgTrueRange(100) then sell short this bar;
If marketposition = 1 and average(c,25) crosses above average (c,15)then buy to cover this bar;

If marketposition<1 and AvgTrueRange(20) crosses below AvgTrueRange(100) then buy this bar;
If marketposition = 1 and average(c,25) crosses below average (c,15) then sell this bar;
BP ATR SWitch.PNG
 
2.) If you have 'been there, done that' then please let us work through some of the issues so we get a feel of ownership. Maybe a few hints now and then would be good too.
Gee whiz I spent much time into the early hours of mornings running mechanical systems on Amibroker and found nothing that gave me real money similar results or confidence to put real money on (since I lost a fair bit on the learning treadmill anyway). The overall market conditions, bad news announcement, a glitch here, a stall there, stopped out on desperate large parcel offloads, missed exits because system said hold and generally different from backtest results. I felt I knew way more than a mechanical system so I stopped and collated all what I have learned and make "decisions" from a variety of set ups (not restricted there) with "consideration" of way more market nuances than my mechanical systems can see. Market depth, short positions open, market sentiment and all the little experiences picked up along the way for example.

Still use the charts but fixed rules did not work for me. I know I am not alone.
 
Gee whiz I spent much time into the early hours of mornings running mechanical systems on Amibroker and found nothing that gave me real money similar results or confidence to put real money on (since I lost a fair bit on the learning treadmill anyway). The overall market conditions, bad news announcement, a glitch here, a stall there, stopped out on desperate large parcel offloads, missed exits because system said hold and generally different from backtest results. I felt I knew way more than a mechanical system so I stopped and collated all what I have learned and make "decisions" from a variety of set ups (not restricted there) with "consideration" of way more market nuances than my mechanical systems can see. Market depth, short positions open, market sentiment and all the little experiences picked up along the way for example.

Still use the charts but fixed rules did not work for me. I know I am not alone.

Remember when you were a smart arse to me when I pointed out your gross errors in you mechanical system a while back? Maybe you failed because you didn't want to listen to other people's input.
https://www.aussiestockforums.com/threads/why-isnt-everyone-rich-trading-these-systems.31106/page-4
 
Certainly intraday systems are pretty difficult to have faith in, but there are still persistent edges trading longer term. At the moment I'm just having fun learning to code. I've no pressure to earn a living from this and along the way I may learn something that helps me in my discretionary trading...
 
My 30/30 intrday strategy now with and optimised trading window and optimised stops. Plus an ATR % filter. Next step is to code up or steal a trailing stop. I think i'll run that on a third data series.3030EQ.PNG 3030Stats.PNG chart FDAX 3030.PNG
 
Thanks Boggo. The expectancy expressed that way certainly doesn't look very good....but I need to have another look when I'm not lying in bed on my iPad.....
 
I've added a trailing stop and although its improved the longs i need to split the inputs in order to max out the usefulness of the trail on short trades as they happen quicker. Trailing stops are definately better than hard targets though. The code, although already in Tradestation had to be integrated and that was challenging, but rewarding when i figured it out. Kicking myself for not learning to code years ago, i could have been a gun by now!3030EQ with ATR Target trail.PNG
 
Kicking myself for not learning to code years ago, i could have been a gun by now!

Coding is a useful skill to have. I've been contributing to open source projects for a number of years (mostly using Python) as a bit of a hobby but have recently been using Python in trading systems. Learnt coding in Amibroker early on which made all the difference with trading mechanical systems.

Even something as simple as using flowcharts to map out code structure is a useful skill to develop.
 
So here is both trailing stops optimised separatly. This strategy work ok, but the numbers are not great. It was a great excercise in adding filters and stops. I also set it up on the Euro and it works ok as well. If anything that i could do that may help is to add a relative volume filter. Something i've wanted to code up anyway, we'll see....3030EQ with ATR Target trail both long and short.PNG 3030StatsATR_L_S.PNG
 
Just for kicks and giggles i thought i'd see how it did on the Swiss Franc....on the right side at least!

Been flat on the OOS data.SF_3030EQ with ATR Target trail.PNG
 
GC_1010EQ with ATR Target trail.PNG GOLD Is a screamer, a little low on the average trade though....no slippage and commisions in these so that would kill it.
 
CL - Again the average trade is too small. Still, tested well OOS so that was encouraging. CL_X_X EQ with ATR Target trail.PNG Stats X_X CL.PNG
 
Here is the code for the system setup for Gold.
Code:
//*************************************Thirty-Ten Breakout************************************************

//************30m10bar breakout strategy for GC by CanOz************
///////////////////Created September 2017////////////////////////////
//This strategy enters the market on a break of the 10 bar high or low and uses a
//trailing stop after an inital stop loss.

//These inouts can be optimised, Bars before break, start time and end time, Long and short stops and the ATR %
//Filter and threshold

Inputs:BBS(15),starttime(300), endtime(830), SLLE(1300),SLSE(350), Length( 30),Threshold( .5),
    
//Long entry ATR Trail stop settings, also optimisable   
    ATRLengthLE( 2) ,
    NumATRsLE( 2) ,
    NumBarsLE(  9),
//Short entry ATR Trail stop settings
    ATRLengthSE(  2) ,
    NumATRsSE( 4) ,
    NumBarsSE(  5) ;


//Filters//////////////////////////////////////////////
//Regime Filter - stays out of extreme low volatility
Condition1 = (AvgTrueRange( Length ) / Close * 100)data2>Threshold;
//Trading time Filter - only trade the first three hours of the European session
Condition2 = time is >=starttime and time is <=endtime;

///////////////////////////////////////////////////////
//Bull_Bear Filter - you can try using this one by uncommenting and cutting in the conditions
//Condition3 = the c[1]data2 > average(c,100)data2;
//condition4 = the c[1]data2 < average(c,100)data2;

 
variables:
MaxN_ATR(0) ,
MP( 0 ),
TT( 0 ),
TargetPrice( 0 );

MP = MarketPosition;
TT = TotalTrades;   

    
If condition1 then begin;
//Long Entry
If MP <1 and Condition2  then buy next bar at highest(h,BBS) stop;

//Initial Stop Loss
Setstoploss(SLLE);
//Exit before the close
Setexitonclose;


//Short Entry
If MP > -1 and Condition2 then sell short next bar at lowest(l,BBS) stop;
//Initial Stop Loss

SetStoploss(SLSE);
//Exit before the close
Setexitonclose;


//Trailing Stop
if MP = 1 then
begin
    if TT <> TT[1] or MP[1] <> 1 then
        TargetPrice = EntryPrice + AvgTrueRange( ATRLengthLE )data3 * NumATRsLE;
    if BarsSinceEntry < NumBarsLE then
        Sell ( !( "ATTLX-Tgt" ) ) next bar at TargetPrice limit
    else
        Sell ( !( "ATTLX-Trl" ) ) next bar at Low stop;
    end;
    
    if MP = -1 then
    begin   
        
    if TT <> TT[1] or MP[1] <> -1 then
        TargetPrice = EntryPrice - AvgTrueRange( ATRLengthSE )data3 * NumATRsSE;
    if BarsSinceEntry < NumBarsSE then
        Buy To Cover ( !( "ATTSX-Tgt" ) ) next bar at TargetPrice limit
    else
        Buy To Cover ( !( "ATTSX-Trl" ) ) next bar at High stop;
end;

end;
////////////////////Enjoy!////////////////////////////////////////////////////////
 
Top