Posted 2/3/2008 03:24:19
|
|
|
|
Just trying to figure out the order types with RE.
1hr bars for EUR/USD
If want to place at long limit order at 12 pm and for it to cancel at 4pm (4 bars later) with a price of 2.00 is this the correct code?
posOrder = New PositionOrder()
posOrder.OrderSymbol = symbol
posOrder.OrderType = OrderType.Limit
posOrder.PositionType = PositionType.Long
posOrder.NumShares = 1000
posOrder.LimitPrice = 2
posOrder.BarsValid = 4
If I am thinking correct this will only open a trade when the price trades through 2 between 12 and 4pm. Using the same code it seams to open a trade as soon as the order is submitted and not waiting for it to hit 2(or what ever price is set). i.e the price when it was submitted was < 2
If I actually set the limit price to 2 it still opens the trade. EUR/USD is no where near $2...
Any ideas?
Thanks
|
|
Posted 2/3/2008 11:40:47
|
|
|
|
You need to use a stop order.
Limit orders mean, "place the order at this price or better."
Stop orders mean, "when the stock reaches this price place a market order."
You can also do a Stop Limit order.
I have had problems with the BarsValid flag not being honored. You can verify this worked by hitting up the TradeOrder.TimeOut property.
And Dev's, BTW- PositionManager.RemoveFromPosition() should really return the TradeOrderAndOrder of the trade just submitted. I need to modify some flags on the trade that are not handled in RemoveFromPosition() and it is a pain to find the correct trade.
|
|
Posted 2/4/2008 02:53:37
|
|
|
|
Still no luck.
I have tried every order type but either get no trades or trades at an price(when the order is submitted)
This is a test system below. All it does is place limit orders when the time is 00:00.
Imports System
Imports System.Drawing
Imports System.Collections.Generic
Imports RightEdge.Common
Imports RightEdge.Indicators
Public Class SystemMainGrid
Inherits SystemBase
Public Overrides Sub Startup()
' Perform initialization or set system wide options here
AddHandler PositionManager.OrderFilled, AddressOf OrderFilled
End Sub
Public Overrides Sub NewSymbolBar(ByVal symbol As Symbol, ByVal bar As BarData)
' This line of code runs the actions you have set up in in the Project Form
Dim posOrder As PositionOrder
Dim i As Integer
Dim pipSpace As Double = symbol.SymbolInformation.TickSize * SystemParameters.Item("Space")
Dim dblSpread As Double = System.Math.Abs(bar.Ask - bar.Bid)
Dim intStpes As Integer = 3
If bar.PriceDateTime.Hour = 0 And bar.PriceDateTime.Minute = 0 And Not bar.PriceDateTime.DayOfWeek = DayOfWeek.Saturday And Not bar.PriceDateTime.DayOfWeek = DayOfWeek.Sunday Then
'we have the start of our trading session so reset the grid.
'first make sure our open order are clsoed.
PositionManager.CloseAllPositions(symbol)
For i = 1 To intStpes
posOrder = New PositionOrder()
posOrder.OrderSymbol = symbol
posOrder.OrderType = OrderType.Stop
posOrder.PositionType = PositionType.Long
posOrder.NumShares = 1000
posOrder.LimitPrice = (pipSpace * i) + bar.Open + dblSpread ' i have tried with a set price as well.
posOrder.BarsValid = -1
PositionManager.OpenPosition(posOrder)
'now open the short orders
posOrder = New PositionOrder()
posOrder.OrderSymbol = symbol
posOrder.OrderType = OrderType.Stop
posOrder.PositionType = PositionType.Short
posOrder.NumShares = 1000
posOrder.LimitPrice = (pipSpace * i) - bar.Open - dblSpread
posOrder.BarsValid = 96 ' 1 day on 15 min bars
'PositionManager.OpenPosition(posOrder)
Next
End If
Actions.RunActions(symbol)
End Sub
Private Sub OrderFilled(ByVal sender As Object, ByVal e As RightEdge.Common.OrderFilledEventArgs) ' (ByVal trade As Trade, ByVal pos As Position, ByVal state As Position.State)
If e.PositionState = Position.State.Closed Then
Exit Sub
End If
'Dim sl As Double
Dim tp As Double = e.Position.Symbol.SymbolInformation.TickSize * SystemParameters.Item("TP")
If e.Trade.TransactionType = BrokerTransactionType.Interest Then Exit Sub
'Set the TP and SL levels with the pip value
If e.Trade.TransactionType = BrokerTransactionType.Buy Then
'sl = e.Position.CurStats.EntryPrice.AccountPrice - (SystemParameters.Item("ATRSL") * ATR)
tp = e.Position.CurStats.EntryPrice.AccountPrice + tp
'PositionManager.SetStopLoss(e.Position.PosID, sl, False)
PositionManager.SetProfitTarget(e.Position.PosID, tp, False)
ElseIf e.Trade.TransactionType = BrokerTransactionType.Short Then
' sl = e.Position.CurStats.EntryPrice.AccountPrice + (SystemParameters.Item("ATRSL") * ATR)
tp = e.Position.CurStats.EntryPrice.AccountPrice - tp
'update the sl and tp levels
'PositionManager.SetStopLoss(e.Position.PosID, sl, False)
PositionManager.SetProfitTarget(e.Position.PosID, tp, False)
End If
End Sub
Private Sub MSG(ByVal text As String)
SystemData.Output.Add(OutputSeverityLevel.Informational, text)
End Sub
End Class
Any ideas?
|
|
Posted 2/4/2008 02:54:51
|
|
|
|
I think Fire Fox makes the coding have doubling spacing as well.
|
|
Posted 2/4/2008 04:08:52
|
|
|
|
Have you tried setting the stop and the target with an explicit order with
PositionManger.SubmitOrder(Position-ID, Order, Description, BarsValid)
I am not sure but in my understanding the problem is that the stop and the target are only valid for one bar and expire afterwards.
Markus Seeli
|
|
Posted 2/4/2008 04:37:34
|
|
|
|
I have not tried that but the order expiry is set in the posOrder.BarsValid = -1
|
|
Posted 2/4/2008 15:42:15
|
|
|
|
The following works with TWS and paper broker so try it out: //Stop Market order PositionOrder Order = new PositionOrder();//defaultsOrder.BarCountExit = 0;//no timed exitOrder.ProfitTarget = double.NaN;//this is a % tgtOrder.StopLoss = double.NaN; Order.TrailingStop = double.NaN; //details Order.OrderSymbol = symbol; Order.PositionType = PositionType.Long; //or PositionType.ShortOrder.NumShares = 1000;//or whatever sizeOrder.OrderType = OrderType.Stop; Order.StopPrice = 2.00 + 0.02; //Whatever the trigger price isOrder.LimitPrice = Limit - 0.03;//Don't care since this becomes Market orderOrder.Description = Comment; Order.BarsValid = - 1; //indefinite //Limit order PositionOrder Order = new PositionOrder();//defaultsOrder.BarCountExit = 0;//no timed exitOrder.ProfitTarget = double.NaN;//this is a % tgtOrder.StopLoss = double.NaN; Order.TrailingStop = double.NaN; //details Order.OrderSymbol = symbol; Order.PositionType = PositionType.Long; //or PositionType.ShortOrder.NumShares = 1000;//or whatever sizeOrder.OrderType = OrderType.Limit; Order.StopPrice = 2.00 + 0.02; //Don't care since Limit orderOrder.LimitPrice = 2.00 + 0.02;//buy for 2.02 or BETTEROrder.Description = Comment; Order.BarsValid = - 1; //indefinite //Stop Limit order -Will work in next release PositionOrder Order = new PositionOrder();//defaultsOrder.BarCountExit = 0;//no timed exitOrder.ProfitTarget = double.NaN;//this is a % tgtOrder.StopLoss = double.NaN; Order.TrailingStop = double.NaN; //details Order.OrderSymbol = symbol; Order.PositionType = PositionType.Long; //or PositionType.ShortOrder.NumShares = 1000;//or whatever sizeOrder.OrderType = OrderType.StopLimit; Order.StopPrice = 2.00 + 0.02; //Trigger PriceOrder.LimitPrice = 2.00 + 0.03;//Once Triggered, buy for 2.03 or BETTEROrder.Description = Comment; Order.BarsValid = - 1; //indefinite
If you are using TWS and are going to short, you'll need to download the new TWS beta plugin in the Plugins thread. Use at own risk. thx
DoQ_Indicators "better is the enemy of good enough"
|
|
Posted 2/4/2008 21:16:50
|
|
|
|
OK. Fixed. The stopprice was not set in my code.
|
|
Posted 2/6/2008 11:28:12
|
|
|
|
djasek (2/3/2008) And Dev's, BTW- PositionManager.RemoveFromPosition() should really return the TradeOrderAndOrder of the trade just submitted. I need to modify some flags on the trade that are not handled in RemoveFromPosition() and it is a pain to find the correct trade.FYI, this should be improved significantly in RightEdge 1.2. From your system you shouldn't need to use the TradeOrderAndOrder class at all. The new Order class will have the information you need. And when you submit an order on a position it will return the Order object. Daniel
|
|
|
|