COCO研究院

 找回密碼
 註冊
搜索
樓主: kilroy

[教學] [分享] 用AB踏入外期程式交易

  [複製鏈接]
 樓主| 發表於 14-9-11 16:33 | 顯示全部樓層
osdak 發表於 14-9-11 14:41
是會overwrite的, 所以改不了. 大大, 還有一事想請教, 因為想試試上線, 但想先從mini contract開始, 我看了 ...

Hi,

eSignal 的連續月報價(#F)會挑合約較活躍的合約月份

如同 Gold 目前是 Dec. 的月份

symbol: IB 是 GCZ4   eSignal 用 GC #F=1 看

而 GC 的小型合約 (E-Micro Gold)

IB 是 MGCZ4 eSignal 是 MGC #F=1

---
QO 我查看是 Australian/Japanese Yen





評分

參與人數 1金錢 +2 收起 理由
osdak + 2 感謝分享

查看全部評分

發表於 14-9-11 18:03 | 顯示全部樓層
osdak 發表於 14-9-11 14:41
是會overwrite的, 所以改不了. 大大, 還有一事想請教, 因為想試試上線, 但想先從mini contract開始, 我看了 ...

師兄已有可用的策略?
之前我那個策略WF test的績效不太好, 感覺有curve fitting
又再修改策略中
發表於 14-9-11 22:17 | 顯示全部樓層
kilroy 發表於 14-9-11 16:33
Hi,

eSignal 的連續月報價(#F)會挑合約較活躍的合約月份

謝謝, 我想請教, 大大是如何找到? 我一開始是於以下網站去找:

https://www.interactivebrokers.com.hk/cn/index.php?f=marginnew&p=fut

1.PNG

QO應該也是gold吧? 還有, 我於TWS打QO, 價錢看起來也對, 所以想請教應在那裡找資料判斷?

謝謝.




發表於 14-9-11 22:30 | 顯示全部樓層
jacklcl 發表於 14-9-11 18:03
師兄已有可用的策略?
之前我那個策略WF test的績效不太好, 感覺有curve fitting
又再修改策略中

我有一支策想試, 但我有一個問題, 也是怕cruve fit, 我的法想是, 我在WF中把參數的range定很濶, 如果結果都還可以, 那是否可以減少cruve fit機會?帥兄之前分享WF結果很好, 那是什麼原因會擔心curve fit?  可否也分享一下?
發表於 14-9-11 22:57 | 顯示全部樓層
osdak 發表於 14-9-11 22:30
我有一支策想試, 但我有一個問題, 也是怕cruve fit, 我的法想是, 我在WF中把參數的range定很濶, 如果結果 ...

你是說我第一那個策略?
那個有BUG的, 當時並未在real time實測
後來發覺有BUG, 我把那個BUG改了後WF明顯差了, 有時大賺有時大蝕
之後我改了一下, 再加多個FILTER, Backtest是很好, 但WF就不行了, 明顯有curve fitting
現在我再修改, LONG及SHORT只用2個條件, WF穩定了一些
但trade no.少了很多, 平均2天才有1單trade
個人意見參數很闊但WF不錯的話, 應該也沒問題吧
參數闊最怕是有孤島出現, 我自己一般會用3D圖去縮窄參數
不過AB的WF如用genetic optimization的話, 應該它會選到位於高原的那些參數
所以參數很闊應該還可以吧
 樓主| 發表於 14-9-11 23:39 | 顯示全部樓層
osdak 發表於 14-9-11 22:17
謝謝, 我想請教, 大大是如何找到? 我一開始是於以下網站去找:

https://www.interactivebrokers.com.hk/c ...

Hi,


(GC)   Gold 是 100 oz.
(QO)   miNY Gold 是 50 oz.
(MGC) E-Micro Gold 是 10 oz.


*()為 IB symbol




---
但 QO 我在 eSignal 裡查詢是 Australian/Japanese Yen
http://quotes.esignal.com/esignalprod/quote.action?s=QO%201!&type=Future&fromSearch=true

而 eSignal 相對應的 symbol 我就不知道了,要詢問一下客服


發表於 14-10-3 15:11 | 顯示全部樓層
K大您好
想請問您 cross 這個函數

2014-10-03_145311.png
黃色均線是 MA5
在圖中二個框內
想表示 K棒穿過 MA5

到底該如何表示?
1.
黃框 紅框:Cross(C, MA5);

2.
黃框:Cross(MA5, C);
紅框:Cross(C, MA5);

由於AB沒有像MC
在Cross有
crosses_above
crosses_below
來表示上穿與下穿

所以想問問這二種情況如何表示?

還有像MA5穿 MA60 這種是不是都是 Cross(MA5, MA60)  ?


 樓主| 發表於 14-10-3 15:43 | 顯示全部樓層
skyler 發表於 14-10-3 15:11
K大您好
想請問您 cross 這個函數

AB 的 CROSS

就是 EX. CROSS(H,MA5);   HIGH CROSS ABOVE MA5
             CROSS(MA5,L);    LOW CROSS BELOW MA5


---

MA5 向上穿過 MA60 就是 MA5 CROSS ABOVE MA60

所以是 CROSS(MA5,MA60);


參考看看了

評分

參與人數 1金錢 +2 收起 理由
skyler + 2 感謝分享

查看全部評分

發表於 14-10-3 15:48 | 顯示全部樓層
感謝K大
所以圖中
應該就是
黃框:Cross(MA5, C);
紅框:Cross(C, MA5);

對吧!

評分

參與人數 1金錢 +5 收起 理由
kilroy + 5 是的~

查看全部評分

發表於 14-10-24 10:52 | 顯示全部樓層
K大二個簡單問題跟您請教一下


以下看圖說故事

問題一:
2014-10-24_100432.png

中間的錯誤
我應該是要用下面 1 2 3那種寫法才對呢?

---------
問題二
2014-10-24_100700.png

我跑BackTesting
上面的
1. _Trace()  只顯示了最後一個時間的那筆資料,即234500這筆前面的都沒顯示

不知是那裡沒有設定?


2. printf writeif  這二個我在 Interpretation 都沒有看到資料,不知是那裡有錯?



以上再請您指導了
感謝

 樓主| 發表於 14-10-24 17:52 | 顯示全部樓層
skyler 發表於 14-10-24 10:52
K大二個簡單問題跟您請教一下

1. 像是 if 或是 for 迴圈的
    你要放 array 就要用 [] 這個東西

    EX. if(lastvalue(ma20_up))

          for 迴圈的話就是 ma20_up

2. _TRACE() 要先到 Tools -> Preferences -> AFL 裡

    _TRACE() output 勾選 Internal 和 External (DebugView)

    我比較習慣用 PRINTF

    你可以至 Windows -> Interpretation

    而 Writeif 是把你要顯示的資料、數據顯示在圖表上



參考看看了


評分

參與人數 1金錢 +2 收起 理由
skyler + 2

查看全部評分

發表於 14-10-25 07:03 | 顯示全部樓層
本帖最後由 joshsmi 於 14-10-25 07:06 編輯
skyler 發表於 14-10-24 10:52
K大二個簡單問題跟您請教一下

You simply haven't read the manual

Last Value and selectedvalue are for CHART but not to trace results in backtesting.

What does Lastvalue name say? it says LAST. so what does that mean? it means that it returns very last value only.
Selectedvalue is for selecting a value on chart via selection with mouse or left/right arrow keys.
In analysis it returns last value. so it simply makes absolutely no sense to use those functions in analysis.

you simply do all wrong because you dont know becasue you don't read so don't wonder if you get wrong/unexpected output.

Writeif is used wrong also. It is a FUNCTION!

READ the freagging manual!

From HELP file:

Common Coding mistakes in AFLThis document presents most common mistakes and problems that users encounter when writing their custom formulas. Please read carefully to avoid making similar errors.


“=” (assignment)  vs  “==” (equality check)
There are two similar looking but completely different operators in AFL.
“=” is a variable assignment operator
“==” is an equality check operator
EXAMPLE
Incorrect code:
result = IIf( Variable = 10 , High, Low ); // WRONG
If you want to check if variable is equal to 10, you MUST use “==”
Correct code:
result = IIf( Variable == 10 , High, Low ); // CORRECT

Using parentheses
Parentheses can be used to control the operation precedence (the order in which the operators are calculated). AmiBroker always does operations within the innermost parentheses first. To learn the the precedence of operations when parentheses are not used, visit: http://www.amibroker.com/guide/a_language.html
EXAMPLE:
“I would like to buy whenever either Close is higher that it’s 10-periods Moving Average or Close is at least 10% higher than yesterday’s close, but buy should only apply when Current Volume is higher than it’s 10-period Moving Average. However – I get Buy signals for the days when Volume is lower than MA(Volume,10). Why?”
Buy = Close > MA( Close, 10 ) OR Close == 1.1 * Ref( Close, -1 ) AND Volume > MA( Volume, 10 );
The solution is to add parentheses, otherwise system buys whenever Close > MA(Close,10) condition is met ( or Close == 1.1*Ref(Close,-1) AND Volume > MA(Volume,10) are both met).
Buy = ( Close > MA( Close, 10 ) OR Close == 1.1 * Ref( Close, -1 ) )
      AND Volume >
MA( Volume, 10 );


IIf function

The IIf( ) function is used to create conditional assignments.
variable = IIf( EXPRESSION, TRUE_PART, FALSE_PART );
The above "IIf" statement means: For each bar EXPRESSION is true assign TRUE_PART to the variable, otherwise (when EXPRESSION is false) assign FALSE_PART.
EXAMPLE
Incorrect code
IIf( Close > 10, result = 7, result = 9 ); // WRONG
Correct code:
result = IIf( Close > 10, 7, 9 ); // CORRECT

IIf is for arrays, WriteIf is for strings

IIf functions should be used to handle arrays, if you need conditional text function use WriteIf instead.
EXAMPLE
Incorrect code:
variable = IIf(Condition, "Text 1","Text 2" ); // WRONG
IIf( ) function returns array, NOT STRING, so it’s impossible to assign text to variable with use of IIF. Use WriteIf( ) function instead:
Correct code:
variable = WriteIf( condition, "Text 1", "Text 2" ); // CORRECT
Please note however that WriteIf function returns just single STRING, not arrays of strings, so only the selected value is used for evaluation.

if-else statement needs boolean (or single numeric expression), not array
The if keyword executes statement1 if expression is true (nonzero); if else is present and expression is false (zero), it executes statement2. After executing statement1 or statement2, control passes to the next statement. Expression must be boolean ( True/False) type (so it CANNOT be ARRAY because there would be no way do decide whether to execute statement1 or not, if for example array was: [True,True,False,.....,False,True] )
if( expression )
   statement1
else
   statement2
EXAMPLE
if( Close > Open ) // WRONG
   Color =
colorGreen; //statement 1
else
   Color =
colorRed; //statement 2

Plot(Close,"Colored Price",Color,styleCandle);
The above example is wrong, as both Open and Close are arrays and such expression as Close > Open is also an ARRAY. The solution depends on the statement. It’s either possible to implement it on bar-by-bar basis, with use of FOR loop:
for( i = 0; i < BarCount; i++ )
{
  
if( Close[ i ] > Open[ i ] ) // CORRECT
       Color[ i ] =
colorGreen;
  
else
       Color[ i ] =
colorRed;
}

Plot( Close, "Colored Price", Color, styleCandle );
It is also possible in this case to use IIf( ) function:
Color = IIf( Close > Open, colorGreen, colorRed ); // ALSO CORRECT - working directly on arrays
Plot( Close, "Colored Price", Color, styleCandle );


Barcount vs BarIndex()
There is a fundamental difference between BarCount and BarIndex(). BarCount is a numeric variable that holds just one number (the count of elements in array). On the other hand BarIndex() is a function that returns ARRAY representing consecutive index of each bar.
EXAMPLE
Incorrect code:
for (i = 0; i < BarIndex();i++ ) // WRONG
{
  
// your formula
}

It’s not allowed to use ARRAY inside for loop, and Barindex() returns ARRAY. That is why it’s necessary to change the formula.
Correct code:
for (i =0 ; i < BarCount ;i++ )  // CORRECT
{
  //your formula
}



TimeFrameExpand( ) is required to match data with original time frame
The TimeFrameSet( ) replaces current price/volume arrays: open, high, low, close, volume, openint, avg with time-compressed bars of specified interval once you switched to a different time frame all calculations and built-in indicators operate on selected time frame. To get back to original interval call TimeFrameRestore( ) function. The TimeFrameExpand( ) is used to decompress array variables that were created in different time frame. Decompressing is required to properly display and use the array created in different time frame.
EXAMPLE
Incorrect code:
TimeFrameSet( inWeekly );
MA14_Weekly =
MA( Close, 14 );
TimeFrameRestore();
Buy =
Cross( Close, MA14_Weekly ); // WRONG - Close and MA15_Weekly use different time scales
The above formula is wrong, as MA14_Weekly variable should be EXPANDED to match original timeframe. The right contents should be:
Correct code:
TimeFrameSet( inWeekly );
MA14_Weekly =
MA( Close, 14 );
TimeFrameRestore();
Buy =
Cross( Close, TimeFrameExpand( MA14_Weekly, inWeekly ) ); // CORRECT, expanded weekly MA can be matched against daily close
EXAMPLE 2:
Incorrect code:
TimeFrameSet( inWeekly );
MA14_Weekly =
MA( Close, 14 );
TimeFrameRestore();
Buy =
Cross( Close, TimeFrameExpand( MA14_Weekly, inDaily ) ); // WRONG
It’s always necessary to indicate in TimeFrameExpand( ) function, which timeframe was  variable calculated in. So if MA14_Weekly was calculated in out of weekly data, inWeekly should be the correct parameter of TimeFrameExpand( ) function.
Correct code:
TimeFrameSet( inWeekly );
MA14_Weekly =
MA( Close, 14 );
TimeFrameRestore();
Buy =
Cross( Close, TimeFrameExpand( MA14_Weekly, inWeekly ) ); // CORRECT




評分

參與人數 1金錢 +2 收起 理由
skyler + 2 這一堆我都知道! 謝謝~

查看全部評分

發表於 14-10-25 07:09 | 顯示全部樓層
本帖最後由 joshsmi 於 14-10-25 07:17 編輯

printf is not for output in analysis also !!

Writeif:

WriteIf
- commentary conditional text output
Exploration / Indicators


SYNTAX WriteIf( EXPRESSION, "TRUE TEXT", "FALSE TEXT" )
RETURNSSTRING
FUNCTION If EXPRESSION evaluates to "true", then the TRUE TEXT string is displayed within the commentary. If EXPRESSION evaluates to "false", then the FALSE TEXT string is displayed.
EXAMPLEwriteif( c > mov(c,200,s), "The close is above the 200-period moving average.","The close is below the 200-period moving average." )
SEE ALSO
Comments:
Tomasz Janeczko
tj --at-- amibroker.com
2004-06-12 05:56:01
WriteIf in fact does not "write" anything. The name is misleading but it is left
for easy translation of MS formulas to AmiBroker.
WriteIf is just "TextIIF" it RETURNS string value depending on condition.

In commentary window, statements evaluating to STRINGS on global level
are displayed in the output window. However if you do the same inside the FUNCTION
it is no longer in global level (it is on LOCAL, FUNCTION level).

To display actual string in this case use PRINTF function:
http://www.amibroker.com/f?printf


function comment(indicator)
{
printf( "\nComment...\n" );

printf( WriteIf(1, "TrueText", "FalseText") );
printf( WriteVal(indicator) + "\n" );
}
Tomasz Janeczko

2005-08-10 06:37:55
Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION

評分

參與人數 1金錢 +2 收起 理由
skyler + 2

查看全部評分

 樓主| 發表於 14-10-25 14:08 | 顯示全部樓層
joshsmi 發表於 14-10-25 07:09
printf is not for output in analysis also !!

Writeif:

Dude,


I usually use "printf" to show some information I want,


but I don't mean it could be "output" in analysis windows.

You might get me wrong.

Thanks anyway!


發表於 14-10-25 20:46 | 顯示全部樓層
I was not talking to you but to that skyler dude who is constantly looking for bugs because of his inability to read/understand.

評分

參與人數 1金錢 +5 收起 理由
kilroy + 5 Goos

查看全部評分

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-12-23 09:55

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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