Winson 發表於 14-4-5 22:19

更改陣列數據問題

各位大大好 ! 小弟除錯的時候發現有一個 buy signal 很可疑 , 想強行把它變0 作debug 看看 , 於是我先用SetBarsRequired 去 disable QuickAFL , 再用printf , barindex 等去知道它的陣列位置:

SetBarsRequired (sbrAll,sbrAll);
if ( Status( "action" ) == actionCommentary )
{
bi=BArindex();   
SelectBarNum = SelectedValue( bi);

    printf ( "Selected Bar Number is " +NumToStr( SelectBarNum ) + "\n" );
    printf ( "Barcount = " + NumToStr( BarCount ) + "\n" );
}

就這樣用cursor在圖表按一下得知該陣列位置是1480 , 然後再在程式裡加上
buy=0;

問題就來了, compile 時它說
Array subscript out of range. You must not access array elements outside 0..(BarCount-1) range.

但實際上Barcount = 232804 , 為什麼它會說out of range 呢 ? 想了半天想不通..
(我再做多少少, 發覺buy 至 buy都可以直接改數值 , 但200或以上就說我out of range)

謝謝各位 !

joshsmi 發表於 14-4-5 23:56

本帖最後由 joshsmi 於 14-4-5 23:59 編輯

Not sure if it is related as I don't fully understand but maybe this helps


Hello,

Thank you very much for your e-mail.

A fixed number of 200 bars is just used for "Syntax check" function that is triggered whenever you "apply" the formula on the chart. It is correct amount. Only subsequent executions will use more bars.

Best regards,
Tomasz Janeczko
amibroker.com
https://groups.yahoo.com/neo/groups/amibroker/conversations/messages/181041


Hello,

Thank you very much for your e-mail.

Listen, you are making some fundamental mistakes in your thinking.

First, that you are making assumptions that are not valid.

There is no bug. The BarCount == 200 is the result of "AFL Syntaxcheck".
It is NOT run as a part of exploration, it is run as a part of AFLEditor syntax check of your formula. If you used Status("actionex") you would note that the action is NOTequal 4 (exploration) See http://www.amibroker.com/guide/afl/afl_view.php?status

Each formula when it is modified is subject to code check whichinvolves execution of the code with BarCount fixed to 200 (for speed, otherwise you would need to wait for syntax check significantly longer whenformula was
used with symbol that has millions of bars). Also in optimization there is a special setup phase that involvesexecution and reading Optimize() statements.

You are making assumptions that there are no such phases but theseare wrong assumptions.

Secondly, you really need to read the manual:
http://www.amibroker.com/guide/h_multithreading.html

Once you do, you would know that in New Analysis window
you are running in MULTIPLE THREADS and using shared resource suchas
writing SINGLE FILE in "APPEND" mode is recipe for disaster.

You should either use SEPARATE files for each symbol, like this:

FileName      = "C:\\TestingBarNums002"+Name() +".csv";

or you should have proper critical section in your code (describedin the manual) to prevent
multiple threads from writing to the very same file at the very sametime.

Best regards,
Tomasz Janeczko
amibroker.com
https://groups.yahoo.com/neo/groups/amibroker/conversations/messages/180474



Hello,

LastValue( BarIndex() ) is different than BarCount.

BarIndex refers to absolute bar index, while NOT ALL bars are used for indicator calculation.
Indicators usually use visible bars only (plus somemore).

So you must use subscripts in range of 0...(BarCount-1)
============================================
As only BarCount refers to actual number of arrayelements used for AFL calculation.

Best regards,
Tomasz Janeczko
amibroker.com

Winson 發表於 14-4-6 11:44

joshsmi 發表於 14-4-5 23:56 static/image/common/back.gif
Not sure if it is related as I don't fully understand but maybe this helps




Thanks joshsmi !I still remember that you are so kind to help as i am newbie at one year ago. And i am still work hard on AB till now. ^^

I have read through the email achieve you quote , thanks!But i still don't know how to do my task and i am thinking on it.

Actually i simply want to change a value of specify array location which the barindex >200 .
eg.originally , array = 1 .I want to change it to 0 manually (After the AFL calculation code). As the strategy code is complicated and it is difficult to change one specify array location.

So i add array = 0 after the calculation. It is convenient to debug but compliler said i am out of range. Now i know AFL is not using all bar for calculation so is it impossible to do my job ? (it said it is out of range even i use setbarrequired (sbrAll))

zaqimon 發表於 14-4-6 13:04

也許在修改Buy之前先call一次equity(1);試試看

Winson 發表於 14-4-8 15:06

最後想到兩個比較笨的方法 :
method 1,
bi=Barindex();
select=selectedvalue(bi);
arrayitem = select-bi;
Buy=0;把上面的code放在計算程序之後, plot 程序之前 , 用 select bar 在圖表一按 , Buy shape 馬上消失 , 當然其他陣列也可。此方法只能改一個array

Method 2 ,
_date = datenum();
_time = Hour() * 100 + minute();
date1 = 1121205 ;
time1 = 1354; //A specify date and time you choose
buy = IIf ( ( _date == date1 ) and ( _time == time1 ), 0 , buy ); //Force to zero用日期和時間來指出該位置 , 由於date/time 是unique data , 不會受quickAFL 影響 , 也可以同時改幾個point
Thanks all !


Winson 發表於 14-4-8 18:17

Sorry typobi=Barindex();
select=selectedvalue(bi);
arrayitem = select-bi;
Buy=0;
頁: [1]
查看完整版本: 更改陣列數據問題