Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeStopTarget() not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    AtmStrategyChangeStopTarget() not working

    AtmStrategyChangeStopTarget() changes the stop but not the target. The following code tries to continuously move both the stop and the target away from the market, but only the stop is being moved.

    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");
    }
    Last edited by monpere; 06-20-2008, 04:23 PM.

    #2
    Are you getting any errors in Control Center logs along with this? I will play with this in the meantime.
    Last edited by NinjaTrader_JoshP; 06-21-2008, 02:24 AM.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      No errors in the error log. Not, only that, the return value of the method is 'true'.

      Originally posted by Josh View Post
      Are you getting any errors in Control Center logs along with this? I will play with this in the meantime.

      Comment


        #4
        Any news on this issue?

        Originally posted by monpere View Post
        No errors in the error log. Not, only that, the return value of the method is 'true'.

        Comment


          #5
          Is this the cause?
          Your line
          ret = AtmStrategyChangeStopTarget(0,price, "TARGET1", tradeId);
          should be
          ret = AtmStrategyChangeStopTarget(price, 0, "TARGET1", tradeId);

          Comment


            #6
            You have hit the nail on the head MJT. That is the problem. I guess because you provide a name for the order as one of the parameters, I neglected to look at the prices, because since you can identify the order by the name, a separate parameter for target and stop price is redundant.

            Thanks. Good catch!


            Originally posted by MJT View Post
            Is this the cause?
            Your line
            ret = AtmStrategyChangeStopTarget(0,price, "TARGET1", tradeId);
            should be
            ret = AtmStrategyChangeStopTarget(price, 0, "TARGET1", tradeId);

            Comment


              #7
              Yes, thanks MJT!
              RayNinjaTrader Customer Service

              Comment


                #8
                Thanks MJT. I'm going blind here on my end and was just staring at it for awhile.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cre8able, 02-11-2023, 05:43 PM
                3 responses
                232 views
                0 likes
                Last Post rhubear
                by rhubear
                 
                Started by frslvr, 04-11-2024, 07:26 AM
                8 responses
                111 views
                1 like
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                10 responses
                44 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by rocketman7, Today, 09:41 AM
                3 responses
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by traderqz, Today, 09:44 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X