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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      153 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      133 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      128 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X