Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 舍入函数给出错误“;参数非可选';_Vba_Excel - Fatal编程技术网

Vba 舍入函数给出错误“;参数非可选';

Vba 舍入函数给出错误“;参数非可选';,vba,excel,Vba,Excel,我一直得到一个称为“参数非可选”的错误 If Application.WorksheetFunction.RoundDown(units) = 0 Then 在“汇总”部分。我知道代码非常混乱,所以请容忍我,我还是VBA新手。有很多关于这个的帖子,但我似乎仍然无法纠正这个错误 Private Sub Command_button1() Dim buysignal As Range Dim OHLC As Range Dim ffdhigh As Range Dim sellsignal A

我一直得到一个称为“参数非可选”的错误

 If Application.WorksheetFunction.RoundDown(units) = 0 Then
在“汇总”部分。我知道代码非常混乱,所以请容忍我,我还是VBA新手。有很多关于这个的帖子,但我似乎仍然无法纠正这个错误

Private Sub Command_button1()

Dim buysignal As Range
Dim OHLC As Range
Dim ffdhigh As Range
Dim sellsignal As Range
Dim ffdlow As Range
Dim entryprice As Range
Dim stoploss As Range
Dim exitprice As Range
Dim unitsize As Range
Dim position As Range
Dim n As Range
Dim cll As Range
Dim i As Long
Dim v As Long
Dim units As Long
Dim sl As Long
Dim accv As Long
Dim contsize As Long
Dim risk As Long
Dim lastrow As Long
Dim ts As Double


i = 1
v = 0
units = 0
ts = Range("e3")
sl = Range("o1")
risk = Range("l2")
accv = Range("l1")
contsize = Range("e1")
lastrow = Range("a63").End(xlDown).Rows.Count


For i = 63 To 180

        Set OHLC = Range("B" & i & ":" & "E" & i)
        Set ffdhigh = Range("I" & i)
        Set buysignal = Range("M" & i)
        Set cll = Range("B63")
        Set sellsignal = Range("N" & i)
        Set ffdlow = Range("J" & i)
        Set entryprice = Range("p" & i)
        Set stoploss = Range("r" & i)
        Set n = Range("h" & i)
        Set unitsize = Range("t" & i)
        units = (risk * accv) / (contsize * n)


    For Each cll In OHLC


                If cll.Value > (ffdhigh.Value + ts) Then
                '(ignore this) And WorksheetFunction.Sum(Worksheets("Sheet2").Range("T" & 63, "T" & 63 + v)) = 0
                buysignal.Value = "buy"

                ElseIf cll.Value < (ffdlow.Value + ts) Then
                sellsignal.Value = "sell"

                Else: sellsignal.Value = ""
                buysignal = ""

                End If


    Exit For
    Next


        If buysignal = "buy" Then
        entryprice = ffdlow.Value
        stoploss = ffdhigh.Value - (n * sl)
            If Application.WorksheetFunction.RoundDown(units) = 0 Then
            unitsize = Application.WorksheetFunction.RoundUp(units)
            Else: unitsize = Application.WorksheetFunction.RoundDown(units)
            End If

        ElseIf sellsignal = "sell" Then

        entryprice = ffdhigh.Value
        stoploss = ffdlow.Value + (n * sl)



        Else: entryprice = ""

        End If


Next i

End Sub
Private子命令_button1()
变暗信号作为范围
暗淡的OHLC As范围
低FFD高As范围
暗淡信号范围
模糊ffdlow As范围
暗淡的入口价格范围
暗截止损失范围
暗淡的出口价格范围
变暗单位大小为范围
变暗位置作为范围
调光范围
暗cll As范围
我想我会坚持多久
暗v一样长
变暗单位为长单位
长得一样暗
变暗accv为长
尺寸和长度一样大
只要
最后一排一样长
双色调暗
i=1
v=0
单位=0
ts=范围(“e3”)
sl=范围(“o1”)
风险=范围(“l2”)
accv=范围(“l1”)
contsize=范围(“e1”)
lastrow=范围(“a63”).End(xlDown).Rows.Count
对于i=63至180
设置OHLC=范围(“B”和i&“:”和“E”和i)
设置ffdhigh=范围(“I”&I)
设置购买信号=范围(“M”和i)
设置cll=范围(“B63”)
设置信号=范围(“N”和i)
设置ffdlow=范围(“J”和i)
设置入口价格=范围(“p”&i)
设置停止损失=范围(“r”和“i”)
设置n=范围(“h”和“i”)
设置单位大小=范围(“t”和“i”)
单位=(风险*accv)/(续大小*n)
对于OHLC中的每个cll
如果cll.Value>(ffdhigh.Value+ts),则
'和工作表function.Sum(工作表(“Sheet2”).范围(“T”和63,“T”和63+v))=0
buysignal.Value=“购买”
ElseIf cll.Value<(ffdlow.Value+ts)然后
sellsignal.Value=“卖出”
Else:sellsignal.Value=“”
buysignal=“”
如果结束
退出
下一个
如果buysignal=“购买”,则
entryprice=ffdlow.Value
停止损耗=FFD高值-(n*sl)
如果Application.WorksheetFunction.RoundDown(单位)=0,则
unitsize=应用程序.工作表功能.汇总(单位)
Else:unitsize=Application.WorksheetFunction.RoundDown(单位)
如果结束
ElseIf sellsignal=“sell”然后
入口价格=FFD高值
停止损失=ffdlow.Value+(n*sl)
否则:entryprice=“”
如果结束
接下来我
端接头

我不太明白这个选项是什么意思,如果您有任何意见,我将不胜感激。非常感谢各位。

也许你们可以试试。。。给出你需要的小数位数

unitsize = Application.WorksheetFunction.RoundUp(units, 0)

您需要提供第二个参数来指定“位数”。如果将其设置为0,则将四舍五入恢复为整数:

如果Application.WorksheetFunction.RoundDown(单位,0)=0,则


你也需要为综述做同样的事情

谢谢@Bathsheba的帮助!我完全错过了grr。我已经编辑了它,但是现在我得到了行=“units=(risk*accv)/(contsize*n)”的错误“overflow”。尝试在此处搜索错误,但找不到解决方案,给出了什么?在此情况下,ContactSize*n很可能为零。好的,我看到了。。我有什么办法可以绕过这个问题吗?我试着在设置n时改变位置,但那不起作用。n应该是i=63到180的范围(“h”和i)中的值