Help: How to code multiple exits?

Questions about MultiCharts and user contributed studies.
Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Help: How to code multiple exits?

Postby Spaceant » 28 May 2014

Hi,

I am trading a future with 4 ocntracts trade size, with an entry strategy (A) with different entry signals; and exit strategy (B) with a mix exit signals: wtih trailing stop, time exit and target prive exit. I would like to add a "tight % trailing stop" to close half of the holding if triggered (i.e. 2 contracts), leaving the other half (2 contracts) to be exited by exit strategy (B). If a new entry signal is triggered afterwards, I would like to buy back 2 contracts (i.e. max holding still is 4).

How can I code it smartly?
Is there any sample that I can learn from?
What is the ReservedWord, inside of a Signal, to check the number of contracts at broker?

Thanks in advance!

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

Re: Help: How to code multiple exits?

Postby TJ » 28 May 2014

Hi,
I am trading a future with 4 ocntracts trade size, with an entry strategy (A) with different entry signals; and exit strategy (B) with a mix exit signals: wtih trailing stop, time exit and target prive exit. I would like to add a "tight % trailing stop" to close half of the holding if triggered (i.e. 2 contracts), leaving the other half (2 contracts) to be exited by exit strategy (B). If a new entry signal is triggered afterwards, I would like to buy back 2 contracts (i.e. max holding still is 4).
How can I code it smartly?
Is there any sample that I can learn from?
What is the ReservedWord, inside of a Signal, to check the number of contracts at broker?
Thanks in advance!
When you increase the complexity of your logic, even for merely one additional contract, the coding permutation goes up exponentially. You nolonger have the luxury of a "One-size-fits-all" coding you enjoyed while trading a "one-contract" scenario. (ie. other people's sample is not likely to help much). From your simple description above, you have multiple conditional scenarios, which requires multiple "cross-checks" before you can proceed to your order logics. Coding the BUY/SELL is not difficult, the devil is in coding the "cross-checks".

The best suggestion I can give is...
1. draw a comprehensive flow chart before you start coding. (most people ignore this advice.)
2. read read read, and try try try... then test test test, and try again.
3. if time is not on your side, hire a professional programmer. If you have a profitable logic, there is no point in wasting time going around in circles just trying to save a few bucks.

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

Re: Help: How to code multiple exits?

Postby TJ » 28 May 2014

Hi,
::
What is the ReservedWord, inside of a Signal, to check the number of contracts at broker?

Thanks in advance!
Go to wiki,
look under 8 PowerLanguage Keyword Reference
look for the section Strategy Position‎


Return to “MultiCharts”