Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Stop and Target with conditions

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

    Stop and Target with conditions

    I am attemting to set different stop and target levels based on ADX level at Entry. Can someone please tell me how to achieve this correctly?

    if (strx2 == "UT" && strx1 == "UT" && strsignal == "MACD Cross UP" && ADX(14)[2] < ADX(14)[1] && Close[0] > SMA(36)[0])

    {
    Print("-----------RGAuto:" + strsignal);
    Print("signal:" + strsignal + " XAV1:" + strxav1 + " Xav2:" + strxav2);

    {
    int n = 0;
    EnterLong(lots, "UT+UT");
    //EnterLongStopLimit(0, true, 1, High[0] + 4 * TickSize, High[0] + 4 * TickSize, "UT+UT");
    RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Ninja Trader7\MyScalper");
    key.SetValue("signalname", "UT+UT.Long");
    key.Close();
    if (Position.MarketPosition == MarketPosition.Long && ADX(14)[0] <= ADXshort)
    {
    SetProfitTarget(CalculationMode.Ticks, target2);
    SetStopLoss(CalculationMode.Ticks, stop2);
    }
    else if (Position.MarketPosition == MarketPosition.Long && ADX(14)[0] >= ADXshort)
    {
    SetProfitTarget(CalculationMode.Ticks, target1);
    SetStopLoss(CalculationMode.Ticks, stop1);
    }
    }

    #2
    Hello Gille1983,

    You want to place the stop to the price of the ADX?

    Or you are trying to subtract the ADX from the current price?

    Currently, you appear to have the Set methods using a number of ticks.

    Are you wanting to use the ADX as a number of ticks from the current close price?


    I recommend calling Set methods before calling an entry method. Set methods cannot be unset, but can be updated after the order is working. This means they should be set before a new entry is placed so they are not using the values from the previous entry.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, no im trying to set the stop and target depending on the ADX level at entry so:

      I have entered a long position, at the time of market entry the ADX was below 20, so I wish to have a tighter stop and target .

      On the other hand if on entry it was above I want to set another stop and target , hope that makes sense

      Comment


        #4
        Hello Gille1983,

        I'm not certain that I am following.

        If the ADX(14)[0] is greater than 20, you would like to add 1 tick to the price of a stop order and to a limit order so these both become working 1 tick higher than their original working price?

        If the ADX(14)[0] is less than 20, you would like to add 1 tick to the current working price of the stop and subtract 1 tick from the current working price of the limit, is this correct?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thats correct.

          Comment


            #6
            Hello Gille1983,

            If I am understanding this correctly the code would similar to:

            private bool movedOnce = false;
            private double stopPrice, targetPrice;

            if (ADX(14)[0] > 20 && Position.MarketPosition == MarketPosition.Long && !movedOnce)
            {
            stopPrice += TickSize;
            targetPrice += TickSize;

            SetStopLoss(stopPrice);
            SetProfitTarget(targetPrice);
            movedOnce = true;
            }

            If the ADX(14) is greater than 20 and the position is long, add 1 tick to the stopPrice and TargetPrice.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Perfect thank you very much for your help

              Comment


                #8
                Chelsea is the best. I am hereby ordering NinjaTrader to double her salary immediately.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by aa731, Today, 02:54 AM
                0 responses
                1 view
                0 likes
                Last Post aa731
                by aa731
                 
                Started by thanajo, 05-04-2021, 02:11 AM
                3 responses
                469 views
                0 likes
                Last Post tradingnasdaqprueba  
                Started by Christopher_R, Today, 12:29 AM
                0 responses
                10 views
                0 likes
                Last Post Christopher_R  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,237 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                4 views
                0 likes
                Last Post thread
                by thread
                 
                Working...
                X