# How to get the price of entry into the position?

Tags: #<Tag:0x00007f2d8b580c68>

#1

I'm trying to get the entry price for the position with the following formula

``````LongEntry = 130000 == TimeNum();
cvL = ValueWhen(LongEntry, Ref(Open,1)); //entry price
Plot(cvL,"cvL",colorAqua);	//drawing entry price

Sell = DateTime() == _DT("2017-12-15 14:18:00");
``````

But the problem is the following: every day at 13 o'clock, it updates entry price. How to keep the entry price, while the position of Long is active?

#2

Move cvL code to the END of your formula and replace it with `ValueWhen( Buy,...`

``````LongEntry = 130000 == TimeNum();

Sell = DateTime() == _DT("2017-12-15 14:18:00");

cvL = ValueWhen( Buy, Ref(Open,1)); //entry price
Plot(cvL,"cvL",colorAqua);	//drawing entry price
``````

#3

Thank you. This helped to open and close the deal correctly.

But the entry price continues to change every day at 13-00, it shows PLOT (cvL). I need entry price for later use in the formula.

#4

The price changes every day at 13:00
I changed the formula, but it did not help. How to get the entry price (unchanged every day)? Examples in pictures.

``````Kvhod = 130000;
Sell = 0;
trailstop = 0;

for( i = 1; i < BarCount; i++ )

if( trailstop == 0 AND Buy[i] )
}
}

PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

``````

Second day: the price has changed to 30'501.

How to make that BuyPrice does not change in the next days?

#5

Looks like your data source provider is changing (correcting) data after it happen.
Save/export the data right after the open, and next day check if the data has changed.

#6

This is history. The data does not change.

#7

Do you want to plot the price at 1 PM of previous day in next day ?

``````Kvhod = 130000;
PriceAtTime = ValueWhen(ItsTime, Open);
DayChange = Day() != Ref(Day(), -1);
PriceAtTimeYesterday = ValueWhen(DayChange, PriceAtTime);

Plot( PriceAtTimeYesterday,"PriceAtTimeYesterday", colorGold );
``````

#8

I want the next one: i buy 1 unit, for example for \$ 1100. This price should be Plot by a line, until there is a signal to sell it.

``````Kvhod = 130000;
Sell = 0;
trailstop = 0;
trailARRAY = BuyPrice = Pos = Null;

for( i = 1; i < BarCount; i++ )
Pos [i]  = Pos [i-1];

Pos[i] = 1;
}
}