If statement 结清全部头寸问题&;虚假买卖信号

If statement 结清全部头寸问题&;虚假买卖信号,if-statement,debugging,bots,false-positive,thinkscript,If Statement,Debugging,Bots,False Positive,Thinkscript,我已经编程几年了,但我对thinkscript是全新的,遇到了一些无法解决的问题。感谢您的帮助 正如您从下面的屏幕截图中看到的,买卖操作不正常。在这个例子中,这不应该在这里买,因为最后一个酒吧的收盘价是2.24,sma1是2.15,这意味着它是更少的。我不知道为什么在这里买。。。。购买条件为(收盘价1sma1,而不是close1(sma1*.9997))和(close2

我已经编程几年了,但我对thinkscript是全新的,遇到了一些无法解决的问题。感谢您的帮助

正如您从下面的屏幕截图中看到的,买卖操作不正常。在这个例子中,这不应该在这里买,因为最后一个酒吧的收盘价是2.24,sma1是2.15,这意味着它是更少的。我不知道为什么在这里买。。。。购买条件为(收盘价1

在第二个例子中,我不确定它为什么在这里销售。之前的酒吧有close1>sma1,而不是close1

我的另一个问题是,当我使用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, tradeSize = (3333/entryPrice()), condition = (LastPrice crosses above (entryprice()*1.069998)),  name = "TAKE PROFIT 2");
plot tp2 = if (LastPrice crosses above (entryprice()*1.069998),yes,no);
AddOrder(OrderType.SELL_AUTO, tradeSize = (1667/entryPrice()), condition = (LastPrice crosses above (entryprice()*1.149998)),  name = "TAKE PROFIT 3");
plot tp3 = if (LastPrice crosses above (entryprice()*1.149998),yes,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");
input priceType=priceType.LAST;
plot LastPrice=close(priceType=priceType);
图sma1=(关闭[2]+关闭[1])/2;
def close1=关闭[1];
def close2=关闭[2];
def sma2=(关闭[3]+关闭[2])/2;
AddOrder(OrderType.BUY_TO_OPEN,tradeSize=(10000/LastPrice),条件=((close1>(sma1*.9997))和(close2