In May 2015, I covered the Day Scalper strategy, which I used in the same month to rank 25 in trader contest. I promised to turn it into a Visual JForex strategy and that is what this article is about. To better understand what I will be covering, take a look at the Day Scalper article. The strategy utilizes simple moving averages and moving average envelopes. Let’s get started.

Start Point

While Day Scalper runs on bar charts, I will be using daily candles in VisualJF. I start all my strategies by separating signal evaluation with trade management. To avoid nuisances, check if:-
  • Default instrument is equal to candle instrument,
  • “candleTime” variable is 1min and equal to candle period,
  • Open or all positions amount are greater than 1, then flow to trade management. If less than 1, flow to signal evaluation,
  • Last trade event is long or short.
Refer to the image below

Time Blocks

Day Scalper evaluates markets at New York close (17:00EST or 21:00 GMT), so we have to prevent signal evaluation until the market closes. To do this, we use 'getTimeUnit' blocks using last bid candle time. If it is 21:01 GMT, then continue.

Debugging Time

Simply drag the hour and minute variables into the workspace and run a historical test. If everything is working properly, the minute variable should be empty until the time is equal to or greater than 21:01 GMT.

Indicators Used

Moving Average Envelopes

Use derivation 1 and 1.5, time period 9, and the default period is daily. Name the low band mAE1Low, high band mAE1High. The second block is mAE15Low, high band mAE15High and debug like we did on the time unit blocks. To cross check the outputs, plot the moving average envelopes on the chart that pops up during the historical test.

MAE Blocks Example

SMA Blocks

The strategy checks if the current day 18-day SMA is still going up or down by comparing it to the previous day 18-day SMA. Shift 0 is the last closed daily candle (since we are evaluating signals at 21:01 GMT) and shift 1 goes a day back.

I have run into problems implementing the condition:-

The 18-Day SMA should have turned up or be going up already and it's less than 1 month (30 days) since it turned up, you can consider up to 60 days if the trend is still strong.

To check the strength of the trend so that I can consider 30 or 60 days would lead to using the ADX indicator. So, I settled for 60 days using monthly 18-day SMA with shift 2 (90 days), shift 1 (60 days), and shift 0 (30 days).

The logic being, 90-day (18-day SMA) < 60-day (18-day SMA) < 30-day (18-day SMA) for buy signal and the reverse for sell.

From the image above, it is clear it was a downtrend. Again, plot the same indicators on the chart and verify the outputs.

Example of daily chart with 18-day SMA shift 0 (red) and 1 (green), and 9-day SMA (blue)

Monthly chart with 90 (shift 2), 60 (shift 1), and 30 days (shift 0).

Historical Candles

Day Scalper utilizes highest high and lowest low of the past 5 days as well as yesterday's close in calculating entry price and stop loss level.

To achieve this, we need to get the historical candle for the past day and get historical candles for the past 5 days.

Getting a daily historical candle is straightforward, but getting the highest high or the lowest low of the last 5 days involves a loop viewer and several assignments.

You can also use last bid candle variable to get the previous candle on the daily time frame, which represents yesterday. I choose to use 'Get Historical Candle' with shift 0 to avoid confusion.

Drag the ‘Get Historical Candle’ block to the workspace as shown below and 3 'Assign' blocks. Assign yesterdayCandle.Candle close to candleClose, yesterdayCandle.Candle High to candleHigh and yesterdayCandle.Candle Low to candleLow variables and verify the output.

Getting Highest High and Lowest Low of the Last 5 Days

Use a ‘Get Historical Candles’ block with the candle period as daily, shift 0, candles amount 5 and output as candles5Day. On 2 'Assign' blocks assign 0 to high5 (highest high of past 5 days) and 2000 to low5 (lowest low of past 5 days).

Next, use a loop viewer block with the array of data as candle5Day and output as prev5dayCandle. This block should flow into a ‘Multiple Action’ block through the 'loop' output not the 'end of cycle'.

On the 'Multiple Action' block, connect 2 'if' blocks with the first input value as prev5dayCandle.Candle High and second as high5. Repeat this on the second 'if' block using prev5dayCandle.Candle Low and low5.

Next, connect an 'Assign' block on the greater than sign on the first 'if' block (prev5dayCandle.Candle High) with input as prev5dayCandle.Candle High and output high5. Do this on the prev5dayCandle.Candle Low block, but flow from the less than sign.

Verifying the highest and lowest low of the last 5 days output.

Trading Logic

At this point, we have to separate buy and sell signals by comparing the two 18-day SMA. If the last SMA is greater than previous, then it is a bullish signal and when it’s less, it is bearish. We also do not trade when yesterday's close price is same as open price. This is accomplished using 'if' blocks.

Buy Signal
  • 18-day SMA (shift0) is greater than 18-day SMA (shift1)
  • candleClose is greater than 9-day SMA * 0.99 (moving average envelope derivation 1)
  • candleHigh is less than 9-day SMA * 1.5 (moving average envelope derivation 1.5)
Create 2 'Calculation' blocks multiplying sma9 with 0.99 and 1.5 respectively and save the outputs as bullEval1 and bullEval2. Use an 'if' block to evaluate if the first condition is true before going to the next 'Calculation' block - this speeds up execution.

Sell Signal
  • 18-day SMA (shift0) is less than 18-day SMA (shift1)
  • candleClose is less than 9-day SMA * 1.5
  • candleHigh is greater than 9-day SMA * 0.99
The same blocks as for buy are used, but the comparison is reversed.

From the image above, you will notice that I deliberately left out the 'if' block that would check for the same open price and close price. This is because ‘dead heats’ are a rare occurrence and I wish to keep code size to a minimum.

I am almost done with the signal evaluation, but running low on word limitation. In the next article, I will cover order placement and trade management.
Translate to English Show original