Defi Davinci Cheat Code
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JonathanHill19

//@version=5

indicator("Defi Davinci Cheat Code", overlay=true)

//Moving Averages

lengthema1 = input.int(50, "First MA Length", minval = 1) 
lengthema2 = input.int(100, "2nd MA Length", minval =1)
ma = ta.ema(close, lengthema1)
ma2 = ta.ema(close, lengthema2)
plot(ma, "First MA", color=color.red)
plot(ma2, "Second MA", color=color.purple)

//BUY SELL SIGNAL

boxp = input (title="Signal Length", defval=25)

LL = ta.lowest(low, boxp)
k1 = ta.highest(high, boxp)
k2 = ta.highest(high, boxp - 1)
k3 = ta.highest(high, boxp - 2)

NH = ta.valuewhen(high > k1[1], high, 0)
box1 = k3 < k2
TopBox = ta.valuewhen(ta.barssince(high > k1[1]) == boxp - 2 and box1, NH, 0)
BottomBox = ta.valuewhen(ta.barssince(high > k1[1]) == boxp - 2 and box1, LL, 0)

plot(TopBox, linewidth=1, color=color.purple, title="Resistance")
plot(BottomBox, linewidth=1, color=color.black, title="Support")

Buy = ta.crossover(close, TopBox)
Sell = ta.crossunder(close, BottomBox)

alertcondition(Buy, title="Buy Signal", message="Buy")
alertcondition(Sell, title="Sell Signal", message="Sell")

plotshape(Buy, style=shape.labelup, location=location.belowbar, color=color.red, size=size.tiny, title="Buy Signal", text="Buy", textcolor=color.white)
plotshape(Sell, style=shape.labeldown, location=location.abovebar, color=color.purple, size=size.tiny, title="Sell Signal", text="Sell", textcolor=color.white)


//Lot Size Calculator

iBalance = input.float(2000, "Balance (USD)", minval = 0)
iRiskPercent = input.float(2, "Risk Percentage (%)", minval = 0)
iSLPipSize = input.float(12.5, "Stop Loss Pip Size (Pip)", minval = 0)

// Get exRate with USD
currency = "USD" == syminfo.currency ? "" : "USD"+syminfo.currency
exRate = "USD" == syminfo.currency ? 1 : request.security(currency, timeframe.period, close)

// Calculate lot size
exRateFlPoint = "JPY" == syminfo.currency ? 0.01 : 0.0001
lotSize = ((iBalance * (iRiskPercent/100) * exRate) / (iSLPipSize * exRateFlPoint)) / 100000

// Result text
resultLabelText = "Lot Size: " + str.tostring(lotSize, '#.##')

var resultLabel = label.new(
     x=na,
     y=na,
     text="Lot Size Calculator",
     textalign=text.align_center,
     textcolor=color.black,
     color=color.black,
     style=label.style_label_left,
     size=size.normal,
     xloc = xloc.bar_index,
     yloc = yloc.belowbar
     
     )
 
//label.set_text(resultLabel, tostring(resultLabelText))
label.set_text(resultLabel, resultLabelText)
label.set_x(resultLabel, 0)
label.set_xloc(resultLabel, time, xloc.bar_time)
label.set_color(resultLabel, color.white)
label.set_size(resultLabel, size.normal)
