My Issues:
- The ATM strategy works in playback mode & on simulated accounts. When I try to trade with my Apex or TP Accounts it will not enter a trade. I was testing it today on simulated accounts and it just stopped working. I can run the original strategy on a separate chart beside the ATM Added Strategy and the Original executes properly and the ATM does nothing. The ATM Added Strategy worked last week and made me money and then quit.I didn't change anything for it to quit working on active accounts.
- Once the ATM Strategy is working properly, I want it to use the Max Profit & Max Loss so it will not take new trades once it reaches either limit. How would I add that to work off Realized PNL.
public class SampleAtmStrategy : Strategy
{
private string atmStrategyId = string.Empty;
private string orderId = string.Empty;
private bool isAtmStrategyCreated = false;
Then:
IsInstantiatedOnEachOptimizationIteration = true;
ATMStrategy = @"ATM1";
Then:
protected override void OnBarUpdate()
{
if(State == State.Historical)
return;
}
Then: in red is what I added to the first line of my If All for my long entry
if (orderId.Length == 0 && atmStrategyId.Length == 0 && (NBarsUp1[0] == 1)
Then: In red below are the changes made to the SampleATM Strategy
{
BackBrush = Brushes.CornflowerBlue;
isAtmStrategyCreated = false; // reset atm strategy created check to false
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Close[0], 0, TimeInForce.Gtc, orderId, ATMStrategy, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
isAtmStrategyCreated = true;
});
}
// Check that atm strategy was created before checking other properties
if (!isAtmStrategyCreated)
return;
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
} // If the strategy has terminated reset the strategy id
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
atmStrategyId = string.Empty;
if (atmStrategyId.Length > 0)
{
// You can change the stop price
if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
AtmStrategyChangeStopTarget(DefaultQuantity, 0, "Stop1", atmStrategyId);
// Print some information about the strategy to the output window, please note you access the ATM strategy specific position object here
// the ATM would run self contained and would not have an impact on your NinjaScript strategy position and PnL
Print("The current ATM Strategy market position is: " + GetAtmStrategyMarketPosition(atmStrategyId));
Print("The current ATM Strategy position quantity is: " + GetAtmStrategyPositionQuantity(atmStrategyId));
Print("The current ATM Strategy average price is: " + GetAtmStrategyPositionAveragePrice(atmStrategyId)) ;
Print("The current ATM Strategy Unrealized PnL is: " + GetAtmStrategyUnrealizedProfitLoss(atmStrategyId)) ;
}
Please let me know how to get this working and what looks not correct.
Stephen

Comment