Right now I have a system where I enter a trade and use a fixed stop.
I'm interested in running a simulation where I trade 2 contracts and move my stop to breakeven once a profit reaches a certain a dollar amount (i.e. $1,000). If it's not reasonable to use a profit amount, I could replace it with ticks or points to equal $1,000.
I would then exit 1 contract and keep the other one in place until it gets stopped out at the breakeven stop or reaches the end of a seasonal window.
The other stipulation is that, if after moving the stop to breakeven and the trade is then stopped out, I would re-enter another full position (2 contracts) as long my technical parameters were still aligned and the seasonal window were still open.
Any tips on how to code this?
Move Stop to Breakeven
-
- Roundtable Knight
- Posts: 2038
- Joined: Wed Oct 06, 2004 10:52 am
- Location: San Marcos, CA
Your need to reach a predefined gain, exit 1-contract, and adjust the protective price is easily accomplished with a Target Price exit that also includes the script to setup the protective price to the position's fill-price. It would also require this code to be placed in a module that is named so that it is located above the current exit module's displayed location in the System Editor's display. An alternative would be to add the target process to the current exit blox.
Your requirement to re-enter that instrument again after being stopped out would in most cases be controlled by your current entry blox, and in many cases the entry blox wouldn't need any additional coding to re-enter. However, this is a check the code first before making any assumptions about what this second step would need.
Your requirement to re-enter that instrument again after being stopped out would in most cases be controlled by your current entry blox, and in many cases the entry blox wouldn't need any additional coding to re-enter. However, this is a check the code first before making any assumptions about what this second step would need.
-
- Contributing Member
- Posts: 9
- Joined: Thu Jun 14, 2012 2:35 pm
Roger,
Thanks for the help. However, I'm not finding the Target Price exit. I have looked at the AdjustPositionAtLimit price, but that doesn't allow me to move the stop. Where am I going wrong here? Also, is this where I would put the coding, before the technical indicator exit?
If instrument.position == LONG then
'Reduce position once profit taregt is achieved'
broker.AdjustPositionAtLimit (.5, profitTarget)
if adxIndicator < adxIndicator[1]then
broker.exitAllUnitsOnOpen
endif
If instrument.CanTradeLong = 0 then broker.exitAllUnitsOnOpen
Thanks for the help. However, I'm not finding the Target Price exit. I have looked at the AdjustPositionAtLimit price, but that doesn't allow me to move the stop. Where am I going wrong here? Also, is this where I would put the coding, before the technical indicator exit?
If instrument.position == LONG then
'Reduce position once profit taregt is achieved'
broker.AdjustPositionAtLimit (.5, profitTarget)
if adxIndicator < adxIndicator[1]then
broker.exitAllUnitsOnOpen
endif
If instrument.CanTradeLong = 0 then broker.exitAllUnitsOnOpen
-
- Roundtable Knight
- Posts: 2038
- Joined: Wed Oct 06, 2004 10:52 am
- Location: San Marcos, CA
A Target price is a price created through a process of taking the fill-price, and making an estimate of how many points will be possible to capture a reliable gain. With a point projection estimate and a base price put the two values together to obtain the target price level at which you plan on removing some size. Target prices are often not achieved, but when they are reached the order created to make a change and remove some size is almost always an AtLimit type of execution.
Trading Blox provides more than a few AtLimit type executions, but the most popular Broker objet target exit functions are these:
To move the protective price, first capture its current price using:
Then determine the new price you want, and then update it with
With the new exit price in place, the Exit Orders sections in other modules that execute after the module's section where you perform the above can then read the protective new price and honor it with a normal protective Exit-Order.
Keep in mind that scripts with same name execute in the order in which they are sorted and displayed in the System Editor window after the System Editor has been closed so the blox can be sorted. When the System Editor is re-opened again the Blox-name order you see before you add or remove any blox from the system list is the order in which same name scripts will execute.
Trading Blox provides more than a few AtLimit type executions, but the most popular Broker objet target exit functions are these:
Code: Select all
broker.ExitAllUnitsAtLimit
broker.ExitUnitAtLimit
broker.AdjustPositionAtLimit
Code: Select all
instrument.unitExitStop
Then determine the new price you want, and then update it with
Code: Select all
instrument.SetExitStop
Keep in mind that scripts with same name execute in the order in which they are sorted and displayed in the System Editor window after the System Editor has been closed so the blox can be sorted. When the System Editor is re-opened again the Blox-name order you see before you add or remove any blox from the system list is the order in which same name scripts will execute.
-
- Contributing Member
- Posts: 9
- Joined: Thu Jun 14, 2012 2:35 pm
Well, I gave it a go this weekend and I don't think I have the programming quite right. I created a new Entry/Exit block with the following:
I just made a generic target price being entry.fill *20% I added this block to my current system (which I left unchanged)
My skills in this stuff are minimal (at best) so I don't want to keep tying up the conversation, but I certainly appreciate the help!![/code]
Code: Select all
IF instrument.position = LONG AND
instrument.high >= targetPrice THEN
broker.ExitUnitAtLimit (1, targetPrice)AND
instrument.setexitstop (1, instrument.unitEntryFill)
My skills in this stuff are minimal (at best) so I don't want to keep tying up the conversation, but I certainly appreciate the help!![/code]
-
- Roundtable Knight
- Posts: 2038
- Joined: Wed Oct 06, 2004 10:52 am
- Location: San Marcos, CA
Code: Select all
If instrument.position = LONG AND
instrument.high >= targetPrice THEN
' Leave Broker object Function calls as a stand-alone statement
broker.ExitUnitAtLimit (1, targetPrice)
ENDIF
If you use a partial exit, you will have a position with a partial Qty to protect...
Code: Select all
' If you want the previous target as a protective price,...
myNewExitStop = targetPrice
' your solution was giving it its old price.
instrument.SetExitStop (1, myNewExitStop )
Your previous statement above didn't make logic programming sense because the Broker object doesn't return anything, and even if it did, there wasn't any variable being assigned to create a complete logical assignment.