OPV1 - Up & Down Trend Trading Strategy - BTC/USDT 3h

pcooma · strategy · 911 行 · 点赞 498 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@ pcooma
// you are wellcome to tweek settings and get yield as you wish
// This startergy optimized to BNB 15 min standerd candlestic chart and buy & sell signals were based on technical analysis. 
//@version=5
 
strategy("OPV1 - Up & Down Trend Trading Strategy - BTC/USDT 3h", shorttitle="OPV4 U&D - BTC/USDT 3h", overlay=true, calc_on_order_fills=false, close_entries_rule = "FIFO", calc_on_every_tick=false, initial_capital = 1000,pyramiding = 999,precision = 4, process_orders_on_close=false, currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 33, commission_type = strategy.commission.percent, max_lines_count = 500, commission_value = 0.1)
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////INPUTS///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
var     profit_cal          = input.float(defval    = 8.2,      title = "Expected profit % is", minval = 0.2, step = 0.1,           group = "profit Calculation")
bool    enable_stoploss     = input.bool(defval     = false,    title = "Enable stop loss",                                         group = "profit Calculation",   inline = 'stop loss')
var     stop_loss_cal       = input.float(defval    = 10,       title = "& stop loss % is",                                         group = "profit Calculation",   inline = 'stop loss')
bool    enable_int_profit   = input.bool(defval     = true,     title = "Profit take",                                              group = "profit Calculation",   inline = 'take')
var     sell_qty_prc        = input.float(defval    = 11.0,     title = "& quantity is",                                            group = "profit Calculation",   inline = 'take')
var     prc_or_usdt         = input.string(                     title = "", options=['% of strategy size', 'USDT'], defval='USDT',  group = "profit Calculation",   inline = 'take')  
 
//Fund Management
var     int_cap             = input.float(defval    = 5000,     title   = "Cumilative Investment",                                  group = "Fund Management")
var     int_val_prc         = input.float(defval    = 15,       title   = "Value of first purchase will be",                        group = "Fund Management",      inline = "Investment", tooltip  = "Minimum value of initial purchase will be 15USDT" )
var     int_val_allocation  = input.string(title    = "",       options = ['% of cumilative investment', 'USDT'],                   group = "Fund Management",      inline = "Investment", defval   = '% of cumilative investment')  
var     piramiding          = input.int(defval      = 40,       title   = "Numbers of pararal entries",                             group = "Fund Management")
var     r                   = input.float(defval    = 5,        title   = "r starting value (hypothithical value)",                 group = "Fund Management")
var     inceiment_1         = input.float(defval    = 2.279,    title   = "Insert Calculated R value from Data Window",             group = "Fund Management")
 
//Backtest dates
fromDay   = input.int(defval = 01,      title = "From (DD/MM/YYYY) - ",     minval = 1, maxval = 31,    group = 'Time Period Values', inline = 'From')
fromMonth = input.int(defval = 08,      title = "/",                        minval = 1, maxval = 12,    group = 'Time Period Values', inline = 'From')
fromYear  = input.int(defval = 2016,    title = "/",                        minval = 1970,              group = 'Time Period Values', inline = 'From')
 
thruDay   = input.int(defval = 1,       title = "Thru (DD/MM/YYYY) - ",     minval = 1, maxval = 31,    group = 'Time Period Values', inline = 'Thru')
thruMonth = input.int(defval = 1,       title = "/",                        minval = 1, maxval = 12,    group = 'Time Period Values', inline = 'Thru')
thruYear  = input.int(defval = 2112,    title = "/",                        minval = 1970,              group = 'Time Period Values', inline = 'Thru')
 
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)         // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)         // backtest finish window
window()  => 
    time >= start and time <= finish ? true : false                 // create function "within window of time"
    
//Primary Inputs
//Inputs of SAR Indicator
sar1 = input.float(defval=0.09,     title = 'Start',                step=0.0001,    group = 'SAR Values',   inline = 'Start')
sar2 = input.float(defval=0.0009,   title = 'Incriment',            step=0.0001,    group = 'SAR Values',   inline = 'Start')
sar3 = input.float(defval=0.0141,   title = 'Max Value',            step=0.1,       group = 'SAR Values',   inline = 'Start')
bool sar_visible = input(false,     title = "Show SAR",                             group = 'SAR Values')
 
// Inputs of Super trend indicator
ST_T = input.int(defval=9,          title = 'Trend',                step =1,        group = 'Super Trend',  inline = 'Trend')
ST_D = input.int(defval=9,          title = 'Direction',            step =1,        group = 'Super Trend',  inline = 'Trend')
ST_SMA = input.int(defval=3,        title = 'SMA',                  step =1,        group = 'Super Trend',  inline = 'Trend')
bool ST_visible = input(false,      title = "Show Super Trend",                     group = 'Super Trend')
 
//Inputs of SMA500 indicator
src_sma500 = input(high,            title = 'Source of SMA500 is',                  group = 'SMA500',       inline = 'Source')
lb_sma500 = input.int(defval = 50,  title = '& Look back period is', step=10,       group = 'SMA500',       inline = 'Source')
bool sma500_visible = input(false,  title = "Show SMA500",                          group = 'SMA500')
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////UP TREND/////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// Calculations
// SMA500 Indicator
SMA500 = ta.sma(src_sma500,lb_sma500)
SMA700 = ta.sma(close,700)
SMA_Open = ta.sma(open,9)
//SMA9 Indicator
SMA9 = ta.sma((high+low)/2,5)
risingSMA9 = ta.rising(SMA9,1)
fallingSMA9 = ta.falling(SMA9,1)
color  plotcolor1 = color.black
if risingSMA9
    plotcolor1 := color.green
 
// SAR Indicator
sar = ta.sar(sar1, sar2, sar3)
 
