Trying to get up to speed with building a few strategies, testing them etc. It seems this one is triggering a sell-to-close later than the conditions match, or else I have something wrong.
At the point in question, where the Closing trade is indicated, the MACDHistogram values -0.571
However, the MACDHistogram [1] value is -0.038 and MACDHistogram[2] is 0.236, so the sell-to-close should have triggered on the bar before, should it not?
At the point in question, where the Closing trade is indicated, the MACDHistogram values -0.571
However, the MACDHistogram [1] value is -0.038 and MACDHistogram[2] is 0.236, so the sell-to-close should have triggered on the bar before, should it not?
Code:
input MAshortLen = 10;
input MAlongLen = 50;
def shortMA = SimplemovingAvg(length = MAshortLen);
def longMA = SimpleMovingAvg(length = MAlongLen);
def EnterLong = (shortMA[2] < longMA[2] and shortMA[1] < longMA[1] and shortMA > longMA) and (MACDHistogram()."Diff" [1] < MACDHistogram()."Diff");
def CloseLong = MACDHistogram()."Diff" [1] > 0 and MACDHistogram()."Diff" < 0;
# Long entry
addOrder(OrderType.buy_TO_OPEN, EnterLong, Name="EnterLong", arrowColor = Color.DARK_GREEN, tickColor = Color.DARK_GREEN);
# Long exit
addorder(ordertype.SELL_TO_CLOSE,CloseLong, Name="CloseLong", tickColor = Color.DARK_ORANGE, arrowColor = Color.DARK_ORANGE);