baokyo 發表於 10-5-25 12:03

本帖最後由 baokyo 於 10-5-25 12:04 PM 編輯

我也遇到同樣的問題~~板大
我想他說的問題應該是說假如是當下的K棒為接近KD死亡交叉,瞬間跌下死亡交叉,但是後來又有大量
買進拉了長紅棒在當根內 ,硬是把死亡交叉給拉回非死亡交叉, 請問各位是怎麼解決這個問題的阿?
在程式中 總不能單子下了 又反悔吧@@"

good88 發表於 10-5-25 12:30

回復 14# TrendRover


    我回的是他第一篇文,您懂嗎?

good88 發表於 10-5-25 12:40

本帖最後由 good88 於 10-5-25 12:44 PM 編輯

如果要讓買賣訊好看的程式,下面程式碼不錯用!(盤後看簡直天下無敵)

_SECTION_BEGIN("ShenbaKumarpivots");
/* **********************************
Code to automatically identify pivots
By Kumaresan Selvaraj
********************************** */
// -- what will be our lookback range for the hh and ll?
farback = Param("How Far back to go", 100, 50, 5000, 10);
nBars = Param("Number of bars", 12, 5, 40);
// -- Title.

Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ", H: "
+ High + ", L: " + Low + ", C: " + Close;
// -- Plot basic candle chart
PlotOHLC(Open, High, Low, Close,
"BIdx = " + BarIndex() +
"\n" + "O = " + O + "\n" + "H = " + H + "\n" + "L = " + L
+ "\n" + "C ", colorBlack, styleCandle);

GraphXSpace = 7;
// -- Create 0-initialized arrays the size of barcount
aHPivs = H - H;
aLPivs = L - L;
// -- More for future use, not necessary for basic plotting
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
// -- looking back from the current bar, how many bars
// back were the hhv and llv values of the previous
// n bars, etc.?
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
// -- Would like to set this up so pivots are calculated back from
// last visible bar to make it easy to "go back" and see the pivots
// this code would find. However, the first instance of
// _Trace output will show a value of 0
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
// -- Initialize value of curTrend
curBar = (BarCount - 1);
curTrend = "";

if (aLLVBars < aHHVBars)
{
curTrend = "D";
}
else
{
curTrend = "U";
}
// -- Loop through bars. Search for
// entirely array-based approach
// in future version
for (i = 0; i < farback; i++)
{
curBar = (BarCount - 1) - i;
// -- Have we identified a pivot? If trend is down...
if (aLLVBars < aHHVBars)
{
    // ... and had been up, this is a trend change
    if (curTrend == "U")
    {
      curTrend = "D";
      // -- Capture pivot information
      curPivBarIdx = curBar - aLLVBars;
      aLPivs = 1;
      aLPivLows = L;
      aLPivIdxs = curPivBarIdx;
      nLPivs++;
    }
    // -- or current trend is up
}
else
{
    if (curTrend == "D")
    {
      curTrend = "U";
      curPivBarIdx = curBar - aHHVBars;
      aHPivs = 1;
      aHPivHighs = H;
      aHPivIdxs = curPivBarIdx;
      nHPivs++;
    }
    // -- If curTrend is up...else...
}
// -- loop through bars
}
// -- Basic attempt to add a pivot this logic may have missed
// -- OK, now I want to look at last two pivots. If the most
// recent low pivot is after the last high, I could
// still have a high pivot that I didn't catch
// -- Start at last bar
curBar = (BarCount - 1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs;
lastLPL = aLPivLows;
lastHPIdx = aHPivIdxs;
lastHPH = aHPivHighs;

if (lastLPIdx > lastHPIdx)
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aHHVBars;
candPrc = aHHV;
if (
lastHPH < candPrc AND
candIdx > lastLPIdx AND
candIdx < curBar)
{
    // -- OK, we'll add this as a pivot...
    aHPivs = 1;
    // ...and then rearrange elements in the
    // pivot information arrays
    for (j = 0; j < nHPivs; j++)
    {
      aHPivHighs = aHPivHighs[nHPivs -
      (j + 1)];
      aHPivIdxs = aHPivIdxs;
    }
    aHPivHighs = candPrc;
    aHPivIdxs = candIdx;
    nHPivs++;
}
}
else
{
// -- Bar and price info for candidate pivot
candIdx = curBar - aLLVBars;
candPrc = aLLV;
if (lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar)
{
    // -- OK, we'll add this as a pivot...
    aLPivs = 1;
    // ...and then rearrange elements in the
    // pivot information arrays
    for (j = 0; j < nLPivs; j++)
    {
      aLPivLows = aLPivLows;
      aLPivIdxs = aLPivIdxs;
    }
    aLPivLows = candPrc;
    aLPivIdxs = candIdx;
    nLPivs++;
}
}
// -- Dump inventory of high pivots for debugging
/*
for (k=0; k<nHPivs; k++) {
_TRACE("High pivot no. " + k
+ " at barindex: " + aHPivIdxs + ", "
+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs,
DateTime(), 1), formatDateTime)
+ ", " + aHPivHighs);
}
*/
// -- OK, let's plot the pivots using arrows
PlotShapes(IIf(aHPivs == 1, shapeDownArrow, shapeNone), colorRed, 0, High, Offset =- 15);
PlotShapes(IIf(aLPivs == 1, shapeUpArrow, shapeNone), colorGreen, 0, Low, Offset =- 15);
_SECTION_END();

