Indicator · Pine Script v5 · On the chart

MAD Position Starter & Calculator

by regalouisei· code credited to djmad

This indicator assists with trade planning and position risk management by projecting trade parameters directly onto the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code316
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 2026

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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

316 lines of Pine Script v5 from pinescript/editors_picks/mad-position-starter-calculator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mad-position-starter-calculator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © djmad

//@version=5

indicator(title='[MAD] Position starter & calculator', shorttitle='[MAD] Pos. S&C', overlay=true , max_boxes_count=500, max_lines_count=500, max_labels_count=500)

// load Standardparts
import djmad/Position_control/1 as POS_CON
import djmad/Mad_Standardparts/1 as STDP
//


// Variables and definitios {
var int colortheme                          = na
var M_Colors                                = matrix.new<color>(6, 10, na)
var int bartime                             = na
var POS_CON.t_Position_type[] myPosition    = array.new<POS_CON.t_Position_type>()
var POS_CON.t_drawing_parameters myParameters = na

if bar_index == 200
    bartime := STDP.f_getbartime()

//}

///////////////////// INPUTS IN TYPES /////////////////// {
if barstate.isfirst
    colortheme                      :=     input.int(5, "Colortheme",minval = 0, maxval = 5,                                                      group='Colortheme (0 = Darkmode, 1 = Lightmode', tooltip='0 Darkmode, 1 Lightmode, 2 @Wotan_BitBlockArt, 3 @Linden_Blues, 4 @BitcoinFranken87')
    var p_prolong_lines             =      input.bool(false,"Extend lines to the left",                                                           group='Colortheme (0 = Darkmode, 1 = Lightmode')
    var p_showPos                   =      input.bool(false, "Show contracts",                                 inline="AC3",                      group='Leverage/Capital'),
    var p_showLIQ                   =      input.bool(false,"Show liquidation",                                                                   group='Leverage/Capital')
    var float SET_SL_PRICE          =      input.price(defval=100, title= "SL",                                inline="XE1",   confirm = true,    group='SL')
    var float SET_SL_LOT            =      100
    var int SET_Starttime           =      input.time(timestamp("2020-02-19"),title= "Entry - Left limit",     inline="EB1",   confirm = true,    group='Entrybox start'),
    var float SET_Entry_Start       =      input.price(defval=100, title= "Entry_Boxbegin",                    inline="EB1",   confirm = true,    group='Entrybox start'),
    var int SET_Stoptime            =      input.time(timestamp("2020-02-19"),title= "Entry - Right limit",    inline="EB2",   confirm = true,    group='Entrybox stop'),
    var float SET_Entry_Stop        =      input.price(defval=100, title= "Entry_Boxstop",                     inline="EB2",   confirm = true,    group='Entrybox stop'),
    var float SET_Lot               =      input.float(1,"Contracts",minval = 0.000000000000000001,            inline="AC3",                      group='Leverage/Capital'),
    var float SET_Leverage          =      input.float(20,"Leverage",minval = 1,maxval = 100,step=1,           inline="LE1",                      group='Leverage/Capital'),
    var float SET_Maintenance       =      (100-input.float(50, "max. margin %", minval=0, maxval=100 ,        inline="LE1",                      group='Leverage/Capital',step = 1))/10000,
    var float SET_TP_PRICE_1        =      input.price(defval=100.0, title= "TP_1",                            inline="PO1",   confirm = true,    group='Targets')
    var float SET_TP_PRICE_2        =      input.price(defval=110.0, title= "TP_2",                            inline="PO2",   confirm = true,    group='Targets')
    var float SET_TP_PRICE_3        =      input.price(defval=120.0, title= "TP_3",                            inline="PO3",   confirm = true,    group='Targets')
    var float SET_TP_PRICE_4        =      input.price(defval=130.0, title= "TP_4",                            inline="PO4",   confirm = true,    group='Targets')
    var float SET_TP_PRICE_5        =      input.price(defval=140.0, title= "TP_5",                            inline="PO5",   confirm = true,    group='Targets')
    var float SET_TP_LOT_1          =      input.float(defval=20.0, title= "TP_1 %",                           inline="PO1",                      group='Targets')/100
    var float SET_TP_LOT_2          =      input.float(defval=20.0, title= "TP_2 %",                           inline="PO2",                      group='Targets')/100
    var float SET_TP_LOT_3          =      input.float(defval=20.0, title= "TP_3 %",                           inline="PO3",                      group='Targets')/100
    var float SET_TP_LOT_4          =      input.float(defval=20.0, title= "TP_4 %",                           inline="PO4",                      group='Targets')/100
    var float SET_TP_LOT_5          =      input.float(defval=20.0, title= "TP_5 %",                           inline="PO5",                      group='Targets')/100

    var string pStr_fontsize        =     input.string(size.normal, title='Font-Size', options=[size.tiny, size.small, size.normal, size.large, size.huge],   group='common')
    var int pTextshift              =     input.int(70,"Text shifting",minval = 0,maxval = 100,              inline="PP1",                      group='common')
    var int pDecimals_price         =     input.int(2,"Decimals Price",minval = -3,maxval = 10,              inline="PP1",                      group='common')
    var int pDecimals_contracts     =     input.int(2,"Decimals Contracts",minval = -3,maxval = 10,          inline="PP2",                      group='common')
    var int pDecimals_percent       =     input.int(2,"Decimals Percent",minval = -3,maxval = 10,            inline="PP2",                      group='common')
