Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Code Snippet – Simple Intraday Trading System with Target and Stoploss – Tradingview Pinescript

2 min read

Thought of implementing a simple intraday trading system with stoploss and target controls with time-based entry and exit controls. Traders can use this code as a prototype to design their own intraday trading strategy

Tradingview Pinescript brings more interesting way of implementing pure intraday trading system with target and stoploss.

Here is a simple Intraday Trading System Module. Sort of a Coding Snippet to create your own intraday trading system with the following signals

1)Buy Signal
2)Sell Signal
3)Stop Exit
4)Target Exit
5)Square.Off Exit

Note: It is not a Tradingview strategy but more of visual indications. Kindly use the module to build your strategy on top of this code. For simplicity purpose explained with EMA crossover strategy.

Access Tradingview Pinescript : Simple Intraday Trading System with Stop and Target

Intraday Trading System – Pinescript Module (Visual Stop and Target Levels )

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketcalls_in
//Coded by Rajandran R (Founder - Marketcalls/Co-Founder - Algomojo)

//@version=4
study("Simple Intraday Trading System",overlay=true)

ema1 = input(title="Fast EMA",type = input.integer, defval=5,minval=1,maxval=200)
ema2 = input(title="Slow EMA",type = input.integer, defval=10,minval=1,maxval=200)
TradeTime = input(title="Trade Timings",defval="0930-1500", type=input.session)
SqoffTime = input(title="Squareoff Timings",defval="1515-1530", type=input.session)
stop = input(title="Stoploss (Points)",type = input.integer, defval=30,minval=1,maxval=1000,step=0.05)
target = input(title="Target (Points)",type = input.integer, defval=20,minval=1,maxval=1000,step=0.05)
displayema = input(title="Display EMA",type=input.bool,defval=true)

Barsinsession(TradeTime) => time(timeframe.period,TradeTime) != 0



Insession = Barsinsession(TradeTime) ? 1 : 0
endofsession = Insession == 0 and Insession[1] == 1  


Sqsession = Barsinsession(SqoffTime) ? 1 : 0
SqTime = Sqsession == 1 and Sqsession[1] ==0



Buy = crossover(ema(close,ema1),ema(close,ema2)) and Insession
Sell = (crossunder(ema(close,ema1),ema(close,ema2)) and Insession) or SqTime


BuyPrice = valuewhen(Buy,close,0)


targetprice = BuyPrice + target
stopprice = BuyPrice - stop

emacrossexit = crossunder(ema(close,20),ema(close,50))
Targethit = crossover(high,targetprice)
Stophit = crossunder(low,stopprice)

Sell := Sell or Targethit or Stophit

exitprice = valuewhen(emacrossexit or SqTime,close,0)
targetexitprice = valuewhen(Targethit,targetprice,0)
stopexitprice = valuewhen(Stophit,stopprice,0)


newday = dayofmonth != dayofmonth[1]

var isLong = false
var isSell = false

//Removing Excessive Signals
Buy := not isLong and Buy
Sell := not isSell and Sell

if Buy
    isLong := true
    isSell := false

if Sell
    isLong := false
    isSell := true
    
    
//flip
buycontinue = barssince(Buy) < barssince(Sell)
sellcontinue = barssince(Sell) < barssince(Buy)



plot(buycontinue? targetprice : na,color=color.blue,style=plot.style_circles,linewidth=1 )
plot(buycontinue? stopprice : na,color=color.red,style=plot.style_circles,linewidth=1 )



plotshape(Buy,style=shape.labelup,location = location.belowbar,color=color.green,title = "Buy",text="Buy",textcolor=color.white)

plotshape(Sell and not SqTime and not Targethit and not Stophit,style=shape.labeldown,location = location.abovebar,color=color.red,title = "Sell",text="Sell",textcolor=color.white)
plotshape(Sell and SqTime and not Targethit and not Stophit,style=shape.labeldown,location = location.abovebar,color=color.orange,title = "Squareoff.Exit",text="Squareoff.Exit ",textcolor=color.white)

plotshape(Sell and not SqTime and Targethit and not Stophit,style=shape.labeldown,location = location.abovebar,color=color.blue,title = "Sell",text="Target.Exit",textcolor=color.white)
plotshape(Sell and not SqTime and not Targethit and Stophit,style=shape.labeldown,location = location.abovebar,color=color.red,title = "Squareoff.Exit",text="Stop.Exit",textcolor=color.white)



plot(displayema ? ema(close,ema1) : na,color=color.aqua,style=plot.style_line,linewidth=1)
plot(displayema ? ema(close,ema2) : na,color=color.lime,style=plot.style_line,linewidth=1)

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Introducing OpenAlgo V1.0: The Ultimate Open-Source Algorithmic Trading Framework…

OpenAlgo V1.0 is an open-source algorithmic trading platform to automate your trading strategies using Amibroker, Tradingview, Metatrader, Python etc. Designed with the modern trader...
Rajandran R
2 min read

Dive Into the TradingView Paper Trading Competition: A Chance…

Welcome to an exhilarating opportunity presented by TradingView – a paper trading competition that not only tests your trading acumen but also offers a...
Rajandran R
1 min read

Introducing PineGPT – To Build Better Tradingview Pinescript Codes

PineGPT is a customGPT for ChatGPT4 users designed to provide expert guidance on creating and understanding TradingView Pine Script indicators and trading strategies. PineGPT...
Rajandran R
1 min read

2 Replies to “Code Snippet – Simple Intraday Trading System with Target…”

  1. Super script sir, how can we get buy signal candle low is stop loss and target buy signal low +high total sum is target, ple help me sir

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More