Forum Replies Created
Check out all your contributions and responses across the community.
-
AuthorPosts
-
Keymaster
Yes sir, you can definitely create a MACD indicator in Pine Script.
MACD mainly consists of three components:
-> MACD Line = Fast EMA – Slow EMA
-> Signal Line = EMA of MACD Line
-> Histogram = MACD Line – Signal LineYou can create it using:
//@version=6 indicator("Custom MACD", overlay=false) fastLength = input.int(12, "Fast Length") slowLength = input.int(26, "Slow Length") signalLength = input.int(9, "Signal Length") fastEMA = ta.ema(close, fastLength) slowEMA = ta.ema(close, slowLength) macdLine = fastEMA - slowEMA signalLine = ta.ema(macdLine, signalLength) histogram = macdLine - signalLine histColor = histogram >= 0 ? (histogram > histogram[1] ? color.teal : color.new(#9ff3ea, 14)) : (histogram < histogram[1] ? color.red : color.new(#ffadad, 60)) plot(macdLine, "MACD") plot(signalLine, "Signal") plot(histogram, "Histogram", style=plot.style_columns, color=histColor)-> The Fast EMA and Slow EMA are used to calculate the MACD Line.
-> The Signal Line is calculated from the MACD Line.
-> The Histogram shows the difference between the MACD Line and Signal Line.
You can also change the 12, 26, and 9 values from the indicator settings because they are created as user inputs.
So that’s how you can create a basic MACD indicator from scratch in Pine Script.
KeymasterPrice totally depends on the market. From our end, the order is executed in the same second when the order is completed in the master account.
Using Order Manager, you can set a stop-loss.
Order Manager You tube video:
You can view all order details from the “Order History” and “Order Detail” tabs in AlgoDelta.
For placing a manual order, go to the Demat tab in AlgoDelta → click the blue eye button → click “Place Order” → enter the script in which you want to place the order.
Again, the same applies: when an order is completed in the master account, it will be placed in the child accounts.
Keymaster01 ) List of brokers in which daily login is not required:
If you are using any of the following brokers, you need to click the green 🟩 “Relogin All Demat” button located at the top-right corner of the “Demat” tab in AlgoDelta to refresh the token.
This will log in all the accounts with just one click.
Yes, we have a provision for clients to log in by themselves.
If you want to know more about the “Link Sharing Demat Connection” feature, you can drop your query on the support WhatsApp number: 95376 74727.
KeymasterYes, you can easily share an Expert Advisor with someone by sending them the EA file.
First, open MT5 and go to:
File → Open Data Folder → MQL5 → Experts
Inside the
Expertsfolder, find the EA you want to share.You will generally see the EA as a
.ex5file. This is the compiled Expert Advisor file that you can send to the other person.After receiving the file, they can install it by:
- Open MT5.
- Go to File →Right Click → Open Data Folder.
- Open
MQL5 → Experts. - Copy the. ex
5file into theExpertsfolder. - Restart MT5, or right-click the Navigator window and select Refresh.
- The EA should then appear under Navigator → Expert Advisors.
After that, they can drag the EA onto the required chart and enable Auto Trading if the EA requires it.
So, in simple terms:
Your MT5 → Open Data Folder → MQL5 → Experts → Copy the
.ex5file → Send it → Recipient places it in theirMQL5 → Expertsfolder.If you are the developer and want the recipient to modify the source code, you would need to send the
.mq5source file instead. For simply running the EA, the compiled.ex5file is normally sufficient.KeymasterYes, you can display the entry price, stop-loss, and target directly on the chart using
plot().For example, you can calculate the levels based on the strategy’s entry price:
//@version=6 strategy("Entry SL Target", overlay = true) longCondition = ta.crossover(ta.ema(close, 9), ta.ema(close, 21)) if longCondition strategy.entry("Long", strategy.long) entryPrice = strategy.position_avg_price stopLoss = entryPrice - 100 target = entryPrice + 200 plot(strategy.position_size > 0 ? entryPrice : na, "Entry", color = color.blue, linewidth = 2) plot(strategy.position_size > 0 ? stopLoss : na, "Stop Loss", color = color.red, linewidth = 2) plot(strategy.position_size > 0 ? target : na, "Target", color = color.green, linewidth = 2)Here:
strategy.position_avg_pricegives the average entry price.stopLosscalculates the stop-loss level.targetcalculates the target level.plot()displays all three levels on the chart.
You can replace the fixed
100and200values with your own SL and target calculation, such as a percentage, ATR-based distance, or risk-reward ratio.This makes it much easier to visually track your entry, stop-loss, and target while the trade is active.
KeymasterYes, you can create a trailing stop-loss in Pine Script using the
strategy.exit()function.For example, if you want to trail the stop by a fixed number of points, you can use the
trail_pointsparameter.//@version=6 strategy("Trailing Stop Example", overlay = true) fastEMA = ta.ema(close, 9) slowEMA = ta.ema(close, 21) buyCondition = ta.crossover(fastEMA, slowEMA) if buyCondition strategy.entry("Long", strategy.long) strategy.exit("Trailing Stop", from_entry = "Long", trail_points = 100, trail_offset = 100)Here:
trail_pointsdefines the trailing distance.trail_offsetdefines the distance from the entry before the trailing stop starts.
Once the trade moves in your favor, the stop-loss automatically follows the price. If the price reverses and reaches the trailing stop, the position is closed.
You can change the trailing values according to your strategy and the instrument you are trading.
I hope this helps!
KeymasterYes sir, you can configure both Stop Loss and End Time for the same position. Both conditions will work independently, and whichever condition is triggered first will exit the position.
-> If the Stop Loss is hit before the configured End Time, the position will be squared off by the Stop Loss.
-> If the configured End Time is reached before the Stop Loss is hit, the position will be squared off by the End Time.
For example:
-Stop Loss: 100 points
-End Time: 15:15
If the Stop Loss is triggered at 14:45, the position will be exited at that time and the End Time will no longer matter for that position.
If the Stop Loss is not triggered and the position is still open at 15:15, the End Time will trigger the square-off.
=> So, when multiple exit conditions are configured, the first condition that is satisfied will handle the exit of the position.
KeymasterYes sir, both are used for creating alerts in Pine Script, but they work differently and are useful in different situations.
–
alertcondition()is mainly used to create a specific alert condition that appears as an option when creating an alert from the TradingView interface.For example:
//@version=6 indicator("Alert Condition Example", overlay=true) fastEMA = ta.ema(close, 9) slowEMA = ta.ema(close, 21) buySignal = ta.crossover(fastEMA, slowEMA) alertcondition( buySignal, title="Buy Signal", message="Buy Signal Generated" )After adding this indicator to the chart, you can select the
Buy Signalcondition while creating a TradingView alert.–
alert()is used to trigger an alert directly from your Pine Script when your code reaches that statement.For example:
if buySignal alert("BUY Signal Generated", alert.freq_once_per_bar_close)Here, the alert is triggered when
buySignalbecomes true.So the main difference is:
->
alertcondition()→ Defines an alert condition that can be selected from TradingView’s alert creation window.->
alert()→ Directly triggers an alert from inside the script when the specified condition is reached.Another important difference is that
alert()allows you to create dynamic messages using values calculated by your script, which is useful when you want to send changing information such as price, indicator values, or signal details.=> If you want to expose predefined conditions for users to select while creating an alert,
alertcondition()is a good choice.=> If you want your script to trigger alerts programmatically with dynamic messages,
alert()is generally more suitable.So both functions are related to alerts, but the way they are configured and triggered is different.
KeymasterYes sir, you can create automatic support and resistance levels using pivot highs and pivot lows.
Pine Script provides
ta.pivothigh()andta.pivotlow()to identify these points.A simple example:
//@version=6 indicator("Auto Support Resistance", overlay=true) leftBars = 5 rightBars = 5 pivotHigh = ta.pivothigh(high, leftBars, rightBars) pivotLow = ta.pivotlow(low, leftBars, rightBars) plot(pivotHigh, "Resistance", color=color.red, style=plot.style_linebr) plot(pivotLow, "Support", color=color.green, style=plot.style_linebr)Here:
–
ta.pivothigh()identifies a swing high that can be treated as a resistance level.–
ta.pivotlow()identifies a swing low that can be treated as a support level.-The
leftBarsandrightBarsvalues determine how many candles are used to confirm the pivot.You can also use
line.new()if you want to draw and extend the detected support and resistance levels dynamically instead of simply plotting them.One important point is that pivot levels are confirmed only after the required number of candles on the right side has formed. So the level will not be identified immediately at the exact candle where the high or low occurs.
=> This approach can be extended further to keep multiple historical support and resistance levels, remove old levels, or create zones instead of single price lines.
So, by combining pivot detection with drawing functions such as
line.new()orbox.new(), you can build a fully automatic support and resistance indicator.KeymasterYes sir, you can detect the first candle of a new day by comparing the current bar’s day with the previous bar’s day.
A simple way is to use
dayofmonth://@version=6 indicator("First Candle of Day", overlay=true) newDay = ta.change(dayofmonth) != 0 plotshape( newDay, title="First Candle", style=shape.labelup, location=location.belowbar, text="Day Start" )Here,
ta.change(dayofmonth)checks whether the day has changed compared with the previous candle.When the day changes:
->
newDaybecomestrue-> The current candle is treated as the first candle of the new day
-> Your required logic can be executed only when
newDayis trueFor example:
if newDay // Your logic hereYou can use this for tasks such as:
-Resetting daily variables
-Capturing the first candle’s high and low
-Calculating daily opening levels
-Starting a new daily trading cycle
-Resetting strategy conditions
So the main idea is to detect the change from the previous day’s value rather than checking every candle individually.
KeymasterYes sir, Pine Script provides several built-in functions for drawing objects and visual markers directly on the chart.
-Line:
line.new()is used to draw trend lines or connect two price points.-Box:
box.new()is useful for creating rectangular zones such as support, resistance, supply, or demand areas.-Label:
label.new()allows you to display text or custom markers at a specific price and bar.-Plotshape:
plotshape()is useful for showing simple Buy/Sell arrows, triangles, or other predefined shapes when a condition is true.-Horizontal Line:
hline()is used to draw a fixed horizontal level, such as an RSI level at 70 or 30.For example:
//@version=6 indicator("Drawing Example", overlay=true) buySignal = ta.crossover(ta.ema(close, 9), ta.ema(close, 21)) plotshape(buySignal, title="Buy", style=shape.triangleup, location=location.belowbar, text="BUY") hline(100, "Level") if buySignal label.new(bar_index, low, "BUY")If you need dynamic drawings that are created and positioned using specific bar and price coordinates, functions like
line.new(),box.new(), andlabel.new()are more suitable.For simple signal markers,
plotshape()is usually easier.For fixed horizontal levels,
hline()is the appropriate choice.So in simple terms:
->
line.new()→ Dynamic lines and trend lines->
box.new()→ Rectangular zones->
label.new()→ Text and custom markers->
plotshape()→ Signal shapes->
hline()→ Fixed horizontal levelsThese functions allow you to turn a basic Pine Script indicator into a much more visual and informative chart.
KeymasterYes sir, you can definitely do that.
Pine Script provides the barcolor() function, which allows you to change the color of chart candles based on any condition in your script. This is a simple and effective way to visually highlight trading opportunities without modifying the actual price data.
For example, if you want to color candles green when your buy condition is true and red when your sell condition is true, you can use the following code:
//@version=6 indicator("Strategy Candle Colors", overlay=true) fastEMA = ta.ema(close, 10) slowEMA = ta.ema(close, 20) buyCondition = ta.crossover(fastEMA, slowEMA) sellCondition = ta.crossunder(fastEMA, slowEMA) barcolor( buyCondition ? color.green : sellCondition ? color.red : na )In this example:
-> Green candles indicate that the buy condition has been triggered.
-> Red candles indicate that the sell condition has been triggered.
-> If neither condition is true, the candle keeps its default chart color.
You can also use any custom condition from your strategy. For example:
longCondition = close > ta.ema(close, 50) shortCondition = close < ta.ema(close, 50) barcolor( longCondition ? color.lime : shortCondition ? color.orange : na )You are not limited to just buy and sell signals. Candle colors can also represent different market conditions, such as:
-> Trend direction
-> High volume candles
-> Breakout candles
-> Overbought or oversold conditions
-> Volatility-based signals
Using candle colors makes it much easier to analyze your strategy because important conditions become visible directly on the chart without relying only on labels or shapes.
For more details about the available color functions and customization options, you can refer to the official Pine Script documentation:
https://www.tradingview.com/pine-script-docs/So that’s how you can color candles dynamically based on your strategy conditions in Pine Script. This is the recommended way to make your trading strategy more visual and easier to analyze.
KeymasterYes sir, you can definitely do that. Pine Script provides a built-in
tableobject that allows you to create custom dashboards directly on the TradingView chart.A table can be used to display any information that your script calculates, such as:
-Trend Direction
-Current Signal (Buy/Sell)
-EMA Values
-RSI Value
-Any custom calculation from your strategy or indicator
For example, you can create a simple dashboard like this:
//@version=6 indicator("Dashboard Example", overlay = true) emaFast = ta.ema(close, 20) emaSlow = ta.ema(close, 50) rsiValue = ta.rsi(close, 14) trend = emaFast > emaSlow ? "Bullish" : "Bearish" var table dashboard = table.new(position.top_right, 2, 4, frame_color = color.green, frame_width = 2, bgcolor = color.white, border_color = color.teal, border_width = 2) if barstate.islast table.cell(dashboard, 0, 0, "Trend") table.cell(dashboard, 1, 0, trend) table.cell(dashboard, 0, 1, "EMA 20") table.cell(dashboard, 1, 1, str.tostring(emaFast)) table.cell(dashboard, 0, 2, "EMA 50") table.cell(dashboard, 1, 2, str.tostring(emaSlow)) table.cell(dashboard, 0, 3, "RSI") table.cell(dashboard, 1, 3, str.tostring(rsiValue))This creates a dashboard in the top-right corner of the chart that updates automatically on every new bar.
You can also customize the table according to your requirements.
-Change its position using
position.top_left,position.top_right,position.bottom_left,position.bottom_right, or other available positions.-Add more rows and columns.
-Display text, numbers, or calculated values.
-Change the background color and text color.
-Highlight Buy and Sell signals with different colors.
-Show live values from multiple timeframes.
-One important thing to remember is that the table should usually be updated only on the last bar by using
barstate.islast. This improves performance and avoids unnecessary updates on historical bars.So that’s how you can create a professional dashboard on the TradingView chart using Pine Script.
For more information, you can refer to the official Pine Script documentation:
https://www.tradingview.com/pine-script-docs/concepts/tables/KeymasterYes sir, Pine Script provides built-in
input()functions that allow you to create configurable settings for your indicator.Instead of hardcoding values, you can let users modify them directly from the indicator’s Settings window.
For example, to create an integer input:
//@version=6 indicator("Input Example", overlay=true) emaLength = input.int(20, "EMA Length") emaValue = ta.ema(close, emaLength) plot(emaValue)Now, when you add the indicator to the chart, users can open the indicator settings and change the EMA Length without modifying the code.
You can also create different types of inputs depending on your requirements.
-Integer Input
length = input.int(20, "Length")-Float Input
multiplier = input.float(2.5, "Multiplier")-Boolean (Checkbox)
showEMA = input.bool(true, "Show EMA")-String Dropdown
maType = input.string( "EMA", "Moving Average", options = ["EMA", "SMA", "WMA"] )-Color Picker
lineColor = input.color(color.blue, "Line Color")-Timeframe Selector
higherTF = input.timeframe("60", "Higher Timeframe")-Price Source
priceSource = input.source(close, "Price Source")Once these inputs are created, users can change them anytime by opening:
-Indicator Settings
-> InputsThere is no need to edit or save the Pine Script again.
Using inputs is considered a best practice because it makes your indicator reusable and user-friendly. Instead of creating multiple versions of the same indicator with different values, you can create one configurable indicator that users can customize according to their trading style.
-
AuthorPosts
