松书+策略+金字塔+不同的TP + SL +数量

时间:2020-05-09 02:51:01

标签: pine-script

我尝试编写一种策略,该策略允许对每个订单进行多个止盈,一个止损和不同数量的数量的金字塔。

下面的代码正确下订单,但同一水平的止盈是同时进行的。但是我阅读并验证我的代码主要是为了确认没有歧义。

https://imgur.com/dQSQhYj

任何帮助都欢迎您! 代码的第二部分和第三部分在下一条注释中。

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

//@version=4
strategy("TestStrat", overlay=true, pyramiding = 1000, initial_capital=10000, currency="EUR", calc_on_order_fills=true, slippage = 2, calc_on_every_tick=true)

// === INPUT DATE RANGE ===
fromMonth  = input(defval = 1,       title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay    = input(defval = 1,       title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear   = input(defval = 2020,    title = "From Year",       type = input.integer, minval = 1970)
thruMonth  = input(defval = 5,       title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay    = input(defval = 11,       title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear   = input(defval = 2020,    title = "Thru Year",       type = input.integer, minval = 1970)

// === DATE & TIME RANGE FUNCTIONS ===
isDate() =>                                                      // create function "within window of dates"
    start  = timestamp(fromYear, fromMonth, fromDay, 00, 00)     // date start
    finish = timestamp(thruYear, thruMonth, thruDay, 23, 59)     // date finish
    isDate = time >= start and time <= finish                    // current date is "within window of dates"

MA200 = ema(close,200)

///////////////////////// BB

[middle25, upper25, lower25] = bb(close, 20, 2.49)
[middle2, upper2, lower2] = bb(close, 20, 2)

//////////////////////////// ichimoku

conversionPeriods = input(9, minval=1, title="Conversion Line Periods"),
basePeriods = input(26, minval=1, title="Base Line Periods")
laggingSpan2Periods = input(52, minval=1, title="Lagging Span 2 Periods"),
displacement = input(26, minval=1, title="Displacement")

donchian(len) => avg(lowest(len), highest(len))

conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

//////////////////////////// Linear Reg

length = input(5),src = input(close)
//----
n = bar_index
ts = linreg(src,length,1)
upts = ts > ts[1]
downts = ts < ts[1]

///////// Price Conditions

CurrentCloseGreen = open < close  
CurrentCloseRed = open > close
CurrentFlat = open == close

BarPrecGreen = open[1] < close[1] 
BarPrecRed = open[1] > close[1]

Spreadsl = ((syminfo.mintick*15)*2)

/////////////////////////////Order Conditions

UpFlag = CurrentCloseGreen and upts
slUF = low - ((low-lower25)+Spreadsl)
tp1UF = high + ((close-low+Spreadsl)*1)
tp2UF = high + ((close-low+Spreadsl)*2)
tp3UF = high + ((close-low+Spreadsl)*3)
tp4UF = high + ((close-low+Spreadsl)*4)
tp5UF = high + ((close-low+Spreadsl)*5)
tp20UF = high + ((close-low+Spreadsl)*30)
if UpFlag
    label.new(bar_index, na, yloc=yloc.belowbar, color=color.purple, style=label.style_labelup, size=size.auto,
          text=("UpFlag" + "\nStopLoss=" + tostring(slUF) + "\nTP1=" + tostring(tp1UF) + "\nTP2=" + tostring(tp2UF) + "\nTP3=" + tostring(tp3UF)))

DownFlag = CurrentCloseRed and downts
slDF = high + ((upper25-high)+Spreadsl)
tp1DF = low - ((high-close+Spreadsl)*1)
tp2DF = low - ((high-close+Spreadsl)*2)
tp3DF = low - ((high-close+Spreadsl)*3)
tp4DF = low - ((high-close+Spreadsl)*4)
tp5DF = low - ((high-close+Spreadsl)*5)
tp20DF = low - ((high-close+Spreadsl)*30)
if DownFlag 
    label.new(bar_index, na, yloc=yloc.abovebar, color=color.purple, style=label.style_labeldown, size=size.auto,
          text=("DownFlag" + "\nStopLoss=" + tostring(slDF) + "\nTP1=" + tostring(tp1DF) + "\nTP2=" + tostring(tp2DF) + "\nTP3=" + tostring(tp3DF)))
//------------------------------------------------------------------------------------------------------------------------------------//

PipsValue = 0.09
Margin = 33.3
AmountAccountRiskPerPos = (strategy.initial_capital + strategy.netprofit) * 0.01

PipsRiskUF = (tp1UF-slUF)/10/2
PipsRiskDF = (slDF - tp1DF)/10/2

NbslUFContract = round(AmountAccountRiskPerPos / (PipsRiskUF * PipsValue))
NbUFContractToCloseTP1 = round(NbslUFContract * 0.11) - 1
NbUFContractToCloseTP2 = round(NbUFContractToCloseTP1 * 0.12) - 1
NbUFContractToCloseTP3 = round(NbUFContractToCloseTP2 * 0.13) - 1
NbUFContractToCloseTP4 = round(NbUFContractToCloseTP3 * 0.14) - 1
NbUFContractToCloseTP5 = round(NbUFContractToCloseTP4 * 0.15) - 1
NbUFContractToCloseTP20 = NbUFContractToCloseTP5 - 1

NbslDFContract = round(AmountAccountRiskPerPos / (PipsRiskDF * PipsValue))
NbDFContractToCloseTP1 = round(NbslDFContract * 0.11) - 1
NbDFContractToCloseTP2 = round(NbDFContractToCloseTP1 * 0.12) - 1
NbDFContractToCloseTP3 = round(NbDFContractToCloseTP2 * 0.13) - 1
NbDFContractToCloseTP4 = round(NbDFContractToCloseTP3 * 0.14) - 1
NbDFContractToCloseTP5 = round(NbDFContractToCloseTP4 * 0.15) - 1
NbDFContractToCloseTP20 = round(NbDFContractToCloseTP5) - 1

// To save pyramiding state
var float longPyramiding1          = 0
var float longPyramiding2          = 0
var float longPyramiding3          = 0
var float longPyramiding4          = 0
var float longPyramiding5          = 0
var float longPyramiding6          = 0
var float longPyramiding7          = 0
var float longPyramiding8          = 0
var float longPyramiding9          = 0
var float longPyramiding10         = 0
var float longPyramiding11         = 0
var float longPyramiding12         = 0
var float longPyramiding13         = 0
var float longPyramiding14         = 0
var float longPyramiding15         = 0

var float shortPyramiding1         = 0
var float shortPyramiding2         = 0
var float shortPyramiding3         = 0
var float shortPyramiding4         = 0
var float shortPyramiding5         = 0
var float shortPyramiding6         = 0
var float shortPyramiding7         = 0
var float shortPyramiding8         = 0
var float shortPyramiding9         = 0
var float shortPyramiding10        = 0
var float shortPyramiding11        = 0
var float shortPyramiding12        = 0
var float shortPyramiding13        = 0
var float shortPyramiding14        = 0
var float shortPyramiding15        = 0

// To save time price for each order
var float Order1longtime          = na
var float Order2longtime          = na
var float Order3longtime          = na
var float Order4longtime          = na
var float Order5longtime          = na
var float Order6longtime          = na
var float Order7longtime          = na
var float Order8longtime          = na
var float Order9longtime          = na
var float Order10longtime          = na
var float Order11longtime          = na
var float Order12longtime          = na
var float Order13longtime          = na
var float Order14longtime          = na
var float Order15longtime          = na

var float Order1shorttime         = na
var float Order2shorttime         = na
var float Order3shorttime         = na
var float Order4shorttime         = na
var float Order5shorttime         = na
var float Order6shorttime         = na
var float Order7shorttime         = na
var float Order8shorttime         = na
var float Order9shorttime         = na
var float Order10shorttime         = na
var float Order11shorttime         = na
var float Order12shorttime         = na
var float Order13shorttime         = na
var float Order14shorttime         = na
var float Order15shorttime         = na

// To save Stop Loss level for each order
var float Order1longsl             = na
var float Order2longsl             = na
var float Order3longsl             = na
var float Order4longsl             = na
var float Order5longsl             = na
var float Order6longsl             = na
var float Order7longsl             = na
var float Order8longsl             = na
var float Order9longsl             = na
var float Order10longsl             = na
var float Order11longsl             = na
var float Order12longsl             = na
var float Order13longsl             = na
var float Order14longsl             = na
var float Order15longsl             = na

var float Order1shortsl            = na
var float Order2shortsl            = na
var float Order3shortsl            = na
var float Order4shortsl            = na
var float Order5shortsl            = na
var float Order6shortsl            = na
var float Order7shortsl            = na
var float Order8shortsl            = na
var float Order9shortsl            = na
var float Order10shortsl            = na
var float Order11shortsl            = na
var float Order12shortsl            = na
var float Order13shortsl            = na
var float Order14shortsl            = na
var float Order15shortsl            = na

// To save init of Take Profit for each order at different level
//long
var float Order1longtp1          = na
var float Order1longtp2          = na
var float Order1longtp3          = na
var float Order1longtp4          = na
var float Order1longtp5          = na
var float Order1longtp20         = na

var float Order2longtp1          = na
var float Order2longtp2          = na
var float Order2longtp3          = na
var float Order2longtp4          = na
var float Order2longtp5          = na
var float Order2longtp20         = na

var float Order3longtp1          = na
var float Order3longtp2          = na
var float Order3longtp3          = na
var float Order3longtp4          = na
var float Order3longtp5          = na
var float Order3longtp20          = na

var float Order4longtp1          = na
var float Order4longtp2          = na
var float Order4longtp3          = na
var float Order4longtp4          = na
var float Order4longtp5          = na
var float Order4longtp20          = na

var float Order5longtp1          = na
var float Order5longtp2          = na
var float Order5longtp3          = na
var float Order5longtp4          = na
var float Order5longtp5          = na
var float Order5longtp20          = na

var float Order6longtp1          = na
var float Order6longtp2          = na
var float Order6longtp3          = na
var float Order6longtp4          = na
var float Order6longtp5          = na
var float Order6longtp20          = na

var float Order7longtp1          = na
var float Order7longtp2          = na
var float Order7longtp3          = na
var float Order7longtp4          = na
var float Order7longtp5          = na
var float Order7longtp20          = na

var float Order8longtp1          = na
var float Order8longtp2          = na
var float Order8longtp3          = na
var float Order8longtp4          = na
var float Order8longtp5          = na
var float Order8longtp20          = na

var float Order9longtp1          = na
var float Order9longtp2          = na
var float Order9longtp3          = na
var float Order9longtp4          = na
var float Order9longtp5          = na
var float Order9longtp20          = na

var float Order10longtp1          = na
var float Order10longtp2          = na
var float Order10longtp3          = na
var float Order10longtp4          = na
var float Order10longtp5          = na
var float Order10longtp20          = na

var float Order11longtp1          = na
var float Order11longtp2          = na
var float Order11longtp3          = na
var float Order11longtp4          = na
var float Order11longtp5          = na
var float Order11longtp20          = na

var float Order12longtp1          = na
var float Order12longtp2          = na
var float Order12longtp3          = na
var float Order12longtp4          = na
var float Order12longtp5          = na
var float Order12longtp20          = na

var float Order13longtp1          = na
var float Order13longtp2          = na
var float Order13longtp3          = na
var float Order13longtp4          = na
var float Order13longtp5          = na
var float Order13longtp20          = na

var float Order14longtp1          = na
var float Order14longtp2          = na
var float Order14longtp3          = na
var float Order14longtp4          = na
var float Order14longtp5          = na
var float Order14longtp20          = na

var float Order15longtp1          = na
var float Order15longtp2          = na
var float Order15longtp3          = na
var float Order15longtp4          = na
var float Order15longtp5          = na
var float Order15longtp20          = na

// short
var float Order1shorttp1         = na
var float Order1shorttp2         = na
var float Order1shorttp3         = na
var float Order1shorttp4         = na
var float Order1shorttp5         = na
var float Order1shorttp20        = na

var float Order2shorttp1         = na
var float Order2shorttp2         = na
var float Order2shorttp3         = na
var float Order2shorttp4         = na
var float Order2shorttp5         = na
var float Order2shorttp20         = na

var float Order3shorttp1         = na
var float Order3shorttp2         = na
var float Order3shorttp3         = na
var float Order3shorttp4         = na
var float Order3shorttp5         = na
var float Order3shorttp20         = na

var float Order4shorttp1         = na
var float Order4shorttp2         = na
var float Order4shorttp3         = na
var float Order4shorttp4         = na
var float Order4shorttp5         = na
var float Order4shorttp20         = na

var float Order5shorttp1         = na
var float Order5shorttp2         = na
var float Order5shorttp3         = na
var float Order5shorttp4         = na
var float Order5shorttp5         = na
var float Order5shorttp20         = na

// To save init of position size for each order at different level
//Long
var float Order1longsize0          = na
var float Order1longsize1          = na
var float Order1longsize2          = na
var float Order1longsize3          = na
var float Order1longsize4          = na
var float Order1longsize5          = na
var float Order1longsize20         = na

var float Order2longsize0          = na
var float Order2longsize1          = na
var float Order2longsize2          = na
var float Order2longsize3          = na
var float Order2longsize4          = na
var float Order2longsize5          = na
var float Order2longsize20          = na

var float Order3longsize0          = na
var float Order3longsize1          = na
var float Order3longsize2          = na
var float Order3longsize3          = na
var float Order3longsize4          = na
var float Order3longsize5          = na
var float Order3longsize20          = na

var float Order4longsize0          = na
var float Order4longsize1          = na
var float Order4longsize2          = na
var float Order4longsize3          = na
var float Order4longsize4          = na
var float Order4longsize5          = na
var float Order4longsize20          = na

var float Order5longsize0          = na
var float Order5longsize1          = na
var float Order5longsize2          = na
var float Order5longsize3          = na
var float Order5longsize4          = na
var float Order5longsize5          = na
var float Order5longsize20          = na

var float Order6longsize0          = na
var float Order6longsize1          = na
var float Order6longsize2          = na
var float Order6longsize3          = na
var float Order6longsize4          = na
var float Order6longsize5          = na
var float Order6longsize20          = na

var float Order7longsize0          = na
var float Order7longsize1          = na
var float Order7longsize2          = na
var float Order7longsize3          = na
var float Order7longsize4          = na
var float Order7longsize5          = na
var float Order7longsize20          = na

var float Order8longsize0          = na
var float Order8longsize1          = na
var float Order8longsize2          = na
var float Order8longsize3          = na
var float Order8longsize4          = na
var float Order8longsize5          = na
var float Order8longsize20          = na

var float Order9longsize0          = na
var float Order9longsize1          = na
var float Order9longsize2          = na
var float Order9longsize3          = na
var float Order9longsize4          = na
var float Order9longsize5          = na
var float Order9longsize20          = na

var float Order10longsize0          = na
var float Order10longsize1          = na
var float Order10longsize2          = na
var float Order10longsize3          = na
var float Order10longsize4          = na
var float Order10longsize5          = na
var float Order10longsize20          = na

var float Order11longsize0          = na
var float Order11longsize1          = na
var float Order11longsize2          = na
var float Order11longsize3          = na
var float Order11longsize4          = na
var float Order11longsize5          = na
var float Order11longsize20          = na

var float Order12longsize0          = na
var float Order12longsize1          = na
var float Order12longsize2          = na
var float Order12longsize3          = na
var float Order12longsize4          = na
var float Order12longsize5          = na
var float Order12longsize20          = na

var float Order13longsize0          = na
var float Order13longsize1          = na
var float Order13longsize2          = na
var float Order13longsize3          = na
var float Order13longsize4          = na
var float Order13longsize5          = na
var float Order13longsize20          = na

var float Order14longsize0          = na
var float Order14longsize1          = na
var float Order14longsize2          = na
var float Order14longsize3          = na
var float Order14longsize4          = na
var float Order14longsize5          = na
var float Order14longsize20          = na

var float Order15longsize0          = na
var float Order15longsize1          = na
var float Order15longsize2          = na
var float Order15longsize3          = na
var float Order15longsize4          = na
var float Order15longsize5          = na
var float Order15longsize20          = na

//Short
var float Order1shortsize0         = na
var float Order1shortsize1         = na
var float Order1shortsize2         = na
var float Order1shortsize3         = na
var float Order1shortsize4         = na
var float Order1shortsize5         = na
var float Order1shortsize20         = na

var float Order2shortsize0         = na
var float Order2shortsize1         = na
var float Order2shortsize2         = na
var float Order2shortsize3         = na
var float Order2shortsize4         = na
var float Order2shortsize5         = na
var float Order2shortsize20         = na

var float Order3shortsize0         = na
var float Order3shortsize1         = na
var float Order3shortsize2         = na
var float Order3shortsize3         = na
var float Order3shortsize4         = na
var float Order3shortsize5         = na
var float Order3shortsize20         = na

var float Order4shortsize0         = na
var float Order4shortsize1         = na
var float Order4shortsize2         = na
var float Order4shortsize3         = na
var float Order4shortsize4         = na
var float Order4shortsize5         = na
var float Order4shortsize20         = na

var float Order5shortsize0         = na
var float Order5shortsize1         = na
var float Order5shortsize2         = na
var float Order5shortsize3         = na
var float Order5shortsize4         = na
var float Order5shortsize5         = na
var float Order5shortsize20         = na

var float Order6shortsize0         = na
var float Order6shortsize1         = na
var float Order6shortsize2         = na
var float Order6shortsize3         = na
var float Order6shortsize4         = na
var float Order6shortsize5         = na
var float Order6shortsize20         = na

var float Order7shortsize0         = na
var float Order7shortsize1         = na
var float Order7shortsize2         = na
var float Order7shortsize3         = na
var float Order7shortsize4         = na
var float Order7shortsize5         = na
var float Order7shortsize20         = na

var float Order8shortsize0         = na
var float Order8shortsize1         = na
var float Order8shortsize2         = na
var float Order8shortsize3         = na
var float Order8shortsize4         = na
var float Order8shortsize5         = na
var float Order8shortsize20         = na

var float Order9shortsize0         = na
var float Order9shortsize1         = na
var float Order9shortsize2         = na
var float Order9shortsize3         = na
var float Order9shortsize4         = na
var float Order9shortsize5         = na
var float Order9shortsize20         = na

var float Order10shortsize0         = na
var float Order10shortsize1         = na
var float Order10shortsize2         = na
var float Order10shortsize3         = na
var float Order10shortsize4         = na
var float Order10shortsize5         = na
var float Order10shortsize20         = na

var float Order11shortsize0         = na
var float Order11shortsize1         = na
var float Order11shortsize2         = na
var float Order11shortsize3         = na
var float Order11shortsize4         = na
var float Order11shortsize5         = na
var float Order11shortsize20         = na

var float Order12shortsize0         = na
var float Order12shortsize1         = na
var float Order12shortsize2         = na
var float Order12shortsize3         = na
var float Order12shortsize4         = na
var float Order12shortsize5         = na
var float Order12shortsize20         = na

var float Order13shortsize0         = na
var float Order13shortsize1         = na
var float Order13shortsize2         = na
var float Order13shortsize3         = na
var float Order13shortsize4         = na
var float Order13shortsize5         = na
var float Order13shortsize20         = na

var float Order14shortsize0         = na
var float Order14shortsize1         = na
var float Order14shortsize2         = na
var float Order14shortsize3         = na
var float Order14shortsize4         = na
var float Order14shortsize5         = na
var float Order14shortsize20         = na

var float Order15shortsize0         = na
var float Order15shortsize1         = na
var float Order15shortsize2         = na
var float Order15shortsize3         = na
var float Order15shortsize4         = na
var float Order15shortsize5         = na
var float Order15shortsize20         = na

代码的第二部分和第三部分在下一条注释中。

2 个答案:

答案 0 :(得分:0)

第二部分代码:

///////////////////////////////////////////
// fill order info
if (isDate() and UpFlag and longPyramiding1 == 0)
    longPyramiding1 := 1
    if na(Order1longtime)
        Order1longtime := time
    if na(Order1longsl)
        Order1longsl := slUF
    if na(Order1longtp1)
        Order1longtp1 := tp1UF
    if na(Order1longtp2)
        Order1longtp2 := tp2UF
    if na(Order1longtp3)
        Order1longtp3 := tp3UF
    if na(Order1longtp4)
        Order1longtp4 := tp4UF
    if na(Order1longtp5)
        Order1longtp5 := tp5UF
    if na(Order1longtp20)
        Order1longtp20 := tp20UF
    if na(Order1longsize0)
        Order1longsize0 := NbslUFContract
    if na(Order1longsize1)
        Order1longsize1 := NbUFContractToCloseTP1
    if na(Order1longsize2)
        Order1longsize2 := NbUFContractToCloseTP2
    if na(Order1longsize3)
        Order1longsize3 := NbUFContractToCloseTP3
    if na(Order1longsize4)
        Order1longsize4 := NbUFContractToCloseTP4
    if na(Order1longsize5)
        Order1longsize5 := NbUFContractToCloseTP5
    if na(Order1longsize20)
        Order1longsize20 := NbUFContractToCloseTP20
else       
    if (isDate() and UpFlag and longPyramiding1 == 1 and longPyramiding2 == 0)
        longPyramiding2 := 1
        if na(Order2longtime)
            Order2longtime := time
        if na(Order2longsl)
            Order2longsl := slUF
        if na(Order2longtp1)
            Order2longtp1 := tp1UF
        if na(Order2longtp2)
            Order2longtp2 := tp2UF
        if na(Order2longtp3)
            Order2longtp3 := tp3UF
        if na(Order2longtp4)
            Order2longtp4 := tp4UF
        if na(Order2longtp5)
            Order2longtp5 := tp5UF
        if na(Order2longtp20)
            Order2longtp20 := tp20UF
        if na(Order2longsize0)
            Order2longsize0 := NbslUFContract
        if na(Order2longsize1)
            Order2longsize1 := NbUFContractToCloseTP1
        if na(Order2longsize2)
            Order2longsize2 := NbUFContractToCloseTP2
        if na(Order2longsize3)
            Order2longsize3 := NbUFContractToCloseTP3
        if na(Order2longsize4)
            Order2longsize4 := NbUFContractToCloseTP4
        if na(Order2longsize5)
            Order2longsize5 := NbUFContractToCloseTP5
        if na(Order2longsize20)
            Order2longsize20 := NbUFContractToCloseTP20
    else
        if (isDate() and UpFlag and longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 0)
            longPyramiding3 := 1
            if na(Order3longtime)
                Order3longtime := time
            if na(Order3longsl)
                Order3longsl := slUF
            if na(Order3longtp1)
                Order3longtp1 := tp1UF
            if na(Order3longtp2)
                Order3longtp2 := tp2UF
            if na(Order3longtp3)
                Order3longtp3 := tp3UF
            if na(Order3longtp4)
                Order3longtp4 := tp4UF
            if na(Order3longtp5)
                Order3longtp5 := tp5UF
            if na(Order3longtp20)
                Order3longtp20 := tp20UF
            if na(Order3longsize0)
                Order3longsize0 := NbslUFContract
            if na(Order3longsize1)
                Order3longsize1 := NbUFContractToCloseTP1
            if na(Order3longsize2)
                Order3longsize2 := NbUFContractToCloseTP2
            if na(Order3longsize3)
                Order3longsize3 := NbUFContractToCloseTP3
            if na(Order3longsize4)
                Order3longsize4 := NbUFContractToCloseTP4
            if na(Order3longsize5)
                Order3longsize5 := NbUFContractToCloseTP5
            if na(Order3longsize20)
                Order3longsize20 := NbUFContractToCloseTP20
        else
            if (isDate() and UpFlag and longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 1 and longPyramiding4 == 0)
                longPyramiding4 := 1
                if na(Order4longtime)
                    Order4longtime := time
                if na(Order4longsl)
                    Order4longsl := slUF
                if na(Order4longtp1)
                    Order4longtp1 := tp1UF
                if na(Order4longtp2)
                    Order4longtp2 := tp2UF
                if na(Order4longtp3)
                    Order4longtp3 := tp3UF
                if na(Order4longtp4)
                    Order4longtp4 := tp4UF
                if na(Order4longtp5)
                    Order4longtp5 := tp5UF
                if na(Order4longtp20)
                    Order4longtp20 := tp20UF
                if na(Order4longsize0)
                    Order4longsize0 := NbslUFContract
                if na(Order4longsize1)
                    Order4longsize1 := NbUFContractToCloseTP1
                if na(Order4longsize2)
                    Order4longsize2 := NbUFContractToCloseTP2
                if na(Order4longsize3)
                    Order4longsize3 := NbUFContractToCloseTP3
                if na(Order4longsize4)
                    Order4longsize4 := NbUFContractToCloseTP4
                if na(Order4longsize5)
                    Order4longsize5 := NbUFContractToCloseTP5
                if na(Order4longsize20)
                    Order4longsize20 := NbUFContractToCloseTP20
            else
                if (isDate() and UpFlag and longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 1 and longPyramiding4 == 1 and longPyramiding5 == 0)
                    longPyramiding5 := 1
                    if na(Order5longtime)
                        Order5longtime := time
                    if na(Order5longsl)
                        Order5longsl := slUF
                    if na(Order5longtp1)
                        Order5longtp1 := tp1UF
                    if na(Order5longtp2)
                        Order5longtp2 := tp2UF
                    if na(Order5longtp3)
                        Order5longtp3 := tp3UF
                    if na(Order5longtp4)
                        Order5longtp4 := tp4UF
                    if na(Order5longtp5)
                        Order5longtp5 := tp5UF
                    if na(Order5longtp20)
                        Order5longtp20 := tp20UF
                    if na(Order5longsize0)
                        Order5longsize0 := NbslUFContract
                    if na(Order5longsize1)
                        Order5longsize1 := NbUFContractToCloseTP1
                    if na(Order5longsize2)
                        Order5longsize2 := NbUFContractToCloseTP2
                    if na(Order5longsize3)
                        Order5longsize3 := NbUFContractToCloseTP3
                    if na(Order5longsize4)
                        Order5longsize4 := NbUFContractToCloseTP4
                    if na(Order5longsize5)
                        Order5longsize5 := NbUFContractToCloseTP5
                    if na(Order5longsize20)
                        Order5longsize20 := NbUFContractToCloseTP20

//// short
if (isDate() and DownFlag and shortPyramiding1 == 0)
    shortPyramiding1 := 1
    if na(Order1shorttime)
        Order1shorttime := time
    if na(Order1shortsl)
        Order1shortsl := slDF
    if na(Order1shorttp1)
        Order1shorttp1 := tp1DF
    if na(Order1shorttp2)
        Order1shorttp2 := tp2DF
    if na(Order1shorttp3)
        Order1shorttp3 := tp3DF
    if na(Order1shorttp4)
        Order1shorttp4 := tp4DF
    if na(Order1shorttp5)
        Order1shorttp5 := tp5DF
    if na(Order1shorttp20)
        Order1shorttp20 := tp20DF
    if na(Order1shortsize0)
        Order1shortsize0 := NbslDFContract
    if na(Order1shortsize1)
        Order1shortsize1 := NbDFContractToCloseTP1
    if na(Order1shortsize2)
        Order1shortsize2 := NbDFContractToCloseTP2
    if na(Order1shortsize3)
        Order1shortsize3 := NbDFContractToCloseTP3
    if na(Order1shortsize4)
        Order1shortsize4 := NbDFContractToCloseTP4
    if na(Order1shortsize5)
        Order1shortsize5 := NbDFContractToCloseTP5
    if na(Order1shortsize20)
        Order1shortsize20 := NbDFContractToCloseTP20
else
    if (isDate() and DownFlag and shortPyramiding1 == 1 and shortPyramiding2 == 0)
        shortPyramiding2 := 1
        if na(Order2shorttime)
            Order2shorttime := time
        if na(Order2shortsl)
            Order2shortsl := slDF
        if na(Order2shorttp1)
            Order2shorttp1 := tp1DF
        if na(Order2shorttp2)
            Order2shorttp2 := tp2DF
        if na(Order2shorttp3)
            Order2shorttp3 := tp3DF
        if na(Order2shorttp4)
            Order2shorttp4 := tp4DF
        if na(Order2shorttp5)
            Order2shorttp5 := tp5DF
        if na(Order2shorttp20)
            Order2shorttp20 := tp20DF
        if na(Order2shortsize0)
            Order2shortsize0 := NbslDFContract
        if na(Order2shortsize1)
            Order2shortsize1 := NbDFContractToCloseTP1
        if na(Order2shortsize2)
            Order2shortsize2 := NbDFContractToCloseTP2
        if na(Order2shortsize3)
            Order2shortsize3 := NbDFContractToCloseTP3
        if na(Order2shortsize4)
            Order2shortsize4 := NbDFContractToCloseTP4
        if na(Order2shortsize5)
            Order2shortsize5 := NbDFContractToCloseTP5
        if na(Order2shortsize20)
            Order2shortsize20 := NbDFContractToCloseTP20
    else
        if (isDate() and DownFlag and shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 0)
            shortPyramiding3 := 1
            if na(Order3shorttime)
                Order3shorttime := time
            if na(Order3shortsl)
                Order3shortsl := slDF
            if na(Order3shorttp1)
                Order3shorttp1 := tp1DF
            if na(Order3shorttp2)
                Order3shorttp2 := tp2DF
            if na(Order3shorttp3)
                Order3shorttp3 := tp3DF
            if na(Order3shorttp4)
                Order3shorttp4 := tp4DF
            if na(Order3shorttp5)
                Order3shorttp5 := tp5DF
            if na(Order3shorttp20)
                Order3shorttp20 := tp20DF
            if na(Order3shortsize0)
                Order3shortsize0 := NbslDFContract
            if na(Order3shortsize1)
                Order3shortsize1 := NbDFContractToCloseTP1
            if na(Order3shortsize2)
                Order3shortsize2 := NbDFContractToCloseTP2
            if na(Order3shortsize3)
                Order3shortsize3 := NbDFContractToCloseTP3
            if na(Order3shortsize4)
                Order3shortsize4 := NbDFContractToCloseTP4
            if na(Order3shortsize5)
                Order3shortsize5 := NbDFContractToCloseTP5
            if na(Order3shortsize20)
                Order3shortsize20 := NbDFContractToCloseTP20
        else
            if (isDate() and DownFlag and shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 1 and shortPyramiding4 == 0)
                shortPyramiding4 := 1
                if na(Order4shorttime)
                    Order4shorttime := time
                if na(Order4shortsl)
                    Order4shortsl := slDF
                if na(Order4shorttp1)
                    Order4shorttp1 := tp1DF
                if na(Order4shorttp2)
                    Order4shorttp2 := tp2DF
                if na(Order4shorttp3)
                    Order4shorttp3 := tp3DF
                if na(Order4shorttp4)
                    Order4shorttp4 := tp4DF
                if na(Order4shorttp5)
                    Order4shorttp5 := tp5DF
                if na(Order4shorttp20)
                    Order4shorttp20 := tp20DF
                if na(Order4shortsize0)
                    Order4shortsize0 := NbslDFContract
                if na(Order4shortsize1)
                    Order4shortsize1 := NbDFContractToCloseTP1
                if na(Order4shortsize2)
                    Order4shortsize2 := NbDFContractToCloseTP2
                if na(Order4shortsize3)
                    Order4shortsize3 := NbDFContractToCloseTP3
                if na(Order4shortsize4)
                    Order4shortsize4 := NbDFContractToCloseTP4
                if na(Order4shortsize5)
                    Order4shortsize5 := NbDFContractToCloseTP5
                if na(Order4shortsize20)
                    Order4shortsize20 := NbDFContractToCloseTP20
            else
                if (isDate() and DownFlag and shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 1 and shortPyramiding4 == 1 and shortPyramiding5 == 0)
                    shortPyramiding5 := 1
                    if na(Order5shorttime)
                        Order5shorttime := time
                    if na(Order5shortsl)
                        Order5shortsl := slDF
                    if na(Order5shorttp1)
                        Order5shorttp1 := tp1DF
                    if na(Order5shorttp2)
                        Order5shorttp2 := tp2DF
                    if na(Order5shorttp3)
                        Order5shorttp3 := tp3DF
                    if na(Order5shorttp4)
                        Order5shorttp4 := tp4DF
                    if na(Order5shorttp5)
                        Order5shorttp5 := tp5DF
                    if na(Order5shorttp20)
                        Order5shorttp20 := tp20DF
                    if na(Order5shortsize0)
                        Order5shortsize0 := NbslDFContract
                    if na(Order5shortsize1)
                        Order5shortsize1 := NbDFContractToCloseTP1
                    if na(Order5shortsize2)
                        Order5shortsize2 := NbDFContractToCloseTP2
                    if na(Order5shortsize3)
                        Order5shortsize3 := NbDFContractToCloseTP3
                    if na(Order5shortsize4)
                        Order5shortsize4 := NbDFContractToCloseTP4
                    if na(Order5shortsize5)
                        Order5shortsize5 := NbDFContractToCloseTP5
                    if na(Order5shortsize20)
                        Order5shortsize20 := NbDFContractToCloseTP20

// Reset order info
if (longPyramiding1 == 1 and close < Order1longsl)
    longPyramiding1 := 0
    Order1longtime := na
    Order1longsl := na
    Order1longtp1 := na
    Order1longtp2 := na
    Order1longtp3 := na
    Order1longtp4 := na
    Order1longtp5 := na
    Order1longtp20 := na
    Order1longsize0 := na
    Order1longsize1 := na
    Order1longsize2 := na
    Order1longsize3 := na
    Order1longsize4 := na
    Order1longsize5 := na
    Order1longsize20 := na

if (longPyramiding2 == 1 and close < Order2longsl)
    longPyramiding2 := 0
    Order2longtime := na
    Order2longsl := na
    Order2longtp1 := na
    Order2longtp2 := na
    Order2longtp3 := na
    Order2longtp4 := na
    Order2longtp5 := na
    Order2longtp20 := na
    Order2longsize0 := na
    Order2longsize1 := na
    Order2longsize2 := na
    Order2longsize3 := na
    Order2longsize4 := na
    Order2longsize5 := na
    Order2longsize20 := na

if (longPyramiding3 == 1 and close < Order3longsl)
    longPyramiding3 := 0
    Order3longtime := na
    Order3longsl := na
    Order3longtp1 := na
    Order3longtp2 := na
    Order3longtp3 := na
    Order3longtp4 := na
    Order3longtp5 := na
    Order3longtp20 := na
    Order3longsize0 := na
    Order3longsize1 := na
    Order3longsize2 := na
    Order3longsize3 := na
    Order3longsize4 := na
    Order3longsize5 := na
    Order3longsize20 := na

if (longPyramiding4 == 1 and close < Order4longsl)
    longPyramiding4 := 0
    Order4longtime := na
    Order4longsl := na
    Order4longtp1 := na
    Order4longtp2 := na
    Order4longtp3 := na
    Order4longtp4 := na
    Order4longtp5 := na
    Order4longtp20 := na
    Order4longsize0 := na
    Order4longsize1 := na
    Order4longsize2 := na
    Order4longsize3 := na
    Order4longsize4 := na
    Order4longsize5 := na
    Order4longsize20 := na

if (longPyramiding5 == 1 and close < Order5longsl)
    longPyramiding5 := 0
    Order5longtime := na
    Order5longsl := na
    Order5longtp1 := na
    Order5longtp2 := na
    Order5longtp3 := na
    Order5longtp4 := na
    Order5longtp5 := na
    Order5longtp20 := na
    Order5longsize0 := na
    Order5longsize1 := na
    Order5longsize2 := na
    Order5longsize3 := na
    Order5longsize4 := na
    Order5longsize5 := na
    Order5longsize20 := na

if (shortPyramiding1 == 1 and close > Order1shortsl)
    shortPyramiding1 := 0
    Order1shorttime := na
    Order1shortsl := na
    Order1shorttp1 := na
    Order1shorttp2 := na
    Order1shorttp3 := na
    Order1shorttp4 := na
    Order1shorttp5 := na
    Order1shorttp20 := na
    Order1shortsize0 := na
    Order1shortsize1 := na
    Order1shortsize2 := na
    Order1shortsize3 := na
    Order1shortsize4 := na
    Order1shortsize5 := na
    Order1shortsize20 := na

if (shortPyramiding2 == 1 and close > Order2shortsl)
    shortPyramiding2 := 0
    Order2shorttime := na
    Order2shortsl := na
    Order2shorttp1 := na
    Order2shorttp2 := na
    Order2shorttp3 := na
    Order2shorttp4 := na
    Order2shorttp5 := na
    Order2shorttp20 := na
    Order2shortsize0 := na
    Order2shortsize1 := na
    Order2shortsize2 := na
    Order2shortsize3 := na
    Order2shortsize4 := na
    Order2shortsize5 := na
    Order2shortsize20 := na

if (shortPyramiding3 == 1 and close > Order3shortsl)
    shortPyramiding3 := 0
    Order3shorttime := na
    Order3shortsl := na
    Order3shorttp1 := na
    Order3shorttp2 := na
    Order3shorttp3 := na
    Order3shorttp4 := na
    Order3shorttp5 := na
    Order3shorttp20 := na
    Order3shortsize0 := na
    Order3shortsize1 := na
    Order3shortsize2 := na
    Order3shortsize3 := na
    Order3shortsize4 := na
    Order3shortsize5 := na
    Order3shortsize20 := na

if (shortPyramiding4 == 1 and close > Order4shortsl)
    shortPyramiding4 := 0
    Order4shorttime := na
    Order4shortsl := na
    Order4shorttp1 := na
    Order4shorttp2 := na
    Order4shorttp3 := na
    Order4shorttp4 := na
    Order4shorttp5 := na
    Order4shorttp20 := na
    Order4shortsize0 := na
    Order4shortsize1 := na
    Order4shortsize2 := na
    Order4shortsize3 := na
    Order4shortsize4 := na
    Order4shortsize5 := na
    Order4shortsize20 := na

if (shortPyramiding5 == 1 and close > Order5shortsl)
    shortPyramiding5 := 0
    Order5shorttime := na
    Order5shortsl := na
    Order5shorttp1 := na
    Order5shorttp2 := na
    Order5shorttp3 := na
    Order5shorttp4 := na
    Order5shorttp5 := na
    Order5shorttp20 := na
    Order5shortsize0 := na
    Order5shortsize1 := na
    Order5shortsize2 := na
    Order5shortsize3 := na
    Order5shortsize4 := na
    Order5shortsize5 := na
    Order5shortsize20 := na

答案 1 :(得分:0)

第三部分代码:

if (longPyramiding1 == 1 and longPyramiding1[1] == 0 and Order1longtime == time)
    strategy.entry("PyramidingLong1TP1", strategy.long, qty = Order1longsize1)
    strategy.entry("PyramidingLong1TP2", strategy.long, qty = Order1longsize2)
    strategy.entry("PyramidingLong1TP3", strategy.long, qty = Order1longsize3)
    strategy.entry("PyramidingLong1TP4", strategy.long, qty = Order1longsize4)
    strategy.entry("PyramidingLong1TP5", strategy.long, qty = Order1longsize5)
    strategy.entry("PyramidingLong1TP20", strategy.long, qty = Order1longsize20)
    strategy.exit("TP1Long1", "PyramidingLong1TP1", qty = Order1longsize1, limit = Order1longtp1, stop = Order1longsl)
    strategy.exit("TP2Long1", "PyramidingLong1TP2", qty = Order1longsize2, limit = Order1longtp2, stop = Order1longsl)
    strategy.exit("TP3Long1", "PyramidingLong1TP3", qty = Order1longsize3, limit = Order1longtp3, stop = Order1longsl)
    strategy.exit("TP4Long1", "PyramidingLong1TP4", qty = Order1longsize4, limit = Order1longtp4, stop = Order1longsl)
    strategy.exit("TP5Long1", "PyramidingLong1TP5", qty = Order1longsize5, limit = Order1longtp5, stop = Order1longsl)
    strategy.exit("TP20Long1", "PyramidingLong1TP20", qty = Order1longsize20, limit = Order1longtp20, stop = Order1longsl)

if (longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding2[1] == 0 and Order1longtime != time and Order2longtime == time)
    strategy.entry("PyramidingLong2TP1", strategy.long, qty = Order2longsize1)
    strategy.entry("PyramidingLong2TP2", strategy.long, qty = Order2longsize2)
    strategy.entry("PyramidingLong2TP3", strategy.long, qty = Order2longsize3)
    strategy.entry("PyramidingLong2TP4", strategy.long, qty = Order2longsize4)
    strategy.entry("PyramidingLong2TP5", strategy.long, qty = Order2longsize5)
    strategy.entry("PyramidingLong2TP20", strategy.long, qty = Order2longsize20)
    strategy.exit("TP1Long2", "PyramidingLong2TP1", qty = Order2longsize1, limit = Order2longtp1, stop = Order2longsl)
    strategy.exit("TP2Long2", "PyramidingLong2TP2", qty = Order2longsize2, limit = Order2longtp2, stop = Order2longsl)
    strategy.exit("TP3Long2", "PyramidingLong2TP3", qty = Order2longsize3, limit = Order2longtp3, stop = Order2longsl)
    strategy.exit("TP4Long2", "PyramidingLong2TP4", qty = Order2longsize4, limit = Order2longtp4, stop = Order2longsl)
    strategy.exit("TP5Long2", "PyramidingLong2TP5", qty = Order2longsize5, limit = Order2longtp5, stop = Order2longsl)
    strategy.exit("TP20Long2", "PyramidingLong2TP20", qty = Order2longsize20, limit = Order2longtp20, stop = Order2longsl)

if (longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 1 and longPyramiding3[1] == 0 and Order1longtime != time and Order2longtime != time and Order3longtime == time)
    strategy.entry("PyramidingLong3TP1", strategy.long, qty = Order3longsize1)
    strategy.entry("PyramidingLong3TP2", strategy.long, qty = Order3longsize2)
    strategy.entry("PyramidingLong3TP3", strategy.long, qty = Order3longsize3)
    strategy.entry("PyramidingLong3TP4", strategy.long, qty = Order3longsize4)
    strategy.entry("PyramidingLong3TP5", strategy.long, qty = Order3longsize5)
    strategy.entry("PyramidingLong3TP20", strategy.long, qty = Order3longsize20)
    strategy.exit("TP1Long3", "PyramidingLong3TP1", qty = Order3longsize1, limit = Order3longtp1, stop = Order3longsl)
    strategy.exit("TP2Long3", "PyramidingLong3TP2", qty = Order3longsize2, limit = Order3longtp2, stop = Order3longsl)
    strategy.exit("TP3Long3", "PyramidingLong3TP3", qty = Order3longsize3, limit = Order3longtp3, stop = Order3longsl)
    strategy.exit("TP4Long3", "PyramidingLong3TP4", qty = Order3longsize4, limit = Order3longtp4, stop = Order3longsl)
    strategy.exit("TP5Long3", "PyramidingLong3TP5", qty = Order3longsize5, limit = Order3longtp5, stop = Order3longsl)
    strategy.exit("TP20Long3", "PyramidingLong3TP20", qty = Order3longsize20, limit = Order3longtp20, stop = Order3longsl)

if (longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 1 and longPyramiding4 == 1 and longPyramiding4[1] == 0 and Order1longtime != time and Order2longtime != time and Order3longtime != time and Order4longtime == time)
    strategy.entry("PyramidingLong4TP1", strategy.long, qty = Order4longsize1)
    strategy.entry("PyramidingLong4TP2", strategy.long, qty = Order4longsize2)
    strategy.entry("PyramidingLong4TP3", strategy.long, qty = Order4longsize3)
    strategy.entry("PyramidingLong4TP4", strategy.long, qty = Order4longsize4)
    strategy.entry("PyramidingLong4TP5", strategy.long, qty = Order4longsize5)
    strategy.entry("PyramidingLong4TP20", strategy.long, qty = Order4longsize20)
    strategy.exit("TP1Long4", "PyramidingLong4TP1", qty = Order4longsize1, limit = Order4longtp1, stop = Order4longsl)
    strategy.exit("TP2Long4", "PyramidingLong4TP2", qty = Order4longsize2, limit = Order4longtp2, stop = Order4longsl)
    strategy.exit("TP3Long4", "PyramidingLong4TP3", qty = Order4longsize3, limit = Order4longtp3, stop = Order4longsl)
    strategy.exit("TP4Long4", "PyramidingLong4TP4", qty = Order4longsize4, limit = Order4longtp4, stop = Order4longsl)
    strategy.exit("TP5Long4", "PyramidingLong4TP5", qty = Order4longsize5, limit = Order4longtp5, stop = Order4longsl)
    strategy.exit("TP20Long4", "PyramidingLong4TP20", qty = Order4longsize20, limit = Order4longtp20, stop = Order4longsl)

if (longPyramiding1 == 1 and longPyramiding2 == 1 and longPyramiding3 == 1 and longPyramiding4 == 1 and longPyramiding5 == 1 and longPyramiding5[1] == 0 and Order1longtime != time and Order2longtime != time and Order3longtime != time and Order4longtime != time and Order5longtime == time)
    strategy.entry("PyramidingLong5TP1", strategy.long, qty = Order5longsize1)
    strategy.entry("PyramidingLong5TP2", strategy.long, qty = Order5longsize2)
    strategy.entry("PyramidingLong5TP3", strategy.long, qty = Order5longsize3)
    strategy.entry("PyramidingLong5TP4", strategy.long, qty = Order5longsize4)
    strategy.entry("PyramidingLong5TP5", strategy.long, qty = Order5longsize5)
    strategy.entry("PyramidingLong5TP20", strategy.long, qty = Order5longsize20)
    strategy.exit("TP1Long5", "PyramidingLong5TP1", qty = Order5longsize1, limit = Order5longtp1, stop = Order5longsl)
    strategy.exit("TP2Long5", "PyramidingLong5TP2", qty = Order5longsize2, limit = Order5longtp2, stop = Order5longsl)
    strategy.exit("TP3Long5", "PyramidingLong5TP3", qty = Order5longsize3, limit = Order5longtp3, stop = Order5longsl)
    strategy.exit("TP4Long5", "PyramidingLong5TP4", qty = Order5longsize4, limit = Order5longtp4, stop = Order5longsl)
    strategy.exit("TP5Long5", "PyramidingLong5TP5", qty = Order5longsize5, limit = Order5longtp5, stop = Order5longsl)
    strategy.exit("TP20Long5", "PyramidingLong5TP20", qty = Order5longsize20, limit = Order5longtp20, stop = Order5longsl)

if (shortPyramiding1 == 1 and shortPyramiding1[1] == 0 and Order1shorttime == time)
    strategy.entry("Pyramidingshort1TP1", strategy.short, qty = Order1shortsize1)
    strategy.entry("Pyramidingshort1TP2", strategy.short, qty = Order1shortsize2)
    strategy.entry("Pyramidingshort1TP3", strategy.short, qty = Order1shortsize3)
    strategy.entry("Pyramidingshort1TP4", strategy.short, qty = Order1shortsize4)
    strategy.entry("Pyramidingshort1TP5", strategy.short, qty = Order1shortsize5)
    strategy.entry("Pyramidingshort1TP20", strategy.short, qty = Order1shortsize20)
    strategy.exit("TP1short1", "Pyramidingshort1TP1", qty = Order1shortsize1, limit = Order1shorttp1, stop = Order1shortsl)
    strategy.exit("TP2short1", "Pyramidingshort1TP2", qty = Order1shortsize2, limit = Order1shorttp2, stop = Order1shortsl)
    strategy.exit("TP3short1", "Pyramidingshort1TP3", qty = Order1shortsize3, limit = Order1shorttp3, stop = Order1shortsl)
    strategy.exit("TP4short1", "Pyramidingshort1TP4", qty = Order1shortsize4, limit = Order1shorttp4, stop = Order1shortsl)
    strategy.exit("TP5short1", "Pyramidingshort1TP5", qty = Order1shortsize5, limit = Order1shorttp5, stop = Order1shortsl)
    strategy.exit("TP20short1", "Pyramidingshort1TP20", qty = Order1shortsize20, limit = Order1shorttp20, stop = Order1shortsl)

if (shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding2[1] == 0 and Order1shorttime != time and Order2shorttime == time)
    strategy.entry("Pyramidingshort2TP1", strategy.short, qty = Order2shortsize1)
    strategy.entry("Pyramidingshort2TP2", strategy.short, qty = Order2shortsize2)
    strategy.entry("Pyramidingshort2TP3", strategy.short, qty = Order2shortsize3)
    strategy.entry("Pyramidingshort2TP4", strategy.short, qty = Order2shortsize4)
    strategy.entry("Pyramidingshort2TP5", strategy.short, qty = Order2shortsize5)
    strategy.entry("Pyramidingshort2TP20", strategy.short, qty = Order2shortsize20)
    strategy.exit("TP1short2", "Pyramidingshort2TP1", qty = Order2shortsize1, limit = Order2shorttp1, stop = Order2shortsl)
    strategy.exit("TP2short2", "Pyramidingshort2TP2", qty = Order2shortsize2, limit = Order2shorttp2, stop = Order2shortsl)
    strategy.exit("TP3short2", "Pyramidingshort2TP3", qty = Order2shortsize3, limit = Order2shorttp3, stop = Order2shortsl)
    strategy.exit("TP4short2", "Pyramidingshort2TP4", qty = Order2shortsize4, limit = Order2shorttp4, stop = Order2shortsl)
    strategy.exit("TP5short2", "Pyramidingshort2TP5", qty = Order2shortsize5, limit = Order2shorttp5, stop = Order2shortsl)
    strategy.exit("TP20short2", "Pyramidingshort2TP20", qty = Order2shortsize20, limit = Order2shorttp20, stop = Order2shortsl)

if (shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 1 and shortPyramiding3[1] == 0 and Order1shorttime != time and Order2shorttime != time and Order3shorttime == time)
    strategy.entry("Pyramidingshort3TP1", strategy.short, qty = Order3shortsize1)
    strategy.entry("Pyramidingshort3TP2", strategy.short, qty = Order3shortsize2)
    strategy.entry("Pyramidingshort3TP3", strategy.short, qty = Order3shortsize3)
    strategy.entry("Pyramidingshort3TP4", strategy.short, qty = Order3shortsize4)
    strategy.entry("Pyramidingshort3TP5", strategy.short, qty = Order3shortsize5)
    strategy.entry("Pyramidingshort3TP20", strategy.short, qty = Order3shortsize20)
    strategy.exit("TP1short3", "Pyramidingshort3TP1", qty = Order3shortsize1, limit = Order3shorttp1, stop = Order3shortsl)
    strategy.exit("TP2short3", "Pyramidingshort3TP2", qty = Order3shortsize2, limit = Order3shorttp2, stop = Order3shortsl)
    strategy.exit("TP3short3", "Pyramidingshort3TP3", qty = Order3shortsize3, limit = Order3shorttp3, stop = Order3shortsl)
    strategy.exit("TP4short3", "Pyramidingshort3TP4", qty = Order3shortsize4, limit = Order3shorttp4, stop = Order3shortsl)
    strategy.exit("TP5short3", "Pyramidingshort3TP5", qty = Order3shortsize5, limit = Order3shorttp5, stop = Order3shortsl)
    strategy.exit("TP20short3", "Pyramidingshort3TP20", qty = Order3shortsize20, limit = Order3shorttp20, stop = Order3shortsl)

if (shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 1 and shortPyramiding4 == 1 and shortPyramiding4[1] == 0 and Order1shorttime != time and Order2shorttime != time and Order3shorttime != time and Order4shorttime == time)
    strategy.entry("Pyramidingshort4TP1", strategy.short, qty = Order4shortsize1)
    strategy.entry("Pyramidingshort4TP2", strategy.short, qty = Order4shortsize2)
    strategy.entry("Pyramidingshort4TP3", strategy.short, qty = Order4shortsize3)
    strategy.entry("Pyramidingshort4TP4", strategy.short, qty = Order4shortsize4)
    strategy.entry("Pyramidingshort4TP5", strategy.short, qty = Order4shortsize5)
    strategy.entry("Pyramidingshort4TP20", strategy.short, qty = Order4shortsize20)
    strategy.exit("TP1short4", "Pyramidingshort4TP1", qty = Order4shortsize1, limit = Order4shorttp1, stop = Order4shortsl)
    strategy.exit("TP2short4", "Pyramidingshort4TP2", qty = Order4shortsize2, limit = Order4shorttp2, stop = Order4shortsl)
    strategy.exit("TP3short4", "Pyramidingshort4TP3", qty = Order4shortsize3, limit = Order4shorttp3, stop = Order4shortsl)
    strategy.exit("TP4short4", "Pyramidingshort4TP4", qty = Order4shortsize4, limit = Order4shorttp4, stop = Order4shortsl)
    strategy.exit("TP5short4", "Pyramidingshort4TP5", qty = Order4shortsize5, limit = Order4shorttp5, stop = Order4shortsl)
    strategy.exit("TP20short4", "Pyramidingshort4TP20", qty = Order4shortsize20, limit = Order4shorttp20, stop = Order4shortsl)

if (shortPyramiding1 == 1 and shortPyramiding2 == 1 and shortPyramiding3 == 1 and shortPyramiding4 == 1 and shortPyramiding5 == 1 and shortPyramiding5[1] == 0 and Order1shorttime != time and Order2shorttime != time and Order3shorttime != time and Order4shorttime != time and Order5shorttime == time)
    strategy.entry("Pyramidingshort5TP1", strategy.short, qty = Order5shortsize1)
    strategy.entry("Pyramidingshort5TP2", strategy.short, qty = Order5shortsize2)
    strategy.entry("Pyramidingshort5TP3", strategy.short, qty = Order5shortsize3)
    strategy.entry("Pyramidingshort5TP4", strategy.short, qty = Order5shortsize4)
    strategy.entry("Pyramidingshort5TP5", strategy.short, qty = Order5shortsize5)
    strategy.entry("Pyramidingshort5TP20", strategy.short, qty = Order5shortsize20)
    strategy.exit("TP1short5", "Pyramidingshort5TP1", qty = Order5shortsize1, limit = Order5shorttp1, stop = Order5shortsl)
    strategy.exit("TP2short5", "Pyramidingshort5TP2", qty = Order5shortsize2, limit = Order5shorttp2, stop = Order5shortsl)
    strategy.exit("TP3short5", "Pyramidingshort5TP3", qty = Order5shortsize3, limit = Order5shorttp3, stop = Order5shortsl)
    strategy.exit("TP4short5", "Pyramidingshort5TP4", qty = Order5shortsize4, limit = Order5shorttp4, stop = Order5shortsl)
    strategy.exit("TP5short5", "Pyramidingshort5TP5", qty = Order5shortsize5, limit = Order5shorttp5, stop = Order5shortsl)
    strategy.exit("TP20short5", "Pyramidingshort5TP20", qty = Order5shortsize20, limit = Order5shorttp20, stop = Order5shortsl)