I have been using GPT4 for several months and have found it very useful. I started with GPT 3.5 around January and kept running into code that wouldn't compile, as C# code that won't work in NinjaScript would be slipped in without warning. 4 has been much better, though occasionally egregious ignorance of NinjaScript will show up. Here is an example today (7/14):
"for NinjaScript strategy, is there a way to Calculate OnBarClose for the entries, which are taken on a 3 minute bar, and Calculate OnEachTick if the strategy is in a position, so exits can be taken OnEachTick?
ChatGPT
NinjaScript is a C#-based language used in the NinjaTrader trading platform for the creation of strategies, indicators, and automated trading systems.
In NinjaScript, the Calculate property determines when your strategy calculations are performed. The options are OnBarClose, OnPriceChange, and OnEachTick. However, NinjaScript does not natively support changing the Calculate property dynamically within a strategy. This means you can't directly set it to OnBarClose for entries and then change it to OnEachTick for exits within the same strategy.
However, you can achieve a similar effect by using a workaround. Here's a general idea of how you might do it:
Use OnEachTick or OnPriceChange calculation mode: This allows your strategy to calculate on each price change or tick.
Implement custom logic for entries: Instead of placing your entry orders on each tick, you can create a condition to check if the current bar is closed before placing an entry order. You can use the Bars.IsFirstBarOfSession or Bars.IsLastBarOfSession properties to determine if a bar is closed.
Implement custom logic for exits: Since you're in OnEachTick or OnPriceChange mode, you can place your exit orders on each tick or price change as needed.
Here's a very basic example of what this might look like in code:
csharp
Copy code
protected override void OnBarUpdate()
{
// Entry logic: Only enter at the close of a bar
if (Bars.IsLastBarOfSession)
{
// Your entry conditions here
if (Close[0] > Open[0])
{
EnterLongLimit(Close[0]);
}
}
// Exit logic: Exit on each tick
if (Position.MarketPosition != MarketPosition.Flat)
{
// Your exit conditions here
if (Close[0] Open[1]) // Note the index change to 1 to reference the closed bar
{
EnterLongLimit(Close[1]);
}
}
// Exit logic: Exit on each tick
if (Position.MarketPosition != MarketPosition.Flat)
{
// Your exit conditions here
if (Close[0]