net profit trail stop?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
RobBoss

net profit trail stop?

Postby RobBoss » 27 Jul 2016

Hello,

I was able to add StrategyInfo.ClosedEquity to my strategy and have it close out when the net profit reaches a certain amount. However, now I would like to try setting it up so once profit reaches a certain amount, it then focuses on loses, and when/if the loses reach a certain point, it closes out. Much like a trailstop, but according to the prog guide, trailstops are specific to an order and not to overall profit.

Let's say my equity cap is at $1500 for my automated strategy. Now, if it hits $1500, and then over time profit drops below $1200, I want it to close out. I can not picture how to write it using simple if statements, is there something in MC that can help?

Is there any way to write it?

For reference (not super relevant), below is how I am using ClosedEquity:

Code: Select all

if(!money())
{
if(StrategyInfo.MarketPosition > 0)
{
exitLong.Send("Close for profit cap");
}
if(StrategyInfo.MarketPosition < 0)
{
exitShort.Send("Close for profit cap");
}
return;
}
private bool money()
{
if(StrategyInfo.ClosedEquity >= Amount)
return false;
else
return true;
}

mips4pips
Posts: 10
Joined: 27 Nov 2012
Has thanked: 10 times
Been thanked: 2 times

Re: net profit trail stop?

Postby mips4pips » 28 Jul 2016

I have been using the following calculations in my live trading. I hope this helps. If something is incorrect, please help me preserve my dwindling account by letting me know. Thanks.

Session Profit ---> StrategyInfo.OpenEquity

Current Position Profit ---> StrategyInfo.OpenEquity - StrategyInfo.ClosedEquity

Account Closed Balance ---> InitialCapital + StrategyInfo.ClosedEquity

Account Open Balance ---> InitialCapital + StrategyInfo.OpenEquity

RobBoss

Re: net profit trail stop?

Postby RobBoss » 28 Jul 2016

Hey Mips4pips,

Your math makes sense to me, unfortunately, I think your dwindling account is due to other reasons. I also do not think I can use any of that for my situation.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: net profit trail stop?

Postby Henry MultiСharts » 29 Jul 2016

Hello RobBoss,

Your code should work ok, but you need to make sure the strategy is calculated frequently enough to be able to close the position on time.
You can use special orders unconditionally instead:
https://www.multicharts.com/trading-sof ... ial_Orders

RobBoss

Re: net profit trail stop?

Postby RobBoss » 29 Jul 2016

Hello,

Yes the code I provided works great. That is not the issue, it was only to help clarify what I am trying to do.

I want to use overall strategy equity to determine when the code should close out. The special orders only work with one contract at a time, not with total strategy profit.

I want to know if there is a way to write "once net profit reaches a certain value (~$1500), if profit decreases by $300 at any point, close out for the day", in code.

Any ideas?
Thanks

eroleyikan
Posts: 22
Joined: 01 Jun 2016
Has thanked: 4 times
Been thanked: 6 times

Re: net profit trail stop?  [SOLVED]

Postby eroleyikan » 03 Aug 2016

Rob,
To achieve what you are looking for, I would try this:
When you reach that $1500 net income level, calculate (ie back-into) the price that will correspond to that $300 decline and place a stop order at that price.
I do something similar to this and it works for me.
I hope this helps.
Erol


Return to “MultiCharts .NET”