PDA

View Full Version : entry price variable not working!!!


james377
09-22-2010, 03:09 PM
how do I set a variable under onbarupdate to set to the price I entered the market at?

double EntryPrice = Position.AvgPrice;

this doesnt seem to be working for me as when I added

double EntryPrice = Position.AvgPrice;
Print(EntryPrice);

it printed 0! yes...a load of zeros?!!

can anybody help me here???

NinjaTrader_RyanM
09-22-2010, 03:15 PM
Hello James377,

Yes, it will be zero if you are not in a position. You may want to consider this check.

if (Position.MarketPosition (http://www.ninjatrader-support.com/HelpGuideV6/MarketPosition.html)!= MarketPosition.Flat)
{
double EntryPrice = Position.AvgPrice;
Print(EntryPrice);
}

james377
09-22-2010, 03:22 PM
thanks for this but the output window is just returning a load of zeros again?? why is this??help!

james377
09-22-2010, 03:26 PM
profitfactor = 2;
EntryPrice = Position.AvgPrice;
//Print(EntryPrice);
SetProfitTarget("", CalculationMode.Price,EntryPrice + (profitfactor * TickSize));

any ideas why this wont work in onbarupdate?

NinjaTrader_RyanM
09-22-2010, 04:09 PM
Make sure you've recompiled, removed any instances of the strategy and try again.

If you have any issues, please post the most recent OnBarUpdate() block for the code you're working with.