//Supertrend
[supertrend, direction] = ta.supertrend(ST_T, ST_D)
up_trend = ta.sma(direction < 0 ? supertrend : na,ST_SMA)
down_trend = ta.sma(direction < 0? na : supertrend, ST_SMA)
 
// Color change
color  plotcolor2 = color.green
if open>down_trend or close>down_trend
    plotcolor2 := color.lime
if open<down_trend or close<down_trend
    plotcolor2 := color.red
    
color plotcolor3 = color.green
if open>up_trend or close>up_trend
    plotcolor3 := color.yellow
if open<up_trend or close<up_trend
    plotcolor3 := color.red
 
color plotcolor4 = color.black
if (open>sar or close>sar) 
    plotcolor4 := color.white
if (open<sar or close<sar)
    plotcolor4 := color.red
    
color plotcolor5 = color.black
if (open>SMA500 or close>SMA500) 
    plotcolor5 := color.green
if (open<SMA500 or close<SMA500) 
    plotcolor5 := color.red
 
color plotcolor6 = color.green
rising_taalma = ta.rising (ta.alma(open,10,.99,1),1)
falling_taalma = ta.falling (ta.alma(open,10,.99,1),1)
 
if rising_taalma
    plotcolor6 := color.green
if falling_taalma
    plotcolor6 := color.red
    
// buy and sell conditions for uptrend
longCondition1 = (open >= down_trend or high>= down_trend or ta.crossover(open,down_trend)or ta.crossover(high,down_trend))
longCondition2 = (open >= up_trend or high>= up_trend or ta.crossover(open,up_trend)or ta.crossover(high,up_trend))
longCondition3 = (open >= SMA500 or high>= SMA500 or ta.crossover(open,SMA500)or ta.crossover(high,SMA500))
longCondition4 = (open >= sar or high>= sar or ta.crossover(open,sar)or ta.crossover(high,sar))
longCondition5 = rising_taalma
 
shortCondition1 = (close < down_trend or low< down_trend or ta.crossunder(close,down_trend)or ta.crossunder(low,down_trend))
shortCondition2 = (close < up_trend or low< up_trend or ta.crossunder(close,up_trend)or ta.crossunder(low,up_trend))
shortCondition3 = (close < SMA500 or low< SMA500 or ta.crossunder(close,SMA500)or ta.crossunder(low,SMA500))
shortCondition4 = (close < sar or low< sar or ta.crossunder(close,sar)or ta.crossunder(low,sar))
shortCondition5 = falling_taalma
 
comp_buy1 = longCondition1 and longCondition2 and longCondition3 and longCondition4 and longCondition5
op_buy1 = shortCondition3 and longCondition1 and longCondition2 and longCondition4
op_buy2 = shortCondition1 and shortCondition2 and longCondition3 and longCondition4 and longCondition5
 
comp_sell1 = shortCondition1 and shortCondition2 and shortCondition3 and shortCondition4 and shortCondition5
op_sell1 = shortCondition3 and shortCondition4 and longCondition1 and longCondition2
op_sell2 = shortCondition4 and longCondition1 and longCondition2 and longCondition3
op_sell3 = longCondition2 and shortCondition1 and shortCondition4 and shortCondition3
op_sell4 = longCondition2 and shortCondition1 and shortCondition4
 
var b1 = 0
var b2 = 0
var b3 = 0
 
if comp_buy1 == true and comp_buy1[1] == false 
    b1 := 1
else
    b1 := 0
    
if op_buy1 == true and op_buy1[1] == false 
    b2 := 1
else
    b2 := 0
 
if op_buy2 == true and op_buy2[1] == false 
    b3 := 1
else
    b3 := 0
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////DOWN TREND///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// DCA method based on indicators
//RSI Indicator
src_rsi_10 = input(hlc3,        title = "Source of RSI-10  is",         group = "RSI Indicator",                                           inline = 'RSI-10')
len_rsi_10 = input.int(10,      title = "& Look back period is",        group = "RSI Indicator",   minval=1,   maxval = 10,    step = 1,   inline = 'RSI-10')
up_rsi_10 = ta.rma(math.max(ta.change(src_rsi_10), 0), len_rsi_10)
down_rsi_10 = ta.rma(-math.min(ta.change(src_rsi_10), 0), len_rsi_10)
rsi_10 = down_rsi_10 == 0 ? 100 : up_rsi_10 == 0 ? 0 : 100 - (100 / (1 + up_rsi_10 / down_rsi_10))
 
var p_rsi = 0
 
if rsi_10>= 0 and rsi_10<10
    p_rsi := 0
else if rsi_10>= 10 and rsi_10<20
    p_rsi := 10
else if rsi_10>= 20 and rsi_10<30
    p_rsi := 20
else if rsi_10>= 30 and rsi_10<40
    p_rsi := 30
else if rsi_10>= 40 and rsi_10<50
    p_rsi := 40
else if rsi_10>= 50 and rsi_10<60
    p_rsi := 50
else if rsi_10>= 60 and rsi_10<70
    p_rsi := 60
else if rsi_10>= 70 and rsi_10<80
    p_rsi := 70
else if rsi_10>= 80 and rsi_10<90
    p_rsi := 80
else if rsi_10>= 90 and rsi_10<100
    p_rsi := 90
 
src_rsi_50 = input(ohlc4,       title = "Source of RSI-50 is",          group = "RSI Indicator",                                            inline = 'RSI-50')
len_rsi_50 = input.int(50,      title = "& Look back period is",        group = "RSI Indicator",   minval=11,  maxval = 50,    step = 1,    inline = 'RSI-50')
up_rsi_50 = ta.rma(math.max(ta.change(src_rsi_50), 0), len_rsi_50)
down_rsi_50 = ta.rma(-math.min(ta.change(src_rsi_50), 0), len_rsi_50)
rsi_50 = down_rsi_50 == 0 ? 100 : up_rsi_50 == 0 ? 0 : 100 - (100 / (1 + up_rsi_50 / down_rsi_50))
 
