Hello guys,
I’ve been on this forum for a few weeks now, and I’m really grateful to be part of this community. I feel it’s now time for me to contribute as I can.
So I’ve decided to share with you this short idea, basically it takes position only in the first few hours of cash market.
Using SuperTrend and KAMA to filter entries, and trailstop with another (faster) Supertrend.
It is just a draft yet, looking forward to your inputs and ideas on how to make it better.
// Définition des paramètres du code
DEFPARAM CumulateOrders = False // Cumul des positions désactivé
// Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
// DEFPARAM FLATAFTER = 220000
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position avant l'heure spécifiée
noEntryBeforeTime = 090000
timeEnterBefore = time >= noEntryBeforeTime
// Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiée
noEntryAfterTime = 113000
timeEnterAfter = time < noEntryAfterTime
IF (CurrentTime = 090000) THEN
OpeningPrice = Open[0]
ENDIF
/// --- MONEY MANAGEMENT
//Capital = 350
//Risk = 0.0714
//StopLoss = 50 // Could be our variable X
//equity = Capital + StrategyProfit
//maxrisk = round(equity*Risk)
//PositionSize = abs((maxrisk/StopLoss)/PointValue)
PositionSize = 1
/// ---------------------------------- Indicators ------------------------------------- ///
iMACD1850 = MACDline[18,50,9](close)
signal1850 = ExponentialAverage[9](iMACD1850)
iSuperTrend = SuperTrend[3,17]
kama = CALL "KAMA 50"[50, 2, 30]
iVolatStop = SuperTrend[2,15]
//LongStop = close[1] - (iATR[1] * 2)
//ShortStop = close[1] - (iATR[1] * 2)
iATR = AverageTrueRange[20](close)
multiplicatorATR = 1.2
/// ---------------------------------------------------------------------------------- ///
/// --- LONG ENTRY PRICE DEF
BullishOpening = (OpeningPrice > kama) AND (OpeningPrice > iSuperTrend)
PriceBelowKamaST = (close < kama) AND (close < iSuperTrend)
IF BullishOpening THEN
LongEntryPrice = OpeningPrice + (multiplicatorATR*iATR)
ENDIF
IF PriceBelowKamaST THEN
LongEntryPrice = iSuperTrend
ENDIF
///------------------------------------------------------------------///
/// --- SHORT ENTRY PRICES
PriceAboveKamaST = (close > kama) AND (close > iSuperTrend)
BearishOpening = (OpeningPrice < kama) AND (OpeningPrice < iSuperTrend)
IF BearishOpening THEN
ShortEntryPrice = OpeningPrice - (multiplicatorATR *iATR)
ENDIF
IF PriceAboveKamaST THEN
ShortEntryPrice = iSuperTrend
ENDIF
/// -------------------------------- ///
OpenLong = (iMACD1850 > signal1850) AND PriceBelowKamaST
OpenShort = (iMACD1850 < signal1850) AND PriceAboveKamaST
/// BUY
IF OpenLong AND timeEnterBefore AND timeEnterAfter THEN
BUY PositionSize CONTRACT AT LongEntryPrice STOP
lowOpen = low[1]
ENDIF
IF BullishOpening AND timeEnterBefore AND timeEnterAfter THEN
BUY PositionSize CONTRACT AT LongEntryPrice STOP
lowOpen = low[1]
ENDIF
SELL AT lowOpen STOP
SELL AT iVolatStop STOP
/// SELL
IF OpenShort AND timeEnterBefore AND timeEnterAfter THEN
SELLSHORT PositionSize CONTRACT AT ShortEntryPrice STOP
highOpen = high[1]
ENDIF
IF BearishOpening AND timeEnterBefore AND timeEnterAfter THEN
SELLSHORT PositionSize CONTRACT AT ShortEntryPrice STOP
highOpen = high[1]
ENDIF
EXITSHORT AT highOpen STOP
EXITSHORT AT iVolatStop STOP
SET STOP pLOSS iATR*2.5
// TRAILING //////////////////////////////////////////////////////////
Hi Bob and thanks a lot for sharing this strategy. In order to complete the review process before sending it into the library, it would be kind of you if you could do some WF testing, is it possible? Thanks again for your contribution to the website which is greatly appreciate! 😉
Hello Nicolas,
Thanks for your reply. I’ve never run a WF on ProRealTime. Any resources/documentation available to help me with my first one ?
( Et bravo pour le site, c’est top ! Belle communauté 🙂 )
Is below the Indicator you refer to in your code as KAMA 50 ?
If No, where is KAMA 50 or has my coffee not worked through yet? 🙂
https://www.prorealcode.com/prorealtime-indicators/kaufman-adaptive-moving-average-kama/
Hello Grahal,
Haha actually I just imported to try the code of this topic : https://www.prorealcode.com/topic/kama-200-2/
So I don’t know really …
Hi, I ve added the definition of KAMA50 (i think its the good one) and its not too bad on DAX 30 minutes
I get attached over 100k bars with spread = 2.
I like that losses are cut early and not stay in the trade hoping to finish all good!?
Be good if we can increase the Gain to Loss ratio.
RazzParticipant
Master
Hello Roger
Thank you for sharing your trading system. Do you have an explanation why there was movement in the Dax in the gray areas it was not really reflected in the profit? In the areas with the blue line he behaves completely differently?
Probacktest 100.00 Einheiten , 2 Positionen , Spread 1
I am on my phone I am not at home tonight but I try to work on it tomorrow.
What bothers me is the % winning because you lose money most of the time so it is mentally hard.
This kind of strategy reminds me the popular Breakout cac40 strat and these strategies need big and proper market move to make money. You typically lose money when the market reverses on the same day.
RazzParticipant
Master
Thanks for the answer then until tomorrow
This kind of strategy reminds me the popular Breakout cac40 strat and these strategies need big and proper market move to make money. You typically lose money when the market reverses on the same day.
Yes Roger, I just learned about London Morning breakout strategy. That’s very similar indeed, what’s funny is that I noticed the pattern myself while live trading. Unfortunately i didn’t find a good way to trail stop the trade… I used MACD crosses, Supertrend, ATR, lowest low… all with no success.
@BobFlynn have u tried the different kinds of trailing stop losses from this site? Has helped me alot on multiple strategies.
Thanks for your message Jebus. Do you have any useful links ? I think I tried all the basics… but maybe with the wrong parameters so it’s hard to tell.
Try these ones, maybe they can help.
https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/
and
//************************************************************************
// TSL trailing stop function
//************************************************************************
//************************************************************************
//trailing stop function
trailingstart = 50// 20trailing will start @trailinstart points profit
trailingstep = 10// 5trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Attached is a walk forward test. I have randomly chosen some parameters. And its not very good.
Bobflynn have you already optimized the parameters in the code you have posted ?