The Strat with Continuity [starlord_xrp]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © starlord_xrp

//@version=5
indicator("The Strat with Continuity", overlay=true)

int candle_type = na
bool bull = false
bool green = false
color bar_color = na
var float entry = na
var float target = na
var float stoploss = na
var bool open_long = false
bool enter_long = false
var bool open_short = false
bool enter_short = false
float profit_target = input(0.10, "min price target to enter")/100
int leverage = input(30, "Leverage Level - if no levearage put 1")
float trading_fee = input(0.07, "Trading Fee")*leverage
rsi = ta.rsi(close, 14)
var float total_profit = na
float profit = na

daily_open = request.security(syminfo.tickerid, "1D", open, barmerge.gaps_off)
daily_close = request.security(syminfo.tickerid, "1D", close, barmerge.gaps_off)

twelve_open = request.security(syminfo.tickerid, "720", open, barmerge.gaps_off)
twelve_close = request.security(syminfo.tickerid, "720", close, barmerge.gaps_off)

one_open = request.security(syminfo.tickerid, "60", open, barmerge.gaps_off)
one_close = request.security(syminfo.tickerid, "60", close, barmerge.gaps_off)

color new_back = na

long_continuity = daily_close>daily_open and twelve_close>twelve_open and one_close>one_open
short_continuity = daily_close<daily_open and twelve_close<twelve_open and one_close<one_open

if short_continuity
    new_back := color.new(color.maroon, 80)

if long_continuity
    new_back := color.new(color.lime, 80)

bool longs = input(true, "Longs?") //and long_continuity
bool shorts = input(true, "Shorts?") //and short_continuity
//bool use_continuity = input(true, "Use continuity filter?")

//if shorts and use_continuity and short_continuity
//    shorts := true
//else if shorts and use_continuity==false
//    shorts := true
//else
//    shorts := false

//if longs and use_continuity and long_continuity
//    longs := true
//else if longs and use_continuity==false
//    longs := true
//else
//    longs := false

if high>high[1] and low>=low[1]
    candle_type := 2
    bull := true
    bar_color := color.lime

if high<=high[1] and low<low[1]
    candle_type := 2
    bull := false
    bar_color := color.red

if high<=high[1] and low>=low[1]
    candle_type := 1
    bull := na
    bar_color := color.gray

if high>high[1] and low<low[1]
    candle_type := 3
    if close>open
        bull := true
        bar_color := color.new(color.green, 50)
    else
        bull := false
        bar_color := color.new(color.maroon, 50)


