Create a strategy with the code below. Create and ATM called 'TestATM', with 1 contract, Stop Loss 50, Profit Target 50. Bring up the ER2 on a chart with Chart Trader. Connect to the simulator. Create and start the strategy below in control center for ER2 using 30 second bars, and watch the trade on the chart trader, only the stop moves, the target does not.
#region Variables
string tradeId="Trade";
string atm = "TestATM";
double price=0;
bool ret;
#endregion
protected override void Initialize() {
CalculateOnBarClose = true;
}
protected override void OnBarUpdate() {
if ( Historical ) return;
//### Create ATM
if (GetAtmStrategyMarketPosition(tradeId) == MarketPosition.Flat) {
tradeId = "Trade"+CurrentBar;
if (!AtmStrategyCreate(Action.Buy, OrderType.Market, Close[0], 0, TimeInForce.Day, tradeId, atm, tradeId))
Print ("*** Error creating " +tradeId);
}
//### Move Target
price = Close[0]+(40*TickSize);
ret = AtmStrategyChangeStopTarget(0,price, "TARGET1", tradeId);
if ( ret == true )
Print("Moved target to " +price.ToString("#.##"));
else Print("*** Failed to move target");
//### Move Stop
price = Close[0]-(40*TickSize);
ret = AtmStrategyChangeStopTarget(0,price, "STOP1", tradeId);
if ( ret == true )
Print("Moved stop to " +price.ToString("#.##"));
else Print("*** Failed to move target");
}
Comment