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


                  #9
                  I have been struggling with the naming convention. In the Ninjascript documents, it uses the examples Stop1 and Target2. However, I have not been able to get Target1 to work. Is it possible that it is actually TARGET1? Target1 and Stop1 are what I see when right clicking on an active order, so I thought this had to be right, but I am now so frustrated. Obviously, I will now test this, but thought I would ask as well.

                  Comment


                    #10
                    Hello tracyandersonmd,

                    You would generally need to specify the ordername that you see in the control center orders tab, same letters and capitalization. I would also suggest using a Print where you are calling that code to verify that code is being reached.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello tracyandersonmd,

                      You would generally need to specify the ordername that you see in the control center orders tab, same letters and capitalization. I would also suggest using a Print where you are calling that code to verify that code is being reached.
                      Hi Jesse, thanks for the response. I have really been struggling with this. If I move the ATM Strategy TP, I can see the name='Target1' in the log. I have tried multiple names, including this most obvious that the change is continually rejected.

                      Attempting to modify ATM 3ecec426-3970-4886-a05e-360de89cf813 with PT order 'Target1' to 19415.75
                      'AtmStrategyChangeStopTarget' method error: Order name 'Target1' is invalid

                      this is my change code
                      AtmStrategyChangeStopTarget(targetPrice,0"Target1" ,atmStrategyId);​​

                      Comment


                        #12
                        Hello tracyandersonmd,

                        Did the strategy you are using submit the ATM its self? For example like the SampleATMStrategy that comes with the platform?

                        Comment


                          #13
                          Originally posted by NinjaTrader_Jesse View Post
                          Hello tracyandersonmd,

                          Did the strategy you are using submit the ATM its self? For example like the SampleATMStrategy that comes with the platform?
                          Yes, I am having no issues with submitting ATM strategies with my Ninjascript. I simply cannot get the the order change to work. I have tried doing it in its own method, in OnBarUpdate container and in OnMarketUpdate container. Cannot get anything to work.

                          Comment


                            #14
                            Hello tracyandersonmd,

                            I just wanted to confirm, is this question in relation to NT7 specifically, I see you replied to an old thread so I wanted to make sure we are speaking about the same thing.

                            Comment


                              #15
                              Originally posted by NinjaTrader_Jesse View Post
                              Hello tracyandersonmd,

                              I just wanted to confirm, is this question in relation to NT7 specifically, I see you replied to an old thread so I wanted to make sure we are speaking about the same thing.
                              Ah, sorry. No, I am using the latest NT8. This is just the only thing I can find related to my issue.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              55 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              37 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              17 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              19 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              49 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X