I am new to Ninjatrader, and have been trying to develop a system to automatically buy/sell a stock. My whole analysis is written as a python script, and what it outputs is a buy/sell signal into a text file.
What I need to happen is ninjatrader to read the file and either buy or sell a stock depending on the files content. I have written a simple strategy using ninjascript. It reads the buy/sell signal, and then runs:
EnterLong(Quantity, “TradeEntry”);
Or
ExitLong();
I found this online. However, when I turn on the strategy, in the output (console) I see the print message that I put below the EnterLong, so it executes, but there’s no order or position in the corresponding tabs.
I am doing all this on a simulation account.
Maybe my settings for the strategy or something else are wrong? Any help is very appreciated! Thank you everyone!
You are doing it wrong. What you want is to create a web socket connection between NT and a local Python server. You directly communicate with NT and not write the file just for NT to read the file. What you want to do is create a strategy and enable that in NT. Claude or Codex should be able to help you with this.
Do you have any warnings or errors in the command center log (not the output window)? If the order entry commands are failing there can sometimes be something there about why.
And for what it’s worth, I think file based signaling is fine. Would a socket be better, maybe. But since your signaling mechanism is already working I wouldn’t worry about it. “If it ain’t broke, don’t fix it” as they say.
I wouldn’t agree on “maybe” it’ll be better. The socket approach is a significantly better design, especially for real time. With the file approach, NT has to continuously poll and see if the file and content changed. You can potentially run into race conditions, half-written files, multiple writes to it, file locks and probably more. The socket approach immediately pushes the signal to NT with lower latency than polling for a file change. It is better for real time and more reliable.
If the Print runs but no order shows, look at the strategy’s row in the Strategies tab. When a strategy starts, it first runs over historical bars, and EnterLong calls made then are only simulated. If that leaves it in a position, the default Start behavior ‘Wait until flat’ shows it in yellow and sends nothing live until the simulated position is closed. Guard your file check with if (State != State.Realtime) return; so signals are acted on only live, and set TraceOrders = true to see whether EnterLong is ignored and why. Also check the account is Sim101 and the stock has a live data feed. Happy to help further, feel free to DM me.