平仓,发出虚假的买卖信号

问题描述

我已经编程了几年,但是我是thinkscript的新手,遇到了一些我无法解决的问题。任何帮助表示赞赏。

从下面的屏幕截图中可以看到,买卖不正确。在此示例中,不应在此处购买此货币,因为最后一个柱的收盘价为2.24,而sma1为2.15,这意味着收盘价会更低。我不确定为什么要在这里购买...。购买的条件是(close1

False buy

在第二个示例中,我不确定为什么要在这里销售。之前的收盘价为close1> sma1,未收盘

False sell

我遇到的另一个问题是,当我使用entryPrice()时,它并没有真正找到该价格,而只是抓住了最后一个价格,因此我可以以每股1美元的价格购买10股,然后价格升至1.02,现在将要收盘。 9股而不是10股。有人知道如何找到剩下的多少股然后关闭吗?而不是像我一样使这种超级困难。我似乎找不到类似PositionSize()的东西或可以用于tradeSize关闭的东西?谢谢!

这是我的代码

input priceType = PriceType.LAST;
plot LastPrice = close(priceType = priceType);

plot sma1 = (close[2]+close[1])/2;
def close1 = close[1];
def close2 = close[2];
def sma2 = (close[3]+close[2])/2;

AddOrder(OrderType.BUY_TO_OPEN,tradeSize = (10000/LastPrice),condition = ((close1 > (sma1*.9997)) and (close2<sma2)),name = "BUY");

AddOrder(OrderType.SELL_AUTO,tradeSize = (3333/entryPrice()),condition = (LastPrice crosses above (entryprice()*1.039998)),name = "TAKE PROFIT 1");
plot tp1 = if (LastPrice crosses above (entryprice()*1.039998),yes,no);
AddOrder(OrderType.SELL_AUTO,condition = (LastPrice crosses above (entryprice()*1.069998)),name = "TAKE PROFIT 2");
plot tp2 = if (LastPrice crosses above (entryprice()*1.069998),tradeSize = (1667/entryPrice()),condition = (LastPrice crosses above (entryprice()*1.149998)),name = "TAKE PROFIT 3");
plot tp3 = if (LastPrice crosses above (entryprice()*1.149998),no);

AddOrder(OrderType.SELL_TO_CLOSE,tradeSize = if (tp1 == no,10000/entryPrice(),if(tp1 == yes and tp2 == no,(10000*.666666667)/entryPrice(),if(tp1 == yes and tp2 == yes and tp3 == no,(10000*.3333333334)/entryPrice(),if(tp1 == yes and tp2 == yes and tp3 == yes,(10000*.1666667)/entryPrice(),10000/entryPrice())))),condition = (close1 < sma1),name = "CLOSE LONG POS");

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...