thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
double value for entry price and int value for entry bar
Collapse
X
-
Use a struct to hold both related values.Originally posted by kenb2004 View PostCan 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
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
-
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?Originally posted by kenb2004 View Postif (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
-
For a single position, that is not really onerous.Originally posted by kenb2004 View PostNo, 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.
//declare class variables
//use them in the update event.Code:private double entryPrice = 0.00; private int entryBar = -1;
Whether you put that in a struct as I recommended, is up to you.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; }
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
-
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:
Problem is that these values will change. How do I make them remain constant?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]Last edited by kenb2004; 10-04-2012, 01:16 PM.
Comment
-
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.Originally posted by kenb2004 View PostProblem is that these values will change. How do I make them remain constant?
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
-
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
-
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.Originally posted by kenb2004 View PostOk, 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?
You simple need your entry price, not the average price. Am I missing something?
Comment
-
Ken, Position.AvgPrice is going to change when you scale in.Originally posted by kenb2004 View PostOk, 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?
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
-
Originally posted by kenb2004 View PostThanks 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 NullPointStrategies, Today, 05:17 AM
|
0 responses
39 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment