How to correctly use CrossOver/CrossUnder

Questions about MultiCharts .NET and user contributed studies.
et1hugo
Posts: 9
Joined: 25 Oct 2017
Has thanked: 5 times
Been thanked: 1 time

How to correctly use CrossOver/CrossUnder

Postby et1hugo » 18 Jun 2019

Hi all

I'm working on a simple crossover/crossunder study based on John Ehler's super smoother. It is sort of like a moving average but it is supposed to decrease the lag that you typically have with moving averages. Everything works fine except the VariableSeries CrossOver/CrossUnder methods seems to bias the signal to only one side of the market so you get only long or short entries and no entries into the opposing side of the market, e.g. if the first trade was a short trade on the chart you'll only get short trades and not long trades.

I've attached the code I'm using with the indicator and Test2 containing the signal code and the super smoother function. The indicator seems to work fine, it's based on the function so I think the function works fine. But the signal does not take the opposite side of the market when it exit's a position and is supposed to enter a position in the opposite side of the market. When you look at the Test2 signal you'll see the following:
* I use a specific cross_over lookback of 5, I''ve used longer values such as 10 but it has no effect.
* The entry code (calcBarEntry) uses two separate if-statements, I tried to chain them together into an if-else if-statement so that only one long or short order could be posted at a time but it has no effect.
* When I only get short trades on the chart I commented the short entry in the signal and then the long trades would fire off without any issues so the CrossOver entry is working correctly but when it's used with the short exit CrossOver is returns FALSE in the entry code and no order is sent - see my remark after this list on debugging the crossover.
* I tried splitting the signal into two separate signals for the long/short sides of the market like the MC standard delivered signals but this had no effect.
* Currently the SuperSmoother function is defined as a FunctionSimple subclass, I tried defining it as a FunctionSeries just to test it and used the function's CrossOver/CrossUnder methods instead of the VariableSeries but this also had no effect. I changed it back to FunctionSimple since I think this is correct.
* I changed the entry orders to be on the next bar and the exit orders on this bar to try check whether it has anything to do with the timing of the orders being generated but it had no effect.

I've also debugged the code in Visual Studio and when you look at the last 5 data entries after a crossover in the _Fast/_Slow VariableSeries instances you can actually see the crossover in the data, all that occurs is the exit signal from a short position in the calcBarExit, so the CrossOver method returns TRUE here, but the opposing long position is not entered because the CrossOver returns FALSE in the calcBarEntry which is incorrect based on the given data series and the look back of 5-bars (or even 10-bars). Anyway, I'm sure it's probably something simple that I'm missing somewhere but I'm basically staring myself blind against the code at this point.

Thank you in advance for any input.

Best regards
Ettienne
Attachments
SuperSmoother.pln
SuperSmoother indicator, function and test signal
(3.42 KiB) Downloaded 385 times

Return to “MultiCharts .NET”