Thursday, December 29, 2016

isleapyear by Java


public class LeapYear {
    public static final int LEAP = 1;
    public static final int COMMON = 0;
    public static int isLeapYear(int d) {
        if(d%400 == 0) return 1;
        if(d%100 == 0) return 0;
        if(d%4 == 0) return 1;
       
        return 0;
    }
}


import org.junit.*;
import static org.junit.Assert.*;
public class LeapYearTest {
    @Test
    public void test_1996_is_leap_year() {
        int actual = LeapYear.isLeapYear(1996);
        assertEquals(LeapYear.LEAP, actual);
    }
    @Test
    public void test_2001_is_common_year() {
        int actual = LeapYear.isLeapYear(2001);
        assertEquals(LeapYear.COMMON, actual);
    }
    @Test
    public void test_1900_is_common_year() {
        int actual = LeapYear.isLeapYear(1900);
        assertEquals(LeapYear.COMMON, actual);
    }
    @Test
    public void test_2000_is_leap_year() {
        int actual = LeapYear.isLeapYear(2000);
        assertEquals(LeapYear.LEAP, actual);
    }

}

Tuesday, June 28, 2016



Bull trap for oil, falls to middle line and goes back.



Follow H4 bull engulfing, today it breaks the middle line.




For daily chart, it look 46.20 is the bottom, my first target is 49.



Saturday, June 25, 2016



Brexit post a big spike on gold. I was thinking of Soros. He knew Britons.

From James Joyce's Ulysses, the Martello tower,  Citizen, the ordinary people, xenophobia. It's a fact, Brexit is a fact now. The mind can detect this! But not me, because I am too depend on Computer (or technology), that's why I lose the touch with the mind.

It looks to me trading is not about technology, so meditate, reciting the mantra, reading James Joyce & Joseph Campbell, walk in the nature, to have a touch with the mind!



Tuesday, June 21, 2016


For oil, bull engulfing still have effect. In the morning it dropped, but from afternoon, it reversed after API report. (In trading, patience is number 1 factor, I have to wait the day for the trend to continue)


Gold dropped today, will Silver follow?



Silver dropped, but not under the low of previous bear engulfing, so I am still waiting!




Thursday, June 16, 2016



Wait for several days, today silver turned to black. Enter with bear.


Friday, June 10, 2016



Bear engulfing does not need confirmation, today it drops very big. I buy HOU when it's under the middle line, may not be a good time. looks that bear is full in control.


Gold is in bull trend now. I sale the gold for profit, now I am balanced.


Thursday, June 9, 2016



Bear engulfing for today. A signal to buy HOD. For me, just wait (to buy HOU).


Gold, bull no change. Since 1270 is the resistant point, I would think it will stay here for a while, could go up to 1304.

Wednesday, June 8, 2016


Bull move of silver for today, it gets to the resistance at 17, the next point is 17.5.


Gold is also in the bull trend now.

Monday, June 6, 2016



Last Friday, Gold post 2% increase because of May Job report of US. I expect it will continue the trend this week as bull. ( my target for gold is 1263)



For oil, no trade for the past week, I'm waiting it to goes to 52. long time waiting. today as Monday it has increase 2%, because of the production crisis, 50 is likely a ceiling, last week, rig count increased.

Wait for now. (my target for oil is 50.90)






Wednesday, June 1, 2016



My wife is a better trader than me, her strategy is waiting and waiting, and this morning she find the point to enter (buy at low), and sale in the afternoon to cash out. An excellent trade!


My 160 minutes daily sitting meditation start from today, I sit three sits daily as  60, 60 and 40. I was able to completed today. My goal is to practice a total 10000 hours in the next 10 years.


The schedule is 8:30-9:30, 10:30-11:30 and 13:20 to 14:00.
The technique for me to practice:
 - sitting in full lotus posture
 - Anapanna meditation (taught by An Shi Gao)
 - 42 sections (taught by the Buddha)


Tuesday, May 31, 2016




Gold finally post a bullish engulfing today (that little bull is asian trading time), should it move up? Let's see!



For oil, it's a bear for today although it goes to $50 shortly. I have removed 50 MA and 200 MA, just bollinger bands (20, 0.618) and MA (20) which is the middle band (for confirmation of the continuation of the trend).  Now the plot looks simple. (simplicity!!!)

On this bull trend, it's hard to buy HOD for profit.


XP500 looks a clear bearish reverse!


Friday, May 27, 2016



For the week oil is on up channel, keep my position.



Gold is in lower channel, I have sold out my hgd for profit. There's support at $1210. Wait for position for hgu.



Saturday, May 21, 2016


Gold, on daily chart it goes down to $1250, there's some support (50 MA) there. Could go even lower to 200 MA there.
On weekly chart it drops for three weeks. so it has pressure to continue goes down obviously.

Last Wednesday brought up the message of Dollar (increase rate possibilities) which cause the stock drop heavily. I was thinking if there's not such message, the gold will go up.

