Strategy · Pine Script v5 · On the chart

Day Trading With MACD and Point Target Stop

by kritarth2121· code credited to Dynamictradingstrategies

This intraday strategy opens a long when the MACD histogram crosses above zero and a short when it crosses below, only inside a chosen session and only while ADX is below a threshold of 25.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code53
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago10 Dec 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

53 lines of Pine Script v5 from MACD DAY TRADING WITH TGT AND SL.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

MACD DAY TRADING WITH TGT AND SL.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dynamictradingstrategies

//@version=5
strategy("DAY TRADING WITH MACD AND PT BASED TGT & STOPLOSS", overlay  =true)

session = input.session(defval = "0915-1445")
TRADEIN = time("15", session)
SQOFF = time("15", "1445-1500")



[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
[diplus, diminus, adx] = ta.dmi(14, 14)


LONGSTOP = input.int(defval = 50, step = 5, minval =5, maxval = 1000, title = "LONGSTOP")
LONGTGT = input.int(defval = 100, step = 5, minval =5, maxval = 1000, title = "LONGTGT")
SHORTSTOP = input.int(defval = 50, step = 5, minval =5, maxval = 1000, title = "SHORTSTOP")
SHORTTGT = input.int(defval = 100, step = 5, minval =5, maxval = 1000, title = "SHORTTGT")

ADX_LEVEL = input.int(defval = 25, step = 5, minval =5, maxval = 1000, title = "ADX_LEVEL")


///// point based tgt and stoploss 

LT = strategy.position_avg_price + LONGTGT
LSTOP = strategy.position_avg_price - LONGSTOP

SS = strategy.position_avg_price + SHORTSTOP
ST = strategy.position_avg_price - SHORTTGT

buy    = ta.crossover(histLine,0) and TRADEIN and adx < ADX_LEVEL
short = ta.crossunder(histLine,0) and TRADEIN and adx < ADX_LEVEL

sell = SQOFF
cover =SQOFF

///strategy 

strategy.entry("long", when = buy, direction = strategy.long, comment = "BUY")
strategy.close("long", when = sell, comment = "sqoff")
strategy.exit("long", from_entry = "long", stop = LSTOP, limit = LT, comment = "TG/SL-EXIT" )

strategy.entry("short", when = short, direction = strategy.short, comment = "SHORT")
strategy.close("short", when = cover, comment = "sqoff")
strategy.exit("short", from_entry = "short", stop = SS, limit = ST, comment = "TG/SL-EXIT" )

plot(strategy.position_size > 0 ? LT : na, style = plot.style_linebr ) 
plot(strategy.position_size > 0 ? LSTOP : na, style = plot.style_linebr ) 

plot(strategy.position_size < 0 ? SS : na, style = plot.style_linebr ) 
plot(strategy.position_size < 0 ? ST : na, style = plot.style_linebr )

Overview

Each trade has a fixed point-based stop loss and take profit relative to the average entry price, set separately for long and short. Positions are squared off in the last fifteen minutes of the session. Stop and target levels are plotted on the price chart.

Details

Published by

kritarth2121 on GitHub

Code credit

Dynamictradingstrategies, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum, Sessions & time

Markets

Any symbol

Timeframes

M15-H1

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
sessionsession0915-1445session
LONGSTOPint50LONGSTOP
LONGTGTint100LONGTGT
SHORTSTOPint50SHORTSTOP
SHORTTGTint100SHORTTGT
ADX_LEVELint25ADX_LEVEL
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

ARR VWAP Intraday

by hasnocool
106 stars

This strategy plots VWAP on the price chart and trades only between a start hour and an end hour. It enters long when VWAP is rising and RSI is above a threshold, and short when VWAP is falling and RSI is below a threshold. If the reversal option is on, it clo

Strategy v4 Oscillators & momentumVolume Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of ARR VWAP Intraday
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy
43 stars

Donald - AI Futures is a price-chart strategy that estimates inner and outer high-low zones and a smoothed close with rational quadratic kernel regression. It builds bullish and bearish momentum signals, optionally compares volume with a volume-weighted moving

Strategy v5 Oscillators & momentumSMC / ICT / price action Repaints
Updated 2 years ago · None stated GitHub repository of Donald - AI Futures

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter

Morning Scalp

by benso87
24 stars

This strategy tracks an opening session time range to establish directional bias and triggers pullback trades using Stochastic RSI. Once price breaks out of the initial range, it establishes a directional bias and enters when the Stochastic RSI crosses over in

Strategy v5 Sessions & timeBreakout
Updated 4 years ago · MPL-2.0 GitHub repository of Morning Scalp

XAUUSD SMC Bot

by GifariKemal
15 stars

This strategy plots on the XAUUSD price chart and looks for Smart Money Concepts entries on the fifteen-minute timeframe. It scores fair value gaps, order blocks, liquidity sweeps, break of structure, and change of character, plus EMA, RSI, MACD, and higher-ti

Strategy v5 SMC / ICT / price actionOscillators & momentum
Updated 8 months ago · None stated GitHub repository of XAUUSD SMC Bot

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