How to get the price of entry into the position?

howto
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

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

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(); 

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

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

Help me please.
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;
Buy = Kvhod == TimeNum();
Sell = 0;
trailstop = 0;
trailARRAY = BuyPrice = Null;

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

   if( trailstop == 0 AND Buy[i] )  
   {	BuyPrice[i] = Open[i];
		Buy[i] = 1;
   }
   else Buy[i] = 0; // remove excess buy signals
}

PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

Plot( BuyPrice,"BuyPrice", colorGold );

First day: BuyPrice = 30'481
Second day: the price has changed to 30'501.

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

12


#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;
ItsTime = Kvhod == TimeNum();
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;
Buy = Kvhod == TimeNum();
Sell = 0;
trailstop = 0;
trailARRAY = BuyPrice = Pos = Null;

for( i = 1; i < BarCount; i++ )
{	BuyPrice[i] = BuyPrice[i-1];
	Pos [i]  = Pos [i-1];
	
   if( IsNull(Pos [i]) AND Buy[i] OR Pos [i]==1 AND Buy[i] ) 
   {	BuyPrice[i] = Open[i];
		Buy[i] = 1;
		Pos[i] = 1;
		//trailstop = BuyPrice[i]*(1-1/100); 
   }
   else Buy[i] = 0; // remove excess buy signals
}

PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);

Plot( BuyPrice,"BuyPrice", colorGold );

This is not work. :slightly_frowning_face:


#9

Look up Exrem() function. Basically your code is generating a buy single everyday at your specified time.

The usual code would be ExRem(Buy, Sell), however your formula doesn’t have a sell signal from what you posted.