PTS Logo

How to create trading pseudo code to convert into a trading system

Pseudo trading code is a good first step to designing a trading system to crystalise the mind on the details.

It is generally considered the only way to get a programmer to take on your job. Programmers need all the fine details to work on. Nothing vague can be accepted


The easiest  way to find out exactly what your objective are is to write them down on paper.

Lets get started.

Example No1. Simple long only trend following system in pseudo code



A moving average that changes direction is used to enter trades. So this must be clearly defined for the programmer.

If no other trade is running ( market position = 0 ) and a weighted moving average of length 20 is greater than it was one bar ago and one bar ago

it was less than it was two bars ago ( The trend just changed to up) then buy 10 contracts at market on the open of the next bar.
 


We cannot buy now as the condition might change intra-bar so we wait for the bar to close and thus buy the opening of the next bar. This stops any "mistake" trades and confusion.

Some different methods to exit the entire position of this trade.


If long 10 contracts and profit on this trade is greater or equal to 40 points then sell next bar at market ( Take profit on next bar )

If long 10 contracts and loss on this trade is greater or equal to 20 points then sell next bar at market ( Stop loss on next bar )

If long 10 contracts and weighted moving average length 20 is smaller than it was one bar ago then sell next bar at market
(Trend following exit)


If long 10 contracts then sell 10 contracts on a stop order at entry price minus 20 points ( Stop loss exit using a stop order )



Some different methods to make a partial exit on some of the position of this trade

If long 10 contracts then sell 5 contract on a limit price of entry price + 35 points ( Selling half the position using a limit order )

 


Then the remaining 5 contracts can be dealt with in different ways

IIf long 5 contracts then exit long 5 contracts on a stop at the lowest low of the last 20 bars ( Trailing Stop loss exit using an actual stop order )

If long 5 contracts then exit long 5 contracts on a limit at the highest high of this week so far ( Exit long with a limit order at the weekly high price )


If long 5 contracts then exit long 3 contracts on a limit at the entry price + 60 points ( Partial exit on a limit profit target )

If long 2 contracts then exit long 2 contracts on Friday evening at the closing time minus 30 seconds ( Exit of the rest of the trade at the end of week)




Study some real code which is called EasyLangauge code and some examples


Example No.2 Reversing when the trend changes direction


If long 10 contracts and the weighted moving average is less than it was one bar ago then sell 10 contracts and sell short 10 contracts.( Exit and reverse)




Example No.3  Getting out the entire strategy if it does not lead to good results


If total strategy profit is smaller than minus $1500 then close all trades, remove all orders and shut down the strategy (Exit from the entire strategy)


You can use this as a safety feature to disconnect and disable your strategy if it is losing more than the amount you specify.


Example No.4  Placing a fill or kill order on a scalping strategy that seeks high volatility set ups and does not trade on Friday


If day of week is Monday, Tuesday, Wednesday or Thursday and time of day is greater than 8.10am and less than 900am and volatility measured by standard

deviations of period 30 is more than 40 and low of the previous bar is the lowest low of the day then place a fill or kill order to buy 10 contracts at lowest

low of previous bar minus 50 points. Leave buy order in the market for 120 seconds and if not filled then cancel the order.

 

Example No.5  Placing a stop order to open a trade when a high volume break out occurs


If volume of this bar is the highest volume of the last 20 bars and the close is the highest close of the last 100 bars then buy 500 shares on a stop at the

highest close of today plus 10 points.

 

 
So the general idea with pseudo code is to accurately define the rules of your intended strategy. This same technique can be applied to modification of the functionality of my products to be

used in the combo strategies that are offerred as bespoke programming service.

Nothing can be assumed in programming as a computer does not understand the world in the way a human does. It is thinking in 1 or 0 or On and Off events. 




Example No.6  Automatic adjustment of trade size in running

If total strategy profit since the first trade is greater or equal to $2000 then trade size = ( strategy profit + $1000) / 500

If total strategy profit since the first trade is less than 0 then trade size = 4 contracts





I hope this pages helps you develop the correct thinking it through process which Einstien used and is called "Gedanken experimentation"

Once you have the pseudo code ready then you can email it over and get a quote to create it.











 

The elapsure of decay can be utilized in different ways in trading, spending time on testing this was done extensively with the above Precision Index Oscillator indicator (Pi-Osc)

 
View List of other free and paid products for Tradestation

View List of other free and paid products for MultiCharts

View List of other free and paid products for NinjaTrader

View List of other free and paid products for TradingView





IF YOU HAVE ARRIVED AT THIS PAGE AS A BEGINNER THEN HERE ARE SIX TUTORIAL PAGES TO GET YOUR KNOWLEDGE UP TO A BETTER LEVEL

How to trade part 1

How to trade part 2

How to trade part 3

How to trade part 4

How to trade part 5

How to trade part 6

Qstick   

Educational videos

1929 crash

Trading IQ Game tutorial

PLAY FOR FREE  Trading IQ Game  AND WIN PRODUCTS

  




 
 

The help and advice of customers is valuable to me. Have a suggestion? Send it in!

The contact page here has my email address and you can search the site

 

Return to the top of page (In a safe and orderly manner)

 

 If you like what you see, feel free to SIGN UP  to be notified of new products - articles - less than 10 emails a year and zero spam

 

About

Precision Trading Systems was founded in 2006 providing high quality indicators and trading systems for a wide range of markets and levels of experience.

Supporting NinjaTrader, Tradestation and MultiCharts with Trading View coming along and MetaTrader.

 

Bio

Social tags

&nbs 

Admin notes

Page created Sept 7th 2023 to facilitate ease of pseudo code creation  - New responsive page GA4 added canonical this. 5/5 html baloon