Grid System With Fake Martingale
// This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License https://creativecommons.org/licenses/by-sa/4.0/
// © alexgrover

//@version=4
strategy("Grid System With Fake Martingale",process_orders_on_close=true)
point = input(1.)
os    = input(1,"Order Size")
mf    = input(2.,"Martingale Multiplier")
anti  = input(false,"Anti Martingale")
//------------------------------------------------------------------------------
baseline = 0.
baseline := nz(close > baseline[1] + point or close < baseline[1] - point ? 
  close : baseline[1],close)
//------------------------------------------------------------------------------
size = 0.
loss = change(strategy.losstrades)
win = change(strategy.wintrades)
if anti
    size := win ? size[1]*mf : loss ? 1 : nz(size[1],os)
else
    size := loss ? size[1]*mf : win ? 1 : nz(size[1],os)
upper = baseline + point*size
lower = baseline - point*size
//------------------------------------------------------------------------------
if baseline > baseline[1] and strategy.opentrades == 0
    strategy.entry("Buy",strategy.long,qty=os)
    strategy.exit("buy/tp/sl","Buy",stop=lower,limit=upper)
if baseline < baseline[1] and strategy.opentrades == 0
    strategy.entry("Sell",strategy.short,qty=os)
    strategy.exit("sell/tp/sl","Sell",stop=upper,limit=lower)
//------------------------------------------------------------------------------
cap = strategy.initial_capital
eq = strategy.equity
rmax = 0.
rmax := max(eq,nz(rmax[1]))
//----
css = eq > cap ? #0cb51a : #e65100
a = plot(eq,"Equity",#2196f3,2,transp=0)
b = plot(rmax,"Maximum",css,2,transp=0)
fill(a,b,css,80)