Tuesday, December 18, 2012

KD 随机指标


当价格上涨时,收市价倾向于接近当日价格区间的上端;相反,在下降趋势中收市价趋向于接近当日价格区间的下端。随机指标在设计中充分考虑价格波动的随机震幅与中短期波动的测算,使其短期测市功能比移动平均线更加准确有效,在市场短期超买超卖的预测方面又比强弱指标敏感,因此,这一指标被投资者广泛采用。
计算方法
计算随机指标数值时,首先须找出最近N天内曾出现过的最高价、最低价与第N天的收盘价,然后利用这三个数字来计算第N天的未成熟随机值(RSV)。
N:待设定参数,缺省值9日
然后,求RSV的M1日移动平均,得K值;再求K值的M2日移动平均得D值。M1、M2的缺省值都为3。
缺省时,系统在副图上绘制两条线,分别为RSV值的三日平均线K,K值的三日平均线D。
K与D值永远介于0与100之间。
KD线中的RSV,随着9日中高低价、收盘价的变动而有所不同。如果行情是一个明显的涨势,会带动线K(快速平均值)与线D(慢速平均值)向上升。但如涨势开始迟缓,便会慢慢反应到K值与D值,使线K跌破线D,此时中短期跌势确立。由于KD线本质上是一个随机波动的观念,对于掌握中短期的行情走势非常正确。
应用法则
1、D值在70以上时,市场呈现超买现象。D值在30以下时,市场则呈现超卖现象。
2、当随机指数与股价出现背离时,一般为转势的信号。中期或短期的走势有可能已见顶或见底。
3、当K值大于D值,显示目前趋势是向上涨,因此线K向上突破线D时,为买进信号。当D值大于K值,显示趋势是向下跌,因此线K向下跌破线D,为卖出信号。
4、线K与线D的交叉,须在70以上,30以下信号才较为正确。K线与D线在特性上与强弱指标一样,当K值与D值在70以上,已显示超买的现象,30以下出现超卖的现象。KD线不仅能反映市场的超买超卖程度,还能通过交叉突破发出买卖信号。但若这类交叉突破在50左右发生,走势又陷入盘局时,买卖信号可视为无效。
5、当K值和D值上升或下跌的速度减弱,倾斜度趋于平缓是短期转势的预警信号。
6、KD不适用于发行量太小,交易太小的股票;但对指数以及热门大型股有极高的准确性。
[缺点]:
股价短期波动剧烈或者瞬间行情幅度太大时,使用KD值交叉讯号买卖,经常发生买在高点、卖在低点的的窘境。
K值进入超买或超卖区之后,和RSI一样会发生指标徘徊的现象,令股民一时手足无措。

注意!如果波动的幅度够大,买卖之间扣除手续费仍有利润的话,此时将画面转变成五分钟或十五分钟图形,再以KD指标的交叉信号买卖还可以斩获一点利润。
极强或极弱的行情,会造成指标在超买或超卖区内上下徘徊,K值也会发生这种情形,应该参考VR、ROC指标,观察股价是否超出常态分布的范围,一旦确定为极强的走势,则K值的超买超卖的功能将失去作用。
注意!
以D值来代替K值,将可使超买超卖的功能更具效果,一般常态行情,D值大于80时,股价经常向下回跌;D值低于20时,股价容易向上回升。在极端行情中,D值大于90时,股价容易产生瞬间回档;D值低于15时,股价容易产生瞬间反弹。
[诀窍]
(1)K、D值交叉讯号的可靠度如何?要怎样辨认是极端行情还是常态行情?经常困扰着股民,致使这个指标看似有用,实际上又存在着许多无法理清的盲点。此时,你可以试着找两线交叉时所产生的“风洞”。
所谓的风洞就是K、D两线第一次相交时两线所夹成的一个空间,但都是已下跌一段了。[风洞的具体用法]
(2)J值>100时,股价会形成头部。
(3)J值<0时,股价会形成底部。
注意!
J值的讯号不会经常出现,一旦出现,则可信度相当高,很多有心的投机客专门寻找J值的讯号,而且,运用人工智慧选股扫描系统,很轻易的找到最佳买卖点的个股这个讯号可以说是随机指标的精华。
因此,倒过来使用JDK是使用短线指标KDJ的要诀。J值钝化向下发散的一刹那是决定出货日的时机,然而打开5分钟或60分钟KDJ,5分钟K线跌20日均线(系指分时图内)是当日较佳出货点,60分钟K线20日均线一个时段(比如一周内)当然也可以注视5分钟J线,钝化向下发散的瞬间,或60分钟J线钝化向下发散的时点。随机指标KD的标准参数为9,5,3,1;修正参数为27,5,3,1。

