How to build a Pin Bar EA

Download the Pin Bar EA 

Building the Pin Bar EA

Pin Bars are one of the mainstays of candlestick reversal patterns. What if we could code them into a robot and trade them automatically whenever they appear?

This article will teach you how.

We will first need to define a ‘Pin Bar’ so the computer can read it.

Bullish Pin Bar

  1. Bar Close > Bar Open
  2. Bar Body < 25% of Bar range (high – low of bar)
  3. Bar Open > (Bar low + 75% of the total bar range)

Bullish Pin Bar (simple explanation)

  1. Bar close needs to be greater than Bar open (for bullish pin bar)
  2. Bar body needs to be less than 25% of Bar range (A pin bar has small bodies)
  3. Bar open needs to be in the top 25% of the of the Bar range.

Pin Bar EA

Let’s code it!

Step 1 – Code outline

  1. Check for new bar
  2. If there is a new bar, check total number of orders
  3. If there are no orders, check for buy and sell signals
  4. Place orders

Pin Bar EA

Step 2 – Defining the entry signals

Remember this from earlier?

  1. Bar close needs to be greater than Bar open (for bullish pin bar)
  2. Bar body needs to be less than 25% of Bar range (A pin bar has small bodies)
  3. Bar open needs to be in the top 25% of the of the Bar range.

Pin Bar EA

Here is the explanation of the entry signal:

Pin Bar EA

Step 3 (last step): Placing a trade

  1. Once the above buy condition is met, the EA will place a Buy order
  2. The order is placed using the PlaceOrder function, which you will have access to when you download the code below

Pin Bar EA

Pin Bar EA in action

Pin Bar EA

I hope you have benefited from this tutorial on how to code your Pin Bar EA!

Download the Pin Bar EA


2 thoughts on “How to build a Pin Bar EA

    1. Linton Post author

      Hi Chris,

      You can check out our upcoming tutorials on how to make more EAs, or you can check out EA Lab from Tradeview.com.au (where you can learn to code by drag & drop), or sign up for some of the courses they have on learning to make your own EAs.

      Best regards,
      Linton

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *