When working with Python – Remember Indentations and You are the Master of your Domain!

            if myLow[curBar]<=shortLevel and mp !=-1:
price = min(myOpen[curBar],shortLevel)
tradeName = "TF-Bol-S"
numShares = posSize
if mp >= 1:
profit,curShares,trades = bookTrade(-1,0,price,myDate[curBar],"RevLongLiq",curShares)
marketMonitorList[curMarket].tradesList.append(trades);todaysCTE = profit
profit,curShares,trades = bookTrade(entry,sell,price,myDate[curBar],tradeName,numShares)
barsSinceEntry = 1
marketMonitorList[curMarket].setSysMarkTrackingInfo(tradeName,cumuProfit,mp,barsSinceEntry,curShares,trades)
Remember Indentations are So IMPORTANT!

Indent four spaces after an if statement.

if x ==1:

++++4x = 2

Let’s break down the above code:  Always test the current bar’s high or low against the signal trigger price.  If the extreme of the bar exceeds the level then you know you were filled.  In TradingSimula18 you are sitting on the close of current day and can look back and see what happened during the day.  Is this future-leak?  It is, but it’s ok as long as you know it and don’t cheat.  The beauty of TS-18 is that it does exactly what you tell it today.  The trade election is not determined by the computer – it is decided by the user.  Once you determine if a signal has been triggered it us up to you to tell the computer what price you were filled at.  If you are testing a stop order then you must check the open price to make sure the open didn’t gap through your price.  If it did, then its up to you to assign the price the open of the day.  Then all you do is assign a name to the trade and the numShares to be executed.  The rest is just minutiae you can ignore.

Are you ready to sit down in front of your computer and start creating?

 

Tags: , ,

classic

yes

About This Site

This site is home to George’s Excellent Adventure into TradingSimula_18 and Python.  George grew tired of the old and expensive back testing software so he created his own and now is able to test and develop  Trend Following Systems utilizing EOD data and EOD intra-testing portfolio management.  This software, TradingSimula_18 can be found in his Trend Following Systems: A DIY Project – Batteries Included book – now in its 2nd edition.

December 2024
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
3031