var p_rsi_50 = 0
 
if rsi_50>= 0 and rsi_50<10
    p_rsi_50 := 0
else if rsi_50>= 10 and rsi_50<20
    p_rsi_50 := 10
else if rsi_50>= 20 and rsi_50<30
    p_rsi_50 := 20
else if rsi_50>= 30 and rsi_50<40
    p_rsi_50 := 30
else if rsi_50>= 40 and rsi_50<50
    p_rsi_50 := 40
else if rsi_50>= 50 and rsi_50<60
    p_rsi_50 := 50
else if rsi_50>= 60 and rsi_50<70
    p_rsi_50 := 60
else if rsi_50>= 70 and rsi_50<80
    p_rsi_50 := 70
else if rsi_50>= 80 and rsi_50<90
    p_rsi_50 := 80
else if rsi_50>= 90 and rsi_50<100
    p_rsi_50 := 90
 
src_rsi_100 = input(ohlc4,      title = "Source of RSI-100 is",         group = "RSI Indicator",                                            inline = 'RSI-100')
len_rsi_100 = input.int(100,    title = "& Look back period is",        group = "RSI Indicator",  minval=51,  maxval = 200,   step = 10,    inline = 'RSI-100')
up_rsi_100 = ta.rma(math.max(ta.change(src_rsi_100), 0), len_rsi_100)
down_rsi_100 = ta.rma(-math.min(ta.change(src_rsi_100), 0), len_rsi_100)
rsi_100 = down_rsi_100 == 0 ? 100 : up_rsi_100 == 0 ? 0 : 100 - (100 / (1 + up_rsi_100 / down_rsi_100))
 
var p_rsi_100 = 0
 
if rsi_100>= 0 and rsi_100<10
    p_rsi_100 := 0
else if rsi_100>= 10 and rsi_100<20
    p_rsi_100 := 10
else if rsi_100>= 20 and rsi_100<30
    p_rsi_100 := 20
else if rsi_100>= 30 and rsi_100<40
    p_rsi_100 := 30
else if rsi_100>= 40 and rsi_100<50
    p_rsi_100 := 40
else if rsi_100>= 50 and rsi_100<60
    p_rsi_100 := 50
else if rsi_100>= 60 and rsi_100<70
    p_rsi_100 := 60
else if rsi_100>= 70 and rsi_100<80
    p_rsi_100 := 70
else if rsi_100>= 80 and rsi_100<90
    p_rsi_100 := 80
else if rsi_100>= 90 and rsi_100<100
    p_rsi_100 := 90
 
// Relative Volatility Indicator
src_rvi_10 = input(ohlc4,                                                               title = "Source of RVI-10 is",              group = "RVI Indicator",  inline = 'RVI-10')
length_rvi_10 = input.int(defval = 10,      minval=1,       maxval = 10,    step = 1,   title = "Look back period of RVI-10 is",    group = "RVI Indicator",  inline = 'Look back period of RVI-10')
len_rvi_10 = input.int(defval = 10,         minval=1,       maxval = 10,    step = 1,   title = "& EMA is",                         group = "RVI Indicator",  inline = 'Look back period of RVI-10')
stddev_rvi_10 = ta.stdev(src_rvi_10, length_rvi_10)
upper_rvi_10 = ta.ema(ta.change(src_rvi_10) <= 0 ? 0 : stddev_rvi_10, len_rvi_10)
lower_rvi_10 = ta.ema(ta.change(src_rvi_10) > 0 ? 0 : stddev_rvi_10, len_rvi_10)
rvi_10 = upper_rvi_10 / (upper_rvi_10 + lower_rvi_10) * 100
 
var p_rvi_10 = 0
 
if rvi_10 >= 0 and rvi_10 <10
    p_rvi_10 := 0
else if rvi_10 >= 10 and rvi_10 <20
    p_rvi_10 := 10
else if rvi_10 >= 20 and rvi_10 <30
    p_rvi_10 := 20
else if rvi_10 >= 30 and rvi_10 <40
    p_rvi_10 := 30
else if rvi_10 >= 40 and rvi_10 <50
    p_rvi_10 := 40
else if rvi_10 >= 50 and rvi_10 <60
    p_rvi_10 := 50
else if rvi_10 >= 60 and rvi_10 <70
    p_rvi_10 := 60
else if rvi_10 >= 70 and rvi_10 <80
    p_rvi_10 := 70
else if rvi_10 >= 80 and rvi_10 <90
    p_rvi_10 := 80
else if rvi_10 >= 90 and rvi_10 <100
    p_rvi_10 := 90
 
src_rvi_50 = input(hlc3,                                                                        title = "Source of RVI-50 is",              group = "RVI Indicator",  inline = 'RVI-50')
length_rvi_50 = input.int(defval = 50,      minval=11,      maxval = 50,        step = 1,       title="Look back period of RVI-50 is",      group = "RVI Indicator",  inline = 'Look back period of RVI-50')
len_rvi_50 = input.int(defval = 50,         minval=11,      maxval = 50,        step = 1,       title="& EMA is",                           group = "RVI Indicator",  inline = 'Look back period of RVI-50')
stddev_rvi_50 = ta.stdev(src_rvi_50, length_rvi_50)
upper_rvi_50 = ta.ema(ta.change(src_rvi_50) <= 0 ? 0 : stddev_rvi_50, len_rvi_50)
lower_rvi_50 = ta.ema(ta.change(src_rvi_50) > 0 ? 0 : stddev_rvi_50, len_rvi_50)
rvi_50 = upper_rvi_50 / (upper_rvi_50 + lower_rvi_50) * 100
 
var p_rvi_50 = 0
 
if rvi_50 >= 0 and rvi_50 <10
    p_rvi_50 := 0