Thursday, November 22, 2012

C# Get IPV4 ipaddress


Option 1 :  

public static string GetIP4Address()
{
    string IP4Address = String.Empty;

    foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
    {
        if (IPA.AddressFamily == AddressFamily.InterNetwork)
        {
            IP4Address = IPA.ToString();
            break;
        }
    }

    return IP4Address;
}


 Option 2 :  
 /// <summary> 
/// This utility function displays all the IP (v4, not v6) addresses of the local computer. 
/// </summary> 
public static void DisplayIPAddresses() 

    StringBuilder sb = new StringBuilder(); 

    // Get a list of all network interfaces (usually one per network card, dialup, and VPN connection) 
    NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); 

    foreach (NetworkInterface network in networkInterfaces) 
    { 
        // Read the IP configuration for each network 
        IPInterfaceProperties properties = network.GetIPProperties(); 

        // Each network interface may have multiple IP addresses 
        foreach (IPAddressInformation address in properties.UnicastAddresses) 
        { 
            // We're only interested in IPv4 addresses for now 
            if (address.Address.AddressFamily != AddressFamily.InterNetwork) 
                continue; 

            // Ignore loopback addresses (e.g., 127.0.0.1) 
            if (IPAddress.IsLoopback(address.Address)) 
                continue; 

            sb.AppendLine(address.Address.ToString() + " (" + network.Name + ")"); 
        } 
    } 

    MessageBox.Show(sb.ToString()); 
}

Tuesday, November 20, 2012

Windows Domain Controller NTP 設定



DC NTP對時的方式需透過GPO來設定, 修改Registry是無效的

開啟GPO->電腦設定->系統管理範本->系統->Windows時間服務->時間提供者

要去向別人校時就必須啟用『Windows NTP用戶端』

要給別人校時就必須啟用『Windows NTP伺服器』

在『設定Windows NTP用戶端』內設定NTP Server

NoSync: The client does not synchronize time.
NTP: The client synchronizes time from an external time source. Review the values in the NtpServer line in the output to see the name of the server or servers that the client uses fortime synchronization.(其他外部NTP Server)
NT5DS: The client is configured to use the domain hierarchy for its time synchronization.(當電腦在Domain內時使用)
AllSync: The client synchronizes time from any available time source, including domainhierarchy and external time sources.(任一種皆可)
所以DC角色就是全開, 因為他要當Domain User的NTP Server, 又要當NTP Client去跟中華電信校時

另外, 有遇到網路設備無法跟Windows NTP Server校時的問題
因為w32tm使用的是sntp與一般unix, linux及網路設備懂的ntp不同, 所以無法校時
解法就是別用w32tm......

Thursday, October 4, 2012

WCF REST: Get the requested URL

Finding the Request.Url is a lot different from standard web work when working in a WCF REST context. It can be quite difficult to find the URL of the request in your WCF REST service.

?
var context = OperationContext.Current;
var requestedUrl =  context.IncomingMessageHeaders.To.PathAndQuery;


Monday, September 24, 2012

Malaysia Second Hand Car Website



