Indicator · Pine Script v4 · On the chart

Arty-W

by GreyssonEnterprises

A Pine v4 indicator that draws four smoothed moving averages (21, 50, 100 and 200) on the price chart, with a fill between a two-period EMA and the 200 average that turns green or red with trend.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code694
Settings31inputs
LicenceMIT
Last update2 months ago1 Aug 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

694 lines of Pine Script v4 from strategies/polish/documentation/artyW.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

artyW.pine
//@version=4
study(title="Arty-W", shorttitle="Arty-W", overlay=true, precision=8)

// ### Four Smoothed Moving Averages

len1 = 21
//input(21, minval=1, title="Length 1", group = "Smoothed MA Inputs")
src1 = close
//input(close, title="Source 1", group = "Smoothed MA Inputs")
smma1 = 0.0
sma_1 = sma(src1, len1)
smma1 := na(smma1[1]) ? sma_1 : (smma1[1] * (len1 - 1) + src1) / len1
plot(smma1, color=color.green, linewidth=2, title="21 SMMA")

len2 = 50
//input(50, minval=1, title="Length 2", group = "Smoothed MA Inputs")
src2 = close
//input(close, title="Source 2", group = "Smoothed MA Inputs")
smma2 = 0.0
sma_2 = sma(src2, len2)
smma2 := na(smma2[1]) ? sma_2 : (smma2[1] * (len2 - 1) + src2) / len2
plot(smma2, color=color.yellow, linewidth=2, title="50 SMMA")

h100 = input(title="Show 100 Line", type=input.bool, defval=false, group = "Smoothed MA Inputs")
len3 = 100
//input(100, minval=1, title="Length 3", group = "Smoothed MA Inputs")
src3 = close
//input(close, title="Source 3", group = "Smoothed MA Inputs")
smma3 = 0.0
sma_3 = sma(src3, len3)
smma3 := na(smma3[1]) ? sma_3 : (smma3[1] * (len3 - 1) + src3) / len3
sma3plot = plot(h100 ? smma3 : na, color=color.orange, linewidth=2, title="100 SMMA")

len4 = 200
//input(200, minval=1, title="Length 4", group = "Smoothed MA Inputs")
src4 = close
//input(close, title="Source 4", group = "Smoothed MA Inputs")
smma4 = 0.0
sma_4 = sma(src4, len4)
smma4 := na(smma4[1]) ? sma_4 : (smma4[1] * (len4 - 1) + src4) / len4
sma4plot = plot(smma4, color=color.red, linewidth=2, title="200 SMMA")

// Trend Fill

trendFill = input(title="Show Trend Fill", type=input.bool, defval=true, group = "Smoothed MA Inputs") 
ema2 = ema(close, 2)
ema2plot = plot(ema2, color=#2ecc71, transp=100, style=plot.style_line, linewidth=1, title="EMA(2)", editable = false)

fill(ema2plot, sma4plot, color=ema2 > smma4 and trendFill ? color.green : ema2 < smma4 and trendFill ? color.red : na, transp=85, title = "Trend Fill")

// End ###

src = input(title="Source", type=input.source, defval=close)
//option_potential = input(defval = false, title = "Show unconfirmed")

includePrice = true
strictPrice = input(defval=false, title="Strict Structure")
rangePrice = input(9, minval=5, title="Max. width of price W/M")  // e.g. allow an price W/M to form over 7 bars. 
offsetPrice = input(0, minval=0, title="Max. offset of price W/M")  // e.g. allow an price W/M to form 1 bar in history. Keep this number low. The goal is to synch the market structure over multiple indicators.


// limit by period option
limitPeriod = input(defval=true, title="Limit period (increases perfomance)")
lengthPeriod = input(240, minval=1, title="Length of period (hours)")

hours_in_milliseconds = 1000 * 60 * 60
withinPeriod = not limitPeriod or timenow - time < hours_in_milliseconds * lengthPeriod

//Find structure
series_a_above_series_b(seriesA, seriesB, aRange) =>
    result = true
    for i = 0 to aRange - 1 by 1
        if seriesB[i] > seriesA[i]
            result := false
            break
    result := result
    result

series_a_below_series_b(seriesA, seriesB, aRange) =>
    result = true
    for i = 0 to aRange - 1 by 1
        if seriesB[i] < seriesA[i]
            result := false
            break
    result := result
    result

dirmov(len) =>
    up = change(high)
    down = -change(low)
    truerange = rma(tr, len)
    plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, len) / truerange)
    minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, len) / truerange)
    [plus, minus]