else if rvi_50 >= 10 and rvi_50 <20
    p_rvi_50 := 10
else if rvi_50 >= 20 and rvi_50 <30
    p_rvi_50 := 20
else if rvi_50 >= 30 and rvi_50 <40
    p_rvi_50 := 30
else if rvi_50 >= 40 and rvi_50 <50
    p_rvi_50 := 40
else if rvi_50 >= 50 and rvi_50 <60
    p_rvi_50 := 50
else if rvi_50 >= 60 and rvi_50 <70
    p_rvi_50 := 60
else if rvi_50 >= 70 and rvi_50 <80
    p_rvi_50 := 70
else if rvi_50 >= 80 and rvi_50 <90
    p_rvi_50 := 80
else if rvi_50 >= 90 and rvi_50 <100
    p_rvi_50 := 90
 
src_rvi_100 = input(hl2,                                                                title = "Source of RVI-100 is",             group = "RVI Indicator",  inline = 'RVI-100')
length_rvi_100 = input.int(defval = 100,        minval=51,  maxval = 200,   step = 10,  title = "Look back period of RVI-100 is",   group = "RVI Indicator",  inline = 'Look back period of RVI-100')
len_rvi_100 = input.int(defval = 100,           minval=51,  maxval = 200,   step = 10,  title = "& EMA is",                         group = "RVI Indicator",  inline = 'Look back period of RVI-100')
 
stddev_rvi_100 = ta.stdev(src_rvi_100, length_rvi_100)
upper_rvi_100 = ta.ema(ta.change(src_rvi_100) <= 0 ? 0 : stddev_rvi_100, len_rvi_100)
lower_rvi_100 = ta.ema(ta.change(src_rvi_100) > 0 ? 0 : stddev_rvi_100, len_rvi_100)
rvi_100 = upper_rvi_100 / (upper_rvi_100 + lower_rvi_100) * 100
 
var p_rvi_100 = 0
 
if rvi_100 >= 0 and rvi_100 <10
    p_rvi_100 := 0
else if rvi_100 >= 10 and rvi_100 <20
    p_rvi_100 := 10
else if rvi_100 >= 20 and rvi_100 <30
    p_rvi_100 := 20
else if rvi_100 >= 30 and rvi_100 <40
    p_rvi_100 := 30
else if rvi_100 >= 40 and rvi_100 <50
    p_rvi_100 := 40
else if rvi_100 >= 50 and rvi_100 <60
    p_rvi_100 := 50
else if rvi_100 >= 60 and rvi_100 <70
    p_rvi_100 := 60
else if rvi_100 >= 70 and rvi_100 <80
    p_rvi_100 := 70
else if rvi_100 >= 80 and rvi_100 <90
    p_rvi_100 := 80
else if rvi_100 >= 90 and rvi_100 <100
    p_rvi_100 := 90
 
// Money flow index
src_mfi_10 = input(hlcc4,                                                                   title = "Source of MFI-10 is",      group = "MFI Indicator",  inline = 'Source of MFI-10')
len_mfi_10 = input.int(defval = 10,         minval=1,           maxval = 10,    step = 1,   title = "& Look back period is",    group = "MFI Indicator",  inline = 'Source of MFI-10')
 
mf_10 = ta.mfi(src_mfi_10, len_mfi_10)
 
var p_mfi_10 = 0
 
if mf_10>= 0 and mf_10<10
    p_mfi_10 := 0
else if mf_10>= 10 and mf_10<20
    p_mfi_10 := 10
else if mf_10>= 20 and mf_10<30
    p_mfi_10 := 20
else if mf_10>= 30 and mf_10<40
    p_mfi_10 := 30
else if mf_10>= 40 and mf_10<50
    p_mfi_10 := 40
else if mf_10>= 50 and mf_10<60
    p_mfi_10 := 50
else if mf_10>= 60 and mf_10<70
    p_mfi_10 := 60
else if mf_10>= 70 and mf_10<80
    p_mfi_10 := 70
else if mf_10>= 80 and mf_10<90
    p_mfi_10 := 80
else if mf_10>= 90 and mf_10<100
    p_mfi_10 := 90
 
src_mfi_50 = input(hlc3,                                                        title = "Source of MFI-50 is",      group = "MFI Indicator",  inline = 'Source of MFI-50')
len_mfi_50 = input.int(defval = 50,     minval=11,  maxval = 50,    step = 1,   title="& Look back period is",      group = "MFI Indicator",  inline = 'Source of MFI-50')
 
mf_50 = ta.mfi(src_mfi_50, len_mfi_50)
 
var p_mfi_50 = 0
 
if mf_50>= 0 and mf_50<10
    p_mfi_50 := 0
else if mf_50>= 10 and mf_50<20
    p_mfi_50 := 10
else if mf_50>= 20 and mf_50<30
    p_mfi_50 := 20
else if mf_50>= 30 and mf_50<40
    p_mfi_50 := 30
else if mf_50>= 40 and mf_50<50
    p_mfi_50 := 40
else if mf_50>= 50 and mf_50<60
    p_mfi_50 := 50
else if mf_50>= 60 and mf_50<70
    p_mfi_50 := 60
else if mf_50>= 70 and mf_50<80
    p_mfi_50 := 70
else if mf_50>= 80 and mf_50<90
    p_mfi_50 := 80
else if mf_50>= 90 and mf_50<100
    p_mfi_50 := 90
 
src_mfi_100 = input(hlc3,                                                                   title = "Source of MFI-100 is",     group = "MFI Indicator",  inline = 'Source of MFI-100')
len_mfi_100 = input.int(defval = 100,       minval=51,          maxval = 200,   step = 10,  title="& Look back period is",      group = "MFI Indicator",  inline = 'Source of MFI-100')
 
mf_100 = ta.mfi(src_mfi_100, len_mfi_100)
 
