Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set exit with variables

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

    Set exit with variables

    Hello please i need to set the exit profit of my strategy

    Example:

    Entryprice: 20
    Shortstop: 25
    Shortprofit: 10 . I need set this price but i dont know the correct syntax.

    I try with this but dont work

    // Set 1
    if ((EMA1[0] < EMA2[0])
    && (CrossBelow(Close, EMA3, 1))
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    EnterShort(Convert.ToInt32(QuantityStocks), @"sell");
    Shortloss = Swing1.SwingHigh[0];
    Shortprofit = ((Swing1.SwingHigh[0] - ((Position.AveragePrice)*2 ) - (Position.AveragePrice))) ;
    }

    // Set 2
    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShortStopMarket(Convert.ToInt32(QuantityStocks ), Shortloss, @"exitshortloss", @"sell");
    }

    // Set 3
    if (Position.MarketPosition == MarketPosition.Short)
    {
    ExitShortMIT(Convert.ToInt32(QuantityStocks), Shortprofit, @"sellprofit", @"sell");
    }

    #2
    Hello walter739,

    When you mention "I need set this price but i dont know the correct syntax.", what is "this price"?

    What is the price you want to set to the Shortprofit variable?

    Are you trying to set Shortprofit to an exact price of 10?
    private Shortprofit;
    Shortprofit = 10;

    Do you mean 10 ticks above the current ask price?
    Shortprofit = GetCurrentAsk() + 10 * TickSize;

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB, thanks for answer, sorry i m not explain well. I need the Shortprofit variable an relation 2 to 1 to the Shorlloss Variable. If the price of stop is 5 greater the entry, the profit must be 10 less the entry, it the stop is 6 the profit must be 12.

      I set fine the Shortstop with indicator Swing high, but i dont know how set the formula for Shortprofit .using reference the Shortloss and Position.AveragePrice

      Shortloss = Swing1.SwingHigh[0];
      Shortprofit = ((Swing1.SwingHigh[0] - ((Position.AveragePrice)*2 ) - (Position.AveragePrice))) ;

      Only examples the entry price:

      Entryprice: 30
      Shortstop: 35
      Shortprofit: 20

      Entryprice: 40
      Shortstop: 45
      Shortprofit: 30

      I try with the code above but dont work.

      If you can help me with the syntax

      Regards

      Comment


        #4
        Hello walter739,

        I am not able to assist with a custom formula or custom logic but I can assist with an error message?

        Are you getting an error?

        What is the error message?


        If you are wanting assistance writing a formula, this thread will remain open for the community to assist.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello, ChelseaB, thanks for your time.

          I work with this formula and work fine. I write for other users in the future.

          Shortprofit = (Math.Abs(Position.AveragePrice - (Shortloss - Position.AveragePrice))

          Regards

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          43 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          47 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X