Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to code a strategy in ThinkorSwim to Buy when the MACD Down Bar turns from Red to DarkRed and the RSI < 45, Then Sell when the Up Bar turn from Green to Dark Green and RSI > 65
This is my coding so far
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
def buy = diff < diff[1] and rsi > RSIBuy
AddOrder(OrderType.SELL_TO_CLOSE, buy, name = "BUY_LE");
def sell = diff > diff[1] and rsi > RSISell;
AddOrder(OrderType.SELL_TO_CLOSE, sell, name = "SELL_SE");
It's not liking the def lines how do I fix it
See Attached for a diagram of what I want to do
Can you help answer these questions from other members on NexusFi?
There were a couple issues, one in the order syntax and there was a missing ';' and since there are no plots called all the plotting information irritated the compiler. I reworked the code a little bit because TOS hates it when you reference several other studies in a single script and tossed in my usual positioning code snipet. Enjoy
Change 'open[-1]' to 'close'. The reason I do this is because you don't know that it will be a signal until the bar actually closes, therefore the absolute earliest you can get in is the open of the next bar (open[-1]).
The attached doc's explain what I am trying to accomplish on the Custom TOS MACD
After thinking about it be nice to trigger on bar sooner on the last GREEN OR RED
def colorB = if isLastBar = (Color.GREEN) and color.CURRENT = (Color.DARK_GREEN) then 1 else 0;
def colorS = if isLastBar = (Color.RED) and color.CURRENT = (Color.DARK_RED) then 1 else 0;