Home › Forums › Trading System Mentor Course Community › AmiBroker Coding and AFL › Converting a Number To An Array
- This topic is empty.
-
AuthorPosts
-
June 25, 2021 at 8:42 pm #113487ScottMcNabParticipant
Have you tried that code snippet ? I am not sure why it would work with my afl and not yours
June 26, 2021 at 5:43 am #113468ScottMcNabParticipantI just tried another quick test Terry
first is with:
SetPositionSize(10,spsPercentOfEquity);this next one is using:
PS = IIf(Name()==”NUE” OR Name()==”UAA”,5,10);SetPositionSize(Ref(PS,-1),spsPercentOfEquity);
June 26, 2021 at 6:46 am #113488JulianCohenParticipantIt works!!! Eureka
June 26, 2021 at 7:21 am #113489TerryDunneParticipantHi Scott,
Thanks for taking the time to try to solve my problem, but unfortunately I don’t think this idea works.
I think what happens is that you get fewer positions – you might have 20% position size versus 10% normally and ten positions but the backtest will only take five positions as the available capital runs out. I think margin has to be adjusted as well…
You’ll note that I keep saying “…I think…”. This is because I’m not able to recheck this right now, probably not until after the weekend.
My apologies – and gratitude – if I’m wrong about this but that’s my recollection.
Thanks again,
Terry
June 27, 2021 at 9:14 am #113490TerryDunneParticipantBack at my laptop, I’m pretty sure it doesn’t work..
June 28, 2021 at 8:33 pm #113469ScottMcNabParticipantHi Terry. Based on past experience I am probably incorrect but hopefully I can learn something here…when I run the code with a PS multiplier to reduce PS in high vola the only thing that seems to happen is the number of shares for the stock with high vola is halved….so PS goes from 10% to 5%…not from 10% to 20%….I have done other test using HVola this time and compared it to my live results (the first table posted)….the trades taken are the same but some of the stocks just have the number of shares halved
code used for PS in this example:
HVola = 100 * StDev(log(C/Ref(C,-1)),10) * sqrt(252);
PSMult = IIf(HVola>30,0.5,1);
PS = 10*PSMult;SetPositionSize(Ref(PS,-1),spsPercentOfEquity);
June 29, 2021 at 12:07 am #113491TerryDunneParticipantHi Scott,
I think I just had a light bulb moment…I can’t increase position size because of the problem I gave above, but I can do what you’ve done – reduce the position size – because then I won’t run out of cash. So for back testing purposes only, I could set leverage to say 10:1 and then have criteria that reduce position size to whatever I wish to test.
I can’t wait to get home to try this!!!
Thanks for your involvement Scott, (I hope) you’ve put me on the right track!!
Terry
June 29, 2021 at 4:02 am #113492JulianCohenParticipantHa Ha…I couldn’t work out why it wasn’t working for you and now I realise. This happens to me all the time…something is only obvious when it’s pointed out, or when you see it for the first time.
June 29, 2021 at 8:44 am #113493TerryDunneParticipantYes, I’ve been walking around the office slapping my head most of the day, feeling like a complete idiot
June 29, 2021 at 10:05 pm #113494JulianCohenParticipantDid anyone video that?
June 29, 2021 at 11:18 pm #113495TerryDunneParticipantJune 29, 2021 at 11:24 pm #113496TerryDunneParticipantOK (sigh) I think I still have a problem.
As a checking mechanism, I set up the code to adjust position size and then I made both settings the same as my original position size.In other words, if the ‘regular’ position size is 20%, I made the two settings 20%…this should give the exact same back test results, right?
Well, it didn’t.
Could I ask if somebody would mind doing the same exercise and seeing what result they get? I really hope I’m just continuing to be an idiot
Thanks in advance,
Terry
July 1, 2021 at 12:37 am #113497ScottMcNabParticipantAre you able to post the code Terry? One of the stronger coders here might be able to shed some light in case we are doing something wrong
July 1, 2021 at 1:56 am #113502TerryDunneParticipantGood idea Scott, I could do with all the help I can get. There’s only a couple of lines of code
In the Index area
MarketStrength = PercentRank(RSI(2),100);
Then in the Fixed % Of Portfolio Equity
FPAmount = IIf(MarketStrength > 50,40,20);
July 1, 2021 at 6:41 am #113505ScottMcNabParticipantAnd in the test that concerns you it was ?
FPAmount = iif(MarketStrength>50,20,20)
SetPositionSize(Ref(FPAmount,-1),spsPercentOfEquity);and the results didn’t match with ?
SetPositionSize(20,spsPercentOfEquity);
-
AuthorPosts
- You must be logged in to reply to this topic.