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 warreng86, 11-10-2020, 02:04 PM
                4 responses
                1,355 views
                0 likes
                Last Post mathewlo  
                Started by Perr0Grande, Today, 08:16 PM
                0 responses
                2 views
                0 likes
                Last Post Perr0Grande  
                Started by elderan, Today, 08:03 PM
                0 responses
                5 views
                0 likes
                Last Post elderan
                by elderan
                 
                Started by algospoke, Today, 06:40 PM
                0 responses
                10 views
                0 likes
                Last Post algospoke  
                Started by maybeimnotrader, Today, 05:46 PM
                0 responses
                12 views
                0 likes
                Last Post maybeimnotrader  
                Working...
                X