COCO研究院

 找回密碼
 註冊
搜索
查看: 2485|回復: 5

更改陣列數據問題

[複製鏈接]
發表於 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[1480]=0;

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

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

謝謝各位 !
發表於 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

評分

參與人數 1金錢 +2 收起 理由
Winson + 2 Thanks you joshsmi 大大

查看全部評分

 樓主| 發表於 14-4-6 11:44 | 顯示全部樓層
joshsmi 發表於 14-4-5 23:56
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[1000] = 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[1000] = 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))
發表於 14-4-6 13:04 | 顯示全部樓層
也許在修改Buy之前先call一次equity(1);試試看

評分

參與人數 1金錢 +2 收起 理由
Winson + 2 感恩, 但還是不行

查看全部評分

 樓主| 發表於 14-4-8 15:06 | 顯示全部樓層
最後想到兩個比較笨的方法 :
method 1,
  1. bi=Barindex();
  2. select=selectedvalue(bi);
  3. arrayitem = select-bi[0];
  4. Buy[select]=0;
複製代碼
把上面的code放在計算程序之後, plot 程序之前 , 用 select bar 在圖表一按 , Buy shape 馬上消失 , 當然其他陣列也可。此方法只能改一個array

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

Thanks all !



 樓主| 發表於 14-4-8 18:17 | 顯示全部樓層
Sorry typo
  1. bi=Barindex();
  2. select=selectedvalue(bi);
  3. arrayitem = select-bi[0];
  4. Buy[arrayitem]=0;
複製代碼
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-12-21 22:01

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |