Quant Zone Rules Examples

browse

Disclaimers

  1. None of this is investment advice.
  2. Users should use the Quant Zone at their own risk.
  3. The below are rough descriptions of how Quant Zone Rules are designed to work, but they make some approximations and should not be taken to be precise.  There are no guarantees that rules or the platform will always be available or execute as intended.
  4. The Quant Zone, like the rest of FTX, is not being offered to US users.

 

PLEASE NOTE RULES ARE DESIGNED TO LOOP EVERY 15 SECONDS

 

FTX Quant Zone Homepage: https://ftx.com/quant-zone 

FTX Quant Zone Telegramhttps://t.me/FTX_Quant_Zone

Note: users should think carefully before using any Quant Zone rules, including the examples below.  Users are responsible for the performance of their Quant Zone rules.  This article is not an endorsement of the below rules, just an illustration of how one could construct rules.

 

Quant Zone Rule Building Competition Winners

These are the winners of the competition. If anyone has a useful rule and wants it to be listed here, feel free to reach out to us. There were enough good submissions we decided to award two winners instead of one!

Tied 1st Place: Supertrend by CheshireCatNick - Wins an HTC EXODUS Smartphone and an FTX swagpack!

Supertrend is a basic yet powerful indicator that can decide whether we are in a bull trend or bear trend.

The author has helpfully put up a description of the strategy here.

 

Tied 1st Place: MA based BTC buy/sell strategy by 8baller030 - Wins an HTC EXODUS Smartphone and an FTX swagpack!

We have used pyalgo trade to optimise a simple buy strategy for BTC. We have optimised for the difference between the price and moving average along with % of portfolio staked. 

8baller has written up their strategy here

 

Dynamic RSI Period Reversal Algo by Casper Cheng - Wins 200FTT

Casper wrote a set of rules to implement Dynamic RSI Period Reversal (see here ).  He also did a backtest here.

 

Support/Resistance Trading by Yu-Shiuan Chen - Wins 200FTT

Yu-Shuan’s strategy (see here) uses the price momentum by dynamically developing the BTC-PERP prices resistance and support from 5 Days, 10 Days, 20 Days, and 60 days moving averages.

 

Converting Collateral by Ankit - Wins 200FTT

The rule finds the ratios of various types of non-USD collaterals in the wallet, & books USD profits in that ratio. For eg. your USD profits are booked equally in BTC & ETH if you have equal $ values of ETH and BTC in your wallet

Note: Ankit has written up his rules here.

 

Miscellaneous Functions

  1. Daily Open price
    1. price("BTC-PERP",minute+60*hour)
  2. 1 minute halflife EWMA price
    1. (price("BTC-PERP")+0.5*price("BTC-PERP",1)+0.25*price("BTC-PERP",1)+0.125*price("BTC-PERP",1)+0.0625*price("BTC-PERP",1)+0.03125*price("BTC-PERP",1)+0.015625*price("BTC-PERP",1))/1.984375
  3. Periodically updating variables
    1. It might be helpful to have a rule that just cycles every 15s and has lots of Update Variable actions to keep variables up to date
  4. Only run a rule once
    1. have as part of the trigger .... and get_variable("v1") == 0
    2. have as one of the actions Set Variable; v1; 1
  5. Price X days ago, Y hours + Z minutes into the day:
    1. price("BTC-PERP",minute+60*hour+X*24*60-Y*60-Z)

 

EMA

Below is a set of rules for the following bot: "Once per day, if BTC is below its 10 minute EMA, buy 1 BTC; otherwise sell 1 BTC".

Rule 1 -- Variable_loop

Trigger

true

Action 1

Set Variable; BTC_EMA_10; (1*price("BTC-PERP",0)+0.93*price("BTC-PERP",1)+0.87*price("BTC-PERP",2)+0.81*price("BTC-PERP",3)+0.75*price("BTC-PERP",4)+0.70*price("BTC-PERP",5)+0.65*price("BTC-PERP",6)+0.61*price("BTC-PERP",7)+0.57*price("BTC-PERP",8)+0.53*price("BTC-PERP",9)+0.5*price("BTC-PERP",10)+0.46*price("BTC-PERP",11)+0.43*price("BTC-PERP",12)+0.40*price("BTC-PERP",13)+0.37*price("BTC-PERP",14)+0.35*price("BTC-PERP",15))/9.93

mceclip0.png

Rule 2 -- Buy_rule

Trigger

get_variable("BTC_EMA_10") != 0 and get_variable("BTC_EMA_10") > price("BTC-PERP")

Action 1

Place Custom Order; Market order; Buy; BTC-PERP; 1

Action 2

Pause Rule; Current Rule; 1 Day

Screenshot_2020-04-10_at_2.34.59_PM.png

Rule 2 -- Sell_rule

Trigger

get_variable("BTC_EMA_10") != 0 and get_variable("BTC_EMA_10") < price("BTC-PERP")

Action 1

Place Custom Order; Market order; Sell; BTC-PERP; 1

Action 2

Pause Rule; Current Rule; 1 Day

Screenshot_2020-04-10_at_2.35.36_PM.png

 

 

SMA Crossover Strategy


I have written a strategy consisting of 3 different rules that form the following bot: “Once per day, if the 3 day SMA is above the 11 SMA long and risk no more than 10% of available balance and close any open short positions, if the 3 days SMA is below the 11 SMA then sell short and risk no more than 10% of available balance and close any open long positions”.

Rule 1: The 11 and 3 SMA Variables

Trigger: true

 mceclip0.png

 

Action1:  (a “Set Variable”) that makes up the 11 Day SMA:

(price("BTC-PERP")+price("BTC-PERP", minute+60*hour)+price("BTC-PERP", minute+60*hour+1440)+price("BTC-PERP", minute+60*hour+2880)+price("BTC-PERP", minute+60*hour+4320)+price("BTC-PERP",minute+60*hour+5760)+price("BTC-PERP",minute+60*hour+7200)+price("BTC-PERP", minute+60*hour+8640)+price("BTC-PERP",minute+60*hour+10080)+price("BTC-PERP",minute+60*hour+11520)+price("BTC-PERP",minute+60*hour+12960))/11

mceclip1.png

 

Action 2:  (a “Set Variable”) that makes up the 3 Day SMA:

(price("BTC-PERP")+price("BTC-PERP", minute+60*hour)+price("BTC-PERP", minute+60*hour+1440))/3

mceclip2.png

 

Rule 2: Buy_Crossover Rule

Trigger: get_variable("11 SMA") != 0 and get_variable("3 SMA") != 0 and get_variable("3 SMA") > get_variable("11 SMA")

mceclip3.png

 

Action 1: (a “Close Position”) that closes any open short positions:

mceclip4.png

 

Action 2: (a “Place Custom Order”) that opens a long with a market order and risks 10% of available balance:

mceclip5.png

 

Action 3: (a “Pause Rule”) pauses this rule for 1 day:

mceclip6.png

 

Rule 3: The Sell_Crossunder rule

Trigger: get_variable("11 SMA") != 0 and get_variable("3 SMA") != 0 and get_variable("3 SMA") < get_variable("11 SMA")

mceclip7.png

 

Action 1: (a “Close Position”) that closes any open long positions:

mceclip8.png

 

Action 2: (a “Place Custom Order”) that opens a long with a market order and risks 10% of available balance:

mceclip9.png

 

Action 3: (a “Pause Rule”) pauses this rule for 1 day:

mceclip10.png

 

MAX Buy

Below is a set of rules for the following bot: "when BTC trades above its 1 day hourly high, buy".

Rule 1 -- variable_loops

Trigger

true

Action 1

Set Variable.  max_px_1.

max(price("BTC-PERP",60),price("BTC-PERP",120),price("BTC-PERP",180),price("BTC-PERP",240),price("BTC-PERP",300),price("BTC-PERP",360),price("BTC-PERP",420),price("BTC-PERP",480),price("BTC-PERP",540),price("BTC-PERP",600),price("BTC-PERP",660),price("BTC-PERP",720))

Action 2

Set Variable.  max_px_2.

max(price("BTC-PERP",780),price("BTC-PERP",840),price("BTC-PERP",900),price("BTC-PERP",960),price("BTC-PERP",1020),price("BTC-PERP",1080),price("BTC-PERP",1140),price("BTC-PERP",1200),price("BTC-PERP",1260),price("BTC-PERP",1320),price("BTC-PERP",1380),price("BTC-PERP",1440))

mceclip1.png

Rule 2 -- buy_max

Trigger

price("BTC-PERP") > get_variable("max_px_1") and price("BTC-PERP") > get_variable("max_px_2")

Action 1

Place Custom Order.  Market order; buy; BTC-PERP; 1.

mceclip3.png

Arbitrage

Below is a set of rules for the following bot: "when perpetual futures are trading above spot, buy spot and sell futures; otherwise, unwind any position you had on".

Rule 1 -- sell_rule

Trigger

premium("BTC-PERP") > 1.001 and (position_leverage("BTC-PERP")*position_side("BTC-PERP") > -0.8 or balance("USD") / collateral > 0.75)

Action 1

Place Custom Order.  Market order; Buy; BTC/USD.  Order Size: max((balance("USD") / price("BTC/USD") + balance("BTC"))* 0.98 - balance("BTC"),0).  IOC.  Cancel and place a new order.

Action 2

Place Custom Order.  Market order; Sell; BTC-PERP.  Order Size: balance("BTC") + position_net("BTC-PERP").  IOC.  Cancel and place a new order.

mceclip4.png

Rule 2 -- buy_rule

Trigger

premium("BTC-PERP") < 1.0002 and (position("BTC-PERP") != 0 or balance("BTC") != 0)

Action 1

Place Custom Order.  Market order; Sell; BTC/USD.  Order Size: balance("BTC").  IOC.  Cancel and place a new order.

Action 2

Close Position.  Buy; BTC-PERP.  Close the entire position.

 mceclip3.png

Known Flaws:

  1. The "sell_rule" will buy the BTC spot in one cycle and then sell the BTC-PERP in the next cycle, instead of doing them both at once
  2. "premium" might be counter-intuitive when markets are moving--what if BTC-PERP has moved but the index data is lagging by a few seconds? 
  3. Doesn't bother checking if you have the right type of assets in your account; you need spot USD to get this started
  4. Doesn't check your account leverage settings
  5. Uses non-USD collateral and doesn't think carefully about collateral conversions
  6. Uses market orders; there might be slippage!

 

Constant Leverage

Below is a set of rules for the following bot: "every 15 seconds, resets your account leverage to +2x".

Rule 1 -- 2x_leverage_buy

Trigger

leverage < 2

Action 1

Open Position.  Buy; BTC-PERP; 2.

mceclip5.png

Rule 2 -- 2x_leverage_sell

Trigger

leverage > 2

Action 1

Close Position.  Sell; BTC-PERP; Reduce position leverage: 2.

mceclip6.png

 

Known Flaws:

  1. Trades a lot 
  2. Doesn't bother checking what type of account collateral you have
  3. Doesn't check your account leverage settings
  4. Uses market orders; there might be slippage!
  5. Can get confused if you start out short BTC-PERP
  6. Account leverage can be approximate; it depends on the prices of assets at the time the orders are computed

 

ALT TWAP

Below is a set of rules for the following bot: "each day, buy ALT-PERP TWAP over the first hour if it was up yesterday, and sell if it was down, trading $2000 over the course of the hour".

Rule 1 -- twap_buy

Trigger

hour < 1 and price("ALT-PERP",minute) > price("ALT-PERP",minute + 60*24)

Action 1

Place Custom Order.  Market order; Buy; ALT-PERP.  Order Size: 2000 * 15 / (60 * 60 * price("ALT-PERP")).  IOC.  Cancel and place a new order.

Screenshot_2020-04-14_at_12.47.09_PM.png

Rule 2 -- twap_sell

Trigger

hour < 1 and price("ALT-PERP",minute ) < price("ALT-PERP",minute + 60*24)

Action 1

Place Custom Order.  Market order; Sell; ALT-PERP.  Order Size: 2000 * 15 / (60 * 60 * price("ALT-PERP")).  IOC.  Cancel and place a new order.

Screenshot_2020-04-14_at_12.50.49_PM.png

Known Flaws:

  1. Doesn't check collateral or liquidation risk
  2. Doesn't update behavior of ALT-PERP price changes
  3. Market orders can have slippage

 

 

Ping Pong Bot

The Ping Pong Bot works best in ranging markets.

Below are a set of rules for the following bot: 

"If BTC goes below 6800, long 1 BTC. If BTC reaches 6900, close long position.”

“If BTC goes above 6900, short 1 BTC. If BTC reaches 6800, close short position.”

“If BTC goes above 7000 or below 6700, close long/short positions.”

mceclip0.png

 

Rule 1 -- long_pingPong

Trigger

(price("BTC-PERP") <= 6800) and (position_net("BTC-PERP") == 0)

Action 

Place Custom Order; Market order; Buy; BTC-PERP; 1

mceclip1.png


Rule 2 -- closeLong_pingPong

Trigger

((price("BTC-PERP") >= 6900) or (price("BTC-PERP") <= 6700)) and (position_net("BTC-PERP") > 0)

Action

Close the entire long Position. Sell; BTC-PERP.

mceclip2.png

 Rule 3 -- short_pingPong

Trigger

(price("BTC-PERP") >= 6900) and (position_net("BTC-PERP") == 0)

Action 

Place Custom Order; Market order; Sell; BTC-PERP; 1

mceclip3.png

 

Rule 4 -- closeShort_pingPong

Trigger

((price("BTC-PERP") <= 6800) or (price("BTC-PERP") >= 7000)) and (position_net("BTC-PERP") < 0)

Action

Close the entire short Position. Buy; BTC-PERP.


mceclip4.png

 

Rule 5 -- pause_pingPong

Trigger

((price("BTC-PERP") <= 6700) or (price("BTC-PERP") >= 7000)) and (position_net("BTC-PERP") == 0)

Action

Pause Rule; All Rules; 100 Days

pause_pingPongRule.jpg

Known Flaws:

  1. Doesn't check your account leverage settings
  2. Doesn't bother checking what type of account collateral you have
  3. Variables could be used instead of hardcoding values in triggers
  4. Stops could be used in separate rules to pause them temporarily
  5. Preference to closing existing positions first before opening new positions
  6. Rules should be paused manually when not required
  7. Uses market orders; there might be slippage!

 

 

__________________________________________

 

Previous
Next
360041935611
Didn't find what you were looking for?
Create a support ticket
Community

Was this article helpful?

1 out of 1 found this helpful