---
title: "Amazing Synthetic Trading Class"
description: "Just spent a week in Newark Ohio working on creating this new synthetic trading class to track and monitor synthetic trades."
url: https://www.quantifiedmodels.com/synthetic-trading-class/
date: 2023-04-28
modified: 2023-06-06
author: "Quantified Models"
image: https://www.quantifiedmodels.com/wp-content/uploads/2023/04/BLOG-WEB-Quantified-Models-4.png
categories: ["Python"]
tags: ["code", "EasyLanguage", "TradeStation"]
type: post
lang: en
---

# Amazing Synthetic Trading Class

## Synthetic Trading Class

Just spent a week in Newark Ohio working on creating this new class to track and monitor synthetic trades so that decisions can be made from the status of the equity curve.  This class contains three methods, and the module includes two additional functions.

Class methods are:

1. calcDailyEquity
2. setSynthTradeInfo
3. __inti__

Module includes:

1. calcEquCurveRetAndRec
2. calcSynthTotEquity functions.

Here is an example of what you can do with this:

Here is the code from a simple ES Mean Reversion System

# This module turns trading on and off based on the retracement and recovery of the equity curve
if curMarket == 0:
if len(synthEquity) > 0: print(myDate," ", synthEquity[-1])
prevStopTrading = stopTrading
equCurveRet,equCurveRec = calcEquCurveRetandRec(synthEquity,100,equityAnchor)
if equCurveRet >= 0.10 and stopTrading == False:
stopTrading = True
equityAnchor = len(synthEquity)
print(myDate,", stopTrading,",equCurveRet)
equCurveRet,equCurveRec = calcEquCurveRetandRec(synthEquity,100,equityAnchor)
if stopTrading == True and equCurveRec >= 0.10:
stopTrading = False
equityAnchor = len(synthEquity)
print(myDate,", startTrading,",equCurveRec,",",equityAnchor)
synthMP = 0
if len(synthTrade.mp) != 0:
synthMP = synthTrade.mp[-1]

# Now you have to weave your synthetic orders inside the real order directives

if mp < 1 and dnCloses == 2 and stopTrading == False:
price = myOpen
tradeName = "ESBuyNDC"
numShares = posSize
enterLongPosition(price,posSize,tradeName,sysMarkDict)
unPackDict(sysMarkDict)

if synthMP < 1 and dnCloses == 2: price = myOpen tempMP = 1 # print(myDate," ",mySymbol," Buy @ ",price," ",tempMP) synthMP = synthTrade.setSynthTradeInfo('l',tempMP,myDate,curBar,posSize,price) # Long Exits if mp == 1 and barsSinceEntry > 4:
price =myOpen
tradeName = "4thDayOut"
numShares = curShares
exitPosition(price, curShares, tradeName, sysMarkDict)
unPackDict(sysMarkDict)

if synthMP == 1 and synthTrade.barsSinceEntry > 4:
price = myOpen
tempMP = 0
tempPosSize = synthTrade.numShares[-1]
# print(myDate," ",mySymbol," LiqLong @ ",price," ",tempMP," ",tempPosSize)
synthMP = synthTrade.setSynthTradeInfo('lx',tempMP,myDate,curBar,tempPosSize,price)

Weave synthetic orders into regular order directives

 

This looks a little rough right now but I will clean it up and finalize robustness of the synthetic testing engine in September.  It will look  a lot better when I release it.  

Article written by George Pruitt

We have several videos available on our YouTube channel that you may find very useful in developing trading systems.

We hope this information has been useful to you.
