I don't have any coding experience so have been working with ChatGPT to generate the script.
So far I have this:
using System;
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript.Strategies;
public class MyCustomStrategy : Strategy
{
private double entryPrice = 0.0;
private double stopLossPrice = 0.0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Places a take profit order with a 1:1 risk-reward ratio upon order fill.";
Name = "MyCustomStrategy";
}
else if (State == State.DataLoaded)
{
// Initialization code can go here
}
}
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
int quantity, int filled, double averageFillPrice,
Cbi.OrderState orderState, DateTime time, ErrorCode error,
string nativeError)
{
if (order.OrderState == OrderState.Filled)
{
if (order.OrderType == OrderType.StopMarket || order.OrderType == OrderType.StopLimit)
{
stopLossPrice = order.StopPrice;
}
else if (order.OrderType == OrderType.MIT)
{
entryPrice = order.AverageFillPrice;
if (stopLossPrice != 0 && entryPrice != 0)
{
CalculateAndPlaceTakeProfitOrder();
}
}
}
}
private void CalculateAndPlaceTakeProfitOrder()
{
double riskAmount = Math.Abs(entryPrice - stopLossPrice);
double takeProfitPrice = entryPrice > stopLossPrice ? entryPrice + riskAmount : entryPrice - riskAmount;
if (entryPrice > stopLossPrice)
{
EnterLongLimit(1, takeProfitPrice, "TakeProfitLong");
}
else
{
EnterShortLimit(1, takeProfitPrice, "TakeProfitShort");
}
}
}
| MyCustomStrategy.cs | The type or namespace name 'Cbi' could not be found (are you missing a using directive or an assembly reference?) | CS0246 | 23 | 43 |
Thanks
Dan

Comment