@@ -0,0 +1,3240 @@
+/**%0A * The MIT License (MIT)%0A *%0A * Copyright (c) 2014 Marc de Verdelhan%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy of%0A * this software and associated documentation files (the %22Software%22), to deal in%0A * the Software without restriction, including without limitation the rights to%0A * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of%0A * the Software, and to permit persons to whom the Software is furnished to do so,%0A * subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS%0A * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR%0A * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER%0A * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN%0A * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0A */%0Apackage eu.verdelhan.ta4j.strategies;%0A%0Aimport eu.verdelhan.ta4j.Operation;%0Aimport eu.verdelhan.ta4j.OperationType;%0Aimport eu.verdelhan.ta4j.Strategy;%0Aimport eu.verdelhan.ta4j.Trade;%0Aimport eu.verdelhan.ta4j.mocks.MockIndicator;%0Aimport eu.verdelhan.ta4j.mocks.MockStrategy;%0Aimport static org.assertj.core.api.Assertions.*;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Apublic class MaxValueStarterStrategyTest %7B%0A%0A    private MockIndicator%3CDouble%3E indicator;%0A%0A    private int startValue;%0A%0A    private Operation%5B%5D enter;%0A%0A    private Operation%5B%5D exit;%0A%0A    private Strategy alwaysBuy;%0A%0A    private Strategy starter;%0A%0A    @Before%0A    public void setUp() %7B%0A        indicator = new MockIndicator%3CDouble%3E(96d, 95d, 90d, 92d, 95d);%0A        startValue = 93;%0A        enter = new Operation%5B%5D %7B new Operation(0, OperationType.BUY), new Operation(1, OperationType.BUY),%0A                new Operation(2, OperationType.BUY), new Operation(3, OperationType.BUY),%0A                new Operation(4, OperationType.BUY) %7D;%0A        exit = new Operation%5B%5D %7B null, null, null, null, null %7D;%0A        alwaysBuy = new MockStrategy(enter, exit);%0A        starter = new MaxValueStarterStrategy(indicator, alwaysBuy, startValue);%0A    %7D%0A%0A    @Test%0A    public void strategyShouldBuy() %7B%0A        Trade trade = new Trade();%0A%0A        Operation buy = new Operation(2, OperationType.BUY);%0A        assertThat(starter.shouldOperate(trade, 2)).isTrue();%0A        trade.operate(2);%0A        assertThat(trade.getEntry()).isEqualTo(buy);%0A%0A        trade = new Trade();%0A        buy = new Operation(3, OperationType.BUY);%0A%0A        assertThat(starter.shouldOperate(trade, 3)).isTrue();%0A        trade.operate(3);%0A%0A        assertThat(starter.shouldOperate(trade, 3)).isFalse();%0A        assertThat(trade.getEntry()).isEqualTo(buy);%0A    %7D%0A%0A    @Test%0A    public void strategyShouldNotBuyEvenIfFakeIsSayingTo() %7B%0A        Trade trade = new Trade();%0A        assertThat(starter.shouldOperate(trade, 0)).isFalse();%0A        assertThat(starter.shouldOperate(trade, 1)).isFalse();%0A        assertThat(starter.shouldOperate(trade, 4)).isFalse();%0A    %7D%0A%7D%0A

Create MaxValueStarterStrategyTest.java