Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stoploss and profit are not working. Why?

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

    stoploss and profit are not working. Why?

    Hello everyone,
    I created a # region Position to define target and stop the long and short positions, then once # region OrderRouting, private void MenagerOrder. Then, in section protected override void OnBarUpdate () First, recall MenagerOrder (), then if I define the input. Why in the chart when I apply the strategy does not occur in transactions as MenagerOrder ()?
    Here is the code I wrote:
    CalculateOnBarClose = true;
    # Region Position
    private void GoLong ()
    (
    SetStopLoss (LongBuy "CalculationMode.Price, Low [2] - ATR (14) [0] * 0.3 * TickSize, false);

    SetProfitTarget ("1st Step LongBuy" CalculationMode.Price, Close [0] + ATR (14) [0]);
    Print ("level LongBUy Stop Loss");
    )
    private void GoShort ()
    (
    SetStopLoss (ShortSell "CalculationMode.Price, High [2] + ATR (14) [0] * 0.3 * TickSize, false);
    SetProfitTarget ("1st Step ShortSell" CalculationMode.Price, Close [0] + ATR (14) [0]);
    Print ("Stop Loss level ShortSell");
    )

    #region OrderRouting
    private void MenagerOrder()
    {
    if (Position.MarketPosition == MarketPosition.Long)
    {
    if( High[0]> Position.AvgPrice + ATR (14)[0])
    ExitLong(1, "1° Target LongBuy", "");
    SetStopLoss("LongBuy",CalculationMode.Price,Positi on.AvgPrice,false);
    }
    if (Position.MarketPosition == MarketPosition.Short)
    {
    if( Low[0]< Position.AvgPrice - ATR (14)[0])
    ExitShort(1, "1° Target ShortSell", "");
    SetStopLoss("LongBuy",CalculationMode.Price,Positi on.AvgPrice, false);

    }


    protected override void OnBarUpdate()
    {
    MenagerOrder();

    if (Position.MarketPosition == MarketPosition.Flat &&
    CrossAbove(StochasticsFast(3, 14).K, StochasticsFast(3, 14).D, 1)
    && StochasticsFast(3, 14).D[0] >= 75)
    {
    EnterLong(2, " Long Stocastico");
    Print (" long" );

    }
    if (Position.MarketPosition == MarketPosition.Flat &&
    CrossBelow(StochasticsFast(3, 14).K, StochasticsFast(3, 14).D, 1)
    && StochasticsFast(3, 14).D[0] < 26)
    {
    EnterShort(2, " Short Stocastico");
    Print (" short");

    }



    Thank you.
    Ciao.
    Italy

    #2
    Hello,

    Thank you for your forum post.

    Just wanted to let you know that we received your note and that someone will respond this weekend or at the latest Monday.

    Thank You for your Patience.
    BrettNinjaTrader Product Management

    Comment


      #3
      Italy, please enable TraceOrders in your strategy to debug your order behavior further -



      From a quick look at your code I think the signal naming is off, i.e. you refer to entry signal names in your exit orders that do not exist, hence they get ignored - this would show up in the trace orders output for example and then you could address it in your code.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      582 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X