ma 20 high-low
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlanAntony

//@version=4


strategy("ma 20 high-low",overlay=true)

//compute the indicators

smaH = sma(high, 20)
smaL = sma(low, 20)


//plot the indicators
plot(smaH,title="smaHigh", color=color.green, linewidth=2)


plot(smaL,title="smaLow", color=color.red, linewidth=2)


//trading logic
enterlong = crossover(close,smaH) //positive ema crossover
exitlong = crossunder(close,0.99*smaH)  //exiting long


entershort = crossunder(close,smaL) //negative EMA Crossover
exitshort = crossover(close,1.01*smaH) //exiting shorts


notintrade = strategy.position_size<=0
bgcolor(notintrade ? color.red:color.green)

//execution logic

start = timestamp(2015,6,1,0,0)
//end = timestamp(2022,6,1,0,0)

if time >= start
    strategy.entry( "long", strategy.long,100, when = enterlong)
    strategy.entry( "short", strategy.short,100, when = entershort) 
    
    strategy.close("long", when = exitlong)
    strategy.close("short", when = exitshort)

//if time >= end
   // strategy.close_all()