Strategy · Pine Script v5 · On the chart

Mavezo

by arrabyte· code credited to Alessandro Arrabito - 2023 Strambatax

Strategy built on exponential moving averages and an optional volume zone oscillator filter.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code186
Settings23inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago30 Jul 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

186 lines of Pine Script v5 from mavezo.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mavezo.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alessandro Arrabito - 2023 Strambatax 
// 

// ████████  ██     ██
// ██░██░░░   ██  ██
// ████████░    ██
//    ██ ██   ██  ██
// ████████  ██     ██

// MAVEZO: is the anagram of ema and vzo as the strategy is mainly based on this two tecnical indicator/oscillator
// revisions and settings available on https://github.com/arrabyte/pinescript_snippets

//@version=5

strategy("mavezo", overlay=true, default_qty_type=strategy.cash, initial_capital = 1000, default_qty_value=2000, 
 commission_type=strategy.commission.percent, commission_value=0.061, margin_long=0.5, margin_short=0.5)

import TradingView/ta/5

// Campi di input nella scheda dei settting 
int emaFastLen = input.int(7, "Ema Fast", step = 1, group = "Ma settings")
int emaSlowLen = input.int(25, "Ema Slow", step = 1, group = "Ma settings") 
int trendMaLen = input.int(200, "Trend Ma", step = 1, group = "Ma settings")

// offset del trailing stop espresso in percentuale
bool enableTrailStopOnTp = input.bool(false, "Enable Trail stop on take profit", group = "risk management")
float trailStopOffsetPrc = input.float(1.0, "Trail offset Prc", step=0.1, group = "risk management") / 100
bool enableTrailStopLossAtr = input.bool(false, "Trail stop loss by Atr", group = "risk management")
 
// risk reward ratio. Default 1 (risk = reward).
float riskReward = input.float(1.0, "risk reward ratio", step=0.1, group = "risk management")
bool breakEvenEnabled = input.bool(true, "Break Even Enabled", tooltip = "if enabled move stop to breakevent if price reach partial take profit", group = "risk management")

// periodo atr
int atrLen = input.int(11, "atr len", group = "atr settings")

// moltiplicatore per definire il livello di stop loss
float atrMultiplier = input.float(3.0, "atr Multiplier", step=0.1, group = "atr settings")

bool atrDraw = input.bool(false, "atr band draw", group = "atr settings")

// ----- ema ------ //
// Calcolo delle medie mobili esponenziali
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
trendMa = ta.ema(close, trendMaLen)
plot(emaFast, color = color.yellow, linewidth = 2)
plot(emaSlow, color = color.blue, linewidth = 2)
plot(trendMa, color = color.gray, linewidth = 2)
// ----- ENd ema ------ //

// ----- vzo ------ //
vzo_enabled     = input.bool(false, 'vzo', group = 'vzo filter')
vzo_length      = input.int(14, 'vzo Length', minval=2, group = 'vzo filter')
vzo_average    = input.bool(true, 'average:Enable Smoothing', group = 'vzo filter')
vzo_noise       = input.int(4, 'average:Noise Filter', minval=2, group = 'vzo filter')
vzo_long_threshold  = input.int(0, 'long threshold', minval=-40, maxval=100, group = 'vzo filter', inline='long thresholds')
vzo_long_threshold_upperbound = input.int(100, 'bound', minval=0, maxval=100, group = 'vzo filter', inline='long thresholds')
vzo_short_threshold  = input.int(0, 'short threshold', minval=-100, maxval=40, group = 'vzo filter', inline='short thresholds')
vzo_short_threshold_lowerbound = input.int(-100, 'bound', minval=-100, maxval=0, group = 'vzo filter', inline='short thresholds')

vzo =  ta.vzo(vzo_length)

if vzo_average
    vzo := ta.ema(vzo, vzo_noise)

vzo_long = vzo_enabled ? vzo >= vzo_long_threshold and vzo  <= vzo_long_threshold_upperbound : true
vzo_short = vzo_enabled ? vzo <= vzo_short_threshold and vzo >= vzo_short_threshold_lowerbound : true
// ----- ENd vzo ------ //

string botLongEntryCmd = input.text_area("", "wundertrading entry long command", group = "bot")
string botLongExitCmd = input.text_area("", "wundertrading exit long command", group = "bot")
string botShortEntryCmd = input.text_area("", "wundertrading entry short command", group = "bot")
string botShortExitCmd = input.text_area("", "wundertrading exit short command", group = "bot")

// Condizioni di ingresso
bool entryLong = ta.crossover(emaFast, emaSlow) and emaSlow > trendMa and vzo_long
bool entryShort = ta.crossunder(emaFast, emaSlow) and emaSlow < trendMa and vzo_short

//// Trade variables.
var float stopLossLevel = na
var float takeProfitLevel = na
var float partialTakeProfitLevel = na
var float entryLevel = na
var float beLevel = na

/// ----- atr ------ //
float atr = ta.atr(atrLen)
float atrOffset = atr*atrMultiplier

plot(atrDraw ? close + atrOffset : na)
plot(atrDraw ? close - atrOffset : na)
// ----- ENd atr ------ //

getTickValue() =>
    syminfo.mintick * syminfo.pointvalue

trailStopOffset = close * trailStopOffsetPrc / getTickValue()

