Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Procedure closing current positions. Is it valid?

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

    Procedure closing current positions. Is it valid?

    the code is:

    private void exit0()
    {
    if (Position.Quantity!=0 && Position.MarketPosition==MarketPosition.Long)
    {
    curPL=Position.GetProfitLoss(GetCurrentAsk(), PerformanceUnit.Points);
    if (Position.AvgPrice < GetCurrentAsk() - tProf0 * TickSize)
    {ExitLong(1); start=GetCurrentAsk();
    Print("LongProfit "+curPL+" avg:"+Position.AvgPrice+" cls:"+Close[0]);
    }
    if (Position.AvgPrice > GetCurrentAsk() + sLoss0 * TickSize)
    {
    ExitLong(1); start=GetCurrentAsk();
    Print("LongLoss"+curPL+" avg:"+Position.AvgPrice+" cls:"+Close[0]);
    }
    }
    curPL=Position.GetProfitLoss(GetCurrentBid(), PerformanceUnit.Points);
    if (Position.Quantity!=0 && Position.MarketPosition==MarketPosition.Short)
    {
    if (Position.AvgPrice > GetCurrentBid() + tProf0 * TickSize)
    {
    ExitShort(1); start=GetCurrentBid();
    Print("ShortProfit"+curPL+" avg:"+Position.AvgPrice+" cls:"+Close[0]);
    }
    if (Position.AvgPrice < GetCurrentBid() - sLoss0 * TickSize)
    {
    ExitShort(1); start=GetCurrentBid();
    Print("ShortLoss"+curPL+" avg:"+Position.AvgPrice+" cls:"+Close[0]);
    }
    }
    }

    The question is is in the subject actually... any coments? suggestions? can not use builtin stoploss/takeprofit functions due to strategy limitations...

    Is it better to use Position.GetProfitLoss function insted of my manual calcultaion?

    Cheers

    #2
    greed999, I would depend on your scenario and what you would like to see taking place, these exits here are market orders once the condition hits, so this would not be a stop market / stop limit order resting at your price.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you Bertrand, my idea is to exit position when it reaches predefined stopsloss takeprofit targets... as far as there are more than on entries built in functions wouldn't be usefull.

      If I describe exit conditions this way, will it work? Lets say, I have 1 long position:

      if (Position.AvgPrice < GetCurrentAsk() - tProf0 * TickSize) ExitLong(1);
      Last edited by greed999; 06-29-2011, 07:22 AM.

      Comment


        #4
        The exits as you coded in would work, my point was rather the timing of the order execution / submission and what you seeked here, with the order resting it could execute intrabar - with your code and the CalculateOnBarClose = true you would see the submission on the bar after the condition triggered it.

        You could though process exits with CalculateOnBarClose = false so the condition is monitored on each tick.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Wow... very interesting... so you are saying that I'm missing intrabar ticks and my condition would trigger only after the bar is closed?

          I'm calling my exit0 procedure from OnBarUpdate... thats why it wasn't working the way it should... In this case, where should I call it from?

          Comment


            #6
            It will entirely depend on what CalculateOnBarClose setting the OnBarUpdate() uses:

            BertrandNinjaTrader Customer Service

            Comment


              #7
              That was extremly helpful...
              Can you please tell me if there is a defference between these two expressions?
              Position.GetProfitLoss(GetCurrentAsk(), PerformanceUnit.Points)
              Position.AvgPrice - GetCurrentAsk() (lets assume that result is positive and the market position is long)

              Will the result be equal to PnL in (Positions) tab of the (Control Center)?

              Comment


                #8
                greed999, if you are only trading one share, then the values would be the same. Your equations do not take into account quantity, nor point value. You would have to do something like this to get actual p/l:
                Code:
                Position.GetProfitLoss(GetCurrentAsk(), PerformanceUnit.Currency);
                (GetCurrentAsk() - Position.AvgPrice) * Position.Quantity * MasterInstrument.PointValue;
                AustinNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by f.saeidi, Today, 11:02 AM
                0 responses
                1 view
                0 likes
                Last Post f.saeidi  
                Started by geotrades1, Today, 10:02 AM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by rajendrasubedi2023, Today, 09:50 AM
                3 responses
                15 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by lorem, Today, 09:18 AM
                2 responses
                11 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by geddyisodin, Today, 05:20 AM
                4 responses
                30 views
                0 likes
                Last Post geddyisodin  
                Working...
                X