Overall gold is still in bull market (50MA is on top of 200 MA, and 200 MA 's direction it is move up)

My strategy is I am not sale my bull HGU for loss. I still own portion of HGD to cover the loss on HGU.

Next week,

  1. Wednesday again an event day. 
  2. can oil goes up to $50? If it goes to 50, gold will also move up. 




It looks DXY is on up channel, that is why Gold and Silver is losing, can DXY drop next week? doji there, lets wait the direction on Wednesday.



Thursday, May 19, 2016



Today gold goes to 1250, in the trading time, the HGU and ABX are all up a little bit following yesterday's bearish report.

I would think  it could continue to go low tomorrow.

I sale HGD at beginning of the market with trailing stop loss, but buy it back a bit early. The is hope HGD and HGU close to each other.

I would have the following additional rules for my trading.

1. Always have protect with money. (I main if I have Yin, I should have the money to cover Yang, right now I don't have in my account, which put me to the loss)
2. After sale a stock to take profit and buy it back I should buy with less money.



Yesterday HGU drops larger than HGD, that is difficult the two are not balanced. so everytime I make money, when I enter back, I should always put less from what I earned.








Wednesday, May 18, 2016



After two bull day for this week, it finally turns to bear today (Event Wednesday).

Monday I bought HGU, yesterday sold to take profit, but this morning I bought it back. then it drops 5 dollar per stock.

My HGD is profiting finally, but I am  not put it on sale because I don't know whether it will drop over night.

Three factors are  important for trading at stock market, first is defence (for a monk, the defence is their precepts, for me as a trader, I follow my rules (or discipline).

One rule is when stock drops I don't sale and buy it at lower price, it does not work for me, because I may miss to buy before it goes up)
the second rule is when stock drops, and I already have one, I don't buy it at already lower price, because the stock could go even lower, and I will be imbalanced (to put too much position on the losing stock)

To support my two rule, when the stock "yin" drops, I buy "yang" to cover the loss of "yin", after sale yang, I wait "yin" to go back, or buy "yang" again to fence off  "yin" .

Now my problem this week is I don't have enough cash to cover all three yin-yang stocks. for gold and silver, I can only cover one with my cash. (reality, I have to cover gold and abandon silver for now, silver is less volatility)

The second factor is the ability to keep unmoved.(the samadhi power) This is a practise, you are not moved by the wind of market, for the wind I mean the emotions of greed and fear.

The last factor is the ability to win (wisdom). Currently I am still in loss. It will come when I practice the first two really good. For win, here are the things I am looking for:
- candlestick & bollinger bands for a good setup to enter
- weekly chart after a week, and determine the trend for the next week
- chart for years, determine the overall trend currently. (hold for longer position)
so far I put longer position on gold, silver  and oil they are all bull (my previous post), but this week it is bearish on gold and silver.


Just keep practice.





Tuesday, May 17, 2016

Gold and Silver are in bull trend



For gold and silver, the trend is BULL right now, and they just break the lowest low (like oil), so it is a good time to invest.


Saturday, May 14, 2016


For Silver and Gold Weekly chart, for the past two weeks it is bear, I think it will be bear for the next week too. For Oil daily chart, it is also bearish, so holding all bear will be strategy for the next week.






Thursday, May 12, 2016



Take profit for silver HZD.  I entered yesterday, that's a good enter point.

Wednesday, May 11, 2016



It's event day, I saw a big bear candle and enter with HOD but it boosted up.
So candlesticks is not working for event day.


Noticed bearish engulfing, enter with hzd, but not sold, because my volume is small, wait for tomorrow.


Tuesday, May 10, 2016



After bullish engulfing, notice that long bull candle which means bull in control, so I entered and exit after an hour (did not wait tomorrow)


Monday, May 9, 2016



The bears finally came at Sunday, so I take profit this Monday morning. It looks to me, DXY is still the major indicator for gold. I predict bear but enter a little bit early to the market.

Friday, May 6, 2016



I refer to DXY and have an idea that dollar will be up (strong), so I think gold will be bear, but the moment bull is in control, and I enter with bear which makes me have no profit for today.




Thursday, May 5, 2016




Engulfing pattern is my choice to play in the stock market. Today I noticed engulfing for bear, enter a little bit hesitate, but still make profit on it.

Moving average makes me notice the pace to enter and exit.

The decision is also refer to DXY, since this week still bullish.

Wednesday, May 4, 2016


  • lavender (20 moving average, bollinger bands)
  • steelblue (50 moving average)
  • khaki (200 moving average)


I tried to use different average lines to determine enter and exit. Usually observe H1 plot on 20 & 50 moving average. If 20 & 50 crosses, it means the trend has changed. Also 200 (or on H4) average line shows the long term trend, which can be used to hold some position. with 20 & 50 I do short trading.



Enter when 20 and 50 average line cross over. Cross Over, exit  due to fear.

Dollar index is switching to up band for this week, can be used for reference on gold (oil and silver).




For silver, I also enter with bear, it also cross over 200 average line.



Oil runs fast compare to gold and silver, silver runs slowest, I can use oil plot for reference on gold and silver.



Friday, April 29, 2016



Dollar turns bearish for the past week, Wednesday is a big day that Fed reserves decides not raising interest rate, so dollar slumps, oil, gold and silver goes high.



Crude oil is in up channel,  for now just keep HOU and wait for sign to buy HOD.


I sold HZD when I noticed that high wave fails. it is good that I do it, then it flies on.