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?
Setprofittarget function with profit in percent [SOLVED]
-
- Posts: 74
- Joined: 25 Aug 2007
- Been thanked: 6 times
Re: Setprofittarget function with profit in percent
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.
Re: Setprofittarget function with profit in percent
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.
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.
-
- Posts: 74
- Joined: 25 Aug 2007
- Been thanked: 6 times
Re: Setprofittarget function with profit in percent
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.
Make sure you do the rounding and put it to an integer number.
Re: Setprofittarget function with profit in percent
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?
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?
-
- Posts: 74
- Joined: 25 Aug 2007
- Been thanked: 6 times
Re: Setprofittarget function with profit in percent [SOLVED]
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
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
Re: Setprofittarget function with profit in percent
Erik,
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:
Any ideas?
Not for me. In my backtest all exits are wrongly taken at the close of the bar. Not where my optimimized profit target is.With intrabarorder generation on, "this bar on close" will fire immediately and not really wait for the bar to close.
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;
-
- Posts: 74
- Joined: 25 Aug 2007
- Been thanked: 6 times
Re: Setprofittarget function with profit in percent
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.
So daily chart for analysis and tick for trading.
E.