|
|
“Initial Balance” Strategy: Part 12 – Alternate Methods(This is a continuation in our blog series on creating a trading system from start to finish. Want to see more? Click here for our main RTL support page, which links to all the articles in this series and many more tutorials. Questions? Click here for the RTL Community Forum where you can get help on your programming.) Today, we demonstrate the flexibility of RTL and show an entirely different method you could have used to code this system, yet have the same results. RTL is a basic programming language, and as such it can take any form desired by the programmer. The programmer’s creativity determines the flow of the system’s logic, and different programmers may approach the same task in different ways. To demonstrate this, we will alter how the system triggers all the exits: the stops, scales and final targets. You may find that today’s methodology is more elegant than the prior methods introduced in this article series. No method is better than the other; they are simply different approaches. Here is the primary change we will make to the system:Instead of calculating the exit levels within each exit rule, we will instead determine all our exit points up front at the moment we enter a trade, as part of the entry rules. This will make our separate exit rules very simple and easy to understand. It also lets us adjust the stop levels to breakeven without actually adjusting the stop exit rules. Before, we had a total of 4 stop-loss exit rules. 2 for the long trades and 2 for the short trades. One stop level was the initial stop set at the time of entry. Another stop rule set the breakeven level for when the trade exited at its first profit scale. But now we will effectively combine these two stop levels into one single rule and adjust the stop-loss level on the fly, letting us have fewer rules in our system. The Main RuleWe are going to introduce 3 additional V# variables. At this point, it is a good idea to define all your user variables in the Main rule of the system as a comment. This makes it easier to troubleshoot your system later, or for other programmers to understand how you coded the system. Our new Main rule shall look like this:
We have not actually made any change to the logic of this Main rule. But we have added numerous comments to the end that serve as a form of documentation for our system. Most notably, we have declared that our subsequent rules will use three new user variables, V#6, V#7 and V#8, and each of these will hold the actual price level of our exit targets. Delete the prior Breakeven Stop RulesAs mentioned, we will not need the two old breakeven stop rules, so you can delete them now. We will still keep the two other general stop rules we created.
Special Note: Because our new stop rules are going to cover all stop scenarios, you might want to use this method for complex stop scenarios where you have multiple adjustments to stops, such as with trailing stop strategies. This would greatly reduce the number of rules you might need in your system since you won’t have to code multiple stops as individually separate trading rules. This will be more obvious below. The New Entry RulesAs part of our Entry rules, we will set all the exits in advance, and assign them to our three new user variables: Short Rule: SET(V#1,(SESST + (SESST – SESST_LOW))) AND HI >= V#1 AND TIME >930 AND TIME < 1400 AND V#2=0 AND SET(V#6,V#1-V#5) AND SET(V#7,V#1-V#3) AND SET(V#8,V#1+V#4) Long Rule: SET(V#1,(SESST_LOW – (SESST – SESST_LOW))) AND LO <=V#1 AND TIME >930 AND TIME < 1400 AND V#2=0 AND SET(V#6,V#1+V#5) AND SET(V#7,V#1+V#3) AND SET(V#8,V#1-V#4) The underlined portion represents the new parts of this rule. Note that the math used for each of the three user variable levels is the same math we previously used in our individual exit rules. The Stop Rules and Final Exit RulesSince our exit rules no longer need to contain logic for the actual math needed to calculate the price level, we can remove that logic from those rules and make them particularly simple rules. Consider our new Long Stop and Short Stop rules: Stop rule for long -
Stop rule for Short -
Pretty clear and concise! The final exit rules are equally as basic: Long exit - HI >= V#7 Short exit - LO <= V#7 Rules don’t get much more basic than this! Rule PricesWe have another efficiency that is now built-in to this system: except for our entry rules, we no longer need to calculate and assign the Rule Price to V#1 using the SET token because each of these rules already has a user variable calculated for the price level, something that didn’t exist before. So change the Rule Price for these rules to match the user variable of the rule itself, as follows:
The Scale Out RulesSince we are adjusting stop-loss levels on the fly, our scale out rules need to accomplish two things:
We will use the IF…THEN logic to reset the V#8 variable. Here is the new first-exit rule for a long trade:
The second line in this code should be obvious; like our other exit rules, it is simplified for V#6 but must still include the POS_SIZE token from previously; and the Rule Price is set to V#6. The first line basically repeats this logic as a condition; IF the condition is true, THEN it resets our stop-loss level, V#8. Note the semicolon at the end of this line; this is required in RTL (and most programming languages) to signify the end of one statement before beginning another. Here is the short scale-out rule:
That’s it! We now have a new RTL environment for the exact same strategy. Here is all that it accomplished:
Finally, press the Backtest button, and………..
Same exact backtesting results as in Part 10 of this series, which uses different RTL for most of the rules. In ConclusionThis blog series has demonstrated the power of RTL and introduced a wide range of techniques for many different scenarios. We hope you have enjoyed it and will continue to experiment with RTL for your own ideas now that its possibilities are made obvious. Your strategy may be entirely different than the IB Rotational Strategy discussed in this series, but the programming concepts and techniques are the same. 0 Responses to “Initial Balance” Strategy: Part 12 – Alternate Methods
No comments. Add a Comment |





You can use the “Modify Rule” button to do this.


