ProRealCode - Trading & Coding with ProRealTime™
//the 13th V1.5 /////////////by Joe Szeles//////////////////////
//IDEA BASED ON:
// The13thWarrior_V1.1
// 06.09.2020 (Release 1.1)
// Thomas Geisler
// Sharing ProRealTime knowledge
// https://www.prorealcode.com/library/////
Defparam cumulateorders = false
positionsize=2
myOBVn = 5
myCandle = 1
//Heikin Ashi
ONCE haOpen = OPEN
ONCE haClose = CLOSE
N = 0
IF BARINDEX = 0 THEN
haOpen = OPEN
haClose = CLOSE
ELSIF N = 0 THEN
haClose =(OPEN+HIGH+LOW+CLOSE)/4
haOpen =(haOpen[1]+haClose[1])/2
ENDIF
once tradetype = 1 // [1]long&short;[2]long;[3]short
mm6= average[299]
mm5= average[120]
mm4= average[10]
mm3= average[7]
mm2= average[4]
mm1= average[3]
mm0= average[2]
mm= average[1]
//long
tradelong = mm>mm0 and mm0>mm1 and mm1>mm2 and mm2>mm3 and mm3>mm4 and mm4>mm5 and mm5>mm6
//short
tradeshort = mm<mm0 and mm0<mm1 and mm1<mm2 and mm2<mm3 and mm3<mm4 and mm4<mm5 and mm5<mm6
//Candle-Colour from OBV and HA
IF myCandle = 1 THEN
myOBV = OBV(CLOSE)
myAV = Average[myOBVn](myOBV)
IF myOBV > myAV AND haClose > haOpen and (tradetype=1 or tradetype=2) and tradelong THEN
if not onmarket then
buy positionsize contract at market
endif
endif
if myOBV < myAV AND haClose < haOpen and (tradetype=1 or tradetype=3) and tradeshort THEN
if not onmarket then
sellshort positionsize contract at market
endif
endif
ENDIF
//%trailing stop function
trailingPercent = .278 //org .26
stepPercent = .0155//org .014
if onmarket then
trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
trailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stop
endif
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
newSL = tradeprice(1)+trailingstep
ENDIF
//next moves
IF newSL>0 AND close-newSL>trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
set stop loss 400
set target profit 1600
Thanks for sharing your idea and yourcode.
Any suggestion about which TF’s and instruments are best best suited for this strategy?
HA candlesticks are used only for entry conditions, not for indicators nor trailing stop, is that correct?
Attached is one possibility … spread = 5, position size = 1
Strangely with 200K spead 5 and position size 1 it doesn’t give any trades before July 2016 ??
On a 2h system, there are probably not bars before that date if tick-by-tick option is selected. Try not selecting it.
Already done but the result is identical.
Yes, the same start for the 4h TF. It’s similar for many instruments, so I think that’s the limit.
I had really good results with wall street cash $1 at 2h time-frame.
I tried it for day trading in various x-seconds (2, 6 19, 24, 71) , but they need readjustment every 2 or 3 days. the ones i started 4 days ago still work, but they fail in the simulation at the current date. because of that I added a maximum for the strategy profit and trading time limitation in some versions, to lower the risk of loosing the gains. some gained 1000$ over night, but the bad trades are mostly really bad. the Friday crash was really bad and took all the gains from the days before. Also good results with HUF Hungary 12 cach (13thworrior v1.3 HUF 30min.itf)
It worked fine @ 39 seconds for days, when i simulate now it doesn`t work at all, except i move one second forward to 40 second time frame. strange psitionsize =2, spread =6, 40 second timeframe, DJ $1
////////v.3.3.c 2 sec DOW/////////////////////////////////////
//the 13th warrior
Defparam cumulateorders = true
positionsize=2
myOBVn = 5
myCandle = 1
//Heikin Ashi
ONCE haOpen = OPEN
ONCE haClose = CLOSE
N = 0
IF BARINDEX = 0 THEN
haOpen = OPEN
haClose = CLOSE
ELSIF N = 0 THEN
haClose =(OPEN+HIGH+LOW+CLOSE)/4
haOpen =(haOpen[1]+haClose[1])/2
ENDIF
once positionsize = 1
once tradetype = 1 // [1]long&short;[2]long;[3]short
//========= STRATEGY ===================================
mm6= average[299]
mm5= average[120]
mm4= average[10]
mm3= average[7]
mm2= average[4]
mm1= average[3]
mm0= average[2]
mm= average[1]
//long/////////////////////////////////////////////////////////////////////////
c10=low<lowest[2](low[1])
c11=close<low[1]
tradelong = (c10 and c11) or (mm>mm0 and mm0>mm1 and mm1>mm2 and mm2>mm3 and mm3>mm4 and mm4>mm5 and mm5>mm6)
//short
c20=high>highest[2](high[1])
c21=close>high[1]
tradeshort = (c20 and c21) or (mm<mm0 and mm0<mm1 and mm1<mm2 and mm2<mm3 and mm3<mm4 and mm4<mm5 and mm5<mm6)
//Candle-Colour from OBV and HA//////////////////////////////////////////
IF myCandle = 1 THEN
myOBV = OBV(CLOSE)
myAV = Average[myOBVn](myOBV)
IF myOBV > myAV AND haClose > haOpen and (tradetype=1 or tradetype=2) and tradelong THEN
if not onmarket then
buy positionsize contract at market
endif
endif
endif
if myOBV < myAV AND haClose < haOpen and (tradetype=1 or tradetype=3) and tradeshort THEN
if not onmarket then
sellshort positionsize contract at market
endif
endif
//%trailing stop function/////////////////////////////////////////////////////////////
trailingPercent = .23 //org .26
stepPercent = .015//org .014
if onmarket then
trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
trailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stop
endif
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions/////////////////////////////////////////////////////////////////////
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
newSL = tradeprice(1)+trailingstep
ENDIF
//next moves
IF newSL>0 AND close-newSL>trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions/////////////////////////////////////////////////////////////////
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
////////EXIT STRATEGY DAYTRADING - GRAB CASH AND RUN///////////////////
x=250-rsi// max stop loss value in $$
contractprofit = 3000 //maximum target profit
set stop loss x
set target profit contractprofit/3
if strategyprofit >= contractprofit then //stop bot from trading and take profits
quit
endif
now it doesn`t work at all,
Maybe just no conditions that match your trigger conditions?
Anyway we are all best to steer clear of Non Standard Timeframes (TF) that don’t add up to 1 min (so 40 sec in non standard TF also) and 1 hour etc.
There is a big discussion topic on here about use of the 29 second TF if you need to be convinced?
There is a big discussion topic on here about use of the 29 second TF if you need to be convinced?
Im convinced, I was experimenting with the code and was surprised about the results, but its too hard to replicate the results, so ill stay clear of these TF in real trades, thanks a lot.
I couldnt get it going on the standard timeframe , just works fine on the 11 minute and 6 minute time frame. but couldnt simulate longer than 2 months. anybody some ideas how to get it going on a standard timeframe??
///////v.3.1.d 19 sec DOW//////////////////////////////////
//the 13th warrior NIFTY 6min/////////////////
Defparam cumulateorders = false
//Money Management DOW
MM = 1 // = 0 for optimization
if MM = 0 then
positionsize=2
ENDIF
if MM = 1 then
ONCE startpositionsize = 2
accelerator=1.5 //goes parabolic in an extreme volatile market
ONCE factor = 5 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
ONCE tier1 = 55 // DOW €1 IG first tier margin limit
ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
ONCE minpositionsize = 2 // enter minimum position allowed
IF Not OnMarket THEN
positionsize = round (startpositionsize + Strategyprofit/(factor*margin))*accelerator
ENDIF
IF Not OnMarket THEN
IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
positionsize = round((((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1)*accelerator //incorporating tier 2 margin
ENDIF
IF Not OnMarket THEN
if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
positionsize = round (minpositionsize) //keeps positionsize from going below allowed minimum
ENDIF
IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
positionsize = round (maxpositionsize)// keeps positionsize from going above IG tier 2 margin limit
ENDIF
ENDIF
ENDIF
ENDIF
myOBVn = 5
myCandle = 1
//Heikin Ashi
ONCE haOpen = OPEN
ONCE haClose = CLOSE
N = 0
IF BARINDEX = 0 THEN
haOpen = OPEN
haClose = CLOSE
ELSIF N = 0 THEN
haClose =(OPEN+HIGH+LOW+CLOSE)/4
haOpen =(haOpen[1]+haClose[1])/2
ENDIF
once positionsize = 1
once tradetype = 2 // [1]long&short;[2]long;[3]short
//========= STRATEGY ===================================
//long
c10=low<lowest[2](low[1])
c11=close<low[1]
tradelong = c10 and c11
//short////
c20=high>highest[2](high[1])
c21=close>high[1]
tradeshort = c20 and c21
//Candle-Colour from OBV and HA
IF myCandle = 1 THEN
myOBV = OBV(CLOSE)
myAV = Average[myOBVn](myOBV)
IF myOBV > myAV AND haClose > haOpen and (tradetype=1 or tradetype=2) and tradelong THEN
if not onmarket then
buy positionsize contract at market
set stop loss 41+rsi
set target profit 70+rsi
endif
endif
if myOBV < myAV AND haClose < haOpen and (tradetype=1 or tradetype=3) and tradeshort THEN
if not onmarket then
sellshort positionsize contract at market
set stop loss 43+rsi
set target profit 70+rsi
endif
endif
ENDIF
//%trailing stop function//////////////////////////////////////////////////////////
trailingPercent = .19 //org .26
stepPercent = .0155//org .014
if onmarket then
trailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailinstart points profit
trailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stop
endif
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions/////////////////////////////////////////////////////////////////////
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart THEN
newSL = tradeprice(1)+trailingstep
ENDIF
//next moves
IF newSL>0 AND close-newSL>trailingstep THEN
newSL = newSL+trailingstep
ENDIF
ENDIF
//manage short positions/////////////////////////////////////////////////////////////////
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart THEN
newSL = tradeprice(1)-trailingstep
ENDIF
//next moves
IF newSL>0 AND newSL-close>trailingstep THEN
newSL = newSL-trailingstep
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
The 13th Worrier Automated v1.5 based on Thomas Geislers Indicator idea. (13th Worrior)
This topic contains 19 replies,
has 4 voices, and was last updated by Szeles
5 years, 4 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 10/05/2020 |
| Status: | Active |
| Attachments: | 20 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.