data_W(aSeries, aRange, anOffset, strict) =>
    e = 0
    d = 0
    c = 0
    b = 0
    a = 0
    valueE = aSeries[0]
    valueD = aSeries[0]
    valueC = aSeries[0]
    valueB = aSeries[0]
    valueA = aSeries[0]
    found = false

    for offset = 0 to anOffset by 1
        if found
            break
        e := 0
        d := 0
        c := 0
        b := 0
        a := 0
        valueE := aSeries[0]
        valueC := aSeries[0]
        valueD := aSeries[0]
        valueB := aSeries[0]
        valueA := aSeries[0]

        for i = 1 to aRange - 1 by 1
            // find d
            if aSeries[i + offset] < aSeries[i + offset - 1] and valueC == aSeries[0]
                d := i + offset
                valueD := aSeries[i + offset]
                continue
            if d == 0
                break
            // find c
            if aSeries[i + offset] > aSeries[i + offset - 1] and valueB == aSeries[0]
                c := i + offset
                valueC := aSeries[i + offset]
                continue
            if c == 0
                break
            if aSeries[i + offset] < aSeries[i + offset - 1] and valueA == aSeries[0]
                b := i + offset
                valueB := aSeries[i + offset]
                continue
            if b == 0
                break
            if aSeries[i + offset] > aSeries[i + offset - 1]
                a := i + offset
                valueA := aSeries[i + offset]
                continue
            if a == 0
                break
        // W found if we have found point A, and point B has a lower value than point D                
        found := a > 0 and a != b and c != 0 and d != 0 and aSeries[e] > aSeries[c] and 
           aSeries[d] < aSeries[e] and aSeries[d] < aSeries[c] and 
           (aSeries[b] <= aSeries[d] or not strict) and aSeries[b] < aSeries[a]
        found
    entry = found ? aSeries[c] : na
    stopLoss = found ? aSeries[b] * ((100 - stopLossPercentage) / 100) : na
    target = found ? entry + (entry - stopLoss) * riskRewardRatio : na
    [found, entry, stopLoss, target, a, b, c, d, e]

data_M(aSeries, aRange, anOffset, strict) =>
    e = 0
    d = 0
    c = 0
    b = 0
    a = 0
    valueE = aSeries[0]
    valueD = aSeries[0]
    valueC = aSeries[0]
    valueB = aSeries[0]
    valueA = aSeries[0]
    found = false

    for offset = 0 to anOffset by 1
        if found
            break
        e := 0
        d := 0
        c := 0
        b := 0
        a := 0
        valueE := aSeries[0]
        valueC := aSeries[0]
        valueD := aSeries[0]
        valueB := aSeries[0]
        valueA := aSeries[0]

        for i = 1 to aRange - 1 by 1
            // find d
            if aSeries[i + offset] > aSeries[i + offset - 1] and valueC == aSeries[0]
                d := i + offset
                valueD := aSeries[i + offset]
                continue
            if d == 0
                break
            // find c
            if aSeries[i + offset] < aSeries[i + offset - 1] and valueB == aSeries[0]
                c := i + offset
                valueC := aSeries[i + offset]
                continue
            if c == 0
                break
            if aSeries[i + offset] > aSeries[i + offset - 1] and valueA == aSeries[0]
                b := i + offset
                valueB := aSeries[i + offset]
                continue
            if b == 0
                break
            if aSeries[i + offset] < aSeries[i + offset - 1]
                a := i + offset
                valueA := aSeries[i + offset]
                continue
            if a == 0
                break
        // M found if we have found point A, and point B has a greater value than point D                
        found := a > 0 and a != b and c != 0 and d != 0 and aSeries[e] < aSeries[c] and 
           aSeries[d] > aSeries[e] and aSeries[d] > aSeries[c] and 
           (aSeries[b] >= aSeries[d] or not strict) and aSeries[b] > aSeries[a]
        found
    entry = found ? aSeries[c] : na
    stopLoss = found ? aSeries[b] * ((100 + stopLossPercentage) / 100) : na
    target = found ? entry - (stopLoss - entry) * riskRewardRatio : na
    [found, entry, stopLoss, target, a, b, c, d, e]


