COME MIGLIORARE UNA STRATEGIA
Forums › ProRealTime forum Italiano › Supporto ProOrder › COME MIGLIORARE UNA STRATEGIA
- This topic has 2 replies, 2 voices, and was last updated 5 years ago by Mauro T. “Algorithm System”.
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
01/10/2019 at 6:25 PM #88329
Ho trovato questo articolo di Nicolas che in alcune strategie è migliorata non come performance ma come Max Drawdown ……però è solo per operazioni Long, ho cercato purtroppo invano di metterla anche per lo Short.
Se qualcuno è in grado di aiutarmi
Grazie Mauro
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102defparam cumulateorders=false// --- strategy settingstpratio = 2.7stoploss = 65takeprofit = stoploss*tpratio// --- simulated trading settingsequityCurvePeriod = 20 //orders quantity for the equity curve averageactivateSimulatedTrading = 1 //(0= false / 1 =true)//strategiesbuysignal = average[7] crosses over average[21]//rsi[2] crosses over 30if realtrading then //real tradingif not longonmarket and buysignal thenbuy at marketordercount=ordercount+1 //counting the order to know we have sufficient ones to activate the simulation laterendifset target pprofit takeprofitset stop ploss stoplosselsif not realtrading and ordercount>equityCurvePeriod then //fake tradingif not longontrading and buysignal thenopenprice=close //fake order open pricelongontrading=1 //we are now on market//reset MFE & MAE valuesmfe=0mae=0//fake orders countfakeorders=fakeorders+1endifendif//check profit n loss of the fake orderif longontrading=1 thenmfe = max(high-openprice,mfe) //compute the MaxFavorableExcursionmae = min(low-openprice,mae) //compute the MaxAdverseExcursion//profit achievedif mfe>=takeprofit*pointsize then //testing the takeprofitorderPNL=((openprice+takeprofit*pointsize)/openprice)-1longontrading=0 //not on market anymoreendif//shit happens!if mae<=-stoploss*pointsize then //testing the stoplossorderPNL=-(((openprice-stoploss*pointsize)/openprice)-1)longontrading=0 //not on market anymoreendifendif//compute equity curve and its averageif ( (not onmarket and onmarket[1]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1]) or (not longontrading and longontrading[1]) ) and lastcheck<>barindex then //check if an order has just closed or notlastcheck = barindexif(not longontrading[1]) then //if it was a real orderorderPNL = positionperf(1) //let's take the real position perf (otherwise the last orderPNL is kept (fake order)endifstrategyPNL = strategyPNL+orderPNL //cumulate the strategy PnL//build a loop to make the equity curve averagecount=0sum=0lastPNL=0for i = 0 to barindex doif strategyPNL[i]<>lastPNL thenlastPNL=strategyPNL[i]count=count+1sum=sum+strategyPNL[i]if count=equityCurvePeriod+1 thensum=sum-lastlast=strategyPNL[i]break//endifendifnextif last<>last[1] thenavg = (sum/equityCurvePeriod)endifif strategyPNL>avg thenrealtrading=1 //activate real trading if the PnL is superior to its averageelserealtrading=0 //or desactivate real tradingendifif ordercount<=equityCurvePeriod or activateSimulatedTrading=0 thenrealtrading=1 //if not enough orders since the beginning or if simulated trading is force to false, we keep on real tradingendifendif//plot the fake orders activationif longontrading thenplotLong = 0.01 //this value might be changed, depending of the strategyelseplotLong = 0endif////plot valuesgraph strategyPNL //plot the cumulated PnLgraph avg coloured(0,0,255) //plot the average of the equity curvegraph plotLong coloured(0,155,0) //plot the fake orders activation01/10/2019 at 7:21 PM #88335Ho provato a modificarla, ma non sono sicuro funzioni tutto correttamente, almeno per la parte di simulazione.
Fai delle prove:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137defparam cumulateorders=falseonce longontrading=0once shortontrading=0// --- strategy settingstpratio = 2.7stoploss = 65takeprofit = stoploss*tpratio// --- simulated trading settingsequityCurvePeriod = 20 //orders quantity for the equity curve averageactivateSimulatedTrading = 1 //(0= false / 1 =true)//strategiesbuysignal = average[7] crosses over average[21]//rsi[2] crosses over 30sellsignal = average[7] crosses under average[21]//rsi[2] crosses under 30if realtrading then //real tradingif not longonmarket and buysignal thenbuy at marketordercount=ordercount+1 //counting the order to know we have sufficient ones to activate the simulation laterendifif not shortonmarket and sellsignal thensellshort at marketordercount=ordercount+1 //counting the order to know we have sufficient ones to activate the simulation laterendifset target pprofit takeprofitset stop ploss stoplosselsif not realtrading and ordercount>equityCurvePeriod then //fake tradingif not longontrading and buysignal thenopenprice=close //fake order open pricelongontrading=1 //we are now on market//reset MFE & MAE valuesmfe=0mae=0//fake orders countfakeorders=fakeorders+1endifif not shortontrading and sellsignal thenopenprice=close //fake order open priceshortontrading=1 //we are now on market//reset MFE & MAE valuesmfe=0mae=0//fake orders countfakeorders=fakeorders+1endifendif//check profit n loss of the fake orderif longontrading=1 thenmfe = max(high-openprice,mfe) //compute the MaxFavorableExcursionmae = min(low-openprice,mae) //compute the MaxAdverseExcursion//profit achievedif mfe>=takeprofit*pointsize then //testing the takeprofitorderPNL=((openprice+takeprofit*pointsize)/openprice)-1longontrading=0 //not on market anymoreendif//shit happens!if mae<=-stoploss*pointsize then //testing the stoplossorderPNL=-(((openprice-stoploss*pointsize)/openprice)-1)longontrading=0 //not on market anymoreendifelsif shortontrading=1 thenmfe = max(high-openprice,mfe) //compute the MaxFavorableExcursionmae = min(low-openprice,mae) //compute the MaxAdverseExcursion//profit achievedif mfe>=takeprofit*pointsize then //testing the takeprofitorderPNL=((openprice-takeprofit*pointsize)/openprice)-1shortontrading=0 //not on market anymoreendif//shit happens!if mae<=-stoploss*pointsize then //testing the stoplossorderPNL=-(((openprice+stoploss*pointsize)/openprice)-1)shortontrading=0 //not on market anymoreendifendif//compute equity curve and its averageif ( (not onmarket and onmarket[1]) or (tradeindex(1)=tradeindex(2) and tradeindex(1)=barindex[1]) or (not longontrading and longontrading[1]) or (not shortontrading and shortontrading[1]) ) and lastcheck<>barindex then //check if an order has just closed or notlastcheck = barindexif (not longontrading[1]) and (not shortontrading[1]) then //if it was a real orderorderPNL = positionperf(1) //let's take the real position perf (otherwise the last orderPNL is kept (fake order)endifstrategyPNL = strategyPNL+orderPNL //cumulate the strategy PnL//build a loop to make the equity curve averagecount=0sum=0lastPNL=0for i = 0 to barindex doif strategyPNL[i]<>lastPNL thenlastPNL=strategyPNL[i]count=count+1sum=sum+strategyPNL[i]if count=equityCurvePeriod+1 thensum=sum-lastlast=strategyPNL[i]break//endifendifnextif last<>last[1] thenavg = (sum/equityCurvePeriod)endifif strategyPNL>avg thenrealtrading=1 //activate real trading if the PnL is superior to its averageelserealtrading=0 //or desactivate real tradingendifif ordercount<=equityCurvePeriod or activateSimulatedTrading=0 thenrealtrading=1 //if not enough orders since the beginning or if simulated trading is force to false, we keep on real tradingendifendif//plot the fake orders activationif longontrading thenplotLong = 0.01 //this value might be changed, depending of the strategyelseplotLong = 0endifif shortontrading thenplotShort = 0.01 //this value might be changed, depending of the strategyelseplotShort = 0endif////plot valuesgraph strategyPNL //plot the cumulated PnLgraph avg coloured(0,0,255) //plot the average of the equity curvegraph plotLong coloured(0,155,0) //plot the fake orders activationgraph plotShort coloured(255,0,0) //plot the fake orders activation01/10/2019 at 7:28 PM #88337Come al solito grazie…. Provo se funziona.
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
Find exclusive trading pro-tools on
Similar topics: