PA Trading v1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ortakyer

//@version=4
study("PA Trading v1",overlay=true) 
fark = time-time[1]
offset = input(26, title="Çizgi Uzunlukları")

//Günlük, haftalık ve aylık zaman dilimlerinden bilgi çekemi
[gZaman,gAcilis] = security(syminfo.tickerid, "D", [time,open])
[hZaman,hAcilis] = security(syminfo.tickerid, "W", [time,open])
[aZaman,aAcilis,aEnYuksek,aEnDusuk] = security(syminfo.tickerid, "M", [time,open,high,low])
[hZamanOnceki,hAcilisOnceki] = security(syminfo.tickerid, "W", [time[1],open[1]])
[aZamanOnceki,aAcilisOnceki,aEnYuksekOnceki,aEnDusukOnceki] = security(syminfo.tickerid, "M", [time[1],open[1],high[1],low[1]])
var market_open_day_of_week = input(title="Açılış Günü Seçin", type=input.string, options=["Monday"], defval="Monday") // Some exchanges open sunday evening vs crypto std monday

monday_open_time = security(syminfo.tickerid, "D", time("D"), lookahead = barmerge.lookahead_on)
monday_high = security(syminfo.tickerid, "D", high, lookahead = barmerge.lookahead_on)
monday_low = security(syminfo.tickerid, "D", low, lookahead = barmerge.lookahead_on)
monday_midpoint = avg(monday_high, monday_low)
monday = input(#007FFF, "Monday", type = input.color, group = "Çizgi Renkleri", inline="a")

is_monday() => dayofweek(time("D")) == (market_open_day_of_week == "Sunday" ? dayofweek.sunday : dayofweek.monday) and close ? true : false

var can_show_monday_range = not timeframe.isweekly and not timeframe.ismonthly and not timeframe.isseconds // dont show above daily or below minutes

// Calculate the bars until the end of the week
// timeframe.multiplier is either daily or minutes
bars_until_end_of_week = if timeframe.isdaily
    7
else 
    (1440 / timeframe.multiplier) * 7 // (mins in  day / multiplier) * days in a week

line_end_right = monday_open_time + (time - time[1]) * bars_until_end_of_week // try and extend line until the end of the week

if is_monday()
    // Monday high
    monday_high_text = "Monday High    "
    var monday_high_line = line.new(x1 = monday_open_time, x2 = line_end_right, y1 = monday_high, y2 = monday_high, color = monday, width = 1, xloc = xloc.bar_time)
    var monday_high_label = label.new(x = line_end_right, y = monday_open_time, text = monday_high_text, style=label.style_label_left,color=color.new(color.black,100), textcolor = monday, size = size.small, xloc = xloc.bar_time)

    line.set_x1(monday_high_line, monday_open_time)
    line.set_x2(monday_high_line, line_end_right)
    line.set_y1(monday_high_line, monday_high)
    line.set_y2(monday_high_line, monday_high)
    label.set_x(monday_high_label, line_end_right)
    label.set_y(monday_high_label, monday_high)

    // Monday low
    monday_low_text = "Monday Low    "
    var monday_low_line = line.new(x1 = monday_open_time, x2 = line_end_right, y1 = monday_low, y2 = monday_low, color = monday, width = 1, xloc = xloc.bar_time)
    var monday_low_label = label.new(x = line_end_right, y = monday_open_time, text = monday_low_text, style=label.style_label_left,color=color.new(color.black,100), textcolor = monday, size = size.small, xloc = xloc.bar_time)

    line.set_x1(monday_low_line, monday_open_time)
    line.set_x2(monday_low_line, line_end_right)
    line.set_y1(monday_low_line, monday_low)
    line.set_y2(monday_low_line, monday_low)
    label.set_x(monday_low_label, line_end_right)
    label.set_y(monday_low_label, monday_low)

//Günlük açılış
gunlukCizgiRengi= input(color.orange, group = "Çizgi Renkleri", inline="a", title="DO")
gunlukCizgiUzunlugu = input(defval = 1,             title="DO",         group = "Çizgi Kalınlıkları", tooltip="Çizgi Kalınlığı Giriniz",minval = 1,    maxval = 4)
gAcilisCizgi = line.new(gZaman, gAcilis,time+(offset*fark),gAcilis,xloc=xloc.bar_time,width=gunlukCizgiUzunlugu,color=gunlukCizgiRengi)
line.delete(gAcilisCizgi[1])


gAcilisEtiket = label.new(time+(offset*fark), gAcilis,xloc=xloc.bar_time,text="DO",textcolor=color.orange, tooltip=tostring(gAcilis),style=label.style_label_left,color=color.new(color.black,100))
label.delete(gAcilisEtiket[1])

//Haftalık açılış
haftalikCizgiRengi= input(color.orange, group = "Çizgi Renkleri",inline="a", title="WO")
haftalikCizgiUzunlugu = input(defval = 1, title="WO", group = "Çizgi Kalınlıkları" ,tooltip="Çizgi Kalınlığı Giriniz",minval = 1,    maxval = 4)
hAcilisCizgi = line.new(hZaman, hAcilis,time+(offset*fark),hAcilis,xloc=xloc.bar_time,width=haftalikCizgiUzunlugu,color=haftalikCizgiRengi)
line.delete(hAcilisCizgi[1])

ghaftalikCizgiRengi= input(color.blue, group = "Çizgi Renkleri",inline="b", title="PWO")
ghaftalikCizgiUzunlugu = input(defval = 1,             title="PWO",         group = "Çizgi Kalınlıkları",tooltip="Çizgi Kalınlığı Giriniz", minval = 1,    maxval = 4)
ghAcilisCizgi = line.new(hZamanOnceki, hAcilisOnceki,time+(offset*fark),hAcilisOnceki, xloc=xloc.bar_time, width=ghaftalikCizgiUzunlugu, color=ghaftalikCizgiRengi)
line.delete(ghAcilisCizgi[1])

hAcilisEtiket = label.new(time+(offset*fark), hAcilis,xloc=xloc.bar_time,text="WO",textcolor=color.orange,tooltip=tostring(hAcilis),style=label.style_label_left,color=color.new(color.black,100))
label.delete(hAcilisEtiket[1])

ghAcilisEtiket = label.new(time+(offset*fark), hAcilisOnceki,xloc=xloc.bar_time,text="PWO",textcolor=color.blue,tooltip=tostring(hAcilisOnceki),style=label.style_label_left,color=color.new(color.black,100))
label.delete(ghAcilisEtiket[1])

//Aylık açılış
aylikcizgirengi = input(color.orange, group = "Çizgi Renkleri",inline="a", title="MO")
aylikcizgiuzunlugu = input(defval = 1,             title="MO",         group = "Çizgi Kalınlıkları" , tooltip="Çizgi Kalınlığı Giriniz",minval = 1,    maxval = 4)
aAcilisCizgi = line.new(aZaman, aAcilis,time+(offset*fark),aAcilis,xloc=xloc.bar_time,width=aylikcizgiuzunlugu,color=aylikcizgirengi)
line.delete(aAcilisCizgi[1])

paylikCizgiRengi = input(color.blue, group = "Çizgi Renkleri",inline="b", title="PMO")
paylikCizgiUzunlugu = input(defval = 1,             title="PMO",         group = "Çizgi Kalınlıkları"  , tooltip="Çizgi Kalınlığı Giriniz",minval = 1,    maxval = 4)
gaAcilisCizgi = line.new(aZamanOnceki, aAcilisOnceki,time+(offset*fark),aAcilisOnceki,xloc=xloc.bar_time,width=paylikCizgiUzunlugu,color=paylikCizgiRengi)
line.delete(gaAcilisCizgi[1])

aAcilisEtiket = label.new(time+(offset*fark), aAcilis,xloc=xloc.bar_time,text="MO",textcolor=color.orange , tooltip=tostring(aAcilis),style=label.style_label_left,color=color.new(color.black,100))
label.delete(aAcilisEtiket[1])


gaAcilisEtiket =label.new(time+(offset*fark), aAcilisOnceki,xloc=xloc.bar_time,text="PMO",textcolor=color.blue , tooltip=tostring(aAcilisOnceki),style=label.style_label_left,color=color.new(color.black,100))
label.delete(gaAcilisEtiket[1])


