I am having an intermittent problem moving stops/targets. I start a trade using AtmStrategyCreate(). Initially the ATM works as expected and creates stops and targets defined in the ATM. I immediately want to move the ATM preset stops/targets to levels from my strategy. I am using the AtmStrategyChangeStopTarget() to do this. I call my function MoveStopAndTargets() from the OnExecutionUpdate() handler. The calls frequently fail with the error message: 'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid. I need to move 4 orders (2 targets, and 2 stops.) If there are errors moving my orders, I call my MoveStopAndTargets() on each tick from the OnBarUpdate() function until all the targets/stops eventually will be moved to the correct place.
Strategy attached to see the code generating these outputs.
Here is some output I generate to trace things showing that the ATM started correctly:
Output from the ATM callback:
NoError Call Back ID832b00a9633c43378efcd5e842144277 Strat ID: 832b00a9633c43378efcd5e842144277
STATUS Flat
===========================================
Output form the OnExecutionUpdate() handler:
Execution Name: Entry OrderName: Entry Market Position: Flat AtmStrategyId: 832b00a9633c43378efcd5e842144277
ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
================================================== ===================
Output from the my MoveStopAndTargets() function called first from OnExecutionUpdate() then from OnBarUpdate() until orders have be moved:
Move Target1:12571.25
'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
Move Target1:12571.25
'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
Move Target1:12571.25
'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
Move Target1:12571.25
'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid
ATM Entry:12566.25 StrategyId: 832b00a9633c43378efcd5e842144277
Move Target1:12571.25
Move Target2:12576.25
Move Stop1:12556.25
Move Stop2:12556.25
I am not sure why, but frequently, the chart has 'Cancelled pending' orders left on my chart, that can only be removed by resetting the account. If I do not move stops and targets, there is never a 'Cancel pending' order left on the chart. So I assume that moving the orders is causing an error in the ATM.
Two questions:
Why is the ATM not updating the Stops/Targets on the first call to the AtmStrategyChangeStopTarget routine from the OnExecutionUpdate()?
Why are the 'Cancel pending' orders being left on the chart?
Thank you for your help.

Comment