Getting Started

FAQ

MACD

MACD

💡
Educational Purposes The purpose of this page is to demonstrate how you can fully automate a trading strategy on TradingView using PineConnector. Please note that the focus is not on the profitability of the strategy, if any.

MACD Strategy

image

With PineConnector, you can fully automate the MACD strategy, making it a suitable solution for both day and swing traders. This allows you to streamline your trading process, freeing up time, minimizing the risk of human error and eliminating emotion in your trading.

Implementation of the Strategy

💡
Before proceeding, please ensure:
  1. PineConnector EA running on your MetaTrader terminal — you should see your license details printed on your chart.
  2. image
  3. Close on Reverse EA setting set as “On — Hedging”.
  4. image

1. Create a new script

At the bottom of your TradingView tab, click "Pine Editor" → “Open” → “Strategy”.

image

2. Attach the code

Remove the default code generated, and attach the following code:

//@version=5
strategy("MACD Strategy - PineConnector", overlay=true)

LicenseID = 6914107867349 // 1. change to your PineConnector License ID (required)

riskvalue = input.int(1, 'Risk Value') // 2. Change the risk value (optional)
slvalue = input.int(500, 'Sl Value') // 3. Change the sl value (optional)
tpvalue = input.int(1000, 'TP Value') // 4. Change the tp value (optional) 

fastLength = input(34) // 5. Change the fastlength (optional)
slowlength = input(90) // 6. Change the slowlength (optional)
MACDLength = input(144) // 7. Change the MACDlength (optional)


MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)
aMACD = ta.ema(MACD, MACDLength)
delta = MACD - aMACD

MacdBuy = ta.crossover(delta, 0)
MacdSell = ta.crossunder(delta, 0)

plotshape(MacdBuy, style=shape.labelup, location=location.belowbar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Buy', textcolor=color.new(color.white, 0)) //plotting up arrow when buy/long conditions met 
plotshape(MacdSell, style=shape.labeldown, location=location.abovebar, color=color.new(#046ff9, 0), size=size.large, text='PineConnector \n Sell', textcolor=color.new(color.white, 0)) //plotting down arrow when sell/short conditions met


if (ta.crossover(delta, 0))
	strategy.entry("MacdBuy", strategy.long, comment="MacdBuy")
	alert(str.tostring(LicenseID)+',buy,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue)+ ',sl=' + str.tostring(slvalue)+ ',tp=' + str.tostring(tpvalue), alert.freq_once_per_bar_close)

if (ta.crossunder(delta, 0))
	strategy.entry("MacdSell", strategy.short, comment="MacdSell")
	alert(str.tostring(LicenseID)+',sell,' + syminfo.ticker + ',risk=' + str.tostring(riskvalue)+ ',sl=' + str.tostring(slvalue)+ ',tp=' + str.tostring(tpvalue), alert.freq_once_per_bar_close)
💡
Required Change: Instead of the License ID 6914107867349, input your PineConnector License ID you’re entered in the PineConnector EA.

Basic Optional Change:

  • Instead of riskvalue being 1, you may increase or decrease the lot size per trade.
  • How the EA processes this riskvalue depends on your Volume Type in your EA.
    1. image
    2. the default setting of “Lots” will open 1 volume/lot each trade with riskvalue of 1 — use this option if you are a beginner
  • How the EA processes this tp/slvalue depends on your Target Type in your EA.
  • image

Advanced Optional Changes:

  • Instead of fastlength of 34, you may increase or shorten the period fast length.
  • Instead of lowlength of 90, you may increase or shorten the period slow length.
  • Instead of MACDlength of 144, you may increase or shorten MACD length.

3. Save the code and Add Strategy to the Chart

After attaching and amending the above code, click “Save” then “Add to chart” to apply the strategy to your current chart. You should be able to see the MACD entries indicated on the chart:

image
image

4. Create alerts

On your desired instrument and timeframe create the alerts.

💡
In this tutorial, we will execute alerts based on EURUSD on the 1 second chart. You may use the 1 minute chart as well. If you EURUSD symbol in the Symbol List (CTRL+U) has a prefix or suffix such as i.EURUSD.mini, please add those details in the prefix (i.) and suffix (.mini) section in the EA settings — case sensitive.

To create an alert, press Alt+A (Windows) or Option+A (Mac), and configure your alert as follows:

Component
Configuration
Condition
MACD Strategy alert() function calls only
Webhook URL
For PineConnector v2: https://pineconnector.net/webhook/ For PineConnector v3: https://webhook.pineconnector.com
Alert name, Notify on app
“Alert name” does not matter ”Notify on app” selection does not matter as well
image

After proper alert configuration, click “Create”. An active alert will appear under your “Alerts” tab.

💡
With this script, you will only need 1 alert to trigger both buy and sell entries for the current instrument and timeframe — in this example, the BTCUSD 1 minute chart.
image
💡
New code? New alert. Changes to your code won’t automatically update existing alerts—they’ll continue using the original code saved at the time of creation.

To apply the updated code, delete the old alerts and create new ones.

5. Confirm triggered alerts

When entry conditions are met, an alert will fire. You will see an entry in your TradingView’s Alerts Log indicating the time, alert message, instrument and timeframe it fired based on.

image
💡
Sky’s not the limit — 15 Is A single alert can trigger up to 15 times within a 3-minute window. If this limit is exceeded, the alerts will be automatically paused.

After a alert fires, you should see a corresponding trade entry as per the alert message.

image
💡
Troubleshooting Trade Issues If you encounter an error or your trades are not triggering, consult the Error Guide for potential causes and solutions: Error Guide
💡
Monitoring for Success We recommend regularly checking the “Experts” tab to understand how the EA processes your alert messages, particularly when testing new syntax or adjusting EA settings.
image

6. Tailor your alerts (optional)

Consider adding a stop-loss, a comment with the position, or even a spread filter.

Component
Relevant Guide
- Discover more about the proper way to write the alert messages - Add more components such as a spread filter
- Utilise a different Volume Type - Implement a Daily Profit or Loss
- Include additional parameters such as stop-loss - Implement dynamic symbols and values
💡
Maximize your Trading Performance: Use Our Broker of Choice To ensure optimal trading performance, we recommend using the same broker that we use for PineConnector testing. In addition, you can trigger your alerts based on the broker's data source available on TradingView, leading to better trading performance. Minimize errors, maximize your trading potential, and ensure the best possible experience with our platform.

Broker of Choice →