var p_mfi_100 = 0
 
if mf_100>= 0 and mf_100<10
    p_mfi_100 := 0
else if mf_100>= 10 and mf_100<20
    p_mfi_100 := 10
else if mf_100>= 20 and mf_100<30
    p_mfi_100 := 20
else if mf_100>= 30 and mf_100<40
    p_mfi_100 := 30
else if mf_100>= 40 and mf_100<50
    p_mfi_100 := 40
else if mf_100>= 50 and mf_100<60
    p_mfi_100 := 50
else if mf_100>= 60 and mf_100<70
    p_mfi_100 := 60
else if mf_100>= 70 and mf_100<80
    p_mfi_100 := 70
else if mf_100>= 80 and mf_100<90
    p_mfi_100 := 80
else if mf_100>= 90 and mf_100<100
    p_mfi_100 := 90
 
//Balance of power indicator
bop = ((((close - open) / (high - low))*100)+50)
bop_sma_100 = ta.sma(bop,50)
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////HH & LL in 100 days period///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
lookback    =   input.int   (defval = 55,       title = "Look back period for Lower lows and Higher highes",    group = "Lower lows and Higher highes")
show_LL_HH  =   input.bool  (defval = false,    title = "Show Lower lows and Higher highes chart",              group = "Lower lows and Higher highes")
 
lowest = ta.lowest(low, lookback)
var float b = lowest
 
if lowest[1] < lowest
    b := b
else if lowest[1] > lowest
    b := lowest
 
highest = ta.highest(high,lookback)
var float c = highest
 
if highest[1] < highest
    c := highest
else if highest[1] > highest
    c := c
    
var float d = c
 
if c[1] < c
    d := c
else if c[1] > c
    d := d
    
var float e = d
 
if d[1] <= d
    e := d
else if d[1] >= d
    e := e
 
gap_p = math.abs((b - c)*100/c)
 
var float saf = 0
if gap_p >= 10
    saf := 1 + gap_p/100
else if gap_p < 10 and gap_p > 2
    saf :=  (1 + gap_p/100)
else if gap_p <= 2
    saf := na
 
bool buy = ta.cross(b,low) and b[1] > b //and b[2] > b[1]
bool sell = ta.cross(high,e) or ta.cross(e,close) or ta.cross(open,e) or ta.cross(low,e)
 
var float signal = 0
 
if buy == true
    signal := 1
else if signal == 1 and ((open > close) or (open[2] > close))
    signal := 2
else if signal == 2 and (open < close)
    signal := 3
else if signal == 3 and ((open < close) or (open > close))
    signal := 0
else 
    signal := 0
 
sma = ta.sma(close,9)
 
middle = ta.sma(close,500)
l1_cross = ta.cross(sma,strategy.position_avg_price*0.98)
l2_cross = ta.cross(sma,strategy.position_avg_price*0.9)
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////TRADING ARRANGEMENT//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
//Fund management
 
var float int_val_3 = 0
var float installment_2 = 0
var float installment_3 = 0
var float installment_4 = 0
var float r_f = 0
var float int_val = 0
 
if int_cap * int_val_prc/1000 <= 15 and int_val_allocation != "USDT"
    int_val := 15
if int_val_prc <= 15 and int_val_allocation == "USDT"
    int_val := 15
if int_cap * int_val_prc/1000 > 15 and int_val_allocation != "USDT"
    int_val := int_cap * int_val_prc/1000
if int_val_prc > 15 and int_val_allocation == "USDT"
    int_val := int_val_prc
    
r_change = 0.001
    
for i = 0 to piramiding+2 by 1
    if i == 0
        int_val_3 := int_val
    if i <= piramiding
        installment_2 := int_val_3*math.pow((1 + r/100),i)
    if i >= 0 and i < piramiding+1
        installment_3 := installment_3 + installment_2
    if i == piramiding+1
        installment_4 := installment_3 - installment_3[1]
 
if installment_4 < int_cap
    r := r + r_change
else if installment_4 > int_cap
    r := r - r_change
else 
    r := r
    
if r[1] < r
    r_f := r[1] 
 
plot(r_f, title = "Calculated R value")
 
 
// Buy and Sell lavels based on Indicators
gh_val_rsi = input.int  (defval = 50, title = "Higher value of RSI",    maxval = 100, minval = 0, step = 10, group = 'Indicator Higher Values')
gh_val_rvi = input.int  (defval = 50, title = "Higher value of RVI",    maxval = 100, minval = 0, step = 10, group = 'Indicator Higher Values')
gh_val_mfi = input.int  (defval = 50, title = "Higher value of MFI",    maxval = 100, minval = 0, step = 10, group = 'Indicator Higher Values')
gh_val_bop = input.int  (defval = 50, title = "Higher value of BOP",    maxval = 100, minval = 0, step = 10, group = 'Indicator Higher Values')
 
l_val_rsi = input.int   (defval = 50, title = "Lower value of RSI",     maxval = 100, minval = 0, step = 10, group = 'Indicator Lower Values')
l_val_rvi = input.int   (defval = 50, title = "Lower value of RVI",     maxval = 100, minval = 0, step = 10, group = 'Indicator Lower Values')
l_val_mfi = input.int   (defval = 50, title = "Lower value of MFI",     maxval = 100, minval = 0, step = 10, group = 'Indicator Lower Values')
l_val_bop = input.int   (defval = 50, title = "Lower value of BOP",     maxval = 100, minval = 0, step = 10, group = 'Indicator Lower Values')
 
//Identify general market bottoms
buy_rsi = p_rsi_100 <= l_val_rsi and p_rsi_50<p_rsi_100 and p_rsi<=p_rsi_50
buy_rvi = p_rvi_100 <= l_val_rvi and p_rvi_50<=p_rvi_100 and p_rvi_10<=p_rvi_50
buy_mfi = p_mfi_100 <= l_val_mfi and p_mfi_50<=p_mfi_100 and p_mfi_10<=p_mfi_50
buy_bop = bop_sma_100 <= l_val_bop
 
