Strategy · Pine Script v5 · On the chart

Daily High/Low and Andean Oscillator Strategy

by geraked

This strategy plots the previous daily high and low on the price chart and calculates the Andean oscillator bull and bear components with an exponential moving average signal.

View on GitHub

Repaints

GitHub stars104on the repository
Pine versionv5runs as is
Lines of code135
Settings5inputs
LicenceMIT
Last update3 years ago29 Oct 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

135 lines of Pine Script v5 from strategies/DHLAOS.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

DHLAOS.pine
// A strategy using Daily High/Low and Andean Oscillator indicators for scalping
// The strategy has been explained in this video: https://youtu.be/IZVSb1kjduQ
// © 2023 Geraked, Rabist
// Licensed under MIT

// Backtesting result:
//      Symbol:             AUDUSD
//      Timeframe:          5 MIN
//      Range:              2023-08-06 21:00 — 2023-09-03 21:00
//      Percent Profitable: 69.5%
//      Total Trades:       23
//      Profit Factor:      3.098


//@version=5
strategy("Daily High/Low and Andean Oscillator Strategy", "DHLAOS", pyramiding=10, overlay=true)

tpCoef = input.float(1.5, "TP Coef", group="Strategy")
swingLen = input.int(5, "Swing Length", group="Strategy")
reverse = input.bool(false, "Reverse Signal", group="Strategy")

length = input.int(50)
sig_length = input.int(9,'Signal Length')

var alpha = 2/(length+1)
var up1 = 0.,var up2 = 0.
var dn1 = 0.,var dn2 = 0.

C = close
O = open
up1 := nz(math.max(C, O, up1[1] - (up1[1] - C) * alpha), C)
up2 := nz(math.max(C * C, O * O, up2[1] - (up2[1] - C * C) * alpha), C * C)
dn1 := nz(math.min(C, O, dn1[1] + (C - dn1[1]) * alpha), C)
dn2 := nz(math.min(C * C, O * O, dn2[1] + (C * C - dn2[1]) * alpha), C * C)

bull = math.sqrt(dn2 - dn1 * dn1)
bear = math.sqrt(up2 - up1 * up1)
signal = ta.ema(math.max(bull, bear), sig_length)

indexHighTF = barstate.isrealtime ? 1 : 0
indexCurrTF = barstate.isrealtime ? 0 : 1
pricehigh = request.security(syminfo.tickerid, "1D", high[indexHighTF])[indexCurrTF]
pricelow = request.security(syminfo.tickerid, "1D", low[indexHighTF])[indexCurrTF]

plot(pricehigh, "Previous Daily High", color.white, 2, plot.style_linebr)
plot(pricelow, "Previous Daily Low", color.white, 2, plot.style_linebr)

long = bull[1] <= signal[1] and bull > signal
short = bear[1] <= signal[1] and bear > signal

var n = 300
var k = 50
var li = 0
var si = 0

if long
    for i=2 to n
        if bull[i+1] >= bear[i+1] and bull[i] < bear[i]
            long := false
            break
        else if bull[i+1] >= signal[i+1] and bull[i] < signal[i]
            long := false
            break
        else if bull[i+1] <= signal[i+1] and bull[i] > signal[i]
            long := false
            break            
        else if bull[i+1] <= bear[i+1] and bull[i] > bear[i]
            li := i
            break

if short
    for i=2 to n
        if bull[i+1] <= bear[i+1] and bull[i] > bear[i]
            short := false
            break
        else if bear[i+1] >= signal[i+1] and bear[i] < signal[i]
            short := false
            break
        else if bear[i+1] <= signal[i+1] and bear[i] > signal[i]
            short := false
            break                        
        else if bull[i+1] >= bear[i+1] and bull[i] < bear[i]
            si := i
            break

lc = false
sc = false

if long
    for i=li to li + k
        if high[i] < pricelow[i] and bull[i] < bear[i]
            lc := true
            break

if short
    for i=si to si + k
        if low[i] > pricehigh[i] and bull[i] > bear[i]
            sc := true
            break

long := long and lc
short := short and sc

longSl = ta.lowest(low, swingLen)
shortSl = ta.highest(high, swingLen)
var cnt = 1

