• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2 stupid questions

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

    2 stupid questions

    Hello my dear friend! Sorry for this questions but i cant find this

    1. I need if to checking opened position and checking for long or short

    if Opened Position true
    then check long or short

    2 If long/short and profit more then N then close opened position

    thank u very mutch

    #2
    Hello,
    Thank you for your post.
    This is posible by using Position.MarketPosition and Position.GetProfitLoss

    I have provided an example of this below.
    Code:
    if(Position.MarketPosition != MarketPosition.Flat && Position.GetProfitLoss(Close[0], Performance.Currency) > N )//N is variable amount set to desired profit amount
    {
        if(Positiion.MarketPosition == MarketPosition.Long
        {
             ExitLong();
        }
        if(Positiion.MarketPosition == MarketPosition.Long
        {
             ExitShort();
        }
    }
    For more information on Position.MarketPosition and Position.GetProfitLoss see the following link, http://ninjatrader.com/support/helpG...7/position.htm

    If we can be of any other assistance please let us know.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      When i trying to compile this code
      Code:
      	if(Position.GetProfitLoss(Close[0], Performance.Currency) > 0){
      					  ExitLong();
      				}
      I have error that Performance.Currency is not available (code CS1061)

      (checking currency trade position)

      Comment


        #4
        Originally posted by baryshnikov View Post
        I have error that Performance.Currency is not available (code CS1061)
        Are you on NT8? If you are, `Performance` has been replaced by SystemPerformance.
        Last edited by J_o_s; 10-20-2015, 03:52 AM. Reason: typo

        Comment


          #5
          Hello,
          If you are on NinjaTrader 8 you would replace it in the Strategy Code with SystemPerformance.Currency.

          If this is in NinjaTrader 7 please make sure you are entering this with a strategy. This code would not be documented with an Indicator.
          Cody B.NinjaTrader Customer Service

          Comment


            #6
            i added

            Code:
            			Add(PeriodType.Minute, 180);
            			Add(PeriodType.Minute, 60);
            if this code

            Code:
            double ATRPeriod = ATR(20)[1];
            double ATRPeriod = ATR(20)[2];
            generate ATR from 3h and 1h ?
            Last edited by baryshnikov; 10-21-2015, 04:11 PM.

            Comment


              #7
              does anybody know about ATR?

              Comment


                #8
                Hello,
                I apologize on the delay for this response.
                This would not generate this from the 3 hour and 1 hour.
                You would to use a different constructor overload for the ATR:
                Code:
                double ATRPeriod = ATR(BarsArray[1], 20)[0]
                double ATRPeriod = ATR(BarsArray[2], 20)[0]
                For more information on the constructor overloads for the ATR please see the following link, http://ninjatrader.com/support/helpG..._range_atr.htm
                The BarsArray[] collection calls the information from the from the selected added data series. BarsArray[1] will grab data from the 3 hour and BarsArray[2] will get it from the 1 hour. If you do not add in the BarsArray it will plot the data based off of the primary data series of the chart.

                If we can be of any other assistance please let us know.
                Cody B.NinjaTrader Customer Service

                Comment


                  #9
                  hello my dear friend! i have 2 new questions


                  1. I need to check this

                  if current trade was opened on 1 and more Bars ago && currents trade profit > 0 then ...

                  is this code true

                  Code:
                  if (BarsSinceEntry () > 1 
                             && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) > 0
                                 )

                  2. How to check this

                  if i had trade in current bar && trade profit < 0 then ...

                  // i must to checking did i have any trade in current bar with lose profit (<0)

                  Comment


                    #10
                    Hello,
                    The code you have for number 1 is correct.
                    For number 2you could do the following:
                    Code:
                    if(BarsSinceEntry() == 0
                       && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) < 0
                    If we can be of any other assistance please let us know.
                    Cody B.NinjaTrader Customer Service

                    Comment


                      #11
                      thank u!
                      but how i can get opened price for current position? i need

                      SetStopLoss(CalculationMode.Price, here price with which this opsition was opened)

                      Comment


                        #12
                        Hello,
                        You can get the the price of your position by doing Position.AvgPrice.
                        Code:
                        SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                        For more information on Position.AvgPrice please see the following link,

                        Please let us know if you have any other questions.
                        Cody B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello!

                          1. Can i get time when current position was opened? or i must saving time when make any order?

                          2. I need to compare 2 times. if current time > order time 100 min then...
                          how i can compare 2 times in min format?

                          Comment


                            #14
                            Hello,
                            You can use GetBar to get the bar at the time of your entry and then compare that time + 100 minutes and compare it to the current time.

                            I have provided an example of how you can accomplish this.

                            Code:
                            #region Variables
                            private int timeBar = 0;
                            
                            protected overrid voide OnBarUpdate()
                            
                            if(SMA(20)[0] > SMA(5)[0]) //This is just an example condition of a condition for entry
                            {
                            	EnterLong();
                            	timeBar = GetBar(Time[0]);// this Gets the bar of the current time and assigns it to         the int timeBar
                            }				
                            if(Time[0] >= Time[CurrentBar - timeBar].AddMinutes(100));// This gets the current time and then compares it to the Time of the Time at timeBar and adds 100 minutes to it.
                            {
                            	ExitLong();
                            }
                            
                            If we can be of any other assistance please let us know.
                            Cody B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by SAITON, Today, 09:03 PM
                            0 responses
                            1 view
                            0 likes
                            Last Post SAITON
                            by SAITON
                             
                            Started by suprsnipes, Today, 08:26 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post suprsnipes  
                            Started by RobertoPaez, Today, 06:47 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post RobertoPaez  
                            Started by catinabag, Today, 06:45 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post catinabag  
                            Started by darkgreen, Today, 03:35 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post darkgreen  
                            Working...
                            X