buy_compound = buy_rsi and buy_rvi and buy_mfi and buy_bop ? 100 : 0
 
// Identify critical bottoms
cb_rsi = p_rsi_100 <= 30 and p_rsi_50<p_rsi_100 and p_rsi<=p_rsi_50
cb_rvi = p_rvi_100 <= 30 and p_rvi_50<=p_rvi_100 and p_rvi_10<=p_rvi_50
cb_mfi = p_mfi_100 <= 30 and p_mfi_50<=p_mfi_100 and p_mfi_10<=p_mfi_50
cb_bop = bop_sma_100 <= 50
 
cb_compound = cb_rsi and cb_rvi and cb_mfi and cb_bop ? 100 : 0
 
//Identify critical market ups
hh_rsi = p_rsi_100 >= 60 and p_rsi_50 > p_rsi_100 and p_rsi >= p_rsi_50
hh_rvi = p_rvi_100 >= 60 and p_rvi_50 >= p_rvi_100 and p_rvi_10 >= p_rvi_50
hh_mfi = p_mfi_100 >= 60 and p_mfi_50 >= p_mfi_100 and p_mfi_10 >= p_mfi_50
hh_bop = bop_sma_100 >= 60
 
hh_compund = hh_rsi and hh_rvi and hh_mfi and hh_bop ? 100:0
 
//Identify general market ups
gh_rsi = p_rsi_100 >= gh_val_rsi and p_rsi_50 > p_rsi_100 and p_rsi >= p_rsi_50
gh_rvi = p_rvi_100 >= gh_val_rvi  and p_rvi_50 >= p_rvi_100 and p_rvi_10 >= p_rvi_50
gh_mfi = p_mfi_100 >= gh_val_mfi  and p_mfi_50 >= p_mfi_100 and p_mfi_10 >= p_mfi_50
gh_bop = bop_sma_100 >= gh_val_bop 
 
gh_compund = gh_rsi and gh_rvi and gh_mfi and gh_bop ? 100:0
 
var float  buy_compound_f = na
if (buy_compound[1] == 100 and buy_compound == 0) //and open > close
    buy_compound_f := 1
else 
    buy_compound_f := na
 
ma_9 = ta.sma(low,1)
ma_10 = ta.sma(close,9)
ma_10_f = ta.falling(ma_10,4)
ma_10_r = ta.rising(ma_10,5)
 
co_l1 = strategy.position_avg_price*0.95
co_l2 = strategy.position_avg_price*0.90
co_l3 = strategy.position_avg_price*0.85
co_l4 = strategy.position_avg_price*0.80
 
sell_l1 = strategy.position_avg_price*1.15
sell_l2 = strategy.position_avg_price*1.20
sell_l3 = strategy.position_avg_price*1.25
sell_l4 = strategy.position_avg_price*1.30
 
crosover_f = ta.crossunder(low, co_l1) or ta.crossunder(low, co_l2) or ta.crossunder(low, co_l3) or ta.crossunder(low, co_l4) 
change_close = ((close - close[1])/close)*100
 
sell_l1_f = ta.crossover(ma_9, sell_l1)
sell_l2_f = ta.crossover(ma_9, sell_l2)
sell_l3_f = ta.crossover(ma_9, sell_l3)
sell_l4_f = ta.crossover(ma_9, sell_l4)
 
// Uptrend & Downtrend filters
upt_f = close>ta.sma(close,500)
dt_f = close<ta.sma(close,2000)
 
//Purchasing Quantity
var float assert = int_cap
var float quantity = 0
var float income = 0
//var float expence = 0
var float cash_in_hand = 0
 
//Calculation of Cumilative Profit and Assert
t_profit = 0.
expence = 0.
cost = 0.0
 
for i = 0 to strategy.closedtrades - 1
    entryP = strategy.closedtrades.entry_price(i)
    exitP = strategy.closedtrades.exit_price(i)
    commission = strategy.closedtrades.commission(i)
    t_profit += ((exitP - entryP ) * strategy.closedtrades.size(i)) - commission
    expence  += ((entryP + commission) * strategy.closedtrades.size(i))
 
var float entryP_2 = 0
if strategy.position_size > 0
    for i = 0 to 0
        entryP_2 := strategy.closedtrades.exit_price(i)
        cost += strategy.closedtrades.entry_price(i) * strategy.closedtrades.size(i)
profit_f2 = strategy.closedtrades >= 0 ? t_profit : na
 
var float addition = 0
if profit_f2[1] < profit_f2
    addition := (profit_f2 - profit_f2[1])
else
    addition := 0
    
var float realised_profit = 0
if (profit_f2[1] < profit_f2) or (profit_f2[1] > profit_f2)
    realised_profit := (profit_f2 - profit_f2[1])
 
if strategy.position_size[1] > 0 and strategy.position_size == 0
    assert := assert + addition
    
//Take profit in Market ups and bottoms
profit_f = 1.0 + (profit_cal/100)
stop_loss = 1.0 - (stop_loss_cal/100)
 
// intermediate sell profit ajusment
var float prc_change = 0
 
if (strategy.position_size[1] < strategy.position_size) and strategy.position_size[1] == 0
    prc_change := strategy.position_avg_price * profit_f 
if (strategy.position_size[1] < strategy.position_size) and strategy.position_size > 0 
    prc_change := strategy.position_avg_price * profit_f 
if (strategy.position_size[1] > strategy.position_size) and strategy.position_size > 0 
    prc_change := prc_change 
if strategy.position_size == 0
    prc_change := na
 