plotshape(long, style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small)
plotshape(short, style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)

if long
    inn = close
    longTp = inn + tpCoef * (inn - longSl)    
    if not reverse
        id = "long " + str.tostring(cnt)
        strategy.entry(id, strategy.long)
        strategy.exit("exitLong " + str.tostring(cnt), id, stop=longSl, limit=longTp)
    else
        id = "short " + str.tostring(cnt)
        strategy.entry(id, strategy.short)
        strategy.exit("exitShort " + str.tostring(cnt), id, stop=longTp, limit=longSl)
    cnt += 1

if short
    inn = close
    shortTp = inn - tpCoef * (shortSl - inn)
    if not reverse
        id = "short " + str.tostring(cnt)
        strategy.entry(id, strategy.short)
        strategy.exit("exitShort " + str.tostring(cnt), id, stop=shortSl, limit=shortTp)
    else
        id = "long " + str.tostring(cnt)
        strategy.entry(id, strategy.long)
        strategy.exit("exitLong " + str.tostring(cnt), id, stop=shortTp, limit=shortSl)
    cnt += 1

Overview

Daily High/Low and Andean Oscillator Strategy looks for a bull or bear cross of that signal, then confirms the setup against recent oscillator history and the daily levels. Entries use a swing-length stop and a take-profit set by a coefficient of that risk distance. A reverse option flips the signal direction. Pyramiding is enabled. Signals can change before the bar closes.

Details

Published by

geraked on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Support & resistance, Scalping

Markets

Forex

Timeframes

M1-M5

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy can add several entries in the same direction

Topics

backtesting-trading-strategiesexpert-advisorexpert-advisorsforex-botgerakedmetatraderpinescriptrabiststock-markettrading-algorithms

Settings

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

SettingTypeDefaultVariable
TP Coeffloat1.5tpCoef
Swing Lengthint5swingLen
Reverse Signalboolfalsereverse
lengthint50length
Signal Lengthint9sig_length
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

106 stars

This strategy plots on the price chart and enters when three smoothed moving averages are aligned, RSI is on the matching side of 50, and a Williams fractal appears. An upward stack with RSI above 50 and a down fractal opens a long; the opposite setup opens a

Strategy v5 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3SmmaCrossUp + Fractal + RSI
105 stars

Gold Scalping BOS & CHoCH is an overlay strategy designed for detecting market structure shifts. It calculates rolling swing highs and lows to identify Break of Structure (BOS) and Change of Character (CHoCH) events. Long signals trigger when bullish BOS and C

Strategy v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · None stated GitHub repository of Gold Scalping BOS & CHoCH
53 stars

This strategy trades EUR/USD on the price chart using a fast and slow exponential moving average crossover filtered by RSI. It enters long when the fast EMA crosses above the slow EMA while RSI is above 50 and below the overbought level, and enters short on th

Strategy v6 TrendMoving averages
Updated 2 months ago · MPL-2.0 GitHub repository of EUR/USD EMA9-21 + RSI Scalping Strategy

ATOM 1m scalp HK

by dearvn
43 stars

This overlay strategy targets one-minute ATOM scalps. It tracks pivot highs and lows as resistance and support, compares a three-period EMA with a multi-stage smoothed close, and flags long or short when price crosses that curve in the matching direction. Dail

Strategy v5 ScalpingSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of ATOM 1m scalp HK
27 stars

LuxAlgo Hybrid Gold Scalper is a price-chart strategy aimed at gold. It stacks a fast, slow, trend and 200-period bias EMA to mark trend direction, then filters strength with RSI, ADX and an intraday VWAP. Swing highs and lows are marked from pivot length. Set

Strategy v5 TrendOscillators & momentum
Updated 5 months ago · None stated GitHub repository of LuxAlgo Hybrid Gold Scalper

KC15

by benso87
24 stars

KC15 is a price-chart strategy that configures two moving averages, a Bollinger Band Width Percentile filter, and PMARP entry and exit thresholds for long and short trades. Users can switch each average between SMA and EMA, set lengths and colors, and toggle l

Strategy v5 Moving averagesVolatility & bands
Updated 4 years ago · MPL-2.0 GitHub repository of KC15

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