plotshape(candle_type==1, "1", shape.square, location.belowbar, color.gray, 0, "1", color.gray, false, size = size.tiny)
plotshape(candle_type==2 and bull, "2UP", shape.triangleup, location.belowbar, color.lime, 0, "2Up", color.lime, false, size = size.tiny)
plotshape(candle_type==2 and bull==false, "2DN", shape.triangledown, location.belowbar, color.red, 0, "2Dn", color.red, false, size = size.tiny)
plotshape(candle_type==3 and bull, "3", shape.square, location.belowbar, color.green, 0, "3", color.white, false, size = size.tiny)
plotshape(candle_type==3 and bull==false, "3", shape.square, location.belowbar, color.red, 0, "3", color.white, false, size = size.tiny)
barcolor(bar_color)
color back = na

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var label label312 = na
var label label22 = na
var label label212 = na
var label label122 = na
var label label322 = na
var label label1 = na
var label label2 = na
var label label3 = na
var label label4 = na
var line line1 = na
var line line2 = na
var line line3 = na
var line line4 = na
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//2-1-2 watch
if (candle_type[1]==2 and candle_type==1)
    if high[1] > high+(high*profit_target)
        line.delete(line3)
        line.delete(line4)
        label.delete(label3)
        label.delete(label4)
        line3 := line.new(bar_index-1, high[1], bar_index+1, high[1], color=color.green, style = line.style_dotted, width = 2)
        line4 := line.new(bar_index, high, bar_index+1, high, color=color.green, style = line.style_dashed, width = 2)
        label3 := label.new(bar_index+1, high[1], str.tostring(high[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label4 := label.new(bar_index+1, high, str.tostring(high), color = color.blue, size = size.tiny, style = label.style_label_left)
    if low[1]<low-(low*profit_target)
        line.delete(line1)
        line.delete(line2)
        label.delete(label1)
        label.delete(label2)
        line1 := line.new(bar_index-1, low[1], bar_index+1, low[1], color=color.red, style = line.style_dotted, width = 2)
        line2 := line.new(bar_index, low, bar_index+1, low, color=color.red, style = line.style_dashed, width = 2)
        label1 := label.new(bar_index+1, low[1], str.tostring(low[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label2 := label.new(bar_index+1, low, str.tostring(low), color = color.blue, size = size.tiny, style = label.style_label_left)
    //label.delete(label212)
    label212 := label.new(bar_index+1, low[1], "2-1-2", color = color.orange, size = size.tiny, style = label.style_label_up)


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//2-1-2 bull reversal
//if ((candle_type[2]==2 and bull[2]==false) and (candle_type[1]==1) and (candle_type==2 and bull) and longs)
  //  entry := high[1]
   // target := high[2]
   // stoploss := hl2[1]
   // if target > (entry+(entry*profit_target))
        //label.new(bar_index, high[1], "2-1-2 Long Rev", color = color.white, style = label.style_label_right, size = size.tiny)
      //  line.new(bar_index-1, target, bar_index+1, target)
     //   label.new(bar_index+2, target, str.tostring(target), color = color.blue, style = label.style_label_left, size= size.tiny)
    //    enter_long := true
    //    open_long := true
   // else
    //    back := color.new(color.red, 80)

//2-1-2 bear reversal
//if ((candle_type[2]==2 and bull[2]) and (candle_type[1]==1) and (candle_type==2 and bull==false) and shorts)
 //   entry := low[1]
  //  target := low[2]
  //  stoploss := hl2[1]
  //  if target<(entry-(entry*profit_target))
  //      enter_short := true
  //      open_short := true
       // label.new(bar_index, low[1], "2-1-2 Short Rev", color = color.white, style = label.style_label_right, size = size.tiny)
 //   else
   //     back := color.new(color.red, 80)

//2-1-2 bear continuation
//if ((candle_type[2]==2 and bull[2]==false) and (candle_type[1]==1) and (candle_type==2 and bull==false) and shorts)
  //  entry := low[1]
  //  target := low[2]
   // stoploss := hl2[1]
   // if target<(entry-(entry*profit_target))
   //     enter_short := true
   //     open_short := true
      //  label.new(bar_index, low[1], "2-1-2 Short Cont", color = color.white, style = label.style_label_right, size = size.tiny)
  //  else
   //     back := color.new(color.red, 80)

//2-1-2 bull continuation
//if ((candle_type[2]==2 and bull[2]) and (candle_type[1]==1) and (candle_type==2 and bull) and longs)
 //   entry := high[1]
  //  target := high[2]
  //  stoploss := hl2[1]
   // if target > (entry+(entry*profit_target))
       // label.new(bar_index, high[1], "2-1-2 Long Cont", color = color.white, style = label.style_label_right, size = size.tiny)
    //    enter_long := true
      //  open_long := true
   // else
     //   back := color.new(color.red, 80)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//3-1-2 watch
if candle_type[1]==3 and candle_type==1
    if bull[1] and low[1]<low-(low*profit_target)
        line.delete(line1)
        line.delete(line2)
        label.delete(label1)
        label.delete(label2)
        line1 := line.new(bar_index-1, low[1], bar_index+1, low[1], color=color.red, style = line.style_dotted, width = 2)
        line2 := line.new(bar_index, low, bar_index+1, low, color=color.red, style = line.style_dashed, width = 2)
        label1 := label.new(bar_index+1, low[1], str.tostring(low[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label2 := label.new(bar_index+1, low, str.tostring(low), color = color.blue, size = size.tiny, style = label.style_label_left)
    if bull[1]==false and high[1]>high+(high*profit_target)
        line.delete(line3)
        line.delete(line4)
        label.delete(label3)
        label.delete(label4)
        line3 := line.new(bar_index-1, high[1], bar_index+1, high[1], color=color.green, style = line.style_dotted, width = 2)
        line4 := line.new(bar_index, high, bar_index+1, high, color=color.green, style = line.style_dashed, width = 2)
        label3 := label.new(bar_index+1, high[1], str.tostring(high[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label4 := label.new(bar_index+1, high, str.tostring(high), color = color.blue, size = size.tiny, style = label.style_label_left)
    //label.delete(label312)
    label312 := label.new(bar_index+1, low[1], "3-1-2", color = color.orange, size = size.tiny, style = label.style_label_up)



//3-1-2 Bullish Reversal
//if ((candle_type[2]==3 and bull[2]==false) and (candle_type[1]==1) and (candle_type==2 and bull) and longs)
  //  entry := high[1]
   // target := high[2]
   // stoploss := hl2[1]
   // if target > (entry+(entry*profit_target))
       // label.new(bar_index, high[1], "3-1-2 Long Rev", color = color.white, style = label.style_label_right, size = size.tiny)
   //     enter_long := true
   //     open_long := true
   // else
   //     back := color.new(color.red, 80)

//3-1-2 bear reversal
//if ((candle_type[2]==3 and bull[2]) and (candle_type[1]==1) and (candle_type==2 and bull==false) and shorts)
//    entry := low[1]
//    target := low[2]
//    stoploss := hl2[1]
//    if target<(entry-(entry*profit_target))
//        enter_short := true
//        open_short := true
//        //label.new(bar_index, low[1], "3-1-2 Short Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//    else
//        back := color.new(color.red, 80)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//1-2-2 watch
if candle_type[1]==1 and candle_type==2
    if bull and low[1]<low-(low*profit_target)
        line.delete(line1)
        line.delete(line2)
        label.delete(label1)
        label.delete(label2)
        line1 := line.new(bar_index-1, low[2], bar_index+1, low[2], color=color.red, style = line.style_dotted, width = 2)
        line2 := line.new(bar_index, low, bar_index+1, low, color=color.red, style = line.style_dashed, width = 2)
        label1 := label.new(bar_index+1, low[2], str.tostring(low[2]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label2 := label.new(bar_index+1, low, str.tostring(low), color = color.blue, size = size.tiny, style = label.style_label_left)
    if bull[1]==false and high[1]>high+(high*profit_target)
        line.delete(line3)
        line.delete(line4)
        label.delete(label3)
        label.delete(label4)
        line3 := line.new(bar_index-1, high[2], bar_index+1, high[2], color=color.green, style = line.style_dotted, width = 2)
        line4 := line.new(bar_index, high, bar_index+1, high, color=color.green, style = line.style_dashed, width = 2)
        label3 := label.new(bar_index+1, high[2], str.tostring(high[2]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label4 := label.new(bar_index+1, high, str.tostring(high), color = color.blue, size = size.tiny, style = label.style_label_left)
    //label.delete(label122)
    label122 := label.new(bar_index+1, low[1], "1-2-2", color = color.orange, size = size.tiny, style = label.style_label_up)


//1-2-2 Bullish Reversal
//if ((candle_type[2]==1) and (candle_type[1]==2 and bull[1]==false) and (candle_type==2 and bull) and longs)
//    entry := high[1]
//    target := high[3]
//    stoploss := hl2[1]
//    if target > (entry+(entry*profit_target))
//        //label.new(bar_index, high[1], "1-2-2 Long Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//        enter_long := true
//        open_long := true
//    else
//        back := color.new(color.red, 80)

//1-2-2 bear reversal
//if ((candle_type[2]==1) and (candle_type[1]==2 and bull[1]) and (candle_type==2 and bull==false) and shorts)
//    entry := low[1]
//    target := low[3]
//    stoploss := hl2[1]
//    if target<(entry-(entry*profit_target))
//        enter_short := true
//        open_short := true
//        //label.new(bar_index, low[1], "1-2-2 Short Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//    else
//        back := color.new(color.red, 80)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//3-2-2 watch
if candle_type[1]==3 and candle_type==2
    if bull and low[1]<low-(low*profit_target)
        line.delete(line1)
        line.delete(line2)
        label.delete(label1)
        label.delete(label2)
        line1 := line.new(bar_index-1, low[1], bar_index+1, low[1], color=color.red, style = line.style_dotted, width = 2)
        line2 := line.new(bar_index, low, bar_index+1, low, color=color.red, style = line.style_dashed, width = 2)
        label1 := label.new(bar_index+1, low[1], str.tostring(low[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label2 := label.new(bar_index+1, low, str.tostring(low), color = color.blue, size = size.tiny, style = label.style_label_left)
    if bull==false and high[1]>high+(high*profit_target)
        line.delete(line3)
        line.delete(line4)
        label.delete(label3)
        label.delete(label4)
        line3 := line.new(bar_index-1, high[1], bar_index+1, high[1], color=color.green, style = line.style_dotted, width = 2)
        line4 := line.new(bar_index, high, bar_index+1, high, color=color.green, style = line.style_dashed, width = 2)
        label3 := label.new(bar_index+1, high[1], str.tostring(high[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label4 := label.new(bar_index+1, high, str.tostring(high), color = color.blue, size = size.tiny, style = label.style_label_left)
    //label.delete(label322)
    label322 := label.new(bar_index+1, low[1], "3-2-2", color = color.orange, size = size.tiny, style = label.style_label_up)



//3-2-2 Bullish Reversal
//if ((candle_type[2]==3 and bull[2]==false) and (candle_type[1]==2 and bull[1]) and (candle_type==2 and bull) and longs)
//    entry := high[1]
//    target := high[2]
//    stoploss := hl2[1]
//    if target > (entry+(entry*profit_target))
        //label.new(bar_index, high[1], "3-2-2 Long Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//        enter_long := true
 //       open_long := true
 //   else
//        back := color.new(color.red, 80)

//3-2-2 bear reversal
//if ((candle_type[2]==3 and bull[2]) and (candle_type[1]==2 and bull[1]==false) and (candle_type==2 and bull==false) and shorts)
//    entry := low[1]
//    target := low[2]
//    stoploss := hl2[1]
//    if target<(entry-(entry*profit_target))
//        enter_short := true
//        open_short := true
        //label.new(bar_index, low[1], "3-2-2 Short Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//    else
 //       back := color.new(color.red, 80)
/////////////////////////////////////////////////////////////////////////////////////////////

//2-2 watch
if candle_type==2
    if bull and low[1]<low-(low*profit_target)
        line.delete(line1)
        line.delete(line2)
        label.delete(label1)
        label.delete(label2)
        line1 := line.new(bar_index-1, low[1], bar_index+1, low[1], color=color.red, style = line.style_dotted, width = 2)
        line2 := line.new(bar_index, low, bar_index+1, low, color=color.red, style = line.style_dashed, width = 2)
        label1 := label.new(bar_index+1, low[1], str.tostring(low[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label2 := label.new(bar_index+1, low, str.tostring(low), color = color.blue, size = size.tiny, style = label.style_label_left)
    if bull==false and high[1]>high+(high*profit_target)
        line.delete(line3)
        line.delete(line4)
        label.delete(label3)
        label.delete(label4)
        line3 := line.new(bar_index-1, high[1], bar_index+1, high[1], color=color.green, style = line.style_dotted, width = 2)
        line4 := line.new(bar_index, high, bar_index+1, high, color=color.green, style = line.style_dashed, width = 2)
        label3 := label.new(bar_index+1, high[1], str.tostring(high[1]), color = color.blue, size = size.tiny, style = label.style_label_left)
        label4 := label.new(bar_index+1, high, str.tostring(high), color = color.blue, size = size.tiny, style = label.style_label_left)
    label.delete(label22)
    label22 := label.new(bar_index+1, low[1], "2-2 rev", color = color.orange, size = size.tiny, style = label.style_label_up)

//2-2 Bullish Reversal
//if ((candle_type[1]==2 and bull[1]==false) and (candle_type==2 and bull) and longs)
//    entry := high[1]
//    target := high[2]
//    stoploss := hl2[1]
//    if target > (entry+(entry*profit_target))
        //label.new(bar_index, high[1], "2-2 Long Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//        enter_long := true
//        open_long := true
//    else
//        back := color.new(color.red, 80)

//2-2 bear reversal
//if ((candle_type[1]==2 and bull[1]) and (candle_type==2 and bull==false) and shorts)
 //   entry := low[1]
 //   target := low[2]
 //   stoploss := hl2[1]
 //   if target<(entry-(entry*profit_target))
 //       enter_short := true
 //       open_short := true
        //label.new(bar_index, low[1], "2-2 Short Rev", color = color.white, style = label.style_label_right, size = size.tiny)
//    else
//        back := color.new(color.red, 80)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//if low[1]>low[2] and low[2]>low[3] and low[3]>low[4] and low[4]>low[5] and low[5]>low[6]
  //  back := color.new(color.yellow, 80)
   // line.new(bar_index-1, low[1], bar_index+5, low[1], color = color.orange)
    //line.new(bar_index-2, low[2], bar_index+5, low[2], color = color.yellow)
    //line.new(bar_index-3, low[3], bar_index+5, low[3], color = color.yellow)
    //line.new(bar_index-4, low[4], bar_index+5, low[4], color = color.yellow)
    //line.new(bar_index-5, low[5], bar_index+5, low[5], color = color.yellow)



//if high[1]<high[2] and high[2]<high[3] and high[3]<high[4] and high[4]<high[5] and high[5]<high[6]
  //  back := color.new(color.yellow, 80)
   // line.new(bar_index-1, high[1], bar_index+5, high[1], color = color.orange)
  //  line.new(bar_index-2, high[2], bar_index+5, high[2], color = color.yellow)
  //  line.new(bar_index-3, high[3], bar_index+5, high[3], color = color.yellow)
  // line.new(bar_index-4, high[4], bar_index+5, high[4], color = color.yellow)
   // line.new(bar_index-5, high[5], bar_index+5, high[5], color = color.yellow)

//line.delete(line1[1])
//line.delete(line2[1])
//line.delete(line3[1])
//line.delete(line4[1])
//label.delete(label1[1])
//label.delete(label2[1])
//label.delete(label3[1])
//label.delete(label4[1])



bgcolor(new_back)
//bool just_bought = ta.barssince(enter_long)<1 or ta.barssince(enter_short)<1

//plot (entry, color = color.yellow)
//plot (target, color = color.aqua)
//plot (stoploss, color=color.white)
//var int wins = 0
//var int losses = 0

//if open_short and close>=stoploss and just_bought==false
//    label.new(bar_index, stoploss, "Stoploss short", color = color.red, style = label.style_label_left, size = size.tiny)
   // open_short := false
  //  losses += 1

//if open_short and low<=target and just_bought==false
  //  label.new(bar_index, target, "Money short", color = color.lime, style = label.style_label_left, size = size.tiny)
    //open_short := false
  //  wins += 1

//if open_long and (high>=target or open>target) and just_bought==false
    //label.new(bar_index, target, "Money long", color = color.lime, style = label.style_label_left, size = size.tiny)
   // open_long := false
   // wins += 1

//if open_long and close<=stoploss and just_bought==false
    //label.new(bar_index, stoploss, "Stoplos long", color = color.red, style = label.style_label_left, size = size.tiny)
//    open_long := false
//    losses +=1


//newday = ta.change(time_tradingday)

//if newday
 //   label.new(bar_index, low-(low*0.005), "Wins: " + str.tostring(wins) + " Losses: " + str.tostring(losses), color = color.teal, style = label.style_label_center, size = size.tiny)
   // wins := 0
    //losses := 0

//longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
//if (longCondition)
 //   strategy.entry("My Long Entry Id", strategy.long)

//shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
//if (shortCondition)
//    strategy.entry("My Short Entry Id", strategy.short)

//plotshape(enter_long, "enter long", shape.arrowup, location.belowbar, color.green)
