Get time of Buy

Hello all,

How can I know the exact time Buy was executed?
I would like to do something as follow:
“Sell after X days past from Buying”

Thanks in advanced

There is a similar question there.

See More Question (position based management, turns, and triggers)

Perhaps you will find an answer there.

Thanks.
BarsSince(Buy) is perfect for my purpose.

But I think there is a bug in implementation (correct me if I’m wrong)
I want to Sell a stock that bought 5 days ago, no matter what append in stock price.
This is my simple program:

SetOption( "initialequity", 100000 );
SetPositionSize( 100, spsShares );
SetTradeDelays( 0, 0, 0, 0 );

BuyPrice = Close; 
SellPrice = Close;

Buy = Cross( 28, Rsi_Value); 
Sell =  BarsSince(Buy) >= 5;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Filter = Buy OR Sell OR BarsSince(Buy);
AddColumn(Buy, "Buy");
AddColumn(Sell, "Sell");
AddColumn(BarsSince(Buy), "BarsSince(Buy)");
AddColumn(BarsSince(Buy) >= 5, "BarsSince(Buy) >= 5");
AddColumn(Rsi_Value, "RSI");

And when looking at the results ofExploration you can see that after 5 days, BarsSince(Buy) >= 5 is TRUE but Sell is FALSE.
What could be the problem? am I doing something wrong?

Thanks

I suppose that a missing “Rsi_Value” is this: Rsi_Value = CalcRSI();

I removed both ExRem commands

// Buy = ExRem(Buy,Sell);
// Sell = ExRem(Sell,Buy);

Here is my Exploration then:

The problem is, that RSI crosses 28 again - sooner than after 5 bars.
It generates a new Buy signal which “restarts” BarsSince(Buy) command and it starts from zero again.

If RSI does not fall under 28 within 5 bars then it works as expected.

I am not sure how to solve that right now.

Thanks Bob.
I’m waiting for your solution

Can you try this code?

SetOption("Symbols","DVN");

SetOption( "initialequity", 100000 );
SetPositionSize( 100, spsShares );
SetTradeDelays( 0, 0, 0, 0 );

Rsi_Value = RSI();

BuyPrice = Close; 
SellPrice = Close;

Buy = Cross( 28, Rsi_Value); 

//  ======= New code ======>
// Remove consecutive BUYs within 5 bars after BUY (eh - how to say it better...)
counter = 5;
for(i=0;i < BarCount; i++){
  if (counter == 5 and Buy[i]) {
      counter = 0;      
  } else {
    if (counter < 5) {
        Buy[i] = 0;
    	counter = counter + 1;
    }
  }
}
//  <======= New code ======

Sell =  BarsSince(Buy) >= 5;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Filter = Buy OR Sell OR BarsSince(Buy);
AddColumn(Buy, "Buy");
AddColumn(Sell, "Sell");
AddColumn(BarsSince(Buy), "BarsSince(Buy)");
AddColumn(BarsSince(Buy) >= 5, "BarsSince(Buy) >= 5");
AddColumn(Rsi_Value, "RSI");