Hello,
So I am learning here so please go easy on me lol. So I am trying to create a strategy to backtest as follows:
Buy Condition = buy when MACD value is below zero and value crosses above avg.
Edit Condition = Price when buy condition was triggered minus lowest of the price candle and add that to Price at buy condition.
- So let's say Buy condition was triggered when TSLA at 600$, and the lowest of the past three candles is 595. So the target exit would be 600+(600-595) = when the close crosses above 605.
Here is my simple script:
ISSUE: So as you can see from the image, it seems like entry and exit are being triggered almost at the same time and I cant figure out why, I tried info posted here: https://usethinkscript.com/threads/...buy-sell-in-thinkorswim.741/page-8#post-42477. But I am still not able to figure it out...
Thank you for your help, I really appreciate it
So I am learning here so please go easy on me lol. So I am trying to create a strategy to backtest as follows:
Buy Condition = buy when MACD value is below zero and value crosses above avg.
Edit Condition = Price when buy condition was triggered minus lowest of the price candle and add that to Price at buy condition.
- So let's say Buy condition was triggered when TSLA at 600$, and the lowest of the past three candles is 595. So the target exit would be 600+(600-595) = when the close crosses above 605.
Here is my simple script:
Code:
input tradesize = 10;
def Cross = MACD()."Value" is less than or equal to MACD()."ZeroLine" and MACD()."Value" crosses above MACD()."Avg";
def A = if cross then lowest(low,3) else cross[1];
def B = if cross then close else cross[1];
def Target = B+(b-a);
AddOrder(OrderType.BUY_TO_OPEN, cross, open[-1], tradesize, Color.CYAN, Color.CYAN);
AddOrder(OrderType.SELL_TO_CLOSE, close>=target or close <a , open[-1], tradesize, Color.MAGENTA, Color.MAGENTA);
ISSUE: So as you can see from the image, it seems like entry and exit are being triggered almost at the same time and I cant figure out why, I tried info posted here: https://usethinkscript.com/threads/...buy-sell-in-thinkorswim.741/page-8#post-42477. But I am still not able to figure it out...
Thank you for your help, I really appreciate it
Last edited by a moderator: