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
The opinions expressed in these forums do not represent those of C2, and any discussion of profit/loss is not indicative of future performance or success. There is a substantial risk of loss in trading. You should therefore carefully consider whether such trading is suitable for you in light of your financial condition. You should read, understand, and consider the Risk Disclosure Statement that is provided by your broker before you consider trading. Most people who trade lose money.
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");