Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to change the set profit target for short orders

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

    #16
    Hello, I'm not hiding the code. I changed the code and ran as is with the modified names so that it would show in the log. That's why I'm saying that the Set Profit is not doing anything.

    The current code is.

    Code:
    if (AverageDownSet && !AverageDownExecuted)
    {
        Print("Current Ask" + GetCurrentAsk());
        Print("Current Bid" + GetCurrentBid());
        Print("Supplied Price" + AverageDownTP);
        
        if (Position.MarketPosition == MarketPosition.Short)
        {
            SetProfitTarget("Short", CalculationMode.Price, AverageDownTP);
        }
        if (Position.MarketPosition == MarketPosition.Long)
        {
            SetProfitTarget("Long", CalculationMode.Price, AverageDownTP);
        }
        
        AverageDownExecuted = true;
    }​
    
    ShortEntryPrice = Closes[1][0] - TickSize;
    SetStopLoss(CalculationMode.Ticks, (StopLossValueShort));
    SetProfitTarget("Short", CalculationMode.Ticks, 99999);
    // Enter Short
    if (GetCurrentBid() > ShortEntryPrice)
    {
        EnterShortStopMarket(0, false, Qty, ShortEntryPrice, "Short");
    }​
    
    if (Position.MarketPosition == MarketPosition.Short)
    {
        if (Closes[0][0] > ShortEntryPrice && AllowAverageDownShort && !AverageDownSet)
        {
     
            AverageDownEntry = ###
            AverageDownSL = ###
            AverageDownTP = ###
    
            SetStopLoss("Average Down Short", CalculationMode.Ticks, AverageDownSL, false);
            SetProfitTarget("Average Down Short", CalculationMode.Price, AverageDownTP);
            EnterShortLimit(0, false, ReentryQty, AverageDownEntry, "Average Down Short");
        }
    }​
    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
        /* We advise monitoring OnExecution() to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
        which ensures your strategy has received the execution which is used for internal signal tracking.
        
        This first if-statement is in place to deal only with the long entry. */
    
        if (execution.Order.Name == "Average Down Long" || execution.Order.Name == "Average Down Short")
        {
            AverageDownSet = true;
        }
    }​

    Comment


      #17
      Also it's saying that the
      • Error: PHP Max Post Size has been exceeded.
      Which was why I was only grabbing the relevant timestamps on the log files. (Perhaps you should ask if they can allow for larger uploads?)

      Here is the truncated log file that I can't upload. It starts from 10/29/2024 Since I apparently can't upload the whole thing.

      Last edited by mintos; 11-15-2024, 10:09 AM.

      Comment


        #18
        Hello mintos,

        Use a web file sharing service and provide a link if the file is too large.
        The simple, quick and secure way to send your files around the world without an account. Share your files, photos, and videos today for free.



        Where is the SetStopLoss with the FromSignalName 'Short' in this code?

        11/12/2024 4:00:00 AM Strategy 'testcode/-1': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Short' Mode=Ticks Value=99999 IsSimulatedStop=False IsMarketIfTouched=False

        To confirm you are using 99999 as the number of ticks for the target?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Here is the SetStopLoss from signal name "Short" in the code.

          Code:
          ShortEntryPrice = Closes[1][0] - TickSize;
          SetStopLoss(CalculationMode.Ticks, (StopLossValueShort));  // <==============
          SetProfitTarget("Short", CalculationMode.Ticks, 99999);
          // Enter Short
          if (GetCurrentBid() > ShortEntryPrice)
          {
          EnterShortStopMarket(0, false, Qty, ShortEntryPrice, "Short");
          }​​
          Code:
          [NinjaScriptProperty]
          [Range(1, double.MaxValue)]
          [Display(Name = "Stop Loss", Description = "Stop Loss in ticks", Order = 1, GroupName = "Short Parameters")]
          public double StopLossValueShort
          { get; set; }​
          Last edited by mintos; 11-16-2024, 10:57 PM.

          Comment


            #20
            Hello mintos,

            This is not using 'Short' as the FromEntrySignal.

            Use:

            SetStopLoss("Short", CalculationMode.Ticks, (StopLossValueShort));


            The profit target may not have been submitted due to the distance.

            Try using 20 ticks. Does the order get submitted?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            556 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X