find_W(aSeries, aRange, anOffset, strict) =>
    [found, entry, stopLoss, target, a, b, c, d, e] = data_W(aSeries, aRange, anOffset, strict)
    found

find_M(aSeries, aRange, anOffset, strict) =>
    [found, entry, stopLoss, target, a, b, c, d, e] = data_M(aSeries, aRange, anOffset, strict)
    found

[W_found, W_entry, W_stopLoss, W_target, W_pointA, W_pointB, W_pointC, W_pointD, W_pointE] = data_W(src, rangePrice, offsetPrice, strictPrice)
[M_found, M_entry, M_stopLoss, M_target, M_pointA, M_pointB, M_pointC, M_pointD, M_pointE] = data_M(src, rangePrice, offsetPrice, strictPrice)
priceW = includePrice == false or W_found
priceM = includePrice == false or M_found

// ### Trading Session

ts = input(title="Show Trade Session", type=input.bool, defval=true, group = "Trade Session")

tz = input(title="Timezone", type=input.string, defval="America/Chicago", options=["Asia/Sydney", "Asia/Tokyo", "Europe/Frankfurt", "Europe/London", "UTC", "America/New_York", "America/Chicago"], group = "Trade Session")
label = input(title="Label", type=input.string, defval="CME Open", tooltip="For easy identification", group = "Trade Session")

startHour = input(title="analysis Start hour", type=input.integer, defval=7, minval=0, maxval=23, group = "Trade Session")
startMinute = input(title="analysis Start minute", type=input.integer, defval=00, minval=0, maxval=59, group = "Trade Session")

startHour2 = input(title="Session Start hour", type=input.integer, defval=8, minval=0, maxval=23, group = "Trade Session")
startMinute2 = input(title="Session Start minute", type=input.integer, defval=30, minval=0, maxval=59, group = "Trade Session")
endHour2 = input(title="Session End hour", type=input.integer, defval=12, minval=0, maxval=23, group = "Trade Session")
endMinute2 = input(title="Session End minute", type=input.integer, defval=0, minval=0, maxval=59, group = "Trade Session")