TrendRover 發表於 10-5-25 14:05

回復 17# good88


    網路時差,   Sorry!

我愛紅茶 發表於 10-5-25 19:29

本帖最後由 我愛紅茶 於 10-5-25 07:30 PM 編輯

回復 18# good88


   {:4_155:}RUN盤後~結果訊號都會延遲出來~會被巴到死感覺上是在摸頭猜底~而且訊號還會立刻就切換變消失

sdnian 發表於 10-5-25 21:55

假如是當下的K棒為接近KD死亡交叉,瞬間跌下死亡交叉,但是後來又有大量
買進拉了長紅棒在當根內 ,硬是把死亡交叉給拉回非死亡交叉


    如果是這個問題, 那就用前一個 KD 的值, 查一下 ref 指令的用法. 如果是回測, 也可以用 SetTradeDelays(1, 1, 1, 1) 讓訊號產生在下一根 K 棒. 試看看可不可以解決.

RLRAVYRNLCQYBCQ 發表於 10-5-26 08:01

本帖最後由 RLRAVYRNLCQYBCQ 於 10-5-26 08:12 AM 編輯

回復 21# sdnian


   ref 指令
   SetTradeDelays(1, 1, 1, 1)
   FLAG (用for( i = 0; i < BarCount; i++ )寫的)

    全部無效~
    用Bar replay 就可以確認

    我還遇過,明明已經過了五分鐘,前面已經成立的買賣訊號居然消失的~
    太短線的交易不能用

    BACK TEST看到的點位, 在 real time 那個買點(or賣點)你絕對買不到, 因為它會後來才出現給你看

RLRAVYRNLCQYBCQ 發表於 10-5-26 08:23

本帖最後由 RLRAVYRNLCQYBCQ 於 10-5-26 08:25 AM 編輯

回復 16# baokyo

只能做波段吧

good88 發表於 10-5-26 09:25

AB能不能做當沖,或作波段,要看你的操作邏輯和寫程式的功力,像我附上的程式碼,盤後看很棒,盤中大概就陣亡了...
如果回測不是很好的程式,可以修正就修,否則再找(寫)別的吧!

sdnian 發表於 10-5-26 18:14

回復 22# RLRAVYRNLCQYBCQ


    那我就真的不懂這帖說的問題在哪裡, 因為我自己使用就沒問題, 盤中訊號都能出現在我預期的點, 是真的能交易的點 (先不考慮滑價問題). 要注意的是, AFL 程式在線圖的狀態下就會一直執行. 但是某些指令在回測模式才有作用, 例如前面說的 SetTradeDelays. 在線圖模式下這個沒作用, 所以我用 ref 來判斷前一根K線的條件成立, 然後下一根K線出現時立刻交易.

仰望 發表於 10-6-12 14:38

好複雜的感覺,努力學習中
頁: 1 [2]
查看完整版本: AmiBroker不適合當沖