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

Stoploss and Profittarget Problem

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

    Stoploss and Profittarget Problem

    Hi there, i have read many Hours in this forum, but i don´t find a solution.

    Here is my problem

    i will trade a 30 min bar. the ATR of this bar is 20 ticks for example. If i enter this bar i will make a profit target of this 20 ticks. I will make a stoploss of this 20 ticks. The Position will be stopped out or will go in profit. If the Position is closed, with or without Profit the next bar has a range of 15 ticks for example. So i need a PT of entry + 15 and a Stoploss of Entry -15. How can i make this ?

    please help me

    #2
    You could directly use SetProfitTarget and SetStopLoss set to CalculationMode.Ticks for this, as they would automatically reference your entryPrice directly when issuing the needed bracket orders (those Set Methods would be OCO'ed as well).
    BertrandNinjaTrader Customer Service

    Comment


      #3
      hi,

      thanks for your fast reply, but if i use the normal setstoploss ans setprofittarget i can only use normal values.

      i the 30 min bar 40 ticks i need 40 ticks stop and profit from entry if the bar has got 30 ticks i need 30 ticks SL and PT. How i can set the ticksize of PT and SL to the ticksize of my entrybar ?

      Comment


        #4
        You would need to custom code to achieve this - record the range of your entry bar at time of entry and then call SetStopLoss / SetProfitTarget to place the exit bracket at your desired values.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          hi this is what i´m locking for, but i have no idea how i make this ?

          is there a reference oder a code sample ? Sorry ..

          Comment


            #6
            Sorry, I'm not aware of a direct sample for this, the general idea is like demonstrated in this snippet below -

            Code:
             
            if (Position.MarketPosition == MarketPosition.Flat)
            {
            SetProfitTarget(CalculationMode.Ticks, 20);
            }
            
            if (CrossAbove(SMA(Fast), SMA(Slow), 1))
            {
            range = Math.Abs(High[1] - Low[1]);
            EnterLong();
            }
            
            if (Position.MarketPosition == MarketPosition.Long)
            SetProfitTarget(CalculationMode.Price, Position.AvgPrice + range);
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thx bertrand

              entry and PT work, SL don´t work

              Here is my Code

              Code:
              protected override void OnBarUpdate()
                      {
                          // Condition set 1
                          
                          if (Position.MarketPosition == MarketPosition.Flat)
                              {
                              SetProfitTarget(CalculationMode.Ticks, 20);
                              }
              
                          if (entry condition)
                              {
                              range = Math.Abs(High[0] - Low[0]);
                              EnterLong();
                                  }
                          if (Position.MarketPosition == MarketPosition.Long)
                          SetProfitTarget(CalculationMode.Price, Position.AvgPrice + range);
                          SetStopLoss(CalculationMode.Price, Position.AvgPrice - range);
                      }
              Last edited by thunderbolt78; 03-02-2010, 06:59 AM.

              Comment


                #8
                What error do you get with the targets? You would need to reset those as well when flat...
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  i have no error,

                  if i run the script with setstoploss and setprofittarget only Profittargt will filled. No Stoploss will triggered. I i run

                  if (Position.MarketPosition == MarketPosition.Long)
                  // SetProfitTarget(CalculationMode.Price, Position.AvgPrice + range);
                  SetStopLoss(CalculationMode.Price, Position.AvgPrice - range);

                  i have an Entry and after this the position will be stopped out but not with the right range.

                  Comment


                    #10
                    Please run the strategy with TraceOrders = true in your Initialize(), this will give you insight into it's order behavior -

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      May I ask how you guys post your codes in that blue box?

                      Comment


                        #12
                        Just wrap code tags around it...the rhomb symbol when you post...

                        Looks then like below -

                        Code:
                         
                        MyCodeIsHappyInThisBox
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Sorry Bertrand. is this "#" the rhomb symbol you are talking about? when you say wrap code tags around it, do you mean that I paste the code inbetween "
                          Code:
                          " and "
                          "?

                          Comment


                            #14
                            Thanks Bertrand! Got it now!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by gentlebenthebear, Today, 01:30 AM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by Aviram Y, Today, 05:29 AM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by cls71, Today, 04:45 AM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by TradeForge, Today, 02:09 AM
                            1 response
                            22 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by elirion, Today, 01:36 AM
                            2 responses
                            14 views
                            0 likes
                            Last Post elirion
                            by elirion
                             
                            Working...
                            X