dynamic live parameter adjustment
Forums › ProRealTime English forum › ProOrder support › dynamic live parameter adjustment
- This topic has 31 replies, 8 voices, and was last updated 4 years ago by Francesco.
-
-
03/02/2020 at 5:15 PM #120995
some first code, not sure if it’s correct completely, but it looks the way i’am after.
I want that the code automatically adjust a few parameters of a strategy if it determines that long or short doesn’t work anymore.
It’s like live adjustments within the margins set. First off I needed the data to work with so this is a start.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748// period resetonce periodr=1 //0all;1day;2week;3month;4yearif periodr=0 thenif barindex=0 thenlongperf=0shortperf=0endifelsif periodr=1 thenif day<>day[1] thenlongperf=0shortperf=0endifelsif periodr=2 thenif dayofweek=0 thenlongperf=0shortperf=0endifelsif periodr=3 thenif month<>month[1] thenlongperf=0shortperf=0endifelsif periodr=4 thenif year<>year[1] thenlongperf=0shortperf=0endifendifif longonmarket[1] and (not onmarket or shortonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenlongperf=longperf+positionperf(1)*100elselongperf=longperf-positionperf(1)*100endifendifif shortonmarket[1] and (not onmarket or longonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenshortperf=shortperf+positionperf(1)*100elseshortperf=shortperf-positionperf(1)*100endifendifgraph longperf coloured(0,0,255,255) as "long performance"graph shortperf coloured(255,0,0,255) as "short performance"1 user thanked author for this post.
03/03/2020 at 10:11 AM #121041Machine learning … great idea! Got to be the way to go Paul?
Did you see the work Leo did on Neural Network Indicators (links below)? Might spark some ideas for you.
I didn’t understand Leo’s code, but I just spotted something I hadn’t appreciated before!
Also now you are doing above, my task today is to read up on the difference between Machine Learning and Neural Networks.
https://www.prorealcode.com/topic/neural-networks-programming-with-prorealtime/
https://www.prorealcode.com/topic/discussion-on-leos-neural-networks/
1 user thanked author for this post.
03/03/2020 at 10:55 AM #121046I know the topics, but never realised it could be usefull for my goal. I only need 1 parameter to be adjust while trading, so maybe that will fit the purpose. Thanks for the links!
In meantime, something simple which can be used with code above.
Stop trading, long or short each, when profits are >2% or losses <-2%. It depends when the period-reset is set to start trading again.
123456789101112131415// limit & secure profit dailyif longperf>2 or longperf<-2 thentradelong=0elsetradelong=1endifif shortperf>2 or shortperf<-2 thentradeshort=0elsetradeshort=1endif//If longposition and tradelong then03/03/2020 at 11:31 AM #121049I did a lot of work on a code that adapted an indicator setting to what had worked best recently and the back tests were all fantastic but the forward tests turned out to be terrible. It seems that no matter what we do there is some form of curve fitting when using historical data and so I gave up on the concept. Plus at the time without arrays it was a coding nightmare!
03/03/2020 at 11:45 AM #121051I have developed and refined a ‘plug and play’ self contained heuristics algorithm over the last few years that can dynamically adjust any parameter based on it’s performance. I use it in all of my strategies. Let me know if you are interested.
4 users thanked author for this post.
03/03/2020 at 12:24 PM #12105403/03/2020 at 12:31 PM #121055@Vonasi I would then need to direct your attention to this topic I started in 2017: https://www.prorealcode.com/topic/machine-learning-in-proorder/
This is the early idea and birth place of the strategy. I will post the latest version there
03/03/2020 at 12:51 PM #12106005/01/2020 at 12:17 PM #129193I’ve picked up on this. It’s a version of ML in a basic way. It does what I had in mind.
if previous traderesult is positive/negative, it increase (or decrease) the parameter within max/min values
There’s a reset, currently it reset’s the positionperformance for a period, it doesn’t reset the boxsize in a proper way.
And a mention to the snippet above which is optional with below. It calculates the % for the period and if the realised performance exceeds the preset value it stops trading for that period.
if positions have +0.5 +0.2+0.6+1.0 and the total is bigger then i.e. 2%, it won’t take new trades that period. Same for losses. It’s no stoploss, because it looks at realised trade results.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120// dynamic parameter adjustmentonce periodr = 1 // [0]none;[1]day;[2]week;[3]month;[4]year (reset period)once direction= dd // [0] or [1]oppositeonce valuex = aaonce valuey = bbincrement = 5minvalue = 15maxvalue = 40// main setupif periodr=0 thenif barindex=0 thenlongperf=0shortperf=0endifelsif periodr=1 thenif day<>day[1] thenlongperf=0shortperf=0endifelsif periodr=2 thenif dayofweek=0 thenlongperf=0shortperf=0endifelsif periodr=3 thenif month<>month[1] thenlongperf=0shortperf=0endifelsif periodr=4 thenif year<>year[1] thenlongperf=0shortperf=0endifendifif longonmarket[1] and (not onmarket or shortonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenlongperf=longperf+positionperf(1)*100elselongperf=longperf-positionperf(1)*100endifendifif shortonmarket[1] and (not onmarket or longonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenshortperf=shortperf+positionperf(1)*100elseshortperf=shortperf-positionperf(1)*100endifendifif direction=1 thenif longperf>longperf[1] thenif valuex+increment <= maxvalue thenvaluex=valuex+incrementelsevaluex=valuexendifelsif longperf<longperf[1] thenif valuex-increment >= minvalue thenvaluex=valuex-incrementelsevaluex=valuexendifendifif shortperf>shortperf[1] thenif valuey+increment <= maxvalue thenvaluey=valuey+incrementelsevaluey=valueyendifelsif shortperf<shortperf[1] thenif valuey-increment >= minvalue thenvaluey=valuey-incrementelsevaluey=valueyendifendifelseif longperf>longperf[1] thenif valuex-increment >= minvalue thenvaluex=valuex-incrementelsevaluex=valuexendifelsif longperf<longperf[1] thenif valuex+increment <= maxvalue thenvaluex=valuex+incrementelsevaluex=valuexendifendifif shortperf>shortperf[1] thenif valuey-increment >= minvalue thenvaluey=valuey-incrementelsevaluey=valueyendifelsif shortperf<shortperf[1] thenif valuey+increment <= maxvalue thenvaluey=valuey+incrementelsevaluey=valueyendifendifendifgraph longperf*10 coloured(0,0,255,255) as "long performance (*10)"graph shortperf*10 coloured(255,0,0,255) as "short performance (*10)"boxsizes=valueyboxsizel=valuexgraph valuex coloured(0,200,0) as "boxsize long"graph valuey coloured(200,0,0) as "boxsize short"1 user thanked author for this post.
05/01/2020 at 1:41 PM #129212quick fix for the valuex/y reset when periodr > 0
optimise direction 0-1 & valuex/y
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140// dynamic parameter adjustmentonce periodr = 0 // [0]none;[1]day;[2]week;[3]month;[4]year (reset period)once direction= 0 // [0] or [1]oppositeonce valuex = 45once valuey = 45once startvalueL=valuexonce startvalueS=valueyincrement = 5minvalue = 10maxvalue = 50// main setupif periodr=0 thenif barindex=0 thenlongperf=0shortperf=0endifelsif periodr=1 thenif day<>day[1] thenlongperf=0shortperf=0endifelsif periodr=2 thenif dayofweek=0 thenlongperf=0shortperf=0endifelsif periodr=3 thenif month<>month[1] thenlongperf=0shortperf=0endifelsif periodr=4 thenif year<>year[1] thenlongperf=0shortperf=0endifendifif longonmarket[1] and (not onmarket or shortonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenlongperf=longperf+positionperf(1)*100elselongperf=longperf-positionperf(1)*100endifendifif shortonmarket[1] and (not onmarket or longonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenshortperf=shortperf+positionperf(1)*100elseshortperf=shortperf-positionperf(1)*100endifendifif direction=1 thenif longperf<>0 thenif longperf>longperf[1] thenif valuex+increment <= maxvalue thenvaluex=valuex+incrementelsevaluex=valuexendifelsif longperf<longperf[1] thenif valuex-increment >= minvalue thenvaluex=valuex-incrementelsevaluex=valuexendifendifelsevaluex=startvalueLendifif shortperf<>0 thenif shortperf>shortperf[1] thenif valuey+increment <= maxvalue thenvaluey=valuey+incrementelsevaluey=valueyendifelsif shortperf<shortperf[1] thenif valuey-increment >= minvalue thenvaluey=valuey-incrementelsevaluey=valueyendifendifelsevaluey=startvalueSendifelseif longperf<>0 thenif longperf>longperf[1] thenif valuex-increment >= minvalue thenvaluex=valuex-incrementelsevaluex=valuexendifelsif longperf<longperf[1] thenif valuex+increment <= maxvalue thenvaluex=valuex+incrementelsevaluex=valuexendifendifelsevaluex=startvalueLendifif shortperf<>0 thenif shortperf>shortperf[1] thenif valuey-increment >= minvalue thenvaluey=valuey-incrementelsevaluey=valueyendifelsif shortperf<shortperf[1] thenif valuey+increment <= maxvalue thenvaluey=valuey+incrementelsevaluey=valueyendifendifelsevaluey=startvalueSendifendifgraph longperf*10 coloured(0,0,255,255) as "long performance (*10)"graph shortperf*10 coloured(255,0,0,255) as "short performance (*10)"boxsizes=valueyboxsizel=valuexgraph valuex coloured(0,200,0) as "boxsize long"graph valuey coloured(200,0,0) as "boxsize short"05/03/2020 at 10:58 PM #129691a try, up 7 parameters! (vectorial)
it bouches around between min & max value and it checks if it’s better to increase after a win or decrease for each parameter. There is a reset which can be usefull. It only needs to test 0 – 1 except for the reset period if used.
valuex1 ->angle long
valuex2 -> angle short
valuex3-7 for the other parameters from the strategy.
remove once from mma/mmb etc.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371// dynamic parameter adjustmentonce periodr = pp // [0]none;[1]day;[2]week;[3]month;[4]year (reset period)once route1 = p1 // [0] or [1]opposite specific for longonce route2 = p2 // [0] or [1]opposite specific for shortonce route3 = p3 // [0] or [1]oppositeonce route4 = p4 // [0] or [1]oppositeonce route5 = p5 // [0] or [1]oppositeonce route6 = p6 // [0] or [1]oppositeonce route7 = p7 // [0] or [1]opposite// long angle longincrement1 = 2minvalue1 = 16maxvalue1 = 32// short angle shortincrement2 = 2minvalue2 = 16maxvalue2 = 32//increment3 = 1 //periodea 10minvalue3 = 8maxvalue3 = 12//increment4 = 1 //nbchandeliera 15minvalue4 = 13maxvalue4 = 17//increment5 = 1 //periodeb 20minvalue5 = 18maxvalue5 = 22//increment6 = 1 //nbchandelierb 35minvalue6 = 30maxvalue6 = 36//increment7 = 1 //lag 5minvalue7 = 0maxvalue7 = 6once valuex1 = (minvalue1+maxvalue1)/2once valuex2 = (minvalue2+maxvalue2)/2once valuex3 = (minvalue3+maxvalue3)/2once valuex4 = (minvalue4+maxvalue4)/2once valuex5 = (minvalue5+maxvalue5)/2once valuex6 = (minvalue6+maxvalue6)/2once valuex7 = (minvalue6+maxvalue7)/2once startvalue1=valuex1once startvalue2=valuex2once startvalue3=valuex3once startvalue4=valuex4once startvalue5=valuex5once startvalue6=valuex6once startvalue7=valuex7// main setupif periodr=0 thenif barindex=0 thenlongperf=0shortperf=0endifelsif periodr=1 thenif day<>day[1] thenlongperf=0shortperf=0endifelsif periodr=2 thenif dayofweek=0 thenlongperf=0shortperf=0endifelsif periodr=3 thenif month<>month[1] thenlongperf=0shortperf=0endifelsif periodr=4 thenif year<>year[1] thenlongperf=0shortperf=0endifendifif longonmarket[1] and (not onmarket or shortonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenlongperf=longperf+positionperf(1)*100elselongperf=longperf-positionperf(1)*100endifendifif shortonmarket[1] and (not onmarket or longonmarket) thenif strategyprofit[1]>=strategyprofit[2] thenshortperf=shortperf+positionperf(1)*100elseshortperf=shortperf-positionperf(1)*100endifendifif route1=1 thenif longperf<>0 thenif longperf>longperf[1] thenif valuex1+increment1 <= maxvalue1 thenvaluex1=valuex1+increment1elsevaluex1=valuex1endifelsif longperf<longperf[1] thenif valuex1-increment1 >= minvalue1 thenvaluex1=valuex1-increment1elsevaluex1=valuex1endifendifelsevaluex1=startvalue1endifelseif longperf<>0 thenif longperf>longperf[1] thenif valuex1-increment1 >= minvalue1 thenvaluex1=valuex1-increment1elsevaluex1=valuex1endifelsif longperf<longperf[1] thenif valuex1+increment1 <= maxvalue1 thenvaluex1=valuex1+increment1elsevaluex1=valuex1endifendifelsevaluex1=startvalue1endifendifif route2=1 thenif shortperf<>0 thenif shortperf>shortperf[1] thenif valuex2+increment2 <= maxvalue2 thenvaluex2=valuex2+increment2elsevaluex2=valuex2endifelsif shortperf<shortperf[1] thenif valuex2-increment2 >= minvalue2 thenvaluex2=valuex2-increment2elsevaluex2=valuex2endifendifelsevaluex2=startvalue2endifelseif shortperf<>0 thenif shortperf>shortperf[1] thenif valuex2-increment2 >= minvalue2 thenvaluex2=valuex2-increment2elsevaluex2=valuex2endifelsif shortperf<shortperf[1] thenif valuex2+increment2 <= maxvalue2 thenvaluex2=valuex2+increment2elsevaluex2=valuex2endifendifelsevaluex2=startvalue2endifendifif route3=1 then //periodeaif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex3+increment3 <= maxvalue3 thenvaluex3=valuex3+increment3elsevaluex3=valuex3endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex3-increment3 >= minvalue3 thenvaluex3=valuex3-increment3elsevaluex3=valuex3endifendifelsevaluex3=startvalue3endifelseif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex3-increment3 >= minvalue3 thenvaluex3=valuex3-increment3elsevaluex3=valuex3endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex3+increment3 <= maxvalue3 thenvaluex3=valuex3+increment3elsevaluex3=valuex3endifendifelsevaluex3=startvalue3endifendifif route4=1 then //nbchandelieraif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex4+increment4 <= maxvalue4 thenvaluex4=valuex4+increment4elsevaluex4=valuex4endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex4-increment4 >= minvalue4 thenvaluex4=valuex4-increment4elsevaluex4=valuex4endifendifelsevaluex4=startvalue4endifelseif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex4-increment4 >= minvalue4 thenvaluex4=valuex4-increment4elsevaluex4=valuex4endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex4+increment4 <= maxvalue4 thenvaluex4=valuex4+increment4elsevaluex4=valuex4endifendifelsevaluex4=startvalue4endifendifif route5=1 then //periodebif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex5+increment5 <= maxvalue5 thenvaluex5=valuex5+increment5elsevaluex5=valuex5endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex5-increment5 >= minvalue5 thenvaluex5=valuex5-increment5elsevaluex5=valuex5endifendifelsevaluex5=startvalue5endifelseif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex5-increment5 >= minvalue5 thenvaluex5=valuex5-increment5elsevaluex5=valuex5endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex5+increment5 <= maxvalue5 thenvaluex5=valuex5+increment5elsevaluex5=valuex5endifendifelsevaluex5=startvalue5endifendifif route6=1 then //nbchandelierbif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex6+increment6 <= maxvalue6 thenvaluex6=valuex6+increment6elsevaluex6=valuex6endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex6-increment6 >= minvalue6 thenvaluex6=valuex6-increment6elsevaluex6=valuex6endifendifelsevaluex6=startvalue6endifelseif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex6-increment6 >= minvalue6 thenvaluex6=valuex6-increment6elsevaluex6=valuex6endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex6+increment6 <= maxvalue6 thenvaluex6=valuex6+increment6elsevaluex6=valuex6endifendifelsevaluex6=startvalue6endifendifif route7=1 then //lagif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex7+increment7 <= maxvalue7 thenvaluex7=valuex7+increment7elsevaluex7=valuex7endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex7-increment7 >= minvalue7 thenvaluex7=valuex7-increment7elsevaluex7=valuex7endifendifelsevaluex7=startvalue7endifelseif shortperf<>0 or longperf<>0 thenif shortperf>shortperf[1] or longperf>longperf[1] thenif valuex7-increment7 >= minvalue7 thenvaluex7=valuex7-increment7elsevaluex7=valuex7endifelsif shortperf<shortperf[1] or longperf<longperf[1] thenif valuex7+increment7 <= maxvalue7 thenvaluex7=valuex7+increment7elsevaluex7=valuex7endifendifelsevaluex7=startvalue7endifendif3 users thanked author for this post.
05/04/2020 at 11:36 AM #12980105/04/2020 at 12:01 PM #129806yes, saw it later after posting. More bugs most likely. Need a reset day/week/month i.e. on 5 min. to make sense, if it does anyway. The min+max/2 value can be replace with a preferred number. I.e. lag, put in 5, with increment 5 and it will switch between 0 and 5. (with minvalue=0/maxvalue=5)
1 user thanked author for this post.
05/04/2020 at 2:38 PM #12985105/04/2020 at 2:38 PM #129852Altered the min/max values and got it to where it’s very close to the non-dynamic version. Tried using a fixed number for startvalue but (min+max)/2 was better. Feels like it needs just another little push to get up into positive territory!
1234567891011121314151617181920212223242526272829303132333435363738394041424344// dynamic parameter adjustmentonce periodr = 1 // [0]none;[1]day;[2]week;[3]month;[4]year (reset period)once route1 = 1 // [0] or [1]opposite specific for longonce route2 = 1 // [0] or [1]opposite specific for shortonce route3 = 1 // [0] or [1]oppositeonce route4 = 1 // [0] or [1]oppositeonce route5 = 1 // [0] or [1]oppositeonce route6 = 1 // [0] or [1]oppositeonce route7 = 1 // [0] or [1]opposite// long angle long 45increment1 = 2minvalue1 = 37maxvalue1 = 53// short angle short 34increment2 = 2minvalue2 = 26maxvalue2 = 42//increment3 = 1 //periodea 10minvalue3 = 8maxvalue3 = 12//increment4 = 1 //nbchandeliera 14minvalue4 = 12maxvalue4 = 16//increment5 = 1 //periodeb 22minvalue5 = 20maxvalue5 = 24//increment6 = 1 //nbchandelierb 34minvalue6 = 32maxvalue6 = 36//increment7 = 1 //lag 4minvalue7 = 0maxvalue7 = 61 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on