ProRealCode - Trading & Coding with ProRealTime™
Hi, I have looked in these forums for a simple method to increase the number of positions up to a maximum of three, based on successive 30 tic moves in the direction of the trend.
As a discretionary forex trader I would wait for sharp up/down moves in the tick on a 10 min chart and enter with the direction of the move (better to be on the right side of the 2 day trend) adding to the position. I found three positions as much as you would want to handle particularly if volatility increased sharply (fast market). I wanted to see if it worked using a trend filter like the Ehler’s Supersmoother Oscillator before looking at Momentum (proceeds price) indicators indicators and also adding an exit for closing all three positions together during sharp adverse moves.
Based on the forum posts I have the code so far as:
c1 is a long trade based on the Ehler’s Universal Supersmoother Oscillator (found in the PRT indicator section in this forum) crossing over the -0.8 threshold. Yet it won’t take the second and third positions?
Any ideas what I need to add to the code?
The backtest was conducted on the Daily Dow DFB, initially on year 1990. Results were okay with Universal Osc bandedge = 25 and a spread of 3.8 and were left untouched on further date expansion: 1990-1991 and 1990-1992. The Choppiness Indicator that Randy Stuckey used for Catscan IV will stop positions being taken in choppy sideways markets which in non mean reverting systems will lead to losses. The drawdown is still high at 32% which will typically translate into 50% more drawdown when live. This is not a system yet. Different markets tend to have different bandedges. Note: Randy Stuckey used different choppiness index thresholds for each market.
As a further point I noticed whilst looking into position sizing code that there was a lot of discussion on “averaging down trades.” From previous trading experience I would not recommend this “tempting” method to mitigate losses because although it works in many instances and will “save your bacon,” there will always be very large fast adverse moves that will cause problems… like when some idiot at the Fed makes an unexpected and unannounced policy comment on a Bloomberg radio show…
It’s also worth checking out the pyramiding style of Ed Seykota’s hero, Amos Hostetter.//ORIG CODE:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES OVER -0.8)
indicator2 = CALL "Choppiness Index"
c2 = (indicator2 <= 61.8)
IF c1 AND c2 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter short positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES UNDER 0.8)
indicator2 = CALL "Choppiness Index"
c2 = (indicator2 <= 61.8)
IF c1 AND c2 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Stops and targets
//============================================================================
//PYRAMIDING at 30 tic increases up to a maximum of three positions
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES OVER -0.8)
indicator2 = CALL "Choppiness Index"
c2 = (indicator2 <= 61.8)
IF c1 AND c2 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra long positions
//second order
c3 = (indicator1 > -0.8)
indicator2 = CALL "Choppiness Index"
c4 = (indicator2 <= 61.8)
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND c3 AND c4 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND LongOnMarket AND c3 AND c4 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//——————————————————----------------------------------------------//
// Conditions to enter short positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES UNDER 0.8)
indicator2 = CALL "Choppiness Index"
c2 = (indicator2 <= 61.8)
IF c1 AND c2 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra short positions
//second order
c3 = (indicator1 < 0.8)
indicator2 = CALL "Choppiness Index"
c4 = (indicator2 <= 61.8)
IF Close-TRADEPRICE(1)<30 AND ShortOnMarket AND c3 AND c4 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)<60 AND ShortOnMarket AND c3 AND c4 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
// Stops and targets
Thanks
Bard
DEFPARAM CumulateOrders = TRUE // Cumulating positions activated
Copy and replace it in your code to get extra positions according to your strategy.
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter long positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES OVER -0.3)
//indicator2 = CALL "Choppiness Index"
//c2 = (indicator2 <= 61.8)
IF c1 THEN //AND c2
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra long positions
//second order
c3 = (indicator1 > -0.3)
//indicator2 = CALL "Choppiness Index"
//c4 = (indicator2 <= 61.8)
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND COUNTOFPOSITION = 1 AND c3 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND LongOnMarket AND COUNTOFPOSITION = 2 AND c3 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//——————————————————----------------------------------------------//
// Conditions to enter short positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES UNDER 0.3)
indicator2 = CALL "Choppiness Index"
c2 = (indicator2 <= 61.8)
IF c1 AND c2 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra short positions
//second order
c3 = (indicator1 < 0.3)
//indicator2 = CALL "Choppiness Index"
//c4 = (indicator2 <= 61.8)
IF Close-TRADEPRICE(1)<30 AND ShortOnMarket AND COUNTOFPOSITION = 1 AND c3 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)<60 AND ShortOnMarket AND COUNTOFPOSITION = 2 AND c3 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
@Nicolas did you ever come up with a way of finding the best way to determine the bandedge for this oscillator or is it always going to be subject to needing adjustment (which makes automating it hard)?
Perhaps the MESA Trendline and Kalman will need to be used to determine if the market is in trend mode or cycling and then the system can be coded to switch modes and use zero line crossovers for trending and 20/80% thresholds for cycling. But what bandedge to use overall…? That needs testing.
As you said previously the results are (at times) “stunning.” (-:
Cheers
Bard
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter long positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES OVER -0.8)
IF c1 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra long positions
//second order
c3 = (indicator1 > -0.8)
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND COUNTOFPOSITION = 1 AND c3 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND LongOnMarket AND COUNTOFPOSITION = 2 AND c3 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//——————————————————----------------------------------------------//
// Conditions to enter short positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES UNDER 0.8)
IF c1 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra short positions
//second order
c3 = (indicator1 < 0.8)
IF Close-TRADEPRICE(1)>30 AND ShortOnMarket AND COUNTOFPOSITION = 1 AND c3 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND ShortOnMarket AND COUNTOFPOSITION = 2 AND c3 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
TRADEPRICE(1)-Close
You should try also to GRAPH COUNTOFPOSITION, I’m not sure that 10 CONTRACTS = 1 POSITION !
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = close
indicator2 = Average[40](open)
indicator3 = Average[50](open)
c1 = (indicator1 >= indicator2)
c2 = (indicator2 > indicator3)
IF Not LongOnMarket AND c1 AND c2 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra long positions
//second order
c3 = (indicator1 >= indicator2)
c4 = (indicator2 > indicator3)
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND COUNTOFPOSITION = 1 AND c3 AND c4 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND LongOnMarket AND COUNTOFPOSITION = 2 AND c3 AND c4 THEN
BUY 10 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
c5 = (indicator1 < indicator2)
c6 = (indicator2 > indicator3)
IF c5 AND c6 THEN
SELL AT MARKET
ENDIF
//——————————————————----------------------------------------------//
// Conditions to enter short positions
c7 = (indicator1 <= indicator2)
c8 = (indicator2 < indicator3)
IF NOT ShortOnMarket AND c7 AND c8 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra short positions
//second order
c9 = (indicator1 <= indicator2)
c10 = (indicator2 < indicator3)
IF TRADEPRICE(1)-Close>30 AND ShortOnMarket AND COUNTOFPOSITION = 1 AND c9 AND c10 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
//third order
IF TRADEPRICE(1)-Close>60 AND ShortOnMarket AND COUNTOFPOSITION = 2 AND c9 AND c10 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
c11 = (indicator1 > indicator2)
c12 = (indicator2 < indicator3)
IF c11 AND c12 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
Set stop pTrailing 200
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND COUNTOFPOSITION = 1 THEN...
I’ve simplified the system to the point where there are no other criteria for extra positions (#2 and #3) other than an increase of 30 tics from the last position taken. Exits Long and Short have also been removed as per the Moving Average version above.
Thanks for any help,
Bard
// Definition of code parameters
DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
// Conditions to enter long positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c1 = (indicator1 CROSSES OVER -0.8)
IF Not LongOnMarket AND c1 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra long positions
//second order
IF Close-TRADEPRICE(1)>30 AND LongOnMarket AND COUNTOFPOSITION = 1 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
//third order
IF Close-TRADEPRICE(1)>60 AND LongOnMarket AND COUNTOFPOSITION = 2 THEN
BUY 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter short positions
indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"
c2 = (indicator1 CROSSES UNDER 0.8)
IF NOT ShortOnMarket AND c2 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
// Conditions to enter extra short positions
//second order
IF TRADEPRICE(1)-Close>30 AND ShortOnMarket AND COUNTOFPOSITION = 1 THEN
SELLSHORT 10 PERPOINT AT MARKET
ENDIF
//third order
IF TRADEPRICE(1)-Close>60 AND ShortOnMarket AND COUNTOFPOSITION = 2 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
//---------------------------------------------------------------------------------------------------//
//Function : Choppiness Index
//p= 21 -- also use 100
//MaxHi=Highest[p](High)
///MinLo=lowest[p](low)
//chop=100 * LOG( SUMMATION[p](AverageTrueRange[1](close))/log(10) / ( MaxHi - MinLo)) / (LOG(p)/log(10))
//return chop as "Choppiness Index"
//Function : Ehler's Univ Osc SuperSmoother
bandedge= 50 //25
whitenoise= (Close - Close[2])/2
if barindex>bandedge then
// super smoother filter
a1= Exp(-1.414 * 3.14159 / bandedge)
b1= 2*a1 * Cos(1.414*180 /bandedge)
c2= b1
c3= -a1 * a1
c1= 1 - c2 - c3
filt= c1 * (whitenoise + whitenoise[1])/2 + c2*filt[1] + c3*filt[1]
filt1 = filt
if ABS(filt1)>pk[1] then
pk = ABS(filt1)
else
pk = 0.991 * pk[1]
endif
if pk=0 then
denom = -1
else
denom = pk
endif
if denom = -1 then
result = result[1]
else
result = filt1/pk
endif
endif
//RETURN result COLOURED(66,66,255) as "Universal Oscillator", 0 as "0"
Increase number of position based on 30 tic moves
This topic contains 15 replies,
has 4 voices, and was last updated by
Nicolas
6 years, 4 months ago.
| Forum: | ProOrder support |
| Language: | English |
| Started: | 05/12/2017 |
| Status: | Active |
| Attachments: | 5 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.