|
不知道你這裡10日Sell是指10天後(不管是不是交易日都算), 還是指10個交易日後?
我想你應該是想在10天後的同一個時點的K棒才做Sell
兩種我合併在一起提供你範例
你自己再選擇囉
nDayPass = 10;
nDateAtSell = 0;
nDayCountAtBuy = 0;
nTodayBarIndexAtBuy = -1;
vDateNumCompare = (DateNum() != Ref(DateNum(), -1));
vDateNumCompare[0] = True;
vTodayBarIndex = BarsSince(vDateNumCompare);
vDateTime = DateTime();
vTargetDateTime = DateTimeAdd(vDateTime, nDayPass, inDaily);
for(i = 0;i < BarCount;i++)
{
if(Buy[i] == True)
{
nDateAtSell = vTargetDateTime[i];
nDayCountAtBuy = 0;
nTodayBarIndexAtBuy = vTodayBarIndex[i];
}
//這一個Sell是發生在買之後的第10天同一個時點的K棒, 但要注意如果不是交易日則不會發生Sell
if(vDateTime[i] == nDateAtSell)
{
Sell[i] = True;
nDateAtSell = 0;
}
//這一個Sell是發生在買之後的第10個交易日同一個時點的K棒, 但要注意如果在下午1:30後買的, 第10個交易日若為期指結算日那也不會發生Sell, 結算只到1:30
if(nDayCountAtBuy == nDayPass AND vTodayBarIndex[i] == nTodayBarIndexAtBuy)
{
Sell[i] = True;
nDayCountAtBuy = 0;
nTodayBarIndexAtBuy = -1;
}
if(vDateNumCompare[i] == True)
{
nDayCountAtBuy++;
}
}
|
|