//////////////////// Input and Switch of Colors ///////////////////////

// }

///////////////////// INPUTS of colors /////////////////// {
    matrix.set(M_Colors,0,0,          input.color(color.rgb(255, 153, 000, 40),         title= "LIQ D-T",                   inline="Liquidation",             group='Colors'))
    matrix.set(M_Colors,1,0,          input.color(color.rgb(255, 153, 000, 40),         title= "L-T",                       inline="Liquidation",             group='Colors'))
    matrix.set(M_Colors,0,2,          input.color(color.rgb(255, 082, 082, 40),         title= " SL D-T",                   inline="Stoploss",                group='Colors'))
    matrix.set(M_Colors,1,2,          input.color(color.rgb(255, 082, 082, 40),         title= "L-T",                       inline="Stoploss",                group='Colors'))
    matrix.set(M_Colors,0,4,          input.color(color.rgb(255, 255, 255, 60),         title= " Box D-T",                  inline="Entrybox",                group='Colors'))
    matrix.set(M_Colors,1,4,          input.color(color.rgb(000, 000, 000, 60),         title= "L-T",                       inline="Entrybox",                group='Colors'))
    matrix.set(M_Colors,0,6,          input.color(color.rgb(255, 255, 255, 40),         title= " TP D-T",                   inline="TPs",                     group='Colors'))
    matrix.set(M_Colors,1,6,          input.color(color.rgb(054, 058, 069, 40),         title= "L-T",                       inline="TPs",                     group='Colors'))
    matrix.set(M_Colors,0,8,          input.color(color.rgb(255, 255, 255, 33),         title= " Text D-T",                 inline="Text",                    group='Colors'))
    matrix.set(M_Colors,1,8,          input.color(color.rgb(000, 000, 000, 33),         title= "L-T",                       inline="Text",                    group='Colors'))
    matrix.set(M_Colors,0,1,          input.color(color.rgb(255, 153, 000, 40),         title= "LIQ draftline D-T",         inline="Liquidation-helper",      group='Colors'))
    matrix.set(M_Colors,1,1,          input.color(color.rgb(255, 153, 000, 40),         title= "L-T",                       inline="Liquidation-helper",      group='Colors'))
    matrix.set(M_Colors,0,3,          input.color(color.rgb(255, 082, 082, 40),         title= " SL draftline D-T",         inline="Stoploss-helper",         group='Colors'))
    matrix.set(M_Colors,1,3,          input.color(color.rgb(255, 082, 082, 40),         title= "L-T",                       inline="Stoploss-helper",         group='Colors'))
    matrix.set(M_Colors,0,5,          input.color(color.rgb(035, 116, 071, 40),         title= " Box draftline D-T",        inline="Entrybox-helper",         group='Colors'))
    matrix.set(M_Colors,1,5,          input.color(color.rgb(120, 134, 123, 40),         title= "L-T",                       inline="Entrybox-helper",         group='Colors'))
    matrix.set(M_Colors,0,7,          input.color(color.rgb(255, 255, 255, 50),         title= " TP draftline D-T",         inline="TPs-helper",              group='Colors'))
    matrix.set(M_Colors,1,7,          input.color(color.rgb(054, 058, 069, 50),         title= "L-T",                       inline="TPs-helper",              group='Colors'))
//color Wotan
    matrix.set(M_Colors,2,0,          color.rgb(144, 026, 026, 00))
    matrix.set(M_Colors,2,2,          color.rgb(255, 120, 093, 40))
    matrix.set(M_Colors,2,4,          color.rgb(255, 161, 094, 72))
    matrix.set(M_Colors,2,6,          color.rgb(000, 151, 065, 40))
    matrix.set(M_Colors,2,8,          color.rgb(000, 192, 192, 00))
    matrix.set(M_Colors,2,1,          color.rgb(255, 179, 000, 60))
    matrix.set(M_Colors,2,3,          color.rgb(251, 075, 075, 60))
    matrix.set(M_Colors,2,5,          color.rgb(000, 086, 009, 60))
    matrix.set(M_Colors,2,7,          color.rgb(255, 255, 255, 50))
//color Lindener
    matrix.set(M_Colors,3,0,          color.rgb(255, 136, 000, 00))
    matrix.set(M_Colors,3,2,          color.rgb(237, 047, 047, 40))
    matrix.set(M_Colors,3,4,          color.rgb(080, 183, 078, 50))
    matrix.set(M_Colors,3,6,          color.rgb(060, 065, 078, 33))
    matrix.set(M_Colors,3,8,          color.rgb(000, 000, 000, 00))
    matrix.set(M_Colors,3,1,          color.rgb(255, 179, 000, 40))
    matrix.set(M_Colors,3,3,          color.rgb(251, 075, 075, 40))
    matrix.set(M_Colors,3,5,          color.rgb(064, 149, 073, 13))
    matrix.set(M_Colors,3,7,          color.rgb(068, 071, 083, 50))
//color Matze
    matrix.set(M_Colors,4,0,          color.rgb(190, 021, 021, 00))
    matrix.set(M_Colors,4,2,          color.rgb(234, 040, 040, 40))
    matrix.set(M_Colors,4,4,          color.rgb(018, 111, 205, 90))
    matrix.set(M_Colors,4,6,          color.rgb(000, 237, 103, 00))
    matrix.set(M_Colors,4,8,          color.rgb(255, 255, 255, 00))
    matrix.set(M_Colors,4,1,          color.rgb(255, 000, 166, 00))
    matrix.set(M_Colors,4,3,          color.rgb(255, 015, 015, 00))
    matrix.set(M_Colors,4,5,          color.rgb(064, 121, 255, 00))
    matrix.set(M_Colors,4,7,          color.rgb(255, 255, 255, 00))

//color Dark Light compatible
    matrix.set(M_Colors,5,0,          color.rgb(144, 026, 026, 20))
    matrix.set(M_Colors,5,2,          color.rgb(255, 120, 093, 20))
    matrix.set(M_Colors,5,4,          color.rgb(255, 161, 094, 80))
    matrix.set(M_Colors,5,6,          color.rgb(000, 151, 065, 20))
    matrix.set(M_Colors,5,8,          color.rgb(000, 192, 192, 20))
    matrix.set(M_Colors,5,1,          color.rgb(255, 179, 000, 20))
    matrix.set(M_Colors,5,3,          color.rgb(251, 075, 075, 20))
    matrix.set(M_Colors,5,5,          color.rgb(000, 086, 009, 20))
    matrix.set(M_Colors,5,7,          color.rgb(180, 180, 180, 20))


//select colorset
    var A_Colors = matrix.row(M_Colors,colortheme)
/////////////////////  }

// fill a single position with manual Data from Inputs{
    myParameters := POS_CON.t_drawing_parameters.new(ShowPos = p_showPos, ShowLIQ = p_showLIQ, A_Colors = A_Colors, Prolong_lines = p_prolong_lines, Str_fontsize = pStr_fontsize, Textshift = pTextshift, Decimals_contracts = pDecimals_contracts, Decimals_price = pDecimals_price, Decimals_percent = pDecimals_percent, bartime = bartime)

    var TP_Variant_type = POS_CON.t_TP_Variant.new(TP_Type = "Direct", TP_Parameter_1 = 0, TP_Parameter_2 = 0, TP_Parameter_3 = 0, TP_Parameter_4 = 0)

    var TPs_array1 = array.new<POS_CON.t_TPs>(1, POS_CON.t_TPs.new(TP_Price = SET_TP_PRICE_1, TP_Lot = SET_TP_LOT_1, TP_Variant = TP_Variant_type, TP_Active = true))   
    var TPs_array2 = array.new<POS_CON.t_TPs>(1, POS_CON.t_TPs.new(TP_Price = SET_TP_PRICE_2, TP_Lot = SET_TP_LOT_2, TP_Variant = TP_Variant_type, TP_Active = true))   
    var TPs_array3 = array.new<POS_CON.t_TPs>(1, POS_CON.t_TPs.new(TP_Price = SET_TP_PRICE_3, TP_Lot = SET_TP_LOT_3, TP_Variant = TP_Variant_type, TP_Active = true))   
    var TPs_array4 = array.new<POS_CON.t_TPs>(1, POS_CON.t_TPs.new(TP_Price = SET_TP_PRICE_4, TP_Lot = SET_TP_LOT_4, TP_Variant = TP_Variant_type, TP_Active = true))   
    var TPs_array5 = array.new<POS_CON.t_TPs>(1, POS_CON.t_TPs.new(TP_Price = SET_TP_PRICE_5, TP_Lot = SET_TP_LOT_5, TP_Variant = TP_Variant_type, TP_Active = true))   

    var TPs_array_all = array.concat(TPs_array1,array.concat(TPs_array2,array.concat(TPs_array3,array.concat(TPs_array4,TPs_array5))))

    var SLs_array1 =  array.new<POS_CON.t_SLs>(1,POS_CON.t_SLs.new(SL_Price = SET_SL_PRICE, SL_Lot = na, SL_Active = na))
    var SLs_array_all = SLs_array1

    myPosition.unshift(
     POS_CON.t_Position_type.new(Lot = SET_Lot, Leverage = SET_Leverage, Maintenance= SET_Maintenance, Starttime = SET_Starttime, Entry_Start = SET_Entry_Start, Stoptime = SET_Stoptime, Entry_Stop = SET_Entry_Stop, Entryprice = (SET_Entry_Start+SET_Entry_Stop)/2,
      TPs = TPs_array_all,
      SLs = SLs_array_all))

//Bitblockart Release
// Inputs for alarm texts

tooltip_variables = '{{close}}:\n Replaced with the current closing price.\n\n
 {{open}}\n Replaced with the current opening price.\n\n
 {{high}}\n Replaced with the current highest price.\n\n
 {{low}}\n Replaced with the current lowest price.\n\n
 {{close}}\n Replaced with the current close price.\n\n
 {{timestamp}}\n Replaced with the current timestamp in the format "From":"YYYY:MM:DDTHH:MM:SS000000Z".\n\n
 {{tp_number}}\n Replaced with the current take profit number.\n\n
 {{username}}\n Replaced with the current username.\n\n
 {{direction}}\n Replaced with the trade direction: "1" for long, "-1" for short.\n\n
 {{ticker}}\n Replaced with the current ticker symbol.\n\n
 {{exchange}}\n Replaced with the current exchange prefix.'

var bool table_active = input.bool(false, title='Table active',  group='Table')
var string table_size = input.string(size.normal, title='Table size', options=[size.tiny, size.small, size.normal, size.large, size.huge],   group='Table')
var string table_loc = input.string(position.top_right, title='Table location', options=[position.top_right,position.top_center,position.middle_left,position.middle_center,position.middle_right,position.bottom_left,position.bottom_center],   group='Table')

// // Inputs for alarm texts
var string entry_box_alert_text = input.string("Entry order filled: @ {{close}}", title="Entry Box Alert Text", group="Alert Texts")
var string exit_box_alert_text = input.string("Complete order filled: @ {{close}}", title="Exit Box Alert Text", group="Alert Texts")
var string sl_alert_text = input.string("Price hit the Stop Loss: @ {{close}}", title="Stop Loss Alert Text", group="Alert Texts")
var string tp_alert_text = input.string("Price hit TP{{tp_number}}: @ {{close}}", title="Take Profit Alert Text", group="Alert Texts")
var string username = input.string("", title="username/apikey", group="Alert Texts")

// }

// Live view and alerts
// Extract data from myPosition {
var float entry_start = na
var float entry_stop = na

var float entry_start_time = na
var float entry_stop_time = na
var float sl_price = na
var float[] tp_prices = array.new_float(5,na)

// Blockers for alerts
var bool trade_active = false
var bool entry_box_alert_filled = false
var bool sl_alert_triggered = false
var bool[] tp_alert_triggered = array.new_bool(5,false)
var bool trade_short = false
var bool trade_long = false

if barstate.isfirst
    sl_price :=  myPosition.get(0).SLs.get(0).SL_Price
    if array.size(myPosition) > 0 and not trade_active
        entry_start_time := myPosition.get(0).Starttime
        entry_stop_time := myPosition.get(0).Stoptime
        entry_start := myPosition.get(0).Entry_Start
        entry_stop := myPosition.get(0).Entry_Stop
        sl_price := array.size(myPosition.get(0).SLs) > 0 ? myPosition.get(0).SLs.get(0).SL_Price : na
        for i = 0 to array.size(myPosition.get(0).TPs) - 1
            array.set(tp_prices, i, myPosition.get(0).TPs.get(i).TP_Price)

// }

// Initialize the table

// Functions

// Function to update the table {
var table strategyTable = table.new(table_loc, 5, 7, border_color=color.gray, frame_color=color.black, frame_width=1, border_width=1)
f_update_table() =>
    var int row = 0
    var string direction =na
    var string entry_range = na
    var string sl = na
    var string status = na

    table.cell(strategyTable, 0, 1, "Status", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 0, 2, "Direction", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 0, 3, "Entrys", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 0, 4, "SL", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 1, 0, "Position", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 2, 0, "TPs", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)
    table.cell(strategyTable, 3, 0, "Status", text_halign=text.align_center, bgcolor=color.gray, text_size = table_size)

    direction := trade_long ? "Long" : trade_short ? "Short" : "N/A"
    entry_range := str.tostring(entry_start,format.mintick) + " to " + str.tostring(entry_stop,format.mintick)
    sl := na(sl_price) ? "N/A" : str.tostring(sl_price,format.mintick)
    status := sl_alert_triggered? "SL" : entry_box_alert_filled ? "filled" : trade_active ? "Active" : "Inactive"
    
    table.cell(strategyTable, 1, 1, status, text_halign=text.align_center, bgcolor=sl_alert_triggered? color.red : entry_box_alert_filled ? color.rgb(76, 175, 79, 25) : trade_active ? color.rgb(76, 175, 79, 25) : color.rgb(33, 149, 243, 25), text_size = table_size)
    table.cell(strategyTable, 1, 2, direction, text_halign=text.align_center, bgcolor=direction == "Long" ? color.rgb(76, 175, 79, 25) : color.rgb(255, 82, 82, 25) , text_size = table_size)
    table.cell(strategyTable, 1, 3, entry_range, text_halign=text.align_center, text_size = table_size)
    table.cell(strategyTable, 1, 4, sl, text_halign=text.align_center, text_size = table_size)
    
    // Add individual TPs
    row := 0
    for i = 0 to array.size(tp_prices) - 1
        row += 1
        var string tp_status = ""
        tp_status := array.get(tp_alert_triggered, i) == true ? "filled" : "pending"
        table.cell(strategyTable, 2, row, "TP" + str.tostring(i + 1) + ": " + str.tostring(array.get(tp_prices, i),format.mintick), text_halign=text.align_center, bgcolor = tp_status == "filled" ? color.rgb(76, 175, 79, 25):na, text_size = table_size)
        table.cell(strategyTable, 3, row, tp_status, text_halign=text.align_center, bgcolor = tp_status == "filled" ? color.rgb(76, 175, 79, 25):na, text_size = table_size)


// Replace placeholders in alert templates
f_replace_placeholders(string _template, int tp_number = na) =>
    var string template = str.replace_all(_template, "{{close}}", str.tostring(close))
    template := str.replace_all(template, "{{open}}", str.tostring(open))
    template := str.replace_all(template, "{{high}}", str.tostring(high))
    template := str.replace_all(template, "{{low}}", str.tostring(low))
    template := str.replace_all(template, "{{timestamp}}", str.tostring(year)    + ':' + str.tostring(month) + ':' + str.tostring(dayofmonth) + 'T' + str.tostring(hour) + ':' + str.tostring(minute) + ':' + str.tostring(second) + '000000Z')
    template := str.replace_all(template, "{{tp_number}}", str.tostring(tp_number))
    template := str.replace_all(template, "{{username}}", str.tostring(username))
    template := str.replace_all(template, "{{direction}}", trade_long == true ? "1" : trade_short == true ? "-1" : "0")
    template := str.replace_all(template, "{{ticker}}", str.tostring(syminfo.ticker))
    template := str.replace_all(template, "{{exchange}}", str.tostring(syminfo.prefix))
    template
// }

///////////////////// Runtime / Alerts //////////////////////// {

// Runtime
if (barstate.isrealtime or barstate.islast) and myPosition.size() > 0
    STDP.clear_all()

    POS_CON.f_drawposition(_Position = myPosition, _Parameters = myParameters, _Position_index = 0)

if not trade_short and not trade_long 
    if sl_price < math.min(entry_start, entry_stop)
        trade_long := true
    if sl_price > math.max(entry_start, entry_stop)
        trade_short := true

// Alert for Entry Box
if not na(entry_start) and not na(entry_stop) and not sl_alert_triggered and (time > entry_start_time and time < entry_stop_time)
    if low <= math.max(entry_start, entry_stop) and not trade_active and trade_long
        alert(f_replace_placeholders(entry_box_alert_text), alert.freq_once_per_bar)
        trade_active := true
    else if high >= math.min(entry_start, entry_stop) and not trade_active and trade_short
        alert(f_replace_placeholders(entry_box_alert_text), alert.freq_once_per_bar)
        trade_active := true

