TD Sequential Dual-Direction S/R Trading Strategy

Penulis:ChaoZhang, Tanggal: 2024-02-06 12:13:22
Tag:

img

Gambaran umum

Strategi ini mengidentifikasi level support dan resistance dengan melacak bar harga yang berturut-turut naik dan turun, dan menggabungkan moving average sebagai sinyal entry dan stop loss untuk membangun strategi trading long dan short.

Prinsip-prinsip

  1. Identifikasi S/R
    • Ketika harga penutupan lebih tinggi dari penutupan 4 hari yang lalu selama 4 hari berturut-turut, tanda titik sebagai dukungan ke bawah
    • Ketika harga penutupan lebih rendah dari penutupan 4 hari yang lalu selama 4 hari berturut-turut, tanda titik sebagai resistance upside
  2. Generasi sinyal
    • Setelah mengidentifikasi tingkat dukungan, jika jumlah up bar mencapai ambang (default 9 hari), menghasilkan sinyal panjang
    • Setelah mengidentifikasi tingkat resistensi, jika jumlah batang ke bawah mencapai ambang (default 9 hari), menghasilkan sinyal pendek
  3. Filter MA dan stop loss
    • Memerlukan harga untuk melintasi garis MA saat masuk, untuk menyaring sinyal
    • Atur stop loss ke garis MA pada saat masuk

Keuntungan

  1. Penghakiman berdasarkan S/R relatif dapat diandalkan, tidak mudah disesatkan oleh fluktuasi jangka pendek
  2. Menggabungkan filter MA dapat mengurangi sinyal palsu
  3. Pergi panjang dan pendek untuk meningkatkan frekuensi dan peluang keuntungan
  4. Parameter diatur, dapat dioptimalkan untuk produk dan situasi pasar yang berbeda

Risiko dan Solusi

  1. Mungkin mengalami kerugian berturut-turut di pasar tren
    • Meningkatkan periode MA untuk mengurangi frekuensi perdagangan
  2. Kemungkinan penilaian S/R yang salah
    • Batas fine tuning untuk identifikasi S/R
  3. Stop loss mungkin terlalu sering diaktifkan di pasar whipsaw
    • Rentang stop loss yang longgar
    • Tambahkan indikator tren

Arahan Optimasi

  1. Tambahkan lebih banyak indikator teknis untuk meningkatkan ketahanan
    • Tren, momentum dll.
  2. Mengoptimalkan logika identifikasi S/R
    • Dampak uji dari parameter yang berbeda
  3. Penyesuaian parameter untuk produk dan kerangka waktu tertentu
    • Jangkauan yang dapat disesuaikan bervariasi antara produk
  4. Mengembangkan mekanisme stop loss adaptif
    • Mengatur stop loss secara dinamis berdasarkan volatilitas pasar

Kesimpulan

Strategi ini relatif sederhana dan dapat diandalkan. Dengan mengidentifikasi tingkat S / R dengan benar, ia menangkap peluang pembalikan harga dengan probabilitas tinggi. Menggabungkan dengan MA memastikan waktu masuk yang tepat dan menghindari perangkap. Akhirnya, penilaian arah konservatif tetapi dapat disesuaikan. Pengguna dapat mengoptimalkan parameter sesuai dengan pemahaman pasar mereka dan mencapai hasil yang lebih baik.


