Cross Back Under
Author: topcat77
Creation Date: 9/30/2009 1:02 PM
profile picture

topcat77

#1
What is the function that provides a command to sell when the price has crossed back under a value after it has first over it ( for example, sell at market when rsi[bar]<70 after rsi[bar] has crossed over 70) I've searched Wiki and run a search of the site without locating it; but I've seen it somewhere. Thanks
profile picture

Eugene

#2
It seems that CrossOverBar is what you're looking for.
profile picture

topcat77

#3
well,using rsi for illustration,this is an example of the sequence I would like to script:

rsi[bar] crosses above 70
then, sell when rsi[bar] next crosses back under 70
( so it would appear that CrossOverBar and CrossUnderBar would need to work in succession to get there)

I believe that I saw either a function or a snippet of code that achieved this
profile picture

topcat77

#4
maybe I'm over-thinking the problem.
If rsi[bar] is now 45 and the strategy wishes to sell when rsi next crosses under 70 (obviously it would have had to have gotten there first)will the CrossUnderBar function achieve this?
profile picture

Cone

#5
CrossUnderBar tells you the bar on which the DataSeries crossed under the specified value.

(If you're at 45, it's not obvious if the previous value was 71 or 0.)
profile picture

Eugene

#6
QUOTE:
will the CrossUnderBar function achieve this?

No, the purpose of the function is to return the bar where the series have already crossed. The correct sequence is:

1) rsi[bar] crosses above 70... and you're saving the bar in a variable.
2) then, sell when rsi[bar] next crosses back under 70... you sell and reset the variable.

Actually, you don't need no extra indicators. Example:
CODE:
Please log in to see this code.
profile picture

topcat77

#7
Thanks greatly. I am planning to use this (the sell part of the code), like an MFE-triggered stop based on price, except with technical levels as triggers
profile picture

Eugene

#8
You're welcome. Try to understand how the code is constructed and works by reviewing this KB article, the underlying principle is really simple:
Tutorial: Setups, Triggers, Delays, and Timeouts
profile picture

Eugene

#9
rptrader1 asked:

QUOTE:
I tried using the Cross Back Under System strategy.
It gives great results with VXX and VXZ securities,100% Win rate!!
It does well with the index ETFs too - like DIA, SPY.

However, with other stocks and Closed End Funds, some trades result in large losses.
I would like to introduce a stop loss statement, ex.

Position p = LastPosition;
SellAtStop( bar+1, p, p.EntryPrice * 0.95, "5% Stop Loss" );

I do not udnerstand the code well enough to know how to do this.

Can you please help?

Here you go:
CODE:
Please log in to see this code.
profile picture

rptrader1

#10
Thanks very much, Eugene.
profile picture

rptrader1

#11
Hello Eugene,

Tested the code and results are very good.

I did find one case where the stop loss did not work.

For IWM, the strategy entered a Buy on Feb 23, 2007, and exited on July 30, 2009, for a loss of 32.41%.

I noticed that on 2/22, the RSI hit a high of 70.6954 (threshhold = 70).
On 2/23, the stock was bought.
On 2/23, RSi closed at 65.28, less than the threshhold.
However, the trade was not exited until 2009.

Is it because, after the Buy sttaement, the xOver flag is not set?

Appreciate your help.

Thanks and Regards
profile picture

rptrader1

#12
Please note that I ran the strategy for 5 yearsdata range.

Thanks
profile picture

Eugene

#13
Ravi,

For me the exit was made on 02/27/2007, 3 bars since, for a loss of -5% plus costs. Ran it on most recent 5 years of Yahoo! data in both single symbol and portfolio sim. modes.
profile picture

rptrader1

#14
Eugene,

The result I reported was using Fidleity data.
I ran it against Yahoo data, and I get the same resultys:

With 5 Years data:

The Buy is on 2/23/2007, and the trade is exited on 7/30/2009, for -32% loss.


While the difference between your results and mine is perplexing, and needs explanation, I would also like to focus on the code, and what it will do if:

a) The RSI crosses threshhold on Day 1
b) Buy is initiated on Day 2 at open
c) RSI Close for Day 2 is below the threshhold

Will the code initiate a sell for Day 3 at the Open?
Can you please review the code?

Also, how can we troubleshoot the difference between your result and mine?

I can provide screenshots.
Appreciate your help.

Thanks

profile picture

rptrader1

#15
I also found other symbols where the trade is not exited immediately after the thresshold is crossed back.
These are based on Fidelity data.
1. CEE - 1 Year Data

On 4/1, RSI crossed over the 70 threshhold, and closed at 71.58
Buy on 4/4@Open
On 4/12, RSI Crossed under the 70 threshhold, and closed at 63.98
Thye trade is still open, for a loss of 26.52%
Other examples:

2. CH - Trade open 3/25/2011, still open, -31.50% loss
3. IFN - Open 3/31/2011, still open, -31.99% loss
4. TDF - Open 4/1/2011
5. PEO - open 2/22
etc.
Appreciate your help.
Thanks
profile picture

Eugene

#16
The code provided for example purposes appears fully working to me.

Try providing more info on your single-symbol IWM backtest using Yahoo! data (keep in mind that I do not work with WLP and/or Fidelity data): position sizing (Raw Profit mode or Port.Simulation), Preferences (Backtest settings, Slippage
Symbol(s), Advanced Options).
profile picture

rptrader1

#17
Eugene,

Position Size - $25000, raw profit Mode
Preferences -

a) Back test Settings - None checked
b) Slippage - For Equities - 0.10 Percentage slippage
c) Adv Options -
The followinga re checked - Show the Home Page on startup, Expand First Data Set in Tree on Start Up, Open teh Oredrs window when a Trade is staged or placed, Also, switch to view the orders for taht trade's account
Decimal Places - pricing - 2, Indicator - 4

Hope this helps.

Thanks

profile picture

Eugene

#18
I definitely am NOT able to reproduce anything of that. You must be using wrong code (previous version) inadvertently.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).