sell_crossunder = ta.crossunder(low, strategy.position_avg_price * profit_f) 
force_sell = ta.crossunder(low, strategy.position_avg_price * stop_loss)
    
//Calculation of Quantities to purchase
var int factor = 0
if (strategy.position_size[1] == 0 and strategy.position_size > 0) or (strategy.position_size [1] < strategy.position_size)
    factor := factor + 1
else if strategy.position_size[1] > 0 and strategy.position_size == 0
    factor := 0
 
var float assert_prc = 0
if int_val_allocation == "USDT"
    assert_prc := int_val_prc / int_cap
if int_val_allocation == "% of cumilative investment"
    assert_prc := int_val_prc/1000
    
var float assert_f = 0
var float in_cap = 0
if strategy.position_size == 0
    assert_f := assert
    in_cap := assert_prc * assert_f
else
    assert_f := assert_f
 
inceiment = inceiment_1/100
 
//formula = (1 + r)^n, r= inceiment
var float value = 0
 
if (strategy.opentrades == 0) 
    value := in_cap
else if (strategy.opentrades [1] < strategy.opentrades) or ((strategy.opentrades[1] > strategy.opentrades) and strategy.position_size >0)
    value := in_cap * math.pow((1+inceiment),factor)
else if (strategy.position_size[1] > 0 and strategy.position_size == 0)
    value := value
 
// Calculate total value of current invesment
var float cash_invest = 0
if strategy.position_size [1] < strategy.position_size or strategy.position_size [1] > strategy.position_size
    cash_invest := cash_invest + strategy.position_avg_price * (strategy.position_size - strategy.position_size[1])
else if strategy.position_size == 0
    cash_invest := 0
    
// cooldown time
var bool cd = false
if strategy.position_size[10] > 0 or strategy.position_size[9] > 0 or strategy.position_size[8] > 0 or strategy.position_size[7] > 0 or strategy.position_size[6] > 0 or strategy.position_size[5] > 0 or strategy.position_size[4] > 0 or strategy.position_size[3] > 0 or strategy.position_size[2] > 0 or strategy.position_size[1] > 0
    cd := true
else 
    cd := false
    
if (piramiding +1) > strategy.opentrades and (cash_invest + value) <= assert
    quantity := (value)/low[1]
else if (piramiding +1) > strategy.opentrades and (cash_invest + value) > assert
    quantity := (assert - cash_invest)/open
else 
    quantity := 0
 
// Calculate sell quantity
// defalt selling arrangement is 10 times, first short position is 5% of st. position size and increment is 11.4% 
var int sell_fac = 0
var float h_qty = 0
if (strategy.position_size [1] > strategy.position_size)
    sell_fac := sell_fac + 2
    h_qty := h_qty
else if (strategy.position_size [1] < strategy.position_size)
    sell_fac := 0
    h_qty := strategy.position_size[1] + (strategy.position_size - strategy.position_size[1])
else if strategy.position_size == 0
    h_qty := strategy.position_size
    
val = close[1]
var float sell_qty = 0.0
if (val * h_qty * (sell_qty_prc/100) * math.pow(1.114,sell_fac)) > 10
    sell_qty := h_qty * (sell_qty_prc/100) * math.pow(1.114,sell_fac)
else if val * h_qty * (sell_qty_prc/100)*math.pow(1.114,sell_fac) < 10
    sell_qty := strategy.position_size
// or second option to purchase qty
min_qty = sell_qty_prc/close[1]
 
var float qty_f = 0
if prc_or_usdt == "USDT"
    qty_f := min_qty
else
    qty_f := sell_qty
 
// Trading 
var float limit = strategy.position_avg_price * profit_f
 
//Enter Coustom comand to perform buy and sell actions link with webhook
string buy_comment      =   "BUY" 
string sell_comment     =   "SELL" 
 
if ((signal == 2 or buy_compound_f ==1)) and window() and cd == false and strategy.position_size == 0
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
else if ((buy_compound_f ==1 or crosover_f or (b1 ==1 or b2 ==1 or b3==1))  and ma_9 < strategy.position_avg_price *.99 and window() and  strategy.position_size > 0 and ma_10_f) 
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
else if signal == 2 and high[1] < strategy.position_avg_price and strategy.position_size >= 1
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
    
else if (comp_sell1 or op_sell1 or op_sell2 or op_sell3 or op_sell4 or sell_crossunder) and window() and prc_change < ma_9 and strategy.opentrades >= 8 
    strategy.close("long", comment = sell_comment)
else if (gh_compund ==100) and window() and prc_change < ma_9 and strategy.opentrades < 8
    strategy.close("long", comment = sell_comment)
else if force_sell and strategy.opentrades >= piramiding*0.9 and enable_stoploss == true
    strategy.close("long", comment = sell_comment)
else if ((close > strategy.position_avg_price) or gh_compund ==100 )and cd == false and enable_int_profit == true
    strategy.exit("long stop", "long", profit = prc_change, qty = qty_f, comment = sell_comment)
 
//Graphs
bool PM_visible                 = input(true,   "Show Expected Profit, Stop Loss and Average Cost",         group = 'Safty Margins')
bool SM_visible                 = input(false,  "Show Safty Grids",                                         group = 'Safty Margins')
bool gmb_visible                = input(true,   "Show General Market Ups and Bottoms",                      group = 'Indicators')
bool cmb_visible                = input(true,   "Show Critical Market Ups and Bottoms",                     group = 'Indicators')
bool profit_f2_visible          = input(false,  "Show Cumilative Profit (USDT) Graph",                      group = 'Graphs')
bool cash_invest_visible        = input(false,  "Show Total Value of Current Invesment (USDT) Graph",       group = 'Graphs')
bool realised_profit_visible    = input(false,  "Show Last realised profit (USDT Graph",                    group = 'Graphs')
bool assert_visible             = input(false,  "Show Cumilative Assert (USDT)Graph",                       group = 'Graphs')
 
