Strategy · Pine Script v5 · On the chart

3xEMA 1min Startegy

by DaniilOkrug· code credited to icewalk

This strategy identifies entry setups on short timeframes by combining moving average trend filters with Bill Williams fractal breakouts.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code196
Settings3inputs
LicenceMIT
Last update4 years ago15 Dec 2021

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

196 lines of Pine Script v5 from [Order] 3xEMA 1min startegy.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

[Order] 3xEMA 1min startegy.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © icewalk

//@version=5
strategy("[Order] 3xEMA 1min startegy", overlay=true, margin_long=100, margin_short=100)

//--INPUT-----------------------------------------------------------------------

n = input.int(title="Periods", defval=2, minval=2, group="Fractals")
risk = input.float(title="Risk coefficient", defval=1.5, step=0.01, group="TakeProfit/StopLoss")

showFractals = input.bool(title="Show fractals", defval=true, group="Visual part")

//--INPUT END-------------------------------------------------------------------

//--FRACTALS--------------------------------------------------------------------

// UpFractal
bool upflagDownFrontier = true
bool upflagUpFrontier0 = true
bool upflagUpFrontier1 = true
bool upflagUpFrontier2 = true
bool upflagUpFrontier3 = true
bool upflagUpFrontier4 = true

for i = 1 to n
    upflagDownFrontier := upflagDownFrontier and (high[n-i] < high[n])
    upflagUpFrontier0 := upflagUpFrontier0 and (high[n+i] < high[n])
    upflagUpFrontier1 := upflagUpFrontier1 and (high[n+1] <= high[n] and high[n+i + 1] < high[n])
    upflagUpFrontier2 := upflagUpFrontier2 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+i + 2] < high[n])
    upflagUpFrontier3 := upflagUpFrontier3 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+i + 3] < high[n])
    upflagUpFrontier4 := upflagUpFrontier4 and (high[n+1] <= high[n] and high[n+2] <= high[n] and high[n+3] <= high[n] and high[n+4] <= high[n] and high[n+i + 4] < high[n])
flagUpFrontier = upflagUpFrontier0 or upflagUpFrontier1 or upflagUpFrontier2 or upflagUpFrontier3 or upflagUpFrontier4

upFractal = (upflagDownFrontier and flagUpFrontier)


// downFractal
bool downflagDownFrontier = true
bool downflagUpFrontier0 = true
bool downflagUpFrontier1 = true
bool downflagUpFrontier2 = true
bool downflagUpFrontier3 = true
bool downflagUpFrontier4 = true

for i = 1 to n
    downflagDownFrontier := downflagDownFrontier and (low[n-i] > low[n])
    downflagUpFrontier0 := downflagUpFrontier0 and (low[n+i] > low[n])
    downflagUpFrontier1 := downflagUpFrontier1 and (low[n+1] >= low[n] and low[n+i + 1] > low[n])
    downflagUpFrontier2 := downflagUpFrontier2 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+i + 2] > low[n])
    downflagUpFrontier3 := downflagUpFrontier3 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+i + 3] > low[n])
    downflagUpFrontier4 := downflagUpFrontier4 and (low[n+1] >= low[n] and low[n+2] >= low[n] and low[n+3] >= low[n] and low[n+4] >= low[n] and low[n+i + 4] > low[n])
flagDownFrontier = downflagUpFrontier0 or downflagUpFrontier1 or downflagUpFrontier2 or downflagUpFrontier3 or downflagUpFrontier4

downFractal = (downflagDownFrontier and flagDownFrontier)

//--FRACTALS END----------------------------------------------------------------

//--MAIN ALGORITHM--------------------------------------------------------------

var bool isLong = false                     //Determine bullish trend
var bool isShort = false                    //Determine bearish trend

var float stopLoss = na                     //SL
var float takeProfit = na                   //TP
var float openPrice = na                    //Position open price

var bool waitOpenSignal_long = false        //Determine waiting the down fractal
var bool waitOpenSignal_short = false       //Determine waiting the up fractal

//EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema100 = ta.ema(close, 100)

//Determine longs condition
if not isLong and ema20 > ema50 and ema50 > ema100
    isLong := true
    isShort := false
    
    waitOpenSignal_short := false

//Determine short condition
if not isShort and  ema20 < ema50 and ema50 < ema100
    isLong := false
    isShort := true
    
    waitOpenSignal_long := false

//Long Position
if isLong and close > ema20 and close[n] > ema20[n] and not waitOpenSignal_long
    waitOpenSignal_long := true
    waitOpenSignal_short := false

//Short position
if isShort and close < ema20 and close[n] < ema20[n] and not waitOpenSignal_short
    waitOpenSignal_long := false
    waitOpenSignal_short := true

//-Position closing by takeprofit or stoploss

//TP close conditions
takeProfitPositionClose_longCondition = strategy.position_size > 0 and close > takeProfit
takeProfitPositionClose_shortCondition = strategy.position_size < 0 and close < takeProfit

//Close position by TP
if strategy.opentrades > 0 and ( takeProfitPositionClose_longCondition or takeProfitPositionClose_shortCondition )
    stopLoss := na
    takeProfit := na
    openPrice := na
    
    strategy.close_all(comment="TakeProfit")

//Sl close conditions
stopLossPositionClose_longCondition = strategy.position_size > 0 and close < stopLoss
stopLossPositionClose_shortCondition = strategy.position_size < 0 and close > stopLoss

//Close position by SL
if strategy.opentrades > 0 and ( stopLossPositionClose_longCondition or stopLossPositionClose_shortCondition )
    stopLoss := na
    takeProfit := na
    openPrice := na
    
    strategy.close_all(comment="StopLoss")

//-Open postions algorithm

//Open Long
//Fractal in range of ema20 and ema100
fractalCondition_long = downFractal and ema20 > low[n] and low[n] > ema100

//Condition for opening long
longOpenPositionCondition = waitOpenSignal_long and fractalCondition_long and strategy.opentrades == 0
    
if longOpenPositionCondition
    waitOpenSignal_long := false
    
    //Determine TP and SL for position
    if low[n] > ema50[n]
        stopLoss := ema50
        takeProfit := close + (close - stopLoss) * risk
    else
        stopLoss := ema100
        takeProfit := close + (close - stopLoss) * risk
    
    openPrice := close
    strategy.entry("Long", strategy.long)

//Open Short
//Fractal in range of ema20 and ema100
fractalCondition_short = upFractal and ema20 < high[n] and high[n] < ema100

//Condition for opening short
shortOpenPositionCondition = waitOpenSignal_short and fractalCondition_short and strategy.opentrades == 0
    
if shortOpenPositionCondition
    waitOpenSignal_short := false
    
    //Determine TP and SL for position
    if high[n] < ema50[n]
        stopLoss := ema50
        takeProfit := close - (stopLoss - close) * risk
    else
        stopLoss := ema100
        takeProfit := close - (stopLoss - close) * risk
    
    openPrice := close
    strategy.entry("Short", strategy.short)

//--MAIN ALGORITHM END----------------------------------------------------------

//--VISUALISATION---------------------------------------------------------------

//Fractals
plotshape(showFractals and downFractal, style=shape.triangledown, location=location.belowbar, offset=-n, color=color.red, size = size.small)
plotshape(showFractals and upFractal, style=shape.triangleup,   location=location.abovebar, offset=-n, color=color.green, size = size.small)

//EMAs plots
plot(ema20, linewidth=2, color=color.maroon)
plot(ema50, linewidth=2, color=color.orange)
plot(ema100, linewidth=2, color=color.white)

//Stoploss and Takeprofit
var line tpLine = na        //TakeProfit line
var line slLine = na        //StopLoss line
var line openLine = na

line.delete(tpLine)
line.delete(slLine)
line.delete(openLine)

tpLine := line.new(bar_index[1], takeProfit, bar_index, takeProfit, extend=extend.both, style=line.style_dashed, color=color.green)
slLine := line.new(bar_index[1], stopLoss, bar_index, stopLoss, extend=extend.both, style=line.style_dashed, color=color.red)
openLine := line.new(bar_index[1], openPrice, bar_index, openPrice, extend=extend.both, style=line.style_dashed, color=color.blue)

//--VISUALISATION END---------------------------------------------------------------

Overview

3xEMA 1min Startegy tracks multi-bar high and low fractals to establish market structure, waiting for confirmed fractal breaks in the direction of the prevailing trend before initiating trades. User inputs allow adjustment of fractal calculation periods, risk coefficients for target calculations, and visual fractal markers on the price chart.

Details

Published by

DaniilOkrug on GitHub

Code credit

icewalk, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Support & resistance, Scalping

Markets

Any symbol

Timeframes

M1-M5

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Periodsint2n
Risk coefficientfloat1.5risk
Show fractalsbooltrueshowFractals
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

43 stars

This strategy trades SOL perpetual candles on the price chart. It tracks confirmed pivot highs and lows as support and resistance circles, then compares close with a smoothed filter and a three-period EMA to mark long and short conditions after the bar closes.

Strategy v5 Moving averagesSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m Strategy Candle Bar

Omar Edited WF

by Alorse
330 stars

Omar Edited WF is a trading strategy overlay built around Williams Fractals and multiple Exponential Moving Averages. It detects high and low fractal pivot points over configurable lookback periods alongside three adjustable EMA trendlines. Long entries are ma

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Omar Edited WF
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
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

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