想請教先進二種寫法意義相同但結果不同釋疑
本帖最後由 skyler 於 14-4-25 22:14 編輯想法:
以前一根K棒判斷,符合條件,本根K棒開盤下單
Buy : K棒 MA5 均線向上 且K棒向上穿過MA5
Sell : MA5均線向下
Short : MA5 均線向下 且K棒向下穿過MA5
Cover : MA5均線向下
測試標的: 6A #F 1小時線
實作二個 afl1. TestMA5_1.afl
在迴圈前先將判斷式寫好
程式碼如下 :
_SECTION_BEGIN( "Product Settings" );
SetPositionSize( 1 , spsShares );
SetOption( "MaxOpenPositions" , 1 );
SetOption( "InitialEquity" , 10000 );
SetOption( "FuturesMode" , 1 );
SetOption( "CommissionMode" , 3 );
SetOption( "CommissionAmount" , 6.5 );
RoundLotSize = 1;
if ( Name () == "6A #F" )
{
TickSize = 0.0001 ;
MarginDeposit = 2035 ;
PS = 10000;
PointValue = 10 * PS;
}
_SECTION_END();
MA5_P1 = Ref( MA( C, 5 ), -1 ); //前一根的 MA5
MA5_P2 = Ref( MA( C, 5 ), -2 ); //前二根的 MA5
Cond_MA5_Buy = MA5_P1 > MA5_P2;//前一根的MA5 > 前二根的MA5 表示 MA5在前一根是向上
Cond_MA5_Sell = MA5_P1 < MA5_P2;//前一根的MA5 < 前二根的MA5 表示 MA5在前一根是向下
Cross5_Buy =Cross ( Ref( C, -1 ), MA5_P1 ); //前一根K棒向上穿過MA5
Cross5_Sell = Cross ( MA5_P1, Ref( C, -1 ) ); //前一根K棒向下穿過MA5
BuyIndex = 0; //判斷是否有多單
ShortIndex = 0; //判斷是否有空單
for ( i = 0 ; i < BarCount ; i++ )
{
//Buy
if ( BuyIndex == 0 )
{
if ( Cond_MA5_Buy AND Cross5_Buy )
{
BuyIndex = i;
Buy = 1;
BuyPrice= O ;
}
}
//Sell
if ( BuyIndex != 0 )
{
if ( Cond_MA5_Sell)
{
BuyIndex = 0;
Sell = 1;
SellPrice = O ;
}
}
//Short
if ( ShortIndex== 0 )
{
if ( Cond_MA5_Sell AND Cross5_Sell )
{
ShortIndex = i;
Short = 1;
ShortPrice = O ;
}
}
//Cover
if ( ShortIndex != 0 )
{
if ( Cond_MA5_Buy )
{
ShortIndex = 0;
Cover = 1;
CoverPrice = O ;
}
}
}
2. TestMA5_2.afl
在迴圈內逐一判斷
程式碼如下 :
_SECTION_BEGIN( "Product Settings" );
SetPositionSize( 1 , spsShares );
SetOption( "MaxOpenPositions" , 1 );
SetOption( "InitialEquity" , 10000 );
SetOption( "FuturesMode" , 1 );
SetOption( "CommissionMode" , 3 );
SetOption( "CommissionAmount" , 6.5 );
RoundLotSize = 1;
if ( Name () == "6A #F" )
{
TickSize = 0.0001 ;
MarginDeposit = 2035 ;
PS = 10000;
PointValue = 10 * PS;
}
_SECTION_END();
MA5 = MA( C, 5 );//MA5
Cross5_Buy =Cross ( C, MA5 ); //K棒向上穿過MA5
Cross5_Sell = Cross ( MA5, C ); // K棒向下穿過MA5
BuyIndex = 0; //判斷是否有多單
ShortIndex = 0; //判斷是否有空單
for ( i = 2 ; i < BarCount ; i++ )
{
//Buy
if ( BuyIndex == 0 )
{
if ( MA5 > MA5 AND Cross5_Buy )//前一根MA5 > 前二根MA5且
{ // 前一根K棒向上穿過MA5
BuyIndex = i;
Buy = 1;
BuyPrice= O ;
}
}
//Sell
if ( BuyIndex != 0 )
{
if ( MA5 < MA5 ) //前一根MA5 < 前二根MA5
{
BuyIndex = 0;
Sell = 1;
SellPrice = O ;
}
}
//Short
if ( ShortIndex== 0 )
{
if ( MA5 < MA5AND Cross5_Sell ) //前一根MA5 < 前二根MA5且
{ // 前一根K棒向下穿過MA5
ShortIndex = i;
Short = 1;
ShortPrice = O ;
}
}
//Cover
if ( ShortIndex != 0 )
{
if ( MA5 > MA5 ) //前一根MA5 > 前二根MA5
{
ShortIndex = 0;
Cover = 1;
CoverPrice = O ;
}
}
}
二者跑出來的結果不同
所以想請教一下先進自己的盲點在那
感謝~(鞠躬)
http://www.coco-in.net/forum.php?mod=image&aid=83914&size=300x300&key=fcc7dc4d5831bd0a&nocache=yes&type=fixnone
http://www.coco-in.net/forum.php?mod=image&aid=83913&size=300x300&key=56a6d24a2b750aa7&nocache=yes&type=fixnone
補上 6A #F的歷史資料
頁:
[1]