Profile Picture

SetStopLoss

Posted By ywlee 4 Years Ago
Message
Posted Sunday October 20 2013
Hi

How do you set a stop loss based on the highest(20) and ATR?

The following code thows an exception when run:

Code:

If (position.Trades.Count = 1) Then

position.SetStopLoss(Highest(20) - 2 * ATR.Current, TargetPriceType.AbsolutePrice)

End If

Error Message:


The service plugin PaperBroker.PaperTrader threw an exception of type RightEdge.Common.RightEdgeError
at RightEdge.Shared.ServiceWrapper.DoError(Exception e)
at RightEdge.Shared.BrokerWrapper.SimTick(Symbol symbol, TickData tick)
at RightEdge.Common.Internal.SystemRunner.ProcessTickInPaperBroker(Symbol symbol, TickData tick)
at RightEdge.Common.FrequencyManager.ProcessTick(Symbol symbol, TickData tick)
at RightEdge.Common.Internal.SystemRunner._tickGenerator_NewTick(Object sender, NewTickEventArgs e)
at RightEdge.Common.TickGenerator.ProcessBar(NewBarEventArgs args)
at RightEdge.Common.Internal.SystemRunner.ProcessBar(NewBarEventArgs newBars)
at RightEdge.Shared.SystemWrapper.RunSystem(SystemData systemData, SharedSystemRunData runData, ServiceFactory brokerFactory)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
at RightEdge.Shared.SystemWrapper.RunSystem(String filename, ServiceFactory brokerFactory, PluginSettings dataStoreSettings)
at RightEdge.Shared.TradingModuleWrapper.Run(String filename)
at RightEdge.Shared.TradingModuleWrapper.RunSystem(SharedSystemRunData systemRunData)
at RightEdge.SystemProgress.InitAndRunSystem()

Inner Exception:
The method or operation is not implemented.

Server stack trace:
at RightEdge.Shared.TradingModuleWrapper.DelegateWrapper.SendException(Object sender, ExceptionEventArgs args)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at RightEdge.Shared.TradingModuleWrapper.ICallbacks.SendException(Object sender, ExceptionEventArgs args)
at RightEdge.Shared.SystemWrapper.b__0(Object sender, ExceptionEventArgs args)
at RightEdge.Shared.CallbackStub.DoCallback()
at RightEdge.Shared.BrokerWrapper.broker_orderUpdated(BrokerOrder order, Fill fill, String information)
at PaperBroker.PaperTrader.OnOrderUpdated(BrokerOrder order, Fill fill, String information)
at PaperBroker.PaperTrader.ProcessOrder(BrokerOrder order, Double bidPrice, Double askPrice, Double prevBid, Double prevAsk, DateTime tickTime, Boolean bGap, Boolean bClose)
at PaperBroker.PaperTrader.SimTick(Symbol symbol, TickData tick)
at RightEdge.Shared.BrokerWrapper.SimTick(Symbol symbol, TickData tick)

Inner Exception:
An exception of type System.NotImplementedException was thrown.
The method or operation is not implemented.
at MySymbolScript.Highest(Int32 p1) in C:\Users\ywlee_000\Google Drive\RightEdge\TrendfollowingV4\TrendfollowingV4\TrendfollowingV4.vb:line 86
at MySymbolScript.OrderFilled(Position position, Trade trade) in C:\Users\ywlee_000\Google Drive\RightEdge\TrendfollowingV4\TrendfollowingV4\TrendfollowingV4.vb:line 70
at RightEdge.Common.SymbolScriptCollection`1.x4e18f4d87e3d473b(Object xe0292b9ed559da7d, OrderFilledEventArgs xfbf34718e704c6bc)
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at RightEdge.Common.PositionManager.OnOrderFilled(Trade trade, Position position, PositionInfo brokerPosition)
at RightEdge.Common.PositionManager.PositionOrderFilled(PositionData pos, PositionState posState, BrokerOrder order, Fill fill, TradeType tradeType, String description, Boolean sendUpdate)
at RightEdge.Common.PositionManager.OnOrderFilled(BrokerOrder order, Fill fill, PositionData pos, PositionState posState, TradeOrder tradeOrder)
at RightEdge.Common.PositionManager.broker_OrderUpdated(BrokerOrder brokerOrder, Fill fill, String information)
at RightEdge.Shared.BrokerWrapper.<>c__DisplayClass3.b__0(Object )
at RightEdge.Shared.CallbackStub.DoCallback()
Posted Sunday October 20 2013
From the stack trace, it looks like the error is coming from the Highest() method, line 86 in your code:

at MySymbolScript.Highest(Int32 p1) in C:\Users\ywlee_000\Google Drive\RightEdge\TrendfollowingV4\TrendfollowingV4\TrendfollowingV4.vb:line 86

Thanks,
Daniel
Posted Tuesday October 22 2013
Hi Daniel

I changed the code as follows. Although VB doesn't return any errors, there were no trades that were activated based on the code. Is the code something that makes sense in RE?


Private lastclose As New AbsoluteValue

Public Class MySymbolScript
Inherits MySymbolScriptBase

lastclose.SetInputs(Close)


Public Overloads Overrides Sub OrderFilled(ByVal position As Position, ByVal trade As Trade)
' This method is called when an order is filled
' Check if this is the entry trade for a position

Dim closeposition_current As Double

closeposition_current = highest20.Current - (2 * ATR.Current)


If (position.Trades.Count = 1) AndAlso lastclose.Current <= closeposition_current Then

position.CloseAtMarket()

End If


End Sub


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems