Reply

Algorithm to understand if a market is trend following or mean reversal

8 replies

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

1 week ago #280948

Hello,
I recently started using Strategy Quant X. I’m trying to create an EA that analyzes a market and understands whether it is a trend following or reversing.
I was trying with AlgoWizard to compose the logic and, based on the backtest results, understand the market typology.
The basic idea to check if a market is trend following is as follows:
– Enter a buy stop if the next bar breaches the previous day’s high.
– Enter a sell short stop if the bar is lower than the previous day’s low.

The idea for testing a mean reverting market is as follows:
– Buy limit if the current bar is lower than the previous day’s low.
– Short limit if the current bar is lower than the previous day’s high.

But I can’t get these ideas to work.

Do you have a suggestion to implement an algorithm to check if a market is trend following or mean reverting?

Thank you very much.

Lorenzo

0

tomas262

Administrator, sq-ultimate, 1 replies.

Visit profile

1 week ago #281025

Hi,

can you make a screenshot of a chart example for both rules? I can make some example on this

0

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

1 week ago #281049

Hi Thomas,
I appreciate your support. Right now, I’m not using the computer where Strategy Quant X is installed. Tomorrow, I’ll gladly send you a screenshot of what I was trying to do.

Thanks, you are very kind.

Lorenzo

0

James Colton

Subscriber, bbp_participant, sq-ultimate, customer, community, 9 replies.

Visit profile

1 week ago #281070

If you go to the getting started or Home screen of SQX there are two options to Start with default generation <button id=”home-start-generating-forex” class=”btn btn-primary
sq-btn-build-main” type=”button”>for forex<i class=”fa
fa-chevron-circle-right” aria-hidden=”true”></i></button> <button id=”home-start-generating-futures” class=”btn btn-primary
sq-btn-build-main” type=”button”>for futures<i class=”fa
fa-chevron-circle-right” aria-hidden=”true”></i></button> and get feel of the platform.

Forex is generally considered to be trend following and futures indices at least are generally considered to be mean reversion markets. Not so sure about futures commodities.

The above are not hard and fast rules. Just general market descriptions.

If you run your select market in forex and futures equally SQX likely has their building blocks reasonably apportioned and your Databank with the better results is a fair indication of what posture your chosen instrument displays more of.

Realize all markets experience regime changes or periods of consolidation (Mean Reversion) as well as periods of momentum (trend following). How you tune your strategies to filter out low probability trades can be almost as important as limiting your leverage in correlated exposure.

1

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

6 days ago #281082

Hi Tomas,
I apologize for my delayed response.
I’m creating a straightforward algorithm for testing the typology of a market. In the screenshot, I’m attempting to implement a simple break-out algorithm to verify from a point of view purely qualitatively if a market is a trend following. To confirm if a market is mean reverting the order type will be limit.
In the strategy that I show in the screenshot you below, I attempted to run the algorithm but I obtained a generic error and needed help understanding what was wrong.
In the backtest, if a market is trend following, I’m expecting an equity line increasing for both long and short.

Thank you very much for your kind and attention.

Lorenzo

0

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

6 days ago #281083

Hi James,
Your comments are correct and meaningful.
The important observation in a trend-following market in the long term, there are moments, such as those of consolidation, in which there are mean reverting behaviors. I was trying a method to understand the nature of a market for educational and indicative purposes, especially a hypothetical market that I had never used.
If you want, see the reply post I sent to Tomas.

Thank you very much for your valuable intervention.

Lorenzo

0

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

6 days ago #281084

I’m sorry Tomas,

I forgot the screenshot, here it is!

 

 

0

James Colton

Subscriber, bbp_participant, sq-ultimate, customer, community, 9 replies.

Visit profile

5 days ago #281089

I know you are looking for an answer from Thomas and he is better qualified to answer.

I wonder of having a buytocover exit from a buy order or a sell to exit a sellshort is viable. It seems counter intuitive to me.

Your logic to buy on a gap up also seems to be something that would or should be instantaneous on bar open. If so, why have a zero in the order valid for selector. Wouldn’t a 1 or even a 2 make sense?

Perhaps one or both details are causing issues.

0

Lorenzo

Subscriber, bbp_participant, customer, community, sq-ultimate, 9 replies.

Visit profile

5 days ago #281091

Hi James,
Excuse me. I need your help to understand your reflection.
Given that the attempt does not intend to generate a strategy to be put to the market, it only wants to try to study the market type on a sufficiently sizeable historical series. So the basic idea (to check if the market historically is a trend following) is to buy whether the bar just formed exceeds the maximum of the previous bar and sell if the new bar is lower than the minimum of the last bar. So in the backtest on a large time interval, I should get a growing equity line for both long and short purchases. Do you share? If you have time, I need clarification because you told me about the Shift of 1 or 2.

My idea is likely wrong. I am still gaining experience on the platform; my basic reasoning could be wrong.

Thank you again for your kindness and the time you have dedicated to helping me.

0

Viewing 9 posts - 1 through 9 (of 9 total)