Type/to search
0
Follow
0
Followers
La fonction getposition signale une erreur s'il n'y a pas de position.
FAQ
Created 2018-04-12 16:36:42  
 3
 2023

Comment puis-je déboguer cette question ?
Si vous n'avez pas de positions sur votre compte, utilisez le code suivant pour obtenir des informations sur les positions
while(true){
var position=_C(exchange.GetPosition)

if(position==null){
continue
}
type=position[0].Type
if(type==PD_LONG){
if(exsell!==sellPrice){
CancelPendingOrders()
exchange.SetDirection("closebuy")
exchange.Sell(sellPrice,position[0].Amount)
exsell=sellPrice
}
}
Si le compte n'a pas de position, getposition devrait obtenir un tableau vide.[[ ], donc continue dans la phrase if pour que la boucle recommence, mais le test sur le disque continuera à produire des erreurs.
TypeError: cannot read property 'Type' of undefined at main (FILE:129)

J'ai essayé de modifier les conditions dans if, comme position[0]==null ou typeof(position)==undefined ne fonctionne pas ou exécute la colonne suivante type=position[0].Type bar rend la stratégie inefficace

Comment résoudre ce problème ?

Related Recommendations
Comment
All comments (3)

    解决办法如下:
    var position = _C(exchange.GetPosition);
    if(position.length>0)
    {
    //请把代码放在这个大括号里. 原理如下: 先判断这个持仓函数返回的数组的长度, 长度大于0, 表示有持仓信息了, 直接用null, undefine判断都不行. 然后才能访问position[0]
    }

    5 years ago

    遇到相同的问题了,感觉有必要针对exchange.GetPosition单独设置一个容错函数,否则在没有持仓的情况下,这个函数几乎完全无法使用
    顺便请问下楼主,最后是如何解决的

    8 years ago

    看下了帖子 ,发现问题了, 在您调用 exchange.GetPosition() 的时候 如果 你没有持仓 , 会返回 [] , 一个空数组, 这个 空数组 并不等于 null , 就是你判断
    position == null 的时候 ,是 false 的, 所以不会 触发 continue, 然后 你访问 position[0] 这个元素是 不存在的,所以是 undefine ,再调用 他的 Type 属性 就报错了。

    8 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)