color_1 = color.blue
color_2 = color.blue
color_3 = color.blue
color_4 = color.blue
 
if profit_f2_visible == true
    color_1 := color.new(#e6d32a,0)
else
    color_1 := color.new(color.blue,100)
    
if realised_profit_visible == true
    color_2 := color.new(color.blue,0)
else
    color_2 := color.new(color.blue,100)
 
if cash_invest_visible == true
    color_3 := color.new(color.maroon,0)
else
    color_3 := color.new(color.blue,100)
    
if assert_visible == true
    color_4 := color.new(color.blue,0)
else
    color_4 := color.new(color.blue,100)    
    
var max_open_trades = 0
if strategy.opentrades > max_open_trades
    max_open_trades := strategy.opentrades
else
    max_open_trades := max_open_trades
 
plot(PM_visible ? strategy.position_avg_price : na,                                                             color = color.green,    title = "Average Cost",             style = plot.style_circles)
plot(PM_visible ? prc_change:na,                                                                                color = color.olive,    title = "Expected Profit Level",    style = plot.style_circles)
plot(PM_visible and strategy.opentrades >= piramiding*0.9 ? strategy.position_avg_price * stop_loss  : na,      color = color.red,      title = "Stop Loss%",               style = plot.style_circles)
 
plot(ST_visible ? down_trend:na,                                        color = plotcolor2,     title = "Down Trend",           linewidth=1)
plot(ST_visible ? up_trend: na ,                                        color = plotcolor3,     title = "Up Trend",             linewidth=1)
plot(sar_visible ? sar:na,                                              color = plotcolor4,     title = 'SAR',                  linewidth=1)
plot(sma500_visible ? SMA500:na,                                        color = plotcolor5,     title = 'SMA500',               linewidth=2)
plot(show_LL_HH == true ? b:na,                                         color = color.orange,   title = "Lower lows" )
plot(show_LL_HH == true ? e:na,                                         color = color.white,    title = "Higher highes")
 
plot(profit_f2,                                                         color = color_1,      linewidth = 4,    style = plot.style_stepline_diamond,        title = "Cumilative Profit (USDT)")
plot(realised_profit,                                                   color = color_2,                                                                    title = "Last realised profit (USDT)")
plot(cash_invest,                                                       color = color_3,      linewidth = 4,    style = plot.style_stepline_diamond,        title = "Total Value of Current Invesment (USDT)")
plot(assert,                                                            color = color_4,                                                                    title = "Cumilative Assert (USDT)")
 
plot(value,                                                             color = color.new(color.white,100),     title = "Value of next Purchase (USDT)")
plot(quantity,                                                          color = color.new(color.white,100),     title = "Quantity to be Purchase")
plot(strategy.opentrades,                                               color = color.new(color.white,100),     title = "Count of Open Trades")
plot(max_open_trades,                                                   color = color.new(color.green,100),     title = "Maximum Count of Open Trades")
plot(strategy.position_size,                                            color = color.new(color.white,100),     title = "Strategy Position Size")
 
//Labels
plotshape((buy_compound_f   ==1     and ma_9 < strategy.position_avg_price and gmb_visible == true),            style =  shape.arrowdown, color = color.new(color.yellow,50),     size = size.large,      text = "GB",                            title = "GB Label")
plotshape((gh_compund       ==100   and ma_9 > strategy.position_avg_price* profit_f and gmb_visible == true),  style =  shape.arrowdown, color = color.new(color.green,50),      size = size.large,      text = "GU",                            title = "GU Label")
plotshape((cb_compound      ==100   and ma_9 < strategy.position_avg_price and cmb_visible == true),            style =  shape.labeldown, color = color.new(color.green,90),      size = size.normal,     text = "DN", textcolor = color.white,   title = "DN Label")
plotshape((hh_compund       ==100   and cmb_visible == true),                                                   style =  shape.labeldown, color = color.new(color.red,90),        size = size.normal,     text = "UP", textcolor = color.white,   title = "UP Label")
//color.new(color, transp)
 
//Table
var tbl = table.new(position.top_right, 2, 9, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.white, 100))
//column values
table.cell(tbl, 0,0, text = "Cumilative profit (USDT)",                                                 text_color = color.white,       text_halign = text.align_left,      text_valign  = text.align_center, bgcolor = color.green)
table.cell(tbl, 0,1, text = "Cumilative assert (USDT)",                                                 text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,2, text = "Average cost (USDT)",                                                      text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,3, text = "Expected profit (USDT)",                                                   text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,4, text = "Current investment (USDT)",                                                text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,5, text = "Next purchase (USDT)",                                                     text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,6, text = "Count of open trades",                                                     text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,7, text = "Strategy position Size",                                                   text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
    
table.cell(tbl, 1,0, str.tostring(profit_f2, format.mintick),                                           text_color = color.white,       text_halign = text.align_right,     text_valign  = text.align_center, bgcolor = color.green)
table.cell(tbl, 1,1, str.tostring(assert, format.mintick),                                              text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,2, str.tostring(strategy.position_avg_price, format.mintick),                         text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,3, str.tostring((strategy.position_avg_price * profit_f), format.mintick),            text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,4, str.tostring(cash_invest, format.mintick), text_color = color.red,                 text_halign = text.align_right, text_valign  = text.align_center)
table.cell(tbl, 1,5, str.tostring(value, format.mintick), text_color = color.red,                       text_halign = text.align_right, text_valign  = text.align_center)
table.cell(tbl, 1,6, str.tostring(strategy.opentrades, format.mintick), text_color = color.red,         text_halign = text.align_right, text_valign  = text.align_center)
table.cell(tbl, 1,7, str.tostring(strategy.position_size, format.mintick), text_color = color.red,      text_halign = text.align_right, text_valign  = text.align_center)

← 返回列表