Hi,
How can I code two separate setups, one with only an initial stop loss and the other with an initial stop loss and a profit target.
When I create the code like below what happens is that Setup 1 which has only an initial stop loss (and some other exit rules that are not below), exits with the profit target that I defined for Setup 2. It seems like once a profit target is defined it is applied to any open trade. Why is that?
Can I code it in a way that the profit target is only applied for the trade setup 2?
Thanks
Sascha
if Setup1 then
ISL = 10000*(1*ATR + SBuffer )
TradeRisk = pipvalue*ISL
ContractSize = 100/TradeRisk
SELLSHORT ContractSize SHARES AT market
SET STOP LOSS 1*ATR + SBuffer
ENDIF
if Setup2 then
ISL = 10000*(1*ATR + SBuffer )
TradeRisk = pipvalue*ISL
ContractSize = 100/TradeRisk
SELLSHORT ContractSize SHARES AT close+0.25*ATR Limit
SET STOP LOSS 1*ATR + SBuffer
SET TARGET PROFIT 1.5*ATR + SBuffer
ENDIF
There is no way to identify the orders with code. What you can do is partial closing of position in profit at a desired level with a pending order, example below:
exitshort 1 contract at mylevel limit //mylevel is your desired price level
Thanks for your reply.
That’s unfortunate that this is not working. The goal was that I wanted to have one setup once triggered lets the trade run as long as possible until stopped out with a predefined trailing stop loss. And a second setup that exits with a fixed profit target, and having both setups in one automated trading system.
However, it seems that the solution is only to have two separate trading systems. One with a trailing stop loss and the other with a fixed profit target. The annoying thing is that if I want to run this system on 8 currency pairs, then I have to have 16 systems instead.
I mentioned before that I had the impression that once a profit target is defined (like it is Setup 2 in the example code) it is applied to any open trade. How is that technically possible?
If only the conditions for Setup 1 are me (which has no profit target) and the conditions for Setup 2 are not met, how can the profit target be even triggered as it is only within the if-clause of Setup 2?
Because the Takeprofit is applied directly to any open order, there is no way to select an order specifically.