Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetATMStrategy Breakeven

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

    GetATMStrategy Breakeven

    Hi guys, I am running an ATM strategy with 2 targets. When I run the strategy I normally move the targets manually to where I want them on entry.

    What I'm trying to do is move the second target to BE once the first target is hit. This is easy if I have predefined target without moving the target. ie if I set the first target as vwap then the stop for the remaining contract will move to breakeven once vwap is hit with the following code:

    if (Close[0]> vwap1)
    {AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId1) , "STOP2", atmStrategyId1);
    }

    The problem now is once I manually move the target on entry I'm not sure how to reference it using programming as I have no reference. I need to say something like "if TARGET1 has been reached" or if TARGET1 is no longer active then move stop as follows:

    GetAtmStrategyPositionAveragePrice(atmStrategyId1) , "STOP2", atmStrategyId1);

    I couldn't find anything in the manual or in the threads about this specific issue. I did find this so not sure how it fits in:

    string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");


    Thanks in advance
    DJ

    #2
    Hi DJ,

    You have to monitor for the fill order state on these orders. There is a dedicated method for it:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      OrderState

      Thanks Ryan, although I don't understand that and am trying a workaround. Can I use this instead?

      GetAtmStrategyPositionQuantity("id").

      eg if Close[0] > vwap1 (it will close one of the two contracts if VWAP is reached)

      Something like if GetAtmStrategyPositionQuantity("id") <2 (meaning only one contract remains) then it will move the remain contract to break even as follows:

      AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId1) +1*TickSize, "STOP2", atmStrategyId1);

      Thanks
      DJ

      Comment


        #4
        Yes, if it works for you there's no reason not to use it. Another thing to keep in mind is that stop strategies are already part of the ATM strategy template you save, so it may be simpler just to integrate any stop loss movement within the ATM strategy rather than code for it.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Atm

          Thanks Ryan, actually I need to do it this way because the targets and stops are based on horizontal lines I have pre-drawn on the chart. So once I put on the ATM strategy the stops and targets will then move to these lines on entry and already calculated risk/reward. I have found a much better way now by using this.

          GetAtmStrategyRealizedProfitLoss

          This is even better because only when there is a realized gain by taking off the first contract will it move the second contract to breakeven. When I was using Close[0] > target1 it would sometimes move the stop even though the contract hadn't been taken off. Code as follows:

          // 1. Set targets stop loss on entry

          if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) <1)

          {

          AtmStrategyChangeStopTarget(0, lineStopline, "STOP1", atmStrategyId1);
          AtmStrategyChangeStopTarget(0, lineStopline, "STOP2", atmStrategyId1);
          }

          //2. SET TARGETS ON ENTRY

          AtmStrategyChangeStopTarget(lineTargetone,0, "TARGET1", atmStrategyId1);
          AtmStrategyChangeStopTarget(lineTargettwo,0, "TARGET2", atmStrategyId1);


          //3. Change Stop 2 to Breakeven once 1st Target reached and gain > $1

          //if (Close[0]> lineTargetone)
          if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) >1)

          {
          AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId1) +1*TickSize, "STOP2", atmStrategyId1);
          }

          I just tested it and seems to work perfectly. I'm quite happy about it.

          Thanks
          DJ

          Comment


            #6
            Nice work, DJ! It's good to see that you're able to make these methods work for your purposes. Thanks for sharing your progress on it here.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              How to move or adjust the target price

              I just want to know if there is a way to move or adjust the target price when the trade is filled? Thanks in advance.

              Comment


                #8
                Hi luxurious_04,

                Yes, you can use this method to change the target price for NS > ATM based strategies.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by djkiwi View Post
                  Thanks Ryan, actually I need to do it this way because the targets and stops are based on horizontal lines I have pre-drawn on the chart. So once I put on the ATM strategy the stops and targets will then move to these lines on entry and already calculated risk/reward. I have found a much better way now by using this.

                  GetAtmStrategyRealizedProfitLoss

                  This is even better because only when there is a realized gain by taking off the first contract will it move the second contract to breakeven. When I was using Close[0] > target1 it would sometimes move the stop even though the contract hadn't been taken off. Code as follows:

                  // 1. Set targets stop loss on entry

                  if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) <1)

                  {

                  AtmStrategyChangeStopTarget(0, lineStopline, "STOP1", atmStrategyId1);
                  AtmStrategyChangeStopTarget(0, lineStopline, "STOP2", atmStrategyId1);
                  }

                  //2. SET TARGETS ON ENTRY

                  AtmStrategyChangeStopTarget(lineTargetone,0, "TARGET1", atmStrategyId1);
                  AtmStrategyChangeStopTarget(lineTargettwo,0, "TARGET2", atmStrategyId1);


                  //3. Change Stop 2 to Breakeven once 1st Target reached and gain > $1

                  //if (Close[0]> lineTargetone)
                  if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) >1)

                  {
                  AtmStrategyChangeStopTarget(0, GetAtmStrategyPositionAveragePrice(atmStrategyId1) +1*TickSize, "STOP2", atmStrategyId1);
                  }

                  I just tested it and seems to work perfectly. I'm quite happy about it.

                  Thanks
                  DJ
                  DJ,

                  How do you define the variable atmStrategyId1 ?

                  Omololu

                  Comment


                    #10
                    Atm

                    Hi Lolu,

                    I just have this in variables:

                    private string atmStrategyId1 = string.Empty;
                    private string orderId1 = string.Empty;

                    Cheers
                    DJ

                    Comment


                      #11
                      Realized ATM

                      Hi Ryan, I do have a small problem with this code and would be grateful for a workaround:

                      if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) >1)

                      The problem of course is if you enter another trade using the same atmstrategy and you have a realized profit already booked then the ATM will automatically move to BE. The question is how do I ignore the overall realized gain and just check the realized gain for the current trade?

                      Thanks
                      DJ

                      Comment


                        #12
                        Hi DJ, are you aware of the concepts of this reference sample for working with ATM Strategies and their PnL info?

                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Bertrand, yes I've been using these for awhile now. The question is on the ATMrealized part? Is that specific to the current trade or the trades for the day?

                          For example if I have had 3 trades and they are all winners?Then I enter a new trade the ATMrealized code applies to that new trade only?

                          Thanks
                          DJ

                          Comment


                            #14
                            DJ, that would be specific to the atmStrategyId used - if you nullify that and reuse a fresh id, it would reset as well.
                            BertrandNinjaTrader Customer Service

                            Comment


                              #15
                              Hi Bertrand, sorry I'm not clear on that. If you look at post 5 what would I do there for example?

                              So if I stop the strategy and then restart it, that doesn't reset the getatmrealized to zero? Is the realized for the day only?

                              Thanks in advance
                              DJ

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nightstalker, 05-04-2024, 02:05 PM
                              5 responses
                              53 views
                              1 like
                              Last Post nightstalker  
                              Started by MSerag, Yesterday, 11:52 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post MSerag
                              by MSerag
                               
                              Started by DynamicTest, Yesterday, 11:18 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post DynamicTest  
                              Started by dcriador, Yesterday, 01:43 AM
                              3 responses
                              20 views
                              0 likes
                              Last Post dcriador  
                              Started by smartromain, Yesterday, 10:50 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post smartromain  
                              Working...
                              X