if not na(entry_start) and not na(entry_stop) and not sl_alert_triggered and (time > entry_start_time) and trade_active

    // Alert for Exiting the Entry Box (Fully Filled)
    if not sl_alert_triggered and not entry_box_alert_filled
        if (    trade_short and (   close >= math.max(entry_start, entry_stop) or high >= math.max(entry_start, entry_stop)    )   ) or 
         (  trade_long and (    low <= math.min(entry_start, entry_stop) or close <= math.min(entry_start, entry_stop)  ) )
            alert(f_replace_placeholders(exit_box_alert_text), alert.freq_once_per_bar)
            entry_box_alert_filled := true
    
    // Alert for Stop Loss
    if not na(sl_price)
        if (    (trade_short and (high >= sl_price or close >= sl_price)    ) or (  trade_long and (low <= sl_price or close <= sl_price) )    ) and not sl_alert_triggered
            alert(f_replace_placeholders(sl_alert_text), alert.freq_once_per_bar)
            sl_alert_triggered := true
    
    // Alert for Take Profits
    if not sl_alert_triggered
        for i = 0 to array.size(tp_prices) - 1
            if array.get(tp_alert_triggered, i) == false
                temp_tp = array.get(tp_prices, i)
                if (trade_short and (close <= temp_tp or low <= temp_tp   )) or (trade_long and (close >= temp_tp    or  high >= temp_tp))
                    alert(f_replace_placeholders(tp_alert_text, i+1), alert.freq_once_per_bar)
                    array.set(tp_alert_triggered, i, true)

    //log.info(str.tostring(tp_alert_triggered))

// Update the table
if table_active
    f_update_table()

// }

Overview

MAD Position Starter & Calculator draws an interactive entry box defined by time and price boundaries, up to five take-profit levels with percentage allocations, a stop-loss level, and an estimated liquidation threshold based on leverage and margin inputs. Settings allow users to adjust contract size, leverage, take-profit distributions, color themes, and visual text formatting.

Details

Published by

regalouisei on GitHub

Code credit

djmad, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Support & resistance

Markets

Crypto

Timeframes

Any timeframe

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
Colorthemeint5colortheme
Extend lines to the leftboolfalsep_prolong_lines
Show contractsboolfalsep_showPos
Show liquidationboolfalsep_showLIQ
SLprice100SET_SL_PRICE
Entry - Left limittimetimestamp("2020-02-19")SET_Starttime
Entry_Boxbeginprice100SET_Entry_Start
Entry - Right limittimetimestamp("2020-02-19")SET_Stoptime
Entry_Boxstopprice100SET_Entry_Stop
Contractsfloat1SET_Lot
Leveragefloat20SET_Leverage
max. margin %float50max. margin %
Show all 40 settings
SettingTypeDefaultVariable
TP_1price100.0SET_TP_PRICE_1
TP_2price110.0SET_TP_PRICE_2
TP_3price120.0SET_TP_PRICE_3
TP_4price130.0SET_TP_PRICE_4
TP_5price140.0SET_TP_PRICE_5
TP_1 %float20.0SET_TP_LOT_1
TP_2 %float20.0SET_TP_LOT_2
TP_3 %float20.0SET_TP_LOT_3
TP_4 %float20.0SET_TP_LOT_4
TP_5 %float20.0SET_TP_LOT_5
Font-Sizestringsize.normalpStr_fontsize
Text shiftingint70pTextshift
Decimals Priceint2pDecimals_price
Decimals Contractsint2pDecimals_contracts
Decimals Percentint2pDecimals_percent
LIQ D-Tcolorcolor.rgb(255, 153, 000, 40)LIQ D-T
L-Tcolorcolor.rgb(255, 153, 000, 40)L-T
SL D-Tcolorcolor.rgb(255, 082, 082, 40) SL D-T
L-Tcolorcolor.rgb(255, 082, 082, 40)L-T
Box D-Tcolorcolor.rgb(255, 255, 255, 60) Box D-T
L-Tcolorcolor.rgb(000, 000, 000, 60)L-T
TP D-Tcolorcolor.rgb(255, 255, 255, 40) TP D-T
L-Tcolorcolor.rgb(054, 058, 069, 40)L-T
Text D-Tcolorcolor.rgb(255, 255, 255, 33) Text D-T
L-Tcolorcolor.rgb(000, 000, 000, 33)L-T
LIQ draftline D-Tcolorcolor.rgb(255, 153, 000, 40)LIQ draftline D-T
L-Tcolorcolor.rgb(255, 153, 000, 40)L-T
SL draftline D-Tcolorcolor.rgb(255, 082, 082, 40) SL draftline D-T
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

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers