Profile Picture

Set Exit Based on Indicator

Posted By ywlee 4 Years Ago
Message
Posted Friday November 01 2013
Hi

I'm trying to set a position.CloseAtMarket() method if the price of an open position is less than or equals to the 10D lowest using VB but am having problems using the Lowest() type since it cannot be converted to a Double.

Any suggestions on how to construct the script? Since this is neither a percentage or absolute price exit I don't suppose PositionManager can be used?

Thanks!
phg
Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)
Posted Friday November 01 2013
Could you show us some of your code, please? Particularly the constructor for Lowest(). Are you looking for the lowest close for the previous 10 days? Thank you.

-Pete

See also Yahoo group about applying RE.

Posted Saturday November 02 2013
Hi Pete

Managed to get the syntax right with help from Andreas from tradersplace.net.

However, looking at the simulation results, the CloseAtMarket() method doesn't seem to kick in even though looking at the charts it should have. Am I applying the logic correctly? Here is the code and the bar data.

Private highest55 As New Highest(55)
Private lastclose As New AbsoluteValue
Private lowest10 As New Lowest(10)

   Public Overloads Overrides Sub Startup()
' Perform initialization here

highest55.SetInputs(Close)
lastclose.SetInputs(Close)
lowest10.SetInputs(Close)


   End Sub

   Public Overloads Overrides Sub NewBar()
' Put your trading code here

If lastclose.Current >= highest55.Current Then

OpenPosition(PositionType.Long, OrderType.MarketOnOpen)

End If

End Sub

   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

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

End If


Attachments
AUD.txt (119 views, 184.00 KB)
phg
Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)
Posted Sunday November 03 2013
The code looks more involved than it needs to be I think. My VB is a bit rusty but let me offer some suggestions:

-A one-step definition: highest55 As New Highest (55, Close)
  (same for lowest10)

- I think you can dispense with lastclose. Replace the "If" this way:
If Close.Current >= highest55.Current Then

' Note: The ">" part can never be true as highest55 already incorporates the most recent Close.

Does this help?

-Pete

See also Yahoo group about applying RE.

Posted Sunday November 03 2013
Hi Pete

Thanks for the same. I think the problem is how I nest the code. I'll tinker with the code to get the result I want.

On a separate issue:

A/ how do you set the CloseAtMarket() method to close each position individually based on the code rather than close all positions (for the same symbol) once one position is triggered(which I think is the default)?

B/ for RSIQueue method, my code is: If rsi.Value < 20, then CloseAtMarket (defined RSI As New RSIQueue(7)).

The syntax seems to be correct (it does not trigger any vb code error) but the position does not close. Basically I wish to close the position when RSI for the last 7 days is < 20. Am I using the RSI.value correctly to achieve this?

Thanks
phg
Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)
Posted Monday November 04 2013

I'm not sure I fully understand A/ but
For Each pos As Position in OpenPositions
will let you look at the status of all open positions, if that is what you want.

The default is *not* to close all open positions, but there may be a setting "close after so many bars" that comes into play. Watch out for that.

For B/, I am not familiar with RSIQueue (usually a RSI is chained into it?). The only thing I see is that you may want:
pos.CloseAtMarket
depending on context. However, your words suggest you want just RSI, not RSIQueue; you might look at that more closely.

You might want to re-review the (pdf) user manual. I see it has lots of examples that seem to apply to what you are trying to do. Searching on "position" narrows things down pretty quickly.

Also, are you using "OutputMessage()" to the Output panel? That's the simplest debug tool there is; it will let you look at values wherever you construct a message. I use it liberally.



-Pete

See also Yahoo group about applying RE.

Posted Tuesday November 05 2013
Dear Pete

Thanks for the same.

Actually I couldn't find the RSI indicator. I could only find RSI queue and stochastic RSI.


Warmest regards

Yuen Wai
phg
Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)Supreme Being (44,749 reputation)
Posted Wednesday November 06 2013
Start RE then look under "Momentum" in the Indicators panel on the left. Actually, it looks like there are a number of indicators there that might fit with what you are doing. How about the "RMI" indicator, for example?

-Pete

See also Yahoo group about applying RE.



Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems