Good Day
So a about a week ago I got the idea to code a strategy to exclusively trade XBTUSD (Bitcoin). The idea was to write an algorithm that will keep up with the tremendous bullish momentum of the price while reducing drawdown compared to a buy and hold strategy, but at the same time to be ready to short the hell out of it when things start going south! So yesterday I finally got to see it in action as we saw a minor crash and the result was simply glorious!
The strategy is actually quite simple as it is primarily based around 3 moving averages (5 minutes apart) along with a ADX check for volatility.
//Bitcoin Tripple MA Miner 1Min
//Author: Juan Jacobs
//Exchange: XBTUSD Mini
//Timeframe: 1Min
//Spread: 10 or 20
DEFPARAM FLATBEFORE = 100000 //Adjust for your timezone (currently set for GMT+2)
DEFPARAM FLATAFTER = 230000 //Adjust for your timezone (currently set for GMT+2)
FMA = Average[12,4](close) //Fast Moving Average
MMA = Average[17,4](close) //Medium Moving Average
SMA = Average[22,4](close) //Slow Moving Average
stp = 2 //Points away to place stop orders
If hour < 10 or hour > 23 then //Adjust to match Flat Before/After
possize = 0
If longonmarket then
SELL AT MARKET
ElsIf shortonmarket then
EXITSHORT AT MARKET
EndIf
Else
If ADXR[14] > 18 Then //Check for enough volatility
possize = 1
Else
possize = 0
EndIf
EndIf
If countofposition = 0 or shortonmarket and FMA > MMA and MMA > SMA Then
If shortonmarket then
If close > close[3] and close > close[5] Then
Exitshort at market
Buy possize contract at open - stp stop
EndIf
Else
Buy possize contract at open - stp stop
EndIf
ElsIf countofposition = 0 or Longonmarket and FMA < MMA and FMA < SMA Then
If longonmarket then
If close < close[3] and close < close[5] Then
Sell AT MARKET
Sellshort possize contract at open + stp stop
EndIf
Else
Sellshort possize contract at open + stp stop
EndIf
EndIf
SET STOP $LOSS 100*possize
SET TARGET $PROFIT 1500*possize