May 8

5 comments

Bull Flag on futures markets?

By Juan

May 8, 2023

Algorthmic Trading, EasyLanguage, TradeStation

Recently someone asked on an Easylanguage forum if anyone had coded a Bull flag / Bear flag pattern recognition to use on a futures index strategy. I realized that I did not know the pattern, so I went and looked for it.

Bull flag pattern

A bull flag is a technical chart pattern that is often used by traders to identify potential bullish market movements. The pattern is characterized by a strong upward move, followed by a period of consolidation, or “flag,” that is usually parallel to the trendline of the initial move.

The bull flag pattern is considered a continuation pattern, as it indicates that the current bullish trend will likely continue after the consolidation period. This can be a valuable signal for traders looking to enter long positions or add to existing ones.

The pattern typically forms after a strong upward move, which is known as the “flagpole.” This initial move can be caused by a number of factors, such as positive earnings reports, strong economic data, or other market-moving news. During the consolidation period, the price of the security will generally move sideways, forming a “flag” shape on the chart.

Traders typically look for a breakout above the resistance level of the flag to confirm the continuation of the bullish trend. Additionally, traders may use a stop-loss order below the support level of the flag to protect their position in case the trend does not continue.

Bull flag in quantitative trading

We can get as fancy as we want with Easylenguage, but I wanted to take a straightforward approach:

Flagpole: Two simple moving average (SMA).

  • Bullish flagpole SMA based on the low price, and current SMA bigger than the previous two SMA´s.
  • Bearish flagpole SMA based on the high price, and current SMA lover then the previous two SMA´s.

Breakout: RSI2 that breaks over limit on the direction on the trend.

Exits: Stop loss and profit target.

Long and Shorts: The ability to test only long, only short or both.  

Charting Software: Tradestation 10.0

Code development: Easylenguage 10

Research platform: https://tradesq.net/

Bull Flag on futures markets? –Easylanguage code

Let’s see how it works on a chart:

Long entries on Bull flag on a @CL 1440m chart

Short entries on bear flag on a @CL 1440m chart

Its not perfect “flag” shape, but the concept of entering after the breakout of the retracement works pretty well.

Now that we have the code and the strategy let’s see if it would work in future markets. For the study, Tradesq will test it for us on 43 Future markets and 11 timeframes in a matter of hours. Can you imagine how much time would take to perform the test manually?

Results

We have many edges on currencies, energies, grains, Indexes, and interest sectors.

Results filtered by (NP/DD>4, Number of trades above 200)

Let’s have a look at Some results from every sector.

30Yr Bonds(@US) 240min

Heating Oil(@HO) 360min

British Pound(@BP) 240min

Spring Wheat(@MW) 360min

Nasdaq(@NQ) 30min

Note: All results include trading costs, Slippage and Commission.

Conclusion

I don’t know if the code developed will resolve the poster question on the Bull Bear Flag pattern, but certainly did find really good edges.

The study was intended to show how we can start from a simple idea and use tools like Tradesq and Easylanguage / Powerlanguage to build strategies. As a result, we found firm edges through five (5) different future market sectors. 

It does not mean this are strategies ready to trade, additional filters and robustness tests must be applied, but is a terrific starting point.

>>By Juan Fernando Gómez From blog.tradesq.net  Email: jgomezv2@jgomezv2

About the author

Hello, my name is Juan Fernando Gómez. I am an Industrial Engineer and an avid triathlete with a passion for developing trading strategies, particularly in the futures markets. My preferred tools are TradeStation and EasyLanguage for Trading, Charting and Coding, and Tradesq for identifying where the edges work. Please feel free to contact me at jgomezv2@gmail.com to discuss further.

  • Good evening, Mr. Jeff. Even this is a great strategic idea, but I honestly can’t see any code in any of the strategies on your website. If possible, please send me a working link; otherwise, I haven’t seen anything before. Thank you very much, and see you soon.

  • Thanks for the ideas Juan.
    In the code snapshot, the sellshort conditional is using SMA_Bull and SMA_bear. Is that correct? Or should they all be SMA_bear?

      • Great. Did you use a short time session there? Or the full 24 hour?
        I was working on BP recently, so I was interested in seeing if I could reproduce your BP results. With a 0200-1400 session, I’m seeing low trade counts so far.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Learn To Code & Build Strategies
    Using EasyLanguage. 

    >