I am having some trouble finding a way to SetProfitTarget uniquely for specific entries.
Let's say that I:
Buy 3 Contracts Next Bar At Market;
I want Contract 1 to have a profit target of 12 ticks, contract 2 to have a profit target of 20 ticks, and contract 3 to have a profit target of 64 ticks.
This is very easy to do in NT but I am at a loss as to how to do it in EL. I'm sure I am missing something... but it seems the SetProfitTarget() command is going to evaluate the entire position size.
What can I do?
Thanks for your help!
Mike
Multiple entries/targets, SetProfitTarget uniquely
I should probably add that I tried toying with PositionProfit() but was unable to make it work as expected. I am thinking it is evaluated only at Close of bar during backtests.
That would be like closing a Stop Loss order only after the bar closed and your loss limit was exceed @ close. I want the stop loss to be closed mid-bar at the precise stop-loss limit, and I would expect the profit target to behave the same way. I have no issue with SetStopLoss, it works as expected.
Again thanks for guidance.
Mike
That would be like closing a Stop Loss order only after the bar closed and your loss limit was exceed @ close. I want the stop loss to be closed mid-bar at the precise stop-loss limit, and I would expect the profit target to behave the same way. I have no issue with SetStopLoss, it works as expected.
Again thanks for guidance.
Mike
- Bruce DeVault
- Posts: 438
- Joined: 19 Jan 2010
- Location: Washington DC
- Been thanked: 2 times
- Contact:
SetStopLoss and SetProfitTarget alway exits the entire position. What you want to do instead is specify a price and size, such as "sell ("LX-Tgt1") 1 contract next bar at Target1Price limit". You can also use the phrasing "from entry" is you like, to tie it to a specific purchase on the scale in side. For the scale out, you would typically put this language inside of a check to see if you're already out for that piece, such as by comparison of CurrentContracts with your entry size. In this way, you can have one entry for instance and 1 stop (that perhaps changes as each target is filled) plus 5 targets for varying sizes that add up to your entry.
Bruce,
Thanks, so something like this right?
Mike
Thanks, so something like this right?
Code: Select all
if MarketPosition = 1 then
begin
if CurrentContracts = 1 then Sell 1 Contract Next Bar At EntryPrice(0) + target1profit + target2profit + target3profit Limit;
if CurrentContracts = 2 then
begin
Sell 1 Contract Next bar At EntryPrice(0) + target1profit + target2profit Limit;
Sell 1 Contract Next Bar At EntryPrice(0) + target1profit + target2profit + target3profit Limit;
end;
if CurrentContracts = 3 then
begin
Sell 1 Contract Next bar At EntryPrice(0) + target1profit Limit;
Sell 1 Contract Next bar At EntryPrice(0) + target1profit + target2profit Limit;
Sell 1 Contract Next Bar At EntryPrice(0) + target1profit + target2profit + target3profit Limit;
end;
end;
- Bruce DeVault
- Posts: 438
- Joined: 19 Jan 2010
- Location: Washington DC
- Been thanked: 2 times
- Contact:
Here's a quick example. This example is not intended to represent best practices, but is just to show you how it can work. This example takes a semirandom entry, then scales out in three steps based on the size of the entry order fill, pulling the stop up as each target is hit in succession. It waits until the entry order is filled to put the targets in (but could be adapted easily to do so beforehand) and makes the adjustments on bar completion, without waiting for additional fills.
Code: Select all
//
// demonstrate scaling out in three steps
//
inputs:
EntrySize(3),
Target1Ticks(5),
Stop1Ticks(-20),
Target2Ticks(10),
Stop2Ticks(-10),
Target3Ticks(15),
Stop3Ticks(0);
variables:
CC(0),
SizeRemaining(0),
Target1Size(0),
Target2Size(0),
Target3Size(0);
// place a long entry order at some appropriate junction
if close crosses above average(close, 50) and MarketPosition = 0 then
buy("LE") EntrySize contracts next bar at market;
// if we have a new long fill, determine the scale out sizes for three targets based on our fill size
// (we could do this in advance of a fill also if we're wanting to handle exits on the same bar as
// entry, at the expense of tailoring the sizes specifically for underfills)
CC = CurrentContracts;
if CC > 0 and CC[1] <= 0 then
begin
SizeRemaining = CC;
Target1Size = MinList(Floor(SizeRemaining / 3), 1);
SizeRemaining = SizeRemaining - Target1Size;
Target2Size = 0;
if SizeRemaining > 0 then Target2Size = MinList(Floor(SizeRemaining / 2), 1);
Target3Size = SizeRemaining - Target2Size;
end;
// while we are long, keep the targets in the market (we could also do this by setting a flag that we
// have just entered, and thus get the targets in sooner) - this could also be enhanced to better handle
// if the targets are at the same price, etc. and is just a quick example
if MarketPosition > 0 then
begin
if CurrentContracts >= Target1Size + Target2Size + Target3Size then
begin
sell ("LX-Tgt1") Target1Size contracts next bar at EntryPrice + Target1Ticks * MinMove / PriceScale limit;
sell ("LX-Stp1") next bar at EntryPrice + Stop1Ticks * MinMove / PriceScale stop;
end
else if CurrentContracts >= Target2Size + Target3Size then
begin
sell ("LX-Tgt2") Target2Size contracts next bar at EntryPrice + Target2Ticks * MinMove / PriceScale limit;
sell ("LX-Stp2") next bar at EntryPrice + Stop2Ticks * MinMove / PriceScale stop;
end
else
begin
sell ("LX-Tgt3") Target3Size contracts next bar at EntryPrice + Target3Ticks * MinMove / PriceScale limit;
sell ("LX-Stp3") next bar at EntryPrice + Stop3Ticks * MinMove / PriceScale stop;
end;
end;
- Attachments
-
- Scale Out Demo.png
- (470.76 KiB) Downloaded 535 times