ProRealCode - Trading & Coding with ProRealTime™
Hi all,
I decide to open a new topic because I need help with the strategy I created using my methodology and my style of algorithmic trading (few money per trade to risk, small time frame, mini contract in IG).
After a while studying the double to and double bottom detected by this code https://www.prorealcode.com/prorealtime-market-screeners/double-top-double-bottom-screener/. I realized that I only know that I don’t know anything.
So here is what I got: I open a long order and a short order just below and above a double top/low. When the order are activated i.e. the double bottom/top is either activated or annulated the market almost always move quickly because (I think) because there are many order placed just in that area.
The strategy take very small profits many often but when it loses…. It loses a lot!
I trade this in real life and winning two out of two but I am not happy because I need two win 4 times for compensate a possible future loss. That’s why I do not upload the strategy to the library.
I hope all of you can help me with this endeavour.
Thanks
//M&W HUNTER
//Autor: LEO
DEFPARAM CumulateOrders = false // Cumulating positions deactivated
DEFPARAM PreLoadBars = 3000 //cargar informacion
//VARIABLES TO BE OPTIMIZED
//PERIOD=20 //Period for analysis
//Kdouble=0.2 //Factor for defining what is double top or bottom
//maxrisk0=13 //pips per trade to risk
//Kprofit=0.5 // proportion of profit target
maxrisk=maxrisk0+(n-1)*2
totalrisk=4*maxrisk*PIPVALUE //for stop the robot if things are going bad
spread=0.7
IF TIME < 060000 THEN //(germany time)
spread=2*spread
ELSIF TIME>213000 THEN //(germany time)
spread=2*spread
ENDIF
//Robot Working Time (Germany)
IF TIME>020000 and TIME < 220000 THEN
ontime=1
ELSE
ontime=0
ENDIF
////// RISK CONTROL IF THINGS ARE GOING WONDERFULL //////
n = 1 + (strategyprofit / (77*pipvalue))
n = round(n * 100)
n = n / 100
n = max(1,n)
// >>>>>>>>> M&W patterns <<<<<<
WMA=weightedaverage[period](close)
//Smoothed curve of Leo Moving Average
IF BARINDEX > period THEN
smoothWMA=weightedaverage[period](WMA)
ELSE
smoothWMA=undefined
ENDIF
// << Storage of minimums and maximums >>
once mintemp=low
once posmintemp=1
once maxtemp=high
once posmaxtemp=1
IF BARINDEX>2 THEN
// the value 0.7 is to ensure that the donchian channel is faster than the curves analysis (this value to be checked)
IF low < lowest[round(0.75*period)](low[1]) THEN
mintemp=low //minimum temporal
posmintemp=BARINDEX //postition of minimum temporal
ENDIF
IF high > highest[round(0.75*period)](high[1]) then
maxtemp=high //maximum temporal
posmaxtemp=BARINDEX //position maximum temporal
ENDIF
ENDIF
// << Detecting and locating a local minimums >>
// Where the WMA is crossing the smoothed WMA, there is a maximum or minimum nearby
// If there is a new local min/max, the preivus one is stored in de varible B... (before)
once LEVMIN=low
once POSLEVMIN=1
once LEVMAX=high
once POSLEVMAX=1
once bullcross=0
once bearcross=0
IF BARINDEX > PERIOD THEN //For avoid computer errors
bullcross=WMA crosses over smoothWMA
bearcross=WMA crosses under smoothWMA
ENDIF
IF bullcross and POSLEVMIN<>posmintemp THEN
BLEVMIN=LEVMIN //previus local minimum is saved
BPOSLEVMIN=POSLEVMIN
LEVMIN=mintemp
POSLEVMIN=posmintemp
support=LEVMIN
ENDIF
// --> Detecting and locating a local maximum
IF bearcross and POSLEVMAX<>posmaxtemp THEN
BLEVMAX=LEVMAX //previus local maximum is saved
BPOSLEVMAX=POSLEVMAX
LEVMAX=maxtemp
POSLEVMAX=posmaxtemp
resistance=LEVMAX
ENDIF
once support=low
once resistance=high
support=min(low,support)
resistance=max(high,resistance)
// << DETECTING DOUBLE TOP OR BOTTOMS >>
once WidthDoubleTop = high-low
once WidthDoubleBottom = high-low
once Wpattern=0
once Mpattern=0
// <<<<<< Double bottoms >>>>>>>>>
//looking for the top between two local minimums
IF bullcross THEN
doublebottomtop=high[BARINDEX-POSLEVMIN+1] // we start looking for the top in between two local minimums
//POSdoublebottomtop=BARINDEX-POSLEVMIN+1
FOR i = (BARINDEX-POSLEVMIN+1) to (BARINDEX-BPOSLEVMIN-1) DO
IF high[i] > doublebottomtop THEN
doublebottomtop=high[i]
//POSdoublebottomtop=BARINDEX-i
ENDIF
NEXT
WidthDoubleBottom = doublebottomtop-(BLEVMIN+LEVMIN)/2 // (top betwen local minimums) - (average of the las two local minimums)
IF abs(BLEVMIN-LEVMIN) < Kdouble*WidthDoubleBottom THEN
// we have a double bottom
Wpattern=1
else
Wpattern=0
ENDIF
ENDIF
// <<<<<<<<<< Double tops >>>>>>>
//looking for the bottom between two local maximums
IF bearcross THEN
doubletopbottom=low[BARINDEX-POSLEVMAX+1]
//POSdoubletopbottom=BARINDEX-POSLEVMAX+1
FOR i = (BARINDEX-POSLEVMAX+1) to (BARINDEX-BPOSLEVMAX-1) DO
IF low[i] < doubletopbottom THEN
doubletopbottom=low[i]
//POSdoubletopbottom=BARINDEX-i
ENDIF
NEXT
WidthDoubleTop=(BLEVMAX+LEVMAX)/2 -doubletopbottom
IF abs(BLEVMAX-LEVMAX) < Kdouble*WidthDoubleTop THEN
// we have a double top
Mpattern=1
else
Mpattern=0
ENDIF
ENDIF
// <<<<<<<<<< DOUBLE BOTTOM FOR TRADING >>>>>>>>
once entrylong=undefined
once entryshort=undefined
myATR=AverageTrueRange[2*period](close)
IF Wpattern=1 THEN
IF close > (doublebottomtop+myATR) or close < (LEVMIN-0.5*myATR) THEN
Wpattern=0 // <<<< double bottom has been activated or it was cancelled >>>>>
ELSE
//Here we trade
entrylong = max(doublebottomtop,high)+spread*pipsize/2
entryshort= min(LEVMIN,low)-0.5*myATR-spread*pipsize/2
stoploss = min(maxrisk,WidthDoubleBottom/pipsize+1.5*spread)
StopProfit= WidthDoubleBottom/pipsize*Kprofit
IF NOT LongOnMarket AND ontime=1 THEN
BUY n CONTRACTS AT entrylong STOP
SET STOP pLOSS stoploss
SET TARGET pPROFIT StopProfit
ENDIF
IF NOT ShortOnMarket AND ontime=1 THEN
SELLSHORT n CONTRACTS AT entryshort STOP
SET STOP pLOSS stoploss
SET TARGET pPROFIT StopProfit
ENDIF
ENDIF
ENDIF
// <<<<<<<<<< DOUBLE TOP FOR TRADING >>>>>>>>
IF Mpattern=1 THEN
IF close < (doubletopbottom-myATR) or close > (LEVMAX+0.5*myATR) THEN
Mpattern=0 //double top has been activated or it was cancelled
ELSE
//Here we trade
entrylong = max(LEVMAX,high)+0.5*myATR+spread*pipsize/2
entryshort= min(doubletopbottom,low)-spread*pipsize/2
stoploss = min(maxrisk,WidthDoubleTop/pipsize+1.5*spread)
StopProfit= WidthDoubleTop/pipsize*Kprofit
IF NOT LongOnMarket AND ontime=1 THEN
BUY n CONTRACTS AT entrylong STOP
SET STOP pLOSS stoploss
SET TARGET pPROFIT StopProfit
ENDIF
IF NOT ShortOnMarket AND ontime=1 THEN
SELLSHORT n CONTRACTS AT entryshort STOP
SET STOP pLOSS stoploss
SET TARGET pPROFIT StopProfit
ENDIF
ENDIF
ENDIF
IF longonmarket then
IF close < support[1] THEN //+0.3*(resistance-support)
SELL AT MARKET
ENDIF
IF TIME > 224500 and DayOfWeek=5 then
SELL AT MARKET
ENDIF
endif
IF shortonmarket then
IF close > resistance[1] THEN //-0.3*(resistance-support)
EXITSHORT AT MARKET
ENDIF
IF TIME > 224500 and DayOfWeek=5 then
EXITSHORT AT MARKET
ENDIF
endif
//Quit the robot if things are going bad
Q=MAX(Q,(STRATEGYPROFIT/pipvalue/n))
R=Q-STRATEGYPROFIT/pipvalue/n
IF R > totalrisk THEN
QUIT
ENDIF
IF STRATEGYPROFIT < (-1*totalrisk) THEN
QUIT
ENDIF
Here a WF of the system at 1min time frame…. thats why I need your help to improve this system
so, it was luck or is this the cash cow we all are looking for?This is what I work everyday for 🙂 I hope still working for you. I am not fully satisfied though, because most of the time the price target of a doble bottom is not fully fullfill. This strategy I post make me win like 3 times in a row and with only one fail it deletes the profit of the last two. Maybe as an entry and then you control manually the position can be very profitable. or… let’s improved it together!
maxrisk=maxrisk0+(n-1)*2
totalrisk=10000//4*maxrisk*PIPVALUE //for stop the robot if things are going bad
DOUBLE TOP/BOTTOM HUNTER
This topic contains 23 replies,
has 5 voices, and was last updated by Leo
8 years, 6 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 11/17/2017 |
| Status: | Active |
| Attachments: | 10 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.