TradingView Pinescript Version 5

Job ID: 36308929

Budget: $25 – $50 AUD

Hi there,

I've been trying to work on a script for buy/sell signals on TradingView, but have hit a bit of a wall while trying to get the coding correct. I'm able to get the chart to accept the coding without the Enter And Exit Conditions, however the buy/sell signals do not show up as I think the error lies in the Volume Flow Indicator section.

I'm guessing the way the VFI indicator was added to this script isn't the entire code. I'm not sure if the "ma" value in the conditions for the buy signal and sell signal is correct. It was trying to use "VFI" but VFI was never a declared variable so there is more to the VFI code that needs to be added for it to function and bring up the buy/sell signals. You may need to look at the VFI_LB coding to see if there is anything that needs to be referenced in there.

I'd like to be able to test this in Trading View's Strategy Tester once working, and I have further script I'd like to add once I've seen the results, which will reduce losses on the unsuccessful trades as well as recognising possible trend continuations. So if I can get this first part below working correctly, there will be more to add later on. Here is the code below so far, I am more than happy to do up an illustration to send if anything doesn't make sense. Thanks very much for your help.

//@version=5
indicator("Trading Strategy", overlay=true)

// Moving Average Convergence Divergence (MACD) with default parameters
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)

// Volume Flow Indicator (VFI) by LazyBear with default parameters
len = input.int(title="VFI Length", defval=13)
ma = ta.sma(volume, len)

// Conditions for Buy signal
prevCrossover = ta.valuewhen(ta.crossover(macdLine, signalLine), histLine, 1)
buyCondition = ta.crossover(macdLine, signalLine) and (histLine > prevCrossover +0.0015) and (ma > -23.500 and ma < -5.830)

// Conditions for Sell signal
prevCrossunder = ta.valuewhen(ta.crossunder(macdLine, signalLine), histLine, 1)
sellCondition = ta.crossunder(macdLine, signalLine) and (histLine < prevCrossunder -0.0015) and (ma > +5.830 and ma < +23.500)

// Enter And Exit Conditions
if buyCondition and strategy.position_size == 0
strategy.entry("BuyLong", direction=strategy.long, comment="Buy!")
if sellCondition
strategy.exit("SellLong", from_entry="BuyLong", limit=prevCrossunder)

// Plot signals on chart
plotshape(buyCondition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="Buy")
plotshape(sellCondition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="Sell")


In summary - This script uses indicators MACD and Volume Flow Indicator [Lazy Bear]

Buy signal rules:
* When the blue Moving Average Convergence Divergence line reverses to the upside between -0.002 and -0.005
* If MACD's histogram on previous swing high exceeds +0.0015 within the previous 15 minutes
* If VFI line is between -5.830 and -23.500
* 'Buy' signal is triggered

Sell signal rules:
* When the blue Moving Average Convergence Divergence line reverses to the down side between +0.002 and +0.005
* If MACD's histogram on previous swing low exceeds -0.0015 within the previous 15 minutes
* If VFI line is between +5.830 and +23.500
* 'Sell' signal is triggered
Related categories: Coding Pine Script Trading Automation