motortrader(种类比较多容易找)
http://www.motortrader.com.my
emotors(容易找车少)
http://www.emotors.com.my/
ontheroad(车多又容易找)
http://www.ontheroad.com.my
autoworld(这网车很少)
http://www.autoworld.com.my/aw/dealer/EngHuat/
Mudah(里面很多东西车又多)
http://www.mudah.my/
lelong(买二手东西多二手车比较少)
http://www.lelong.com.my/
carlist(这网站车多又好找)http://www.carlist.my/
topmark(种类少,找车没又小图看没甘方便)
www.topmark.com.my
8carcar(是一个很不错的二手车网站)
www.8carcar.com/
e-kereta(二手零件比二手车多)
www.e-kereta.com
carworld(车不多找不方便)
http://carworld.my/
kereta(比较不整齐的二手车网)
http://www.kereta.org/
star-motoring(不方便的二手车网站)
http://star-motoring.com/
thecar(可以看看的网站)
http://www.thecar.com.my/searchcar.html
zerotohundred(车都有不少也可以看看新报到)
http://www.zerotohundred.com/
carmarket(网站没但是没么车)
http://www.carmarket.com.my/
eoaauto(这网站有进步的空间车不是很多)
http://eoaauto.com/
wemotor(好网站车很多又好找)
http://www.wemotor.com/
autoworld(这里的二手车的功能说的很清楚不错)
http://www.autoworld.com.my/


Source Reference 

Tuesday, September 18, 2012

REST and HTTP Status Codes


REST and HTTP Status Codes

One of the key values of REST is that you are using a universal API known as HTTP.  Because of this you must try to understand the way that HTTP wants you to deal with this.  And how does HTTP want me to deal with this issue?  By using an HTTP Status code.
The first line of an HTTP response is the status line – HTTP clients look to this line to understand the outcome of their request.  It isn’t just a matter of errors, there are many different response codes you could return or encounter when invoking RESTful services.    (For more information on the Status-Line see the HTTP spec, section 6.1)
       Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
The status code comes from a long list of codes, according to the spec, the list of codes is extensible but you should follow the model based on the categories of errors
      - 1xx: Informational - Request received, continuing process
      - 2xx: Success - The action was successfully received,
        understood, and accepted
      - 3xx: Redirection - Further action must be taken in order to
        complete the request
      - 4xx: Client Error - The request contains bad syntax or cannot
        be fulfilled
      - 5xx: Server Error - The server failed to fulfill an apparently
        valid request
Even so, I would not go about creating custom HTTP status codes.  Instead I would try to use the commonly used status codes listed in section 10 of the HTTP spec.

REST equivalent of SOAP faults

The designers of SOAP had exceptions in mind when they created SOAP faults.  Previous distributed computing environments (DCOM, CORBA etc.) did not have a model for propagating exceptions across boundaries.  SOAP came along 10+ years after these technologies a time during which exceptions became accepted as a better way of dealing with errors.  Many SOAP stacks (WCF being the prime example) will catch an exception, turn it into a SOAP fault and pass it along to the client side which will unpack the message and throw an exception on the client side.
SOAP faults are different than HTTP status codes because they are always errors and there is no taxonomy of errors, just whatever you want them to be.  In other words, the “error protocol” is application specific.
In REST HTTP status codes are common and they are not always errors.  However the errors do fall into 2 categories 4XX (Client) and 5XX server errors.   Now let’s consider some common scenarios where you must deal with errors and status codes.

Error Scenarios

The first class of errors you must consider are (4XX) client request errors.  Generally it means that the server rejected the request for some reason.

Get or Update record that does not exist

Client does an HTTP GET for a resource ID that does not exist in the database.  On the server you might call into the data layer to update a record an get a KeyNotFoundException (like I did in the video).  What happens if you do nothing?  Well WCF will catch all unhandled exceptions and return a status code of 500 - “Internal Server Error”.  This is not what you want, because it implies that the problem is a server problem. 
In this case you should return a HTTP status code of 400 404 “Not Found”  (edit – 3/25 – thanks Clemens!)
10.4.1 400 Bad Request
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
Here is some code that processes a GET request by looking it up in a dictionary.  This is the fixed version of what I showed in the video.  As you can see I’m converting an exception into a status code by throwing a WebProtocolException.
[OperationContract]
[WebGet(UriTemplate = "/{id}")]
SessionData GetSession(string id)
{
    try
    {
        return _sessions[id];
    }
    catch (KeyNotFoundException)
    {
        throw new WebProtocolException(
            HttpStatusCode.NotFound);
    }
}