/*backtest
start: 2023-01-30 00:00:00
end: 2024-02-05 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GlobalMarketSignals

//@version=4
strategy("GMS: TD Sequential Strategy", overlay=true)

LongShort     = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
PriceFlipL    = input(title="TD Sequential Long Price Flip", type = input.integer ,defval=9)
PriceFlipS    = input(title="TD Sequential Short Price Flip", type = input.integer ,defval=9)
MAs1          = input(title="Long MA", type=input.string, defval="SMA", options=["SMA", "EMA", "VWMA"])
MAs2          = input(title="Short MA", type=input.string, defval="SMA", options=["SMA", "EMA", "VWMA"])
SMAlenL       = input(title="Long MA Exit Length", type = input.integer ,defval=10)
SMAlenS       = input(title="Short MA Exit Length", type = input.integer ,defval=10)
AboveBelowL   = input(title="Long Trend Filter?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
AboveBelowS   = input(title="Short Trend Filter?", type=input.string, defval="Below", options=["Above", "Below", "Don't Include"])
TLma          = input(title="Trend MA", type=input.string, defval="SMA", options=["SMA", "EMA", "VWMA"])
TrendLength   = input(title="Trend MA Length", type = input.integer ,defval=200)
PTbutton      = input(title="Profit Target On/Off", type=input.bool, defval=true)
ProfitTarget  = input(title="Profit Target %", type=input.float, defval=1, step=0.1, minval=0)
SLbutton      = input(title="Stop Loss On/Off", type=input.bool, defval=true)
StopLoss      = input(title="Stop Loss %", type=input.float, defval=-1, step=0.1, maxval=0)

//PROFIT TARGET & STOPLOSS

if PTbutton == true and SLbutton == true
    strategy.exit("EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick), loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
    if PTbutton == true and SLbutton == false
        strategy.exit("PT EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick))
    else
        if PTbutton == false and SLbutton == true
            strategy.exit("SL EXIT", loss=((close*(StopLoss*-0.01))/syminfo.mintick))
        else    
            strategy.cancel("PT EXIT")

// S/R Code By johan.gradin (lines 36-46)
// Buy setup//
priceflip1 = barssince(close>close[4])
buysetup = close<close[4] and priceflip1
buy = buysetup and barssince(priceflip1!=9)
buyovershoot = barssince(priceflip1!=13) and buysetup
// Sell Setup //
priceflip = barssince(close<close[4])
sellsetup = close>close[4] and priceflip
sell = sellsetup and barssince(priceflip!=9)
sellovershoot = sellsetup and barssince(priceflip!=13)


///////
/////// SMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))  

///////
/////// EMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS)) 



///////
/////// VWMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>sma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<sma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "SMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>sma(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<sma(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "SMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS)) 

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

///////
/////// SMA
///////


if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))  

///////
/////// EMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS)) 



///////
/////// VWMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>ema(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<ema(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "EMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>ema(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<ema(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "EMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS)) 

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

///////
/////// SMA
///////


if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "SMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<sma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "SMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>sma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<sma(close,SMAlenS))  

///////
/////// EMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>ema(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "EMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<ema(close,SMAlenL) )
    strategy.close("LONG", when = close>ema(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<ema(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<ema(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "EMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>ema(close,SMAlenS) )
    strategy.close("SHORT",  when = close<ema(close,SMAlenS)) 



///////
/////// VWMA
///////

if LongShort =="Long Only" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Long Only" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Long Only" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
///////
    
if LongShort =="Short Only" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Short Only" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Short Only" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

///////
    
if LongShort =="Both" and AboveBelowL == "Above" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and close>vwma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
if LongShort =="Both" and  AboveBelowL == "Below" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) and  close<vwma(close,TrendLength))
    strategy.close("LONG", when = close>vwma(close,SMAlenL))

if LongShort =="Both" and  AboveBelowL == "Don't Include" and MAs1 == "VWMA" and TLma == "VWMA"
    strategy.entry("LONG", true, when = buysetup and barssince(priceflip1!=PriceFlipL) and close<vwma(close,SMAlenL) )
    strategy.close("LONG", when = close>vwma(close,SMAlenL))
    
    
if LongShort =="Both" and  AboveBelowS == "Above" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close>vwma(close,TrendLength))
    strategy.close("SHORT", when = close<vwma(close,SMAlenS))
    
if LongShort =="Both" and  AboveBelowS == "Below" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) and close<vwma(close,TrendLength))
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS))

if LongShort =="Both" and  AboveBelowS == "Don't Include" and MAs2 == "VWMA" and TLma == "VWMA"
    strategy.entry("SHORT", false, when = sellsetup and barssince(priceflip!=PriceFlipS) and close>vwma(close,SMAlenS) )
    strategy.close("SHORT",  when = close<vwma(close,SMAlenS)) 

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

Lebih banyak