---
title: "Discussion on \"From TradingView Strategy to MT5 Expert Advisor: A Developer's Checklist\" | Hashnode"
description: "Discussion on \"From TradingView Strategy to MT5 Expert Advisor: A Developer's Checklist\". A lot of traders build a strategy in Pine Script on TradingView, like the backtest, and then want it running automatically on MetaTrader 5. The port looks simple. It usually isn't, and the gaps are wh"
url: "https://hashnode.com/posts/from-tradingview-strategy-to-mt5-expert-advisor-a-developer-s-checklist/6ac8f36430d4862710868954"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [From TradingView Strategy to MT5 Expert Advisor: A Developer's Checklist](https://customtradingbots.hashnode.dev/from-tradingview-strategy-to-mt5-expert-advisor-a-developer-s-checklist?utm_source=hashnode&utm_medium=feed)

A lot of traders build a strategy in Pine Script on TradingView, like the backtest, and then want it running automatically on MetaTrader 5. The port looks simple. It usually isn't, and the gaps are wh

Oct 9 · 3 min read · customtradingbots.hashnode.dev  
Read the article

-   [#mql5](https://hashnode.com/tag/mql5)
-   [#automation](https://hashnode.com/tag/automation)
-   [#algorithmic-trading](https://hashnode.com/tag/algorithmic-trading)
-   [#trading](https://hashnode.com/tag/trading)

## Written by

[Omais Ali](https://hashnode.com/@omaisali)

@omaisali

  
[View profile](https://hashnode.com/@omaisali)

## Responses 3

Markdown supported · ⌘↵ to post

[Arnold Holm](https://hashnode.com/@stratcorealpha)

[Oct 10](https://hashnode.com/posts/from-tradingview-strategy-to-mt5-expert-advisor-a-developer-s-checklist/6ac8f36430d4862710868954/comment/6ac9e7979712736ed962af4a)

The new-bar helper also needs a startup rule. With lastBar initially zero, the first tick after a restart counts as a new bar even if that candle began earlier. I would add one comparison case: restart midway through a candle with an existing position, then check that the closed-bar signal does not create a second entry. Decide explicitly whether startup may act on that old signal or must wait for the next bar.

[Omais Ali](https://hashnode.com/@omaisali)

[Oct 10](https://hashnode.com/posts/from-tradingview-strategy-to-mt5-expert-advisor-a-developer-s-checklist/6ac8f36430d4862710868954/comment/6ac9e7979712736ed962af4a#reply-6ac9f26ad085a8a2b08a2a37)

Good catch Arnold, thanks. You're right, with lastBar at 0 the first tick after attaching or restarting fires as a new bar even mid candle. The fix is to seed it in OnInit with lastBar = iTime(\_Symbol, \_Period, 0); so the EA waits for the next real bar open. Agreed on the restart comparison case too, I've added it to the checklist.

[Arnold Holm](https://hashnode.com/@stratcorealpha)

[Oct 13](https://hashnode.com/posts/from-tradingview-strategy-to-mt5-expert-advisor-a-developer-s-checklist/6ac8f36430d4862710868954/comment/6ac9e7979712736ed962af4a#reply-6acde2b8c456b1b6b533975c)

Your updated OnInit now seeds the current bar, so attaching midway through a candle waits for the next bar. One further negative case is a new bar whose CopyBuffer values are not ready yet. If the helper advances lastBar before a successful read, that closed-bar evaluation can be lost. I would advance the processed-bar marker only after the required values are available, keeping entry deduplication separate.
