yeah, I like it – better % win, better gain/loss, lower drawdown, only slightly lower profit but probably better in the long term. Thanks Fifi! 👍
PaulParticipant
Master
Hi Nonetheless,
Looking at your money management code, it calculates the new positionsize when there’s no market position.
However, if going from long to short directly & visa versa, which can happen a lot, regardless gain or loss there is no change in positionsize, so essentially there could be more gains to explore.
Is this something which can be changed? strategyprofit is only calculated when the position is closed.
Do you think it’s worth the effort to change this?
PaulParticipant
Master
Had a try, but doesn’t make much difference overall on vectorial strategy.
It had to be place right above the entry since it needs to know before the reversal takes place what positionsize to use. Seems to work as I tended in a glance.
once startpositionsize = 1
once factor = 10 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
once margin = (close*.05) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
once margin2 = (close*.05) // tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
once tier1 = 55 // ig first tier margin limit
once maxpositionsize = 550 // ig tier 2 margin limit
once minpositionsize = 1 // enter minimum position allowed
strategypp=strategyprofit+(positionperf(0)*100)*(tradeprice(1)/100)
if not onmarket or ((longonmarket and condsell) or (shortonmarket and condbuy)) then
positionsize = startpositionsize + strategypp/(factor*margin)
endif
if not onmarket or ((longonmarket and condsell) or (shortonmarket and condbuy)) then
if startpositionsize + strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (strategypp/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
endif
if not onmarket or ((longonmarket and condsell) or (shortonmarket and condbuy)) then
if startpositionsize + strategypp/(factor*margin) < minpositionsize then
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
endif
if (((startpositionsize + (strategypp/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above ig tier 2 margin limit
endif
endif
endif
PaulParticipant
Master
one part needed change
if onmarket then
strategypp=strategyprofit+(abs(countofposition)*(positionperf(0)*100)*(tradeprice(1)/100))
else
strategypp=strategyprofit
endif
Downside is, it’s not exactly a snippet anymore because it must know when conditions are met.
it was interesting to test.
Thanks for that, Paul – def worth having a look at. Recently I changed it to
//Money Management NAS
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize=1
ENDIF
if MM = 1 then
ONCE startpositionsize = 1
ONCE factor = f // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 200 // IG first tier margin limit
ONCE maxpositionsize = 2000 // IG tier 2 margin limit
ONCE minpositionsize = 1 // enter minimum position allowed
IF StrategyProfit <> StrategyProfit[1] THEN
positionsize = startpositionsize + Strategyprofit/(factor*margin)
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
ENDIF
IF StrategyProfit <> StrategyProfit[1] THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = minpositionsize //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
using IF StrategyProfit <> StrategyProfit[1] to allow for instant reversals. Seemed to solve the problem of algos that were onmarket near to 100%, but I hadn’t thought of merging it with the entry conditions… could be worth playing around with.
PaulParticipant
Master
I tried that too, but didn’t look close enough using graph! There’s a difference at the bar of the reversal.
Did a side by side comparison between your approach and mine, there’s a very small difference.
It’s easier to use your method which had a +400 on a equity of 117500. I remember you ran into this problem somewhere. I will update it in my strategies. Thanks.
Thank you all for your effor and for sharing this in the forum, it is an inspiration for people like me who are trying to start programming algos in PRT. @nonetheless or anyone, could you tell me which GTM hour is this algo using? I’ve tried it in GMT+2 and it works properly but probably another GMT time would be better to fit the parameters of the algo. Thanks in advance.
Hi @Ryugin, it’s set to UK time so for Spain I expect you need to change it to
Ctime = time >=153000 and time <220000//Euro time, GMT +1
it’s just the Wall St opening hours.
@Paul, did you see I added a line to your %TS
once trailingpercentlong = tsl // %
once trailingpercentshort = tss // %
once accelerator = acc // 1 = default; always > 0 (i.e. 0.5-3)
once accelerator2 = acc2 // 1 = default; always > 0 (i.e. 0.5-3)
once ts2sensitivity = 0 // [0]close;[1]high/low;[2]low;high
//====================
once steppercentlong = (trailingpercentlong/10)*accelerator
once steppercentshort = (trailingpercentshort/10)*accelerator2
accelerator2 gives the option to further optimize the TS going short, usually shows a small advantage.
Hi @Ryugin, it’s set to UK time so for Spain I expect you need to change it to
|
|
Ctime = time >=153000 and time <220000//Euro time, GMT +1
|
it’s just the Wall St opening hours.
Just to make sure I haven’t missed something since the timezone comes up in every thread. If I set custom trading hours in PRT that matches the exchange, for Nasdaq UTC-4. I just set the regular trading hours (9:30-16:00) in the script?
PaulParticipant
Master
yes, I did see that, nice touch! I would like to say it’s perfect now but it is not cuz I found maybe a bug.
Using it on vectorial, I saw a big difference in results using trailing-stop sensitivity 0 or 2 and the difference was too big to explain. Especially the last trade with the big loss. When it uses the close, the trade can exit too early. Something is off there can you ‘ve a look too?
PaulParticipant
Master
I’ve loaded the original one of nicolas & modifcations by robertoguzzi. That seems to work oke.
Then I took the version from your v3 strategy, which uses % instead of points and uses default close which is off too.
Think I found it
if onmarket then
trailingstart = positionprice[0]*(trailingpercent/100) //trailing will start @trailingstart points profit
trailingstep = positionprice[0]*(stepPercent/100) //% step to move the stoploss
endif
It used positionprice[1] and when there’s no market position and opened a new one it went off the rails.
Hello everybody,
can you provide the complete code again after all the others?
Thanks already heard.
Hello, first thanks for your work.
I keep seeing that he makes many entries in a row without closing the first ones. For that you have to have a large capital.
I have also tried reducing the 0.4lotti, but it keeps coming in with 1lotti.
Can you help me please? is there something that escapes me?
NOTE: In this test I have added the chunk of Fifi:
Mrsi=RSI[14](close)
if longonmarket and CurrentDayOfWeek=5 and close>positionprice and Mrsi crosses under 70 then
sell at market
endif
if shortonmarket and CurrentDayOfWeek=5 and close<positionprice and Mrsi crosses over 30 then
exitshort at market
endif
Nasdaq has a minimum position of 1.