Setprofittarget function with profit in percent  [SOLVED]

Questions about MultiCharts and user contributed studies.
orjan
Posts: 12
Joined: 18 Jan 2015
Has thanked: 3 times

Setprofittarget function with profit in percent

Postby orjan » 18 Mar 2015

I use IntrabarOrderGeneration and Bar Magnifier in my strategy, and use

Setprofittarget(amount);
Setstoploss(amount);

for exit. And that works when amount is set in points. But I want to set the exits in percent of entryprice. I have tried:

Input: Percent(1);
Var: Profit(0);
Profit = entryprice*Percent/100;
Setprofittarget(Profit);

But then the backtest did not take exit at the right places. Do you know how to set profit in percent in conjunction with IntrabarOrderGeneration and Bar Magnifier?

Erik Pepping
Posts: 74
Joined: 25 Aug 2007
Been thanked: 6 times

Re: Setprofittarget function with profit in percent

Postby Erik Pepping » 18 Mar 2015

I'm not sure on what instrument you are doing this, this would certainly not work on futures or currencies. The ticks represent not necessarily a money amount. I think the target has to be a whole number (see docs, it takes a numeric simple). Now you are probably calculating a decimal number like 3,50. Maybe if you round the number it will work. Use round.

orjan
Posts: 12
Joined: 18 Jan 2015
Has thanked: 3 times

Re: Setprofittarget function with profit in percent

Postby orjan » 18 Mar 2015

Erik Pepping,

I am doing it on EUR.USD forex. I have tried without decimals, 1 and 2 percent, which is approx the same profit target I know gives good result if I set the profits in points.

But with percent, entry and exit is taken at the same level each time. So backtested profit is 0.

Strange.

Erik Pepping
Posts: 74
Joined: 25 Aug 2007
Been thanked: 6 times

Re: Setprofittarget function with profit in percent

Postby Erik Pepping » 19 Mar 2015

Profit target with setprofit are always in dollar amounts, or the amount of the currency.
Make sure you do the rounding and put it to an integer number.

orjan
Posts: 12
Joined: 18 Jan 2015
Has thanked: 3 times

Re: Setprofittarget function with profit in percent

Postby orjan » 19 Mar 2015

OK, thanks
Then I have to find a way to set the profit target in percent without using the Setprofit function. Anyone who knows how, in conjunction with Intrabar order generation and Bar Magnifier?

Erik Pepping
Posts: 74
Joined: 25 Aug 2007
Been thanked: 6 times

Re: Setprofittarget function with profit in percent  [SOLVED]

Postby Erik Pepping » 19 Mar 2015

Yes you could monitor the trade yourself. Calculate the pips you want stop and profit and generate the order yourself.
After SELLSHORT use buy to cover.
After Buy use SELL to exit your position.

So something like:

if Marketposition=-1 then // You are in a short position
if Close() <= ProfitTarget then
buytocover ("SX") this bar on close;

if Marketposition=1 then // You are in a long position
if Close() >= ProfitTarget then
Sell ("LX") this bar on close;


I always use the labels LX , LE, SX , and SE (loing entery, Short Entry, Long Exit, Short Exit
With intrabarorder generation on, "this bar on close" will fire immediately and not really wait for the bar to close.


Erik

orjan
Posts: 12
Joined: 18 Jan 2015
Has thanked: 3 times

Re: Setprofittarget function with profit in percent

Postby orjan » 21 Mar 2015

Erik,
With intrabarorder generation on, "this bar on close" will fire immediately and not really wait for the bar to close.
Not for me. In my backtest all exits are wrongly taken at the close of the bar. Not where my optimimized profit target is.

My code starts with: [IntrabarOrderGeneration = true];
and I have checked Use Bar Magnifier and 1 minutes (the strategy is on Daily bars)

This is my exit code:

Code: Select all

{PROFIT TARGET AND LOSS FOR LONG:}
if marketposition = 1 and
Close >= profittargetL then
Sell ("PTL") this bar on close;

if marketposition = 1 and
Close <= lossL then
Sell ("SLL") this bar on close;
Any ideas?

Erik Pepping
Posts: 74
Joined: 25 Aug 2007
Been thanked: 6 times

Re: Setprofittarget function with profit in percent

Postby Erik Pepping » 22 Mar 2015

You could try adding a feed on tick bars. 1 tick. Each tick is a close for multicharts.
So daily chart for analysis and tick for trading.

E.


Return to “MultiCharts”