Add a resource with missing or invalid data

Client does an HTTP POST with missing or invalid data in the request body.  The server attempts to validate the request and rejects it because of the invalid or missing data.  The HTTP status code should be 400 – Bad request

Server Processing Errors

Suppose that the request is valid, the resource exists and for whatever reason (concurrency or some other processing error) the server cannot complete the request.  Then what?
10.5 Server Error 5xx
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents SHOULD display any included entity to the user. These response codes are applicable to any request method.
You should return a HTTP status code of 500 along with some text to let the user know what is happening (if you want to).  Here is an example of code that would do this kind of processing. 
[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "/{id}")]
SessionData UpdateSession(string id, SessionData updatedSession)
{
    try
    {
        if (!_sessions.Contains(updatedSession.ID))
            throw new WebProtocolException(HttpStatusCode.BadRequest);

        if (!_sessions.IsValidSession(updatedSession))
            throw new WebProtocolException(HttpStatusCode.BadRequest);

        return _sessions.Update(updatedSession);
    }
    catch (TimeoutException)
    {
        throw new WebProtocolException(HttpStatusCode.InternalServerError,"Update session timeout",null);
    }
}
 
 
Source Reference 

股市心得编


(一)牛市不要过于乐观;熊市不要过于悲观!

牛市不要过于乐观 -- 通常会高档进货!
熊市不要过于悲观 -- 通常会杀到低价!
大牛市要悲观 -- 通常卖到好价!
大熊市要乐观 -- 通常捡到便宜货!
牛市不要过于乐观;熊市不要过于悲观!-- 投资第一招! 

(二)投资 vs 投票! 
由于我是一个长期投资者,所以我投资股票的另一些标准是:
我不投资在会因为某政党执政,而会引起 LICENCE 更新问题的股票如:博彩股及酒类股。
加上我个人觉得:投资赚钱不应损人利己,所以烟草这类有损人体健康的股票,也被我排除在外。
就算这些股票股息佳,业绩佳,我也放弃了。。。
因为股海浩瀚,只怕没钱。。。不怕没股票让我投资。。。 

(三)是偏见?是经验? 
我是个长期投资者,我选股的其中两个标准:
我不投资某族群为大股东的股票。
我不投资某政党为大股东的股票。
因为路遥知马力。。。某族群,某政党的股票似乎经不起时间的考验。。。
就算这些股票容易获得 projects...
就算这些股票容易投机获利。。。。
我总是没信心。。。
我喜欢的是凭真本事的公司。。。

(四)事不过三---在股市的应用: 
古人有云:事不过三,意思是:事情不会连续发生超过三次。
根据我个人的观察:事不过三的道理,在股市里应用之妙,存乎一心!
股市连续大起三天,通常会技术调整!
股市连续大跌三天,通常会技术反弹!

(五)股市顶部,底部的基本判断:
好消息出尽,量大价不起,顶部不远矣!
坏消息尽出,量大价不跌,底部已近矣!
所谓一叶落而知天下秋。。。股海亦是如此矣!本人才浅学疏,以上仅供参考,输赢自负!

Reference Link 

Friday, September 14, 2012

Enable WCF tracing



Tracing mechanism in Windows Communication Foundation is based on the classes that resides in System.Diagnostic namespace.Important classes are Trace, TraceSource and TraceListener.

Following are the steps to enable tracing in WCF:

1. Configuring WCF to emit tracing information/Define Trace Source, we have the following options:
  • System.ServiceModel 
  • System.ServiceModel.MessageLogging 
  • System.ServiceModel.IdentityModel
  • System.ServiceModel.Activation 
  • System.Runtime.Serialization 
  • System.IO.Log
  • Cardspace
      In configuration file, we will define a source to enable this configuration as follows:
      <source name="System.ServiceModel.MessageLogging">
