thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
double value for entry price and int value for entry bar
Collapse
X
-
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
-
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
-
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
Code:private double entryPrice = 0.00; private int entryBar = -1;
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:
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
-
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
-
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?
Comment
-
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?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
Comment