Scaling out code

Questions about MultiCharts and user contributed studies.
AdrianP
Posts: 46
Joined: 02 Sep 2014
Has thanked: 2 times
Been thanked: 1 time

Scaling out code

Postby AdrianP » 09 Jun 2022

Hi,

I'm having some issues getting my code to work properly when scaling out under certain circumstances, and was hoping someone could provide a fresh perspective.

1. We enter with a 2 unit position;
2. I then want to exit 1 unit, when a condition is met, and then the remaining 1 unit when the same or new exit condition is met, but ONLY to be applied ON A TOTALLY NEW SWING.

My problem is that both units often exit on consecutive bars when th econditions are met.
So, even if my exit conditions are slightly different, if they are both met on the initial pullback, they both exit.
But I only want 1 unit exit being allowed per swing, however one might define that.

So, I don't know how to limit my exits to 1 unit per swing.

Let's keep it simple...a 10 period SMA reversal. We want to exit 1 unit each time it reverses.
How do I do this?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Scaling out code

Postby TJ » 09 Jun 2022

Make a counter.
Reset the counter when the new swing begins.


Return to “MultiCharts”