altubers 發表於 13-7-30 18:49

請教簡單的畫圖

本帖最後由 altubers 於 13-7-30 18:52 編輯

請問想在ab的圖上
當紅k時,畫一個向上的arrow
當黑k時,畫一個向下的arrow
就理解上 加了這行code...

IIf( Close > Open ,PlotShapes(shapeUpArrow,colorRed,0,High,10) , PlotShapes(shapeDownArrow,colorBlue,0,Low,10 ));


但為何出現了如圖的清況呢?


謝謝
也有用簡單的if else .. 但出來也是跟著點選的kbar 跑 {:4_154:}

moneymaker 發表於 13-7-30 20:23

用法錯誤....{:4_120:}
參考 http://www.amibroker.com/guide/afl/iif.html

Please note that IIF is a function - so the result of evaluation is returned by that function and should be assigned to some variable. IIf always evaluates both TRUE_PART and FALSE_PART, even though it returns only one of them. Because of this, you should watch for undesirable side effects. The following example shows one common error made with IIF function: IIF( condition, result = 7, result = 9 ); // THIS IS WRONG Correct usage is: result = IIF( condition, 7, 9 ); /* 7 or 9 is *returned* and assigned to a variable depending on condition */

moneymaker 發表於 13-7-30 20:46

所以可行的做法如下

PlotShapes ( IIf( Close > Open, shapeUpArrow, shapeDownArrow), IIf( Close > Open, colorRed, colorGreen),0, IIf( Close > Open, Low-1,High+1));

altubers 發表於 13-7-30 20:54

謝謝,我在試試…

moneymaker 發表於 13-7-30 21:27

看妳的附圖 你要的好像是這樣

PlotShapes ( IIf( Close > Open, shapeUpArrow, shapeDownArrow), IIf( Close > Open, colorRed, colorGreen),0, IIf( Close > Open, HIGH+12,low-12));

altubers 發表於 13-7-30 21:35

感謝moneymaker
我剛也有試出來了

PlotShapes( IIf( C < O,shapeUpArrow ,shapeDownArrow ) ,IIf( C < O,colorRed ,colorGreen ),0,IIf( C < O,H ,L ) ,10) ;
只是在於我要應用的地方是
先求出特定的Direction方向後 劃出arrow... 就失敗了…
PlotShapes(IIf(Direction =="R",shapeUpArrow,shapeDownArrow) ,IIf(Direction =="R",colorRed ,colorGreen ),0,IIf(Direction =="R",H ,L ),10);感覺上c<o是k bar的欄位…direction會是運算完的常數
反成了這樣子


努力破解中~~


altubers 發表於 13-7-30 21:39

太感謝moneymaker大了…
一開始那只是我在測試的… 原本想說應該是一樣的東西
但發現沒想的那麼簡單了
{:4_93:}

moneymaker 發表於 13-7-30 21:40

貼全文來看看....{:4_81:}

altubers 發表於 13-7-30 22:00

本帖最後由 altubers 於 13-7-30 22:03 編輯

function getNum(_value){
      biString = NumToStr(_value);         
      returnStrToNum(biString );
}

function getDirection(){   
    MAD=getNum( MA(C,10) < MA(C,30));
    VAD=getNum(MA(V,10) < MA(V,30));
   //printf(" MAD:"+MAD+" VAD:"+VAD+"\n");
    Direction=   "N";
    if(MAD==VAD   ) Direction=   "R"; else Direction=   "G";

    //printf(" Direction:"+Direction+"\n");
    PlotShapes(IIf(Direction =="R",shapeUpArrow,shapeDownArrow) ,IIf(Direction =="R",colorRed ,colorGreen ),0,IIf(Direction =="R",H ,L ),10);      
}目前測試是拿ma 和mv來計算…arrow到是隨著點到的k bar而改變

在寫的時後還有另一個問題就是
MSD =MA(C,10) < MA(C,30)這時後 If(MSD) 確會是錯的... MA(C,10) < MA(C,30) 不是 bool 還真不習慣~~

enochyu 發表於 13-7-30 22:24

altubers 發表於 13-7-30 22:00 static/image/common/back.gif
目前測試是拿ma 和mv來計算…arrow到是隨著點到的k bar而改變

在寫的時後還有另一個問題就是

可以用下列寫法改看看
_DirectionR = ( Close > Open );
_DirectionG = NOT( _DirectionR );
_ArrowPosY = IIf( _DirectionR , Low, High );
_ArrowColor = IIf( _DirectionR , colorRed, colorGreen );

PlotShapes( shapeUpArrow * _DirectionR + shapeDownArrow * _DirectionG
    , _ArrowColor
    , 0
    , _ArrowPosY
    , -20
);

moneymaker 發表於 13-7-30 23:26

MAD =MA(C,10) - MA(C,30);
VAD =MA(V,10) - MA(V,30);
Direction = IIf ( (MAD>0 AND VAD>0) OR ( MAD<0 AND VAD<0), 1, -1 );
PlotShapes ( IIf(Direction>0 AND C>O, shapeUpArrow, shapeDownArrow), IIf( Direction>0 AND C>O , colorRed, colorGreen),0, IIf(Direction>0 AND C>O,Low-12,High+12));

u04122 發表於 18-4-12 10:40

感謝各位大大的啟發與技巧分享. {:4_160:}
頁: [1]
查看完整版本: 請教簡單的畫圖