Conditional Sell Rule with Conditional Scale Out

Hey guys,

Hope you're all doing ok. Apologies for my noob level coding. There are two concepts below that I am trying to get my head around and still struggling with. If anyone could assist, explain or point me in the right direction that would be a huge help!

These are conditional sell rules - which I think I have achieved.

but more importantly scaling out rules - and how to combine them with the conditional sell rules. I have tried to read the pyramiding threads and examples on the forum, however the logic is not making a lot of sense to me at this stage of my development.

Essentially what I want to do is the following. Say I buy a 52 week high and its an explosive move. I want to be able to say that if the if the move is extended (my condition in this scenario is a certain % above key moving average) I tighten the trailing stop (which is a sell below a faster moving average). I also want to be able to scale out say 50% of my position in this faster moving average and then maybe the remaining 50% on the slower/original moving average in hope of a bigger/longer move in time.

I would like to be able to get to the stage where I could test/implement whether selling a higher % than 50% of my position into an even higher extended or explosive move would benefit my system. So potentially in my script could have multiple conditions depending on how explosive the move is.

However at this stage would appreciate if i could get some help trying to do the basics for a 50% & 50% faster and slower moving average scenario so i can get a better idea of how sigscaleout works with a conditional sell rule

My basic example code below.

Any help would be appreciated. Again, I'm not perfect but I'm trying to learn the best I can.



BuyCondition1 = HHV(C,250);

SellCondition1 = C<MA(C,20);
SellCondition2 = C<MA(C,10);
extended = C>1.1*MA(C,20);

Buy =  C>= BuyCondition1;
Sell = IIf(SumSince(Buy,extended)>1,Sellcondition2,sellcondition1);

SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position

See Scale In/Out Example (Example 4) adjust to suit.

1 Like

Thanks, do you by any chance know of a different example as well that i can refer to?

Would be hugely appreciated,



What is it that you are not sure about?

Run a Backtest and study the 'Detailed Log'.


1 Like

I don't quite understand the code in the example you provided and I cant find many other scale out examples on the site to refer to. If there is another I am missing feel free to send my way.

All good if not, ill continue trial and error.

What part/s of the code?

That's not the solution in this case. The solution is to understand (study & test) the working example given.

I don't understand barcount & the assignment of 'i' and use of 0 and 1's.

See AFL Reference Manual.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.