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

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 maybeimnotrader, Yesterday, 05:46 PM
          3 responses
          23 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by stafe, 04-15-2024, 08:34 PM
          7 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          22 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X