This repository contains a batch script (AlgoBox_NEW_Clean_RealtimePriority_Startup.bat
) and a PowerShell script (NinjaTrader8_Clean_RealtimePriority.ps1
) that automate the process of setting the NinjaTrader 8 application to run with Realtime CPU priority and perform some cleanup tasks on startup.
- Download the ZIP file from the GitHub repository.
- Extract the
AlgoBox_NEW_Clean_RealtimePriority_Startup.bat
andNinjaTrader8_Clean_RealtimePriority.ps1
files to theC:\Users\<user>\Documents\NinjaTrader 8
directory. - Right-click on the
AlgoBox_NEW_Clean_RealtimePriority_Startup.bat
file and select "Run As Administrator".
The batch script will perform the following actions:
- Display a message indicating that NinjaTrader is being launched with Realtime priority.
- Launch a new console window for the PowerShell process and wait for it to complete.
- Display a message indicating that NinjaTrader has been launched with Realtime priority and provide the location of the log file.
- Automatically close the console window.
The PowerShell script will perform the following actions:
- Remove and recreate several directories related to NinjaTrader 8 (cache, db/cache, db/day, db/minute, db/tick, tmp, trace, log).
- Start the NinjaTrader 8 application.
- Set the CPU priority of the NinjaTrader process to Realtime.
- This script modifies the CPU priority of the NinjaTrader process to Realtime. Setting a process to Realtime priority can potentially impact the stability and responsiveness of your system. Use it with caution and ensure that your system has sufficient resources to handle the increased priority.
- The script performs cleanup tasks by removing and recreating certain directories. Make sure you have backups of any important data before running the script.
- The script requires Administrator privileges to run. Ensure that you have the necessary permissions and trust the source of the script before executing it.
- I am not responsible for any damages or issues caused by using this script. Use it at your own risk.
The batch script (AlgoBox_NEW_Clean_RealtimePriority_Startup.bat
) performs the following steps:
- It displays a message indicating that NinjaTrader is being launched with Realtime priority.
- It uses the
start
command with the/wait
option to launch a new console window for the PowerShell process and wait for it to complete. - It displays a message indicating that NinjaTrader has been launched with Realtime priority and provides the location of the log file.
- It automatically closes the console window.
The PowerShell script (NinjaTrader8_Clean_RealtimePriority.ps1
) does the following:
- It removes and recreates several directories related to NinjaTrader 8 (cache, db/cache, db/day, db/minute, db/tick, tmp, trace, log) to clean up any temporary or cached files.
- It starts the NinjaTrader 8 application using the specified path.
- It imports the necessary Win32 API functions to interact with process tokens and privileges.
- It retrieves the process object based on the provided process path.
- It obtains the necessary privileges to adjust the process priority.
- It sets the CPU priority of the NinjaTrader process to Realtime using the
SetPriorityClass
function from the Win32 API. - It logs the execution steps and any errors encountered during the process.
The script aims to solve the problem of easily setting a process to Realtime priority on startup. It provides a streamlined way to automate the process and perform cleanup tasks for NinjaTrader 8.
If you have any suggestions, improvements, or bug fixes, feel free to open an issue or submit a pull request. Contributions are welcome!
This script is released under the MIT License.