InvestorsHub Logo
icon url

simplegreen

04/05/09 2:30 PM

#20759 RE: gitonwithit #20757

Howdy git..,if I had waited a few minutes I could have saved myself a lot of typing(LOL)
icon url

simplegreen

04/05/09 2:42 PM

#20760 RE: gitonwithit #20757

Hey git.., I am adding this to my systems...also am adding ability to be selective on time of day for system to auto trade...example ..I might go to bed at 10PM but at 1:30AM the system starts up in auto trade then stops auto trade when I designate the time for that also...maybe 6:30 AM catching the first 4 or so hours of London session while I sleep!


How-To Start a Trading System in Auto-Trade Mode with Existing Open Position

Every trading system included with VTtrader is designed to be started in auto-trade mode when the user no positions currently active in the market with the exception of the VT-Trailing Stop System. Please note, you can refer to the "Sample Trading Systems" section of the VTtrader Help Manual for full details pertaining to each trading system currently included in VTtrader.

Considering the trading systems are designed to be used with no positions currently open, a very commonly asked question is,


"How can I modify a trading system to make it work correctly when I
already have an open position in the market that I don't wish to exit right
away before starting my trading system in auto-trade mode?"


Here's a very simple solution that any user should be able to implement fairly easily. Please note: It does require you to modify a tiny bit of formula code and create 2 additional input variables, but I assure you that this is not difficult. We'll walk through it step-by-step below. You can refer the to the Trading System Builder section of the VTtrader Help Manual at any time if any of the concepts below are unclear to you.

As an example, we'll walk through modifying an existing trading system that comes with VTtrader so you can see how this task is accomplished. Let's use the VT-Directional Movement Index trading system.

The first thing we need to do is verify that the trading system already includes formula code and output variables capable of performing the auto-trading functionality once added to the chart and started in "Auto-Trade Mode". Since this is a standard trading system included with VTtrader we know it will include this functionality by way of the OpenBuy, CloseBuy, OpenSell, and CloseSell variables included in the trading system. However, for reference the quickest and most reliable method to determine if a trading system includes enabled auto-trade variables is the attach the trading system to a chart, right-click with the mouse on its label, and choose "View Parameters Enabled". When the Trading Systems Events window displays find the "Trading" column. Scroll down the column and take note of any variables (shown the "Variables Name" column) that have a checkmark next to them in the "Trading" column. If you find variables that do, you can proceed to a second check.

Remember the variable names shown in that window and then proceed to the Navigator Window>Tools>Trading Systems Builder menu option. From the Trading Systems list, find the name of the trading system you wish to edit and highlight it by clicking its name once with the left mouse button. Once highlighted, click the [Edit] button. Doing this will display the Trading Systems Editor Window.

Proceed by clicking the Formula Bookmark (right-most tab across the top of the window). This will display the Formula Bookmark. Remembering the variable names from the Trading Systems Event Window, scroll down through the code in the Formula Bookmark (being cautious not to change anything just yet) and find the section of code corresponding to those auto-trade variables. It will likely be towards the bottom of the formula scripting and look very similar to:


{OpenBuy and CloseBuy}

OpenBuy:= Long and (eventCount('OpenBuy')=eventCount('CloseBuy'));
CloseBuy:= Short and (eventCount('OpenBuy')>eventCount('CloseBuy'));

{OpenSell and CloseSell}

OpenSell:= Short and (eventCount('OpenSell')=eventCount('CloseSell'));
CloseSell:= Long and (eventCount('OpenSell')>eventCount('CloseSell'));


Once you've located the code associated with the auto-trade variables it's time to make a few slight modifications.

BUT -- before we do this, you've probably noticed the use of a function called eventcount() in the example code shown above. Please allow me a moment to explain what the eventcount() function is and how it works since it is vital to the auto-trade variables' conditional logic and it's important that you understand its purpose.

The eventcount() function's main purpose is to count the number of order requests made by the automated trading system for a particular "logical variable" (auto-trade variable) ONLY while the trading system is attached to a chart and is running in auto-trade mode. It's important to note that the eventcount() function does not count or keep track of this information if the trading system is not in auto-trade mode. It's also important to note that the eventcount() function does not actually interact with the trader's trading account; this means that there is no "real" trade or account information exchanged between the VT-Server and VTtrader as it would relate to actual position information in the trader's account. The eventcount() function is essentially a simple counter and its functionality is dependent only on the trading system operating in auto-trade mode. You can refer the the VTtrader Help Manual for additional information about the eventcount() function if necessary.

More simplistically, the way eventcount() works is to count a +1 each time a trade action is requested for a particular variable.

So, if you have the following enabled auto-trade variables in your formula:

OpenBuy
CloseBuy
OpenSell
CloseSell

... all of their respective eventcount's will be as such when the system is started...

OpenBuy = 0
CloseBuy = 0
OpenSell = 0
CloseSell = 0

Then, while the trading system is running in auto-trade and requesting automated trade actions, you end up with something like this...

OpenBuy is triggered by the trading system and an order is requested and therefore it increments +1 from its previous value (intially set as 0), and you have this:

OpenBuy = 1
CloseBuy = 0
OpenSell = 0
CloseSell = 0

... then, CloseBuy triggers and it increments +1, and you have this:

OpenBuy = 1
CloseBuy = 1
OpenSell = 0
CloseSell = 0

Next, OpenSell triggers at the same time as CloseBuy since the signals are the same and you have:

OpenBuy = 1
CloseBuy = 1
OpenSell = 1
CloseSell = 0

Continuing, CloseSell triggers next and you have:

OpenBuy = 1
CloseBuy = 1
OpenSell = 1
CloseSell = 1

OpenBuy triggers again at the same time as the CloseSell I just mentioned and you have:

OpenBuy = 2
CloseBuy = 1
OpenSell = 1
CloseSell = 1

.... This pattern continues untils you stop the trading system or interrupt its normal operation by manually closing or opening trades while its running. If you apply the above operation of the eventcount() function to the the auto-trade variables' formula conditions it should start becoming clear as to how the comparison between OpenBuy and CloseBuy eventcounts and OpenSell and CloseSell eventcounts helps to control the number of positions actually opened and closed automatically by the running trading system respective to each auto-trade variable in use.

Ok -- now that eventcount() has been covered, let's continue forward...

The formula modification and input variable creation that I'm about to walk you through effectively allows you to set either the OpenBuy eventcount() or OpenSell eventcount() equal to 1 to jumpstart the system and "trick" it into thinking it already requested either the OpenBuy or OpenSell (based on which one of those you supply a 1 value to at the input screen when adding it to the chart). This is very valuable if you already have an open position running and do not wish to exit the position immediately before starting your auto-trade system in auto-trade mode.

We'll make the tiny code modification first...

Continuing with the example of the VT-Directional Movement Index trading system and using the code I referenced above, we'll only need add a very small portion of additional code. This will very likely be true for ANY trading system that contains similar auto-trade logic. The additional code will be shown in bold:


{OpenBuy and CloseBuy}

OpenBuy:= Long and (eventCount('OpenBuy') +OB=eventCount('CloseBuy'));
CloseBuy:= Short and (eventCount('OpenBuy') +OB>eventCount('CloseBuy'));

{OpenSell and CloseSell}

OpenSell:= Short and (eventCount('OpenSell') +OS=eventCount('CloseSell'));
CloseSell:= Long and (eventCount('OpenSell') +OS>eventCount('CloseSell'));


Notice all we did was add the extra +OB and +OS code to the respective lines of code. Simple!

Next, we need to goto the Input Bookmark to create our 2 new input variables of "OB" and "OS". This will allow us to change their values from the Input Properties screen when we're adding the trading system to the chart.

In the Input Bookmark, to create each of the Input Variables follow the steps below.

For the "OB" variable:

1) Click the [New] Button
2) In the Name Field type "OB" (without the quotes)
3) In the Display Name field type "Initial OpenBuy EventCount" (without the quotes)
4) Choose "Integer" from the Type dropdown selection menu
5) In the Default text field type "0" (zero - without the quotes)

For the "OS" variable:

1) Click the [New] Button
2) In the Name Field type "OS" (without the quotes)
3) In the Display Name field type "Initial OpenSell EventCount" (without the quotes)
4) Choose "Integer" from the Type dropdown selection menu
5) In the Default text field type "0" (zero - without the quotes)

Click the icon that looks like a black disc at the top of the Trading Systems Editor Window to save these changes. If you receive no error message upon doing so the changes will be saved successfully. You can then click the close icon directly to the right of the save icon.

Congratulations! You're done. That's all there was to it!

Lastly, let's put these modifications to use and make this work for you. When you add the trading system to the chart there are 3 possibilities:

1) You have no open positions in the market.

- In this case, leave both OB and OS settings at 0 and start the trading system in auto-trade mode; do not alter these settings while it's running.

2) You have a long position open in the market.

- In this case, you would set the OB variable to 1 and leave the OS variable at 0 and then start the trading system in auto-trade mode; do not alter the trading system while it's running. This tells the trading system that you had a buy position already open when the trading system was started; this means you don't have to exit your existing position before starting the trading system to ensure it's in sync with the current open position.

3) You have a short position open in the market.

- In this case, you would leave the OB variable at 0 and set the OS variable to 1 and then start the trading system in auto-trade mode; do not alter the trading system while it's running. This tells the trading system that you had a sell position already open when the trading system was started; this means you don't have to exit your existing position before starting the trading system to ensure it's in sync with the current open position.

icon url

simplegreen

04/05/09 3:24 PM

#20761 RE: gitonwithit #20757

Ok...git..got the goodie installed..now if all is right then I can set the OB or OS field to a 1 if I already have an open position long or short before I start auto trade.I like that!