// Questa funzione aggiorna i livelli di uscita con trail e senza trail.
updateExits(direction) =>
    if direction == "long"    
        if enableTrailStopOnTp
            strategy.exit("long_exit_id", "long_id", stop = stopLossLevel, trail_price = takeProfitLevel, trail_offset = trailStopOffset)
        else
            strategy.exit("long_exit_id", "long_id", stop = stopLossLevel, limit = takeProfitLevel, alert_message = botLongExitCmd)
    else if direction == "short"   
        if enableTrailStopOnTp
            strategy.exit("short_exit_id", "short_id", stop = stopLossLevel, trail_price = takeProfitLevel, trail_offset = trailStopOffset)
        else
            strategy.exit("short_exit_id", "short_id", stop = stopLossLevel, limit = takeProfitLevel, alert_message = botShortExitCmd)

// blocco di apertura dei trade long e short
// se si verificano le condizioni.
if entryLong and strategy.position_size == 0
    entryLevel := close

    // stop loss proporzionale al livello di atr
    stopLossLevel := close - atrOffset
    takeProfitLevel := close + atrOffset*riskReward
    beLevel := close + atrOffset*riskReward/2

    strategy.entry("long_id", strategy.long, alert_message = botLongEntryCmd)
    if not na(partialTakeProfitLevel)
        strategy.exit("p1_long_exit_id", "long_id", stop = stopLossLevel, limit = partialTakeProfitLevel, qty_percent = 50)
    updateExits("long")
if entryShort and strategy.position_size == 0
    entryLevel := close
    stopLossLevel := close + atrOffset
    takeProfitLevel := close - atrOffset*riskReward
    beLevel := close - atrOffset*riskReward/2

    strategy.entry("short_id", strategy.short, alert_message = botShortEntryCmd)    
    updateExits("short")

// blocco per abilitira la chiusura a breakeven
if breakEvenEnabled and strategy.position_size > 0 and high > beLevel and barstate.isconfirmed
    stopLossLevel := entryLevel
    updateExits("long")
if breakEvenEnabled and strategy.position_size < 0 and low < beLevel and barstate.isconfirmed
    stopLossLevel := entryLevel
    updateExits("short")

// trailing stop loss atr
if strategy.position_size > 0 and barstate.isconfirmed and enableTrailStopLossAtr
    if close - atrOffset > stopLossLevel 
        stopLossLevel := close - atrOffset
        updateExits("long")
if strategy.position_size < 0 and barstate.isconfirmed and enableTrailStopLossAtr
    if close + atrOffset < stopLossLevel 
        stopLossLevel := close + atrOffset
        updateExits("short")

// Reset delle variabili in chiusura del trade.
if strategy.position_size == 0 and strategy.closedtrades.exit_bar_index(strategy.closedtrades - 1) == bar_index
    stopLossLevel := na
    takeProfitLevel := na
    partialTakeProfitLevel := na
    entryLevel := na
    beLevel := na

var float totProfit = 0
if ta.change(strategy.closedtrades)
    tradeIndex = strategy.closedtrades -1
    tradeId = strategy.closedtrades.exit_id(tradeIndex)
    if tradeId == "long_exit_id" or tradeId == "short_exit_id"
        p = strategy.closedtrades.profit(tradeIndex)
        label.new(bar_index, close, str.format("{0, number, #.##}", p), style = label.style_label_lower_left, color = p > 0 ? color.green : color.red)
        totProfit += p

// tabella riepilogo dati strategia
var tableInfo = table.new(position.top_right, 2,2)
tableInfo.set_bgcolor(color.white)
table.cell(tableInfo, 0, 0, "Info")
table.cell(tableInfo, 0, 1, "Profit")
table.cell(tableInfo, 1, 1, str.format("{0, number, #.##}", totProfit))

// Grafica: disegno dei livelli del trade tramite funzioni plot e fill.
entryLine = plot(entryLevel, color=color.yellow, style = plot.style_linebr)
pTpLine = plot(partialTakeProfitLevel, color=color.fuchsia, style = plot.style_linebr, linewidth = 2)
tpLine = plot(takeProfitLevel, color=color.green, style = plot.style_linebr)
slLine = plot(stopLossLevel, color=color.red, style = plot.style_linebr)

fill(entryLine, tpLine, color.new(color.green, 50))
fill(entryLine, slLine, color.new(color.red, 50))

Overview

Mavezo plots fast, slow and 200-period trend EMAs on the price chart. Risk settings include an ATR based stop distance, a risk-to-reward ratio for the take profit, optional break-even move, and optional trailing stops. Text fields hold alert commands for a third-party trading bot. Defaults use a cash order size and a commission setting for backtests, so results depend heavily on inputs.

Details

Published by

arrabyte on GitHub

Code credit

Alessandro Arrabito - 2023 Strambatax, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Ema Fastint7emaFastLen
Ema Slowint25emaSlowLen
Trend Maint200trendMaLen
Enable Trail stop on take profitboolfalseenableTrailStopOnTp
Trail offset Prcfloat1.0trailStopOffsetPrc
Trail stop loss by AtrboolfalseenableTrailStopLossAtr
risk reward ratiofloat1.0riskReward
Break Even EnabledbooltruebreakEvenEnabled
atr lenint11atrLen
atr Multiplierfloat3.0atrMultiplier
atr band drawboolfalseatrDraw
vzoboolfalsevzo_enabled
Show all 23 settings
SettingTypeDefaultVariable
vzo Lengthint14vzo_length
average:Enable Smoothingbooltruevzo_average
average:Noise Filterint4vzo_noise
long thresholdint0vzo_long_threshold
boundint100vzo_long_threshold_upperbound
short thresholdint0vzo_short_threshold
boundint-100vzo_short_threshold_lowerbound
wundertrading entry long commandtextbotLongEntryCmd
wundertrading exit long commandtextbotLongExitCmd
wundertrading entry short commandtextbotShortEntryCmd
wundertrading exit short commandtextbotShortExitCmd
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated yesterday · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers