Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

double value for entry price and int value for entry bar

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

    double value for entry price and int value for entry bar

    Can you please recommend a good way to capture a double value for an entry price and int value for the same entry bar? I'm using Managed Approach.
    thanks

    #2
    Entry price: Position.AvgPrice
    Entry Bar: CurrentBar - BarsSinceEntry

    Comment


      #3
      Originally posted by kenb2004 View Post
      Can you please recommend a good way to capture a double value for an entry price and int value for the same entry bar? I'm using Managed Approach.
      thanks
      Use a struct to hold both related values.

      The members of the struct will be:

      entryPrice = Close[0]; //or however you enter. You just need to capture the price at entry.
      entryBar = CurrentBar;

      You use a filter to ensure that this happens only once until exit from the position. Depending on whether you are all-in/all-out or scaling in and out, this may be as simple as filtering on whether or not the position is flat for the former scenario, or else using bool variables for the latter scenario.
      Last edited by koganam; 10-04-2012, 11:07 AM.

      Comment


        #4
        if (Position.MarketPosition != MarketPosition.Flat){
        _entryprice = Position.AvgPrice;
        _entrybar = CurrentBar-BarsSinceEntry();
        }

        If I used the above code and scaled in another position would these value remain the same or would they change?

        Comment


          #5
          Originally posted by kenb2004 View Post
          if (Position.MarketPosition != MarketPosition.Flat){
          _entryprice = Position.AvgPrice;
          _entrybar = CurrentBar-BarsSinceEntry();
          }

          If I used the above code and scaled in another position would these value remain the same or would they change?
          Based on that code, those values will be updated on every BarUpdate event, as long as you are not flat. Is that really your intent?

          Comment


            #6
            No, my intent is to capture the original entry price and bar index, regardless of any additional positions, and have them remain the same until flat.

            Comment


              #7
              Originally posted by kenb2004 View Post
              No, my intent is to capture the original entry price and bar index, regardless of any additional positions, and have them remain the same until flat.
              For a single position, that is not really onerous.

              //declare class variables
              Code:
              private double entryPrice = 0.00;
              private int entryBar = -1;
              //use them in the update event.
              Code:
              bool entryConditionMet = false;
              entryConditionMet = yadaYadaYada;
              
              if (entryConditionMet && Position.MarketPosition == MarketPosition.Flat)
              {
              entryPrice = Close[0]; //or however you enter. You just need to capture the price at entry.
              entryBar = CurrentBar;
              }
              Whether you put that in a struct as I recommended, is up to you.

              If you are scaling in and out, that is a whole different can of worms. I would suggest that you write the pseudocode for how you will enter and exit. After that, translating to code is not really that hard.

              Comment


                #8
                If you are scaling in and out, that is a whole different can of worms. Yes I am scaling in and out. Worms please.....
                This is the initial entry code:

                Code:
                 
                [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Position.MarketPosition == MarketPosition.Flat && Close[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]]<OpenPrice){[/COLOR][/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]EnterLongLimit([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], OpenPrice - E1 * TickSize, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Buy_Entry"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]); [/SIZE][/FONT]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]if (Position.MarketPosition == MarketPosition.Long){[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]_entryprice = Position.AvgPrice;[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]_entrybar = CurrentBar;[/FONT][/SIZE]
                [SIZE=2][FONT=Courier New]}[/FONT][/SIZE][/SIZE][/FONT]
                Problem is that these values will change. How do I make them remain constant?
                Last edited by kenb2004; 10-04-2012, 01:16 PM.

                Comment


                  #9
                  Use a different variable for each entry, I think that would be the only way.

                  Comment


                    #10
                    Originally posted by kenb2004 View Post
                    Problem is that these values will change. How do I make them remain constant?
                    Precisely.That is why you have to write out in language the entry and exit conditions. Then it is a matter of translating it into code. In other words, there are myriad possibilities when you are scaling ion and out. You have to write down the conditions for exiting. The scaling in part is pretty much making separate entries when conditions are satisfied. You can then decide if you want to keep separate entry prices, or you want to use the average price.

                    The problem is to ensure that the position is property monitored for its actual state as exits are made, and that re-entry only occurs when proper conditions are met. I do not doubt that there are coding gurus who can keep all that in mind, and code it on the fly, but for most of us mortals, we would need the thought stream properly clarified first.

                    Comment


                      #11
                      Ok, maybe I'm missing something here. The issue is NOT the scaling in or out process. That process is the REASON for capturing the first entry value. I already have the thought process for the scaling in and out. I don't need to capture any other entries except entry 1. And that value must not change until, no matter whether I scale in or out. Only entry 1 needs to be captured.

                      So how do you capture the value of a single entry that is not changed by the property of Position.AvgPrice?

                      Comment


                        #12
                        Originally posted by kenb2004 View Post
                        Ok, maybe I'm missing something here. The issue is NOT the scaling in or out process. That process is the REASON for capturing the first entry value. I already have the thought process for the scaling in and out. I don't need to capture any other entries except entry 1. And that value must not change until, no matter whether I scale in or out. Only entry 1 needs to be captured.

                        So how do you capture the value of a single entry that is not changed by the property of Position.AvgPrice?
                        I have already given you that code. Initially in a sketchy fashion then fleshed out in the response to which your current response is directed. You simple need your entry price, not the average price. Am I missing something?

                        Comment


                          #13
                          Originally posted by kenb2004 View Post
                          Ok, maybe I'm missing something here. The issue is NOT the scaling in or out process. That process is the REASON for capturing the first entry value. I already have the thought process for the scaling in and out. I don't need to capture any other entries except entry 1. And that value must not change until, no matter whether I scale in or out. Only entry 1 needs to be captured.

                          So how do you capture the value of a single entry that is not changed by the property of Position.AvgPrice?
                          Ken, Position.AvgPrice is going to change when you scale in.

                          If you need the fill price of an individual order (i.e., your first entry) you will need to switch to an IOrder AvgFillPrice



                          Or if you would like to stick with Position.AvgPrice, you will need to store this value in a variable or even a data series.
                          MatthewNinjaTrader Product Management

                          Comment


                            #14
                            Thanks Mathew

                            "Or if you would like to stick with Position.AvgPrice, you will need to store this value in a variable or even a data series."

                            How would you do that?

                            Comment


                              #15
                              Originally posted by kenb2004 View Post
                              Thanks Mathew

                              "Or if you would like to stick with Position.AvgPrice, you will need to store this value in a variable or even a data series."

                              How would you do that?
                              If I may ask, why are you so enamored of the AvgPrice? Especially since you do not want to track its changing value anyway?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Started by JoMoon2024, Today, 06:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post JoMoon2024  
                              Started by Haiasi, 04-25-2024, 06:53 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post Massinisa  
                              Started by Creamers, Today, 05:32 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Creamers  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              12 responses
                              1,786 views
                              0 likes
                              Last Post Leafcutter  
                              Working...
                              X