RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        



Bizarre Stoploss behaviour Expand / Collapse
Message
Posted 7/3/2008 10:54:43 Post #6084
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
Hi,

I'm not sure if this is a bug or is it due to my misunderstanding of PositionManager.

I've attached the code and pictures to illustrate it. It not the real turtle system, just testing around with RE. Have completed quite some stuff for the pass few days, wrote a couple of RiskAssessment calculators and added a Custom SystemResults Plugin. But I was really stumped when I tried setting stoploss when opening position.

My system does the following
1) When CCI cross below 100, close all long positions and open a short position with a stoploss at half ATR.
2) When CCI cross above -100, close all short positions and open a long position with a stoploss at half ATR.
3) For debugging purposes the value of half ATR was embedded in the description at position opening.
4) Stops are set as Type : Price not Percentage.
5) Positions were opened using PositionSetting object so I can specify the actual amount of Stoploss.

The problem:
1) Long positions never trigger a stoploss. See Long.jpg, position was Close at Market (i.e. close by trading system, not stoploss) at a price point double of supposed stop distance.
2) Short positions always trgger the stoploss at next open. See short.jpg. Looking at the chart, you can see that all shorts were closed at next open.
2a) In short.jpg, if you look at the highlighted Position and trade break down below, you see the position closed due to "Stoploss" but at a profit! Mind you, I didn't set a trailing stop.

I do like RE and I'm not here to bash it. Just seeing a problem that I can't code around and wish to help the team to improve it. In my opinion the biggest weakness in RE right now is the blackbox-like operation of PositionManager. With insufficient documentation and ambiguous definition, we have to "probe test" it to discover how it works. IMHO that is a shame, users should be able to trust the back test results, imagine a customer going live with this strategy because it gives super high returns.

I really liked the ability to add on your RiskAssessment and SystemResults, something missing from many other softwre. It would be wonderful if users are allowed to plugin in their position mangers.

Sorry for the rant, hopefully the team can find the bug in this quickly.

Cheers,
Edison

  Post Attachments 
Long.jpg (11 views, 129.73 KB)
Short.jpg (11 views, 362.22 KB)
turtle.cs (17 views, 2.12 KB)
Posted 7/3/2008 11:22:01 Post #6085
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
Thanks for your comments.

The stop loss is specified using the actual stop price of the stop order that will be submitted, not the change in price from the position entry price.  So for the stop loss for the short position, you could use:

ps.StopLoss = Close.Current + (0.5 * Indicators["ATR"].Current);

This will only use the current close, however, instead of the actual entry price of the position.  To set the stop loss based on the entry price, you have to wait until the open order is filled.  You could use the following OrderFilled method to do this:

public override void OrderFilled(Position position, Trade trade)

{

      if (position.State == PositionState.Open)

      {

            if (position.Type == PositionType.Long)

            {

                  position.SetStopLossPrice(position.EntryPrice.SymbolPrice - (0.5 * ATR.Current));

            }

            else

            {

                  position.SetStopLossPrice(position.EntryPrice.SymbolPrice + (0.5 * ATR.Current));

            }

      }

}

Note here that the ATR is being accessed directly (ATR.Current) instead of using Indicators["ATR"].Current.  I think this is a better way since it's shorter and you will get a compile time error instead of a runtime error if you spell the indicator name wrong.

Thanks,
Daniel

Posted 7/3/2008 12:12:24 Post #6086
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
Thanks Daniel, the code you supplied now works.

Then again, this should also tell you how much we have to "probe" the software to know how to use it because the Developer API is so brief. Take for example the documentation for PositionSetting.StopLoss. It explains the part for using percentage clearly that setting 0.05 will set a 5% stoploss for both long and short trades, the position manager will presumably take care of it using the Filled price for calcuation. Which was why I infer that setting a positive price change value will generate the same results. But there wasn't much info on the "Price" type stoploss.

For Example, take a look at the definition of "Drawdown" under Glossary of Terms in your RightEdge Help file (not Dev API). I'm sure that's not how most people view Drawdown, in fact I have to implement my own SystemResult Plugin and plot my own drawdown curve to make sure that the drawdown curve provided by RightEdge is the drawdown curve I expect it to be. The results matched, but that shows my point that we have to "probe" the software because the docs is not up to it.

Thanks again for the quick reply, but will you add a "feature request" to make the behaviour of "Price" type stoploss similar to "Percentage" type stoploss? Seems the right thing to clear up the imbalance.

Thanks and warmest regards,
Edison
Posted 7/3/2008 17:38:45 Post #6087
 

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru
I too was confused (and about to post)...

Daniel, Is the same situation with "SetProfitTarget" (when its not %)??

Based on this, I'm now coding more the "order filled" event...

Walt

Posted 7/3/2008 20:05:26 Post #6088
 

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being
I say keep it as it is. It says target type price. Not target type distance. If you use stops or targets based on previous highs or lows you would be continually calculating the distance from entry to the price.

Learning videos for traders.
On Demand. Any Time Any Place.

Posted 7/4/2008 08:48:20 Post #6089
 

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru
kaizen,

I was under the impression that "order filled" event happens once (after order is filled)...

Are you saying it is triggered on every bar?

>to me that does not make sense since there is a new bar event...

Walt

Posted 7/4/2008 09:08:10 Post #6090
 

Forum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum GuruForum Guru
i just verified it;

"order filled" happens once for each order so it would be OK to set a target price in that event when the order is opened...

Walt

Posted 7/4/2008 19:40:50 Post #6094
 

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being
hairy_mug (7/4/2008)
i just verified it;

"order filled" happens once for each order so it would be OK to set a target price in that event when the order is opened...

Walt


Yep that is how I do it.

Learning videos for traders.
On Demand. Any Time Any Place.

« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: billb, young, dplaisted

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 3:03pm

2005-2007 © RightEdge Systems