PineConnector Library

This video lesson breaks down how to use my PineConnector library. View the example script template below for how to use it.

Check out my other free lessons!

Changelog

15th October 2024: Released code publicly on TradingView (no known bugs as of this date).

Example Usage Script

Click here for the Library source code.

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ZenAndTheArtOfTrading
// @version=5
strategy("TheArtOfTrading.com", overlay=true)

// Import PineConnector library 
import ZenAndTheArtOfTrading/PineConnector/1 as pc 

// PineConnector Settings 
var string g_pc     = "PineConnector Settings"
bool pc_enabled     = input.bool(title="Enable PineConnector", defval=true, group=g_pc, display=display.none)
bool pc_debug       = input.bool(title="Enable Debug Labels", defval=true, group=g_pc, display=display.none)
string pc_id        = input.string(title="License ID", defval="ID", group=g_pc, display=display.none)
float pc_risk       = input.float(title="Risk", defval=1.0, group=g_pc, display=display.none)

// Display MAs 
plot(ta.sma(close, 14), color=color.blue)
plot(ta.sma(close, 28), color=color.red)

// Mock long trade (enters a new trade only if flat)
longCondition = barstate.isconfirmed and strategy.position_size <= 0 and ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    if (strategy.position_size < 0) // If we have an open short trade, close it
        strategy.close_all()
        if (pc_enabled)
            pc.closeshort(pc_id, debug=pc_debug)
    else
        strategy.entry("My Long Entry Id", strategy.long)
        if (pc_enabled)
            pc.buy(pc_id, pc_risk, sl=10, tp=15, debug=pc_debug)

// Mock short trade (enters a new trade only if flat)
shortCondition = barstate.isconfirmed and strategy.position_size >= 0 and ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    if (strategy.position_size > 0) // If we have an open long trade, close it
        strategy.close_all()
        if (pc_enabled)
            pc.closelong(pc_id, debug=pc_debug)
    else
        strategy.entry("My Short Entry Id", strategy.short)
        if (pc_enabled)
            pc.sell(pc_id, pc_risk, sl=10, tp=15, debug=pc_debug)