rangeColor = input(title="Color", type=input.color, defval=#1976d21f, group = "Trade Session")
showMon = input(title="Monday", type=input.bool, defval=true, group = "Trade Session")
showTue = input(title="Tuesday", type=input.bool, defval=true, group = "Trade Session")
showWed = input(title="Wednesday", type=input.bool, defval=true, group = "Trade Session")
showThu = input(title="Thursday", type=input.bool, defval=true, group = "Trade Session")
showFri = input(title="Friday", type=input.bool, defval=true, group = "Trade Session")
showSat = input(title="Saturday", type=input.bool, defval=false, group = "Trade Session")
showSun = input(title="Sunday", type=input.bool, defval=false, group = "Trade Session")

tzYear = year(time, tz)
tzMonth = month(time, tz)
tzDay = dayofmonth(time, tz)
tzDayOfWeek = dayofweek(time, tz)
startTime = timestamp(tz, tzYear, tzMonth, tzDay, startHour, startMinute)
endTime = timestamp(tz, tzYear, tzMonth, tzDay, endHour2, endMinute2)

active = if startTime <= time and time <= endTime and ts
    if tzDayOfWeek == dayofweek.monday and showMon
        true
    else if tzDayOfWeek == dayofweek.tuesday and showTue
        true
    else if tzDayOfWeek == dayofweek.wednesday and showWed
        true
    else if tzDayOfWeek == dayofweek.thursday and showThu
        true
    else if tzDayOfWeek == dayofweek.friday and showFri
        true
    else if tzDayOfWeek == dayofweek.saturday and showSat
        true
    else if tzDayOfWeek == dayofweek.sunday and showSun
        true
    else
        false
else
    false

bgcolor(color=active ? rangeColor : na, title = "Session Background")


startTime2 = timestamp(tz, tzYear, tzMonth, tzDay, startHour2, startMinute2)
endTime2 = timestamp(tz, tzYear, tzMonth, tzDay, endHour2, endMinute2)

active2 = if startTime2 <= time and time <= endTime2 and ts
    if tzDayOfWeek == dayofweek.monday and showMon
        true
    else if tzDayOfWeek == dayofweek.tuesday and showTue
        true
    else if tzDayOfWeek == dayofweek.wednesday and showWed
        true
    else if tzDayOfWeek == dayofweek.thursday and showThu
        true
    else if tzDayOfWeek == dayofweek.friday and showFri
        true
    else if tzDayOfWeek == dayofweek.saturday and showSat
        true
    else if tzDayOfWeek == dayofweek.sunday and showSun
        true
    else
        false
else
    false
    
bgcolor(color=active2 ? rangeColor : na, title = "Session Background")

///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/// Bull and Bear signal definitions with plots and alerts
///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

BullLabel = "Bullish Signal"
BearLabel = "Bearish Signal"
BullSig = smma1 > smma2 and smma2 > smma4 and priceW[1] and not tradeactive
BearSig = smma1 < smma2 and smma2 < smma4 and priceM[1] and not tradeactive

barcolor( BullSig ? color.yellow : BearSig ? color.white :na)

plotshape(BullSig, title="BullSig", style=shape.triangleup, location=location.belowbar, color=color.lime, text=BullLabel)
plotshape(BearSig, title="BearSig", style=shape.triangledown, location=location.abovebar, color=color.red, text=BearLabel)

// alerts
alertcondition(BullSig, title='Bullish Signal Alert', message='{{ticker}} - BullSig')
alertcondition(BearSig, title='Bearish Signal Alert', message='{{ticker}} - BearSig')


// Variables for Trade Module
USDRiskPerTrade = input(defval=1, title="Fixed risk amount per trade in USD", type=input.integer) // Changing to $1 from $50
Leverage = input(1)
Min_Trade_Risk = 2*atr(14)
Max_Trade_Risk = 4*atr(14)
StatisticsVerticalOffset = 3*atr(14)
HideStatistics = input(false)
DisplayEquityCurve = input(false)
commission = input(title="Estimated commission per round-turn in USD", defval=0.2)
riskRewardRatio = input(defval=3.0, minval=0.0, title="Risk to Reward 1-to-")

///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/// Level definitions:
///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
tradeactive = false
tradeactive := nz(tradeactive[1])
 
 
    // STOP Level:
StopLevel = 0.00000
StopLevel := nz(StopLevel[1])
 
    // Entry Level:
EntryLevel = 0.00000
EntryLevel := nz(EntryLevel[1])
 
    // TP Level:
TPLevel = 0.00000
TPLevel := nz(TPLevel[1])
 
    // Breakeven Level:
BELevel = 0.00000
BELevel := nz(BELevel[1])
 
    // stopdistance
stopdistance = 0.00000
stopdistance := nz(stopdistance[1])
 
    // TradeSizeInXBT
TradeSizeInXBT = 0.00000
TradeSizeInXBT := nz(TradeSizeInXBT[1])
 
    // TradeSizeInUSD
TradeSizeInUSD = 0
TradeSizeInUSD := nz(TradeSizeInUSD[1])
 
    //PositionMarginXBT
PositionMarginXBT = 0.00000
PositionMarginXBT := nz(PositionMarginXBT[1])
 
    //MaxPosMarginXBT
MaxPosMarginXBT = 0.00000
MaxPosMarginXBT := nz(MaxPosMarginXBT[1])
 
// Long and Short trade definitions:
//=============================================================
Longtradeactive = false
Longtradeactive := Longtradeactive[1]
 
Shorttradeactive = false
Shorttradeactive := Shorttradeactive[1]

longCondition = not tradeactive and BullSig
shortCondition = not tradeactive and BearSig


// define plot settings for entry, stoploss and target
show_order_details = true
transparency = show_order_details ? 0 : 100
clr_entry = (longCondition or shortCondition) ? color.white : na
clr_stoploss = (longCondition or shortCondition) ? color.red : na
clr_target = (longCondition or shortCondition) ? color.lime : na
 

//============================================================
// Alerts for Trade opening
//============================================================
alertcondition(longCondition and not longCondition[1], title='Long', message='{{ticker}} LONG') // Original Code
alertcondition(shortCondition and not shortCondition[1], title='Short', message="{{ticker}} SHORT") // Original Code

//============================================================
//Plots for trade signal
//============================================================
 
Longtradetrigger = if (longCondition and not longCondition[1])
    StopLevel := min(low[1],low[2],low[3],low[4])-1
    EntryLevel := close[1]
    TPLevel := EntryLevel + (EntryLevel - StopLevel) * riskRewardRatio
    BELevel := (EntryLevel - StopLevel) + EntryLevel
    stopdistance := EntryLevel - StopLevel
    TradeSizeInXBT := USDRiskPerTrade / stopdistance
    TradeSizeInUSD := round(EntryLevel * TradeSizeInXBT)  //remove factor 1000 for live trading
    PositionMarginXBT := (round(100000 * TradeSizeInXBT / Leverage)) / 100000
    MaxPosMarginXBT := (round(100000 * USDRiskPerTrade / Min_Trade_Risk / Leverage)) / 100000
    tradeactive := true
    Longtradeactive := true

Shorttradetrigger = if (shortCondition and not shortCondition[1])
    StopLevel := max(high[1],high[2],high[3],high[4])+1
    EntryLevel := close[1]
    TPLevel := EntryLevel - (StopLevel - EntryLevel) * riskRewardRatio
    BELevel := EntryLevel - (StopLevel - EntryLevel)
    stopdistance := StopLevel - EntryLevel
    TradeSizeInXBT := USDRiskPerTrade / stopdistance
    TradeSizeInUSD := round(EntryLevel * TradeSizeInXBT)  //remove factor 1000 for live trading
    PositionMarginXBT := (round(100000 * TradeSizeInXBT / Leverage)) / 100000
    MaxPosMarginXBT := (round(100000 * USDRiskPerTrade / Min_Trade_Risk / Leverage)) / 100000
    tradeactive := true
    Shorttradeactive := true
 
// PLOT Triggers
plotshape(Longtradetrigger, title="GrimmHA long", style=shape.triangleup, location=location.belowbar, color=color.lime, text="LONG")
plotshape(Shorttradetrigger, title="GrimmHA short", style=shape.triangledown, location=location.abovebar, color=color.red, text="SHORT")
 

// Plot Levels:
pl1 = plot (StopLevel, title = "Stop", color=color.red)
pl2 = plot (EntryLevel, title = "Entry", color=color.white)
//pl3 = plot (BELevel, title = "BE", color=color.blue)
pl4 = plot (TPLevel, title = "TP", color=color.green)
 
fill(pl1, pl2, color=color.red)
//fill(pl2, pl3, color=color.blue, transp=65)
//fill(pl3, pl4, color=color.green, transp=65)
fill(pl2,pl4,color=color.green)
 
 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Define and plot conflicting candles:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   
// Subtypes of conflicting bars:
//-------------------------------------------------------------------------------------------------------
 
// Bartype 3a is a candle which crosses both BELevel and EntryLevel and has its close above the midline between BELevel and EntryLevel (longs)
// respecively has its close below the midline between BELevel and EntryLevel (shorts)
// In case of a Bartype 3a the logic shall NOT consider a trade as closed as break-even, but shall assume trade continuation with activated break-even-flag.
//-------------------------------------------------------------------------------------------------------
 
Bartype3_a_long = high > BELevel and high < TPLevel and low < EntryLevel and low > StopLevel and close > ((BELevel + EntryLevel)/2) and Longtradeactive
Bartype3_a_short = high > EntryLevel and high  < StopLevel and low < BELevel and low > TPLevel and close < ((BELevel + EntryLevel)/2) and Shorttradeactive
//barcolor(Bartype3_a_long or Bartype3_a_short? color.purple : na)
 
//Bartype3_a_Counter = 0    
//Bartype3_a_Counter := nz(Bartype3_a_Counter[1])
//if Bartype3_a_long or Bartype3_a_short
//    Bartype3_a_Counter := Bartype3_a_Counter + 1
 
// Bartype 4a is a candle which crosses TPLevel, BELevel and EntryLevel and has its close above BELevel (longs) respectively close below BELevel (shorts)
// In case of a Bartype 4a the logic shall consider a trade as closed winner and shall not assume trade as closed break-even.
//-------------------------------------------------------------------------------------------------------
 
Bartype4_a_long = high > TPLevel and low < EntryLevel and low > StopLevel and close > BELevel and Longtradeactive
Bartype4_a_short = high > EntryLevel and high < StopLevel and low < TPLevel and close < BELevel and Shorttradeactive
 
 
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Trade resolution:
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

// Target adjustment
//shorttpadjust = if((Shorttradeactive == true) and bullE)
//    y = 1

//if shorttpadjust == true
//    TPLevel := close-1

//longtpadjust = if((Longtradeactive == true) and bearE)
//    r = 1

//if longtpadjust == true
//    TPLevel := close+1

// Stop Adjustment

//shortstopleveladjust = if((Shorttradeactive == true) and (smma2 < StopLevel))
//    y = 1

//if shortstopleveladjust == true
//    StopLevel := smma2

//longstopleveladjust = if((Longtradeactive == true) and (smma2 > StopLevel))
//    r = 1

//if longstopleveladjust == true
//    StopLevel := smma2


// Breakeven activation
//-------------------------------------------------------------------------------------------------------
shorttradeBElevelactivation = (low < BELevel) and not (low < TPLevel)
longtradeBElevelactivation = (high > BELevel) and not (high> TPLevel)
 
Breakevenactive = false
Breakevenactive := nz(Breakevenactive[1])
 
if ((Shorttradeactive ==  true) and (shorttradeBElevelactivation == true))
    Breakevenactive := false
 
if ((Longtradeactive == true) and (longtradeBElevelactivation == true))
    Breakevenactive := false
   
// loss trades
//-------------------------------------------------------------------------------------------------------
 
PlotLossCounter = 0
LossShort = 0
LossLong = 0
 
PlotLossCounter := nz(PlotLossCounter[1])
LossShort := nz(LossShort[1])
LossLong := nz(LossLong[1])
 
plotlosshort = if ((Shorttradeactive == true) and (high > StopLevel) and (Breakevenactive == false))
    y = 1 // only required to make code work
 
plotchar(plotlosshort, char="X", location=location.abovebar, color=color.red, transp=0, offset=0, size=size.small)
 
if plotlosshort == true
    tradeactive := false
    Shorttradeactive := false
    Breakevenactive := false
    PlotLossCounter := PlotLossCounter + 1
    LossShort := LossShort +1
 
   
//plotlosshort := false
 
plotlosslong = if ((Longtradeactive == true) and (low < StopLevel) and (Breakevenactive == false))
    r = 1 // only required to make code work
   
plotchar(plotlosslong, char="X", location=location.belowbar, color=color.red, transp=0, offset=0, size=size.small)
 
if plotlosslong == true
    tradeactive := false
    Longtradeactive := false
    Breakevenactive := false
    PlotLossCounter := PlotLossCounter + 1
    LossLong := LossLong + 1
   
//plotlosslong := false
 
// Breakeven trades
//-------------------------------------------------------------------------------------------------------
 
PlotBreakEvenCounter = 0
PlotBreakEvenCounter := nz(PlotBreakEvenCounter[1])
BELong = 0
BELong := nz(BELong[1])
BEShort = 0
BEShort := nz(BEShort[1])
 
plotBreakevenshort = if ((Shorttradeactive ==  true) and (high > EntryLevel) and (Breakevenactive == true) and not Bartype3_a_short and not Bartype4_a_short)
    h = 1 // only required to make code work
   
plotchar(plotBreakevenshort, char="0", location=location.abovebar, color=color.blue, transp=0, offset=0, size=size.small)
 
if plotBreakevenshort == true
    tradeactive := false
    Shorttradeactive := false
    Breakevenactive := false
    PlotBreakEvenCounter := PlotBreakEvenCounter + 1
    BEShort := BEShort +1
 
//plotBreakevenshort := false
 
plotBreakevenlong = if ((Longtradeactive ==  true) and (low < EntryLevel) and (Breakevenactive == true) and not Bartype3_a_long and not Bartype4_a_long)
    e = 1 // only required to make code work
   
plotchar(plotBreakevenlong, char="0", location=location.belowbar, color=color.blue, transp=0, offset=0, size=size.small)
 
if plotBreakevenlong == true
    tradeactive := false
    Longtradeactive := false
    Breakevenactive := false
    PlotBreakEvenCounter := PlotBreakEvenCounter + 1
    BELong := BELong +1
   
//plotBreakevenlong := false
 
// Win trades
//-------------------------------------------------------------------------------------------------------
PlotWinCounter = 0
PlotWinCounter := nz(PlotWinCounter[1])
WinLong = 0
WinLong := nz(WinLong[1])
WinShort = 0
WinShort := nz(WinShort[1])
 
plotWinshort = if ((Shorttradeactive ==  true) and (low < TPLevel))
    n = 1  // only required to make code work
 
plotchar(plotWinshort, char="✓", location=location.belowbar, color=color.green, transp=0, offset=0, size=size.small)
 
if plotWinshort == true
    tradeactive := false
    Shorttradeactive := false
    Breakevenactive := false
    PlotWinCounter := PlotWinCounter + 1
    WinShort := WinShort +1
   
//plotWinshort := false
 
plotWinlong = if ((Longtradeactive ==  true) and (high > TPLevel))
    l = 1 // only required to make code work
 
plotchar(plotWinlong, char="✓", location=location.abovebar, color=color.green, transp=0, offset=0, size=size.small)
 
if plotWinlong == true
    tradeactive := false
    Longtradeactive := false
    Breakevenactive := false
    PlotWinCounter := PlotWinCounter + 1
    WinLong := WinLong +1
   
//plotWinlong := false
 
 
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Trade closing signals
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
// c=position e=bitmex-testnet t=market ro=1
// Original Code Below
// alertcondition(plotlosshort or plotlosslong or plotBreakevenshort or plotBreakevenlong, title='Lemon Close Trade BE or Stop', message='Lemon Close at BE or Stop')
// alertcondition(plotWinshort or plotWinlong, title='Lemon Close Trade Win', message='Lemon Win')
 
alertcondition(plotlosshort or plotlosslong or plotBreakevenshort or plotBreakevenlong, title='Lemon Close Trade BE or Stop', message="{{ticker}} Close")
alertcondition(plotWinshort or plotWinlong, title='Lemon Close Trade Win', message="{{ticker}} Take Profit")
 
EquityCurve = PlotWinCounter * 2 * USDRiskPerTrade - PlotLossCounter * USDRiskPerTrade - (PlotWinCounter + PlotLossCounter + PlotBreakEvenCounter) * commission
 
 
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Statistics
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
//if (plotWinlong or plotWinshort or plotBreakevenlong or plotBreakevenshort or plotlosslong or plotlosshort) and not HideStatistics
//    l = label.new(bar_index, high + StatisticsVerticalOffset, style=label.style_none, text="Win : " + tostring(PlotWinCounter)
//      + "\nLoss : " + tostring(PlotLossCounter) + "\nBE : " + tostring(PlotBreakEvenCounter),color = color.white, textcolor=color.white)
 
winpercent = round((PlotWinCounter/(PlotWinCounter+PlotLossCounter+PlotBreakEvenCounter)*100))
losspercent = round((PlotLossCounter/(PlotWinCounter+PlotLossCounter+PlotBreakEvenCounter)*100))
bepercent = round((PlotBreakEvenCounter/(PlotWinCounter+PlotLossCounter+PlotBreakEvenCounter)*100))
rrpercent = round((PlotWinCounter/(PlotWinCounter+PlotLossCounter))*100)
 
//if (plotWinlong or plotWinshort or plotBreakevenlong or plotBreakevenshort or plotlosslong or plotlosshort) and not HideStatistics
//    l = label.new(bar_index, high + StatisticsVerticalOffset, style=label.style_none, text="Win : " + tostring(PlotWinCounter) + " ("+ tostring(winpercent)+")% Long: " +tostring(WinLong) +" Short: "+ tostring(WinShort)
//      + "\nLoss : " + tostring(PlotLossCounter) +" ("+tostring(losspercent)+")%"+" Long: "+tostring(LossLong)+" Short: "+tostring(LossShort)+"\nBE : " + tostring(PlotBreakEvenCounter)+" ("+ tostring(bepercent)+")% Long: "+tostring(BELong)+" Short: "+tostring(BEShort),color = color.white, textcolor=color.white)

if (plotWinlong or plotWinshort or plotBreakevenlong or plotBreakevenshort or plotlosslong or plotlosshort) and not HideStatistics
    l = label.new(bar_index, high + StatisticsVerticalOffset, style=label.style_none, text="Win : " + tostring(PlotWinCounter) + " ("+ tostring(winpercent)+"%)"
      + "\nLoss : " + tostring(PlotLossCounter) +" ("+tostring(losspercent)+"%)" + "\nBE : " + tostring(PlotBreakEvenCounter)+" ("+ tostring(bepercent)+"%)" + "\nRate : " + tostring (rrpercent)+"%)",color = color.white, textcolor=color.white)
      

// The following line is in order to print the equity curve:
//-------------------------------------------------------------------------------------------------------
 
plot (DisplayEquityCurve == true ? EquityCurve : na, title = "Profit and Loss", color=color.yellow, linewidth=3, style=plot.style_line)

Overview

Arty-W also looks for W and M price shapes with adjustable width and offset, and can shade a time-zone trading session. A period limit and fixed risk, commission and statistics inputs are included. Pattern rules are only partly visible.

Details

Published by

GreyssonEnterprises on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Moving averages, Trend, Sessions & time

Markets

Any symbol

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
Show 100 Lineboolfalseh100
Show Trend FillbooltruetrendFill
Sourcesourceclosesrc
Strict StructureboolfalsestrictPrice
Max. width of price W/Mint9rangePrice
Max. offset of price W/Mint0offsetPrice
Limit period (increases perfomance)booltruelimitPeriod
Length of period (hours)int240lengthPeriod
Show Trade Sessionbooltruets
TimezonestringAmerica/Chicagotz
LabelstringCME Openlabel
analysis Start hourint7startHour
Show all 31 settings
SettingTypeDefaultVariable
analysis Start minuteint00startMinute
Session Start hourint8startHour2
Session Start minuteint30startMinute2
Session End hourint12endHour2
Session End minuteint0endMinute2
Colorcolor#1976d21frangeColor
MondaybooltrueshowMon
TuesdaybooltrueshowTue
WednesdaybooltrueshowWed
ThursdaybooltrueshowThu
FridaybooltrueshowFri
SaturdayboolfalseshowSat
SundayboolfalseshowSun
Fixed risk amount per trade in USDint1USDRiskPerTrade
Leverageint1Leverage
HideStatisticsboolfalseHideStatistics
DisplayEquityCurveboolfalseDisplayEquityCurve
Estimated commission per round-turn in USDfloat0.2commission
Risk to Reward 1-to-float3.0riskRewardRatio
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

257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m

Pivot Trendlines

by g-moe
3 stars

This indicator identifies pivot highs and lows using a swing lookback period and connects them with trendlines on the price chart. It generates long and short entry signals when price moves through predefined percentage thresholds in three steps for buy and se

Indicator v5 TrendSupport & resistance
Updated 5 months ago · None stated GitHub repository of Pivot Trendlines

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