2. Setting Tracing Level, we have the following available options, we need to set this tracing level to available options other than default "Off":
  • Off
  • Critical
  • Error
  • Warning
  • Information
  • Verbose
  • ActivityTracing
  • All
      In configuration file, we can choose above values for switchValue attribute as follows:
      <source name="System.ServiceModel.MessageLogging"
                               switchValue=”Information”>

3. Configuring a trace listener
    For configuring a trace listener, we will add following to config file.
     <listeners>
                 <add name="messages"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="d:\logs\messages.svclog" />
      </listeners>

4. Enabling message logging
      <system.serviceModel>
         <diagnostics>
            <messageLogging
                    logEntireMessage="true"
                    logMalformedMessages="false"
                    logMessagesAtServiceLevel="true"
                    logMessagesAtTransportLevel="false"
                    maxMessagesToLog="3000"
                    maxSizeOfMessageToLog="2000"/>
         </diagnostics>
    </system.serviceModel>
logEntireMessage: By default, only the message header is logged but if we set it to true, entire message including message header as well as body will be logged.
logMalformedMessages: this option log messages those are rejected by WCF stack at any stage are known as malformed messages.
logMessagesAtServiceLevel: messages those are about to enter or leave user code.
logMessagesAtTransportLevel: messages those are about to encode or decode.
maxMessagesToLog: maximum quota for messages. Default value is 10000.
maxSizeOfMessageToLog: message size in bytes.

Putting all this together, configuration file will appear like this.
--------------------------------------------------------------------------- 
    <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messagelistener"
               type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\logs\myMessages.svclog"></add>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
    <system.serviceModel>       
      <diagnostics>
        <messageLogging logEntireMessage="true"
                        logMessagesAtServiceLevel="false"
                        logMessagesAtTransportLevel="false"
                        logMalformedMessages="true"
                        maxMessagesToLog="5000"
                        maxSizeOfMessageToLog="2000">         
        </messageLogging>
      </diagnostics>
    </system.serviceModel>
---------------------------------------------------------------------------

Note: In this case, information will be buffered and not published to file automatically, So, we can set the autoflush property of the trace under sources as follows:
<trace autoflush ="true" />
 
 
 

Thursday, August 16, 2012

Shortcut Key Use Code Snippets (C#)


To use code snippets through keyboard shortcut

  1. In the Visual Studio IDE, open the file that you intend to edit.
  2. In the Code Editor, place the cursor where you would like to insert the code snippet.
  3. Type CTRL+K, CTRL+X.
  4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.
    Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

To use code snippets through IntelliSense auto-completion

  1. In the Visual Studio IDE, open the file that you intend to edit.
  2. In the Code Editor, place the cursor where you would like to insert the code snippet.
  3. Type the shortcut for the code snippet that you want to add to your code.
  4. Type TAB, TAB to invoke the code snippet.

To use code snippets through the IntelliSense Complete Word list

  1. In the Visual Studio IDE, open the file that you intend to edit.
  2. In the Code Editor, place the cursor where you would like to insert the code snippet.
  3. Begin typing the shortcut for the code snippet that you want to add to your code. If automatic completion is turned on, then the IntelliSense complete word list will be displayed. If it does not appear, then press CTRL+SPACE to activate it.
  4. Select the code snippet from the complete word list.
  5. Type TAB, TAB to invoke the code snippet.

To use code snippets through the Edit menu

  1. In the Visual Studio IDE, open the file that you intend to edit.
  2. In the Code Editor, place the cursor where you would like to insert the code snippet.
  3. From the Edit menu, select IntelliSense and then select the Insert Snippet command.
  4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.
    Alternatively, you can type the name of the code snippet, and then press TAB or ENTER.

To use code snippets through the context menu

  1. In the Visual Studio IDE, open the file that you intend to edit.
  2. In the Code Editor, place the cursor where you would like to insert the code snippet.
  3. Right-click the cursor and then select the Insert Snippet command from the context menu.
  4. Select the code snippet from the code snippet inserter and then press TAB or ENTER.
    Alternatively, you can type the name of the code snippet, and then press TAB or ENTER


    Reference: Microsoft Knowledge DB