Moving average cross over on multiple timeframes, 1-3 risk reward
Forums › ProRealTime English forum › ProOrder support › Moving average cross over on multiple timeframes, 1-3 risk reward
- This topic has 6 replies, 2 voices, and was last updated 4 years ago by
josward1.
-
-
08/11/2021 at 12:06 PM #175094
Hello i am new on here and have a moving average strategy i wish to put into an automated trading bot. It marrys up data on multiple timeframes.
Im a trader rather than programmer so i need help to do this, although i need to understand the programming side so i can play around with parameters.
The basic structure of the strategy is price to be above or below an SMA on the 4 hour and day timeframe and trade to be taken on a crossoveer of an SMA
on a 15 min timeframe. with a 1-3 risk reward ratio and a trailing stop loss.
I also want a condition on there where if the trigger candle is of a certaine (adjustable) size the trade will trigger on a pullback to 50% of this candle body
Could somebody please advise on how and where to start with this? I am also in the process of reading the manual but unfortunately still cant work out
where to start and the basic structure of how the programming should go.
Thanks,
Joe
1 user thanked author for this post.
08/12/2021 at 11:00 AM #175147There you go:
1234567891011121314151617181920212223242526DEFPARAM CumulateOrders = falseTimeframe(Daily,UpdateOnClose)SmaD = average[100,0](close)//Timeframe(4h,UpdateOnClose)Sma4h = average[100,0](close)//Timeframe(15 Minute,UpdateOnClose)Sma15m = average[100,0](close)//Timeframe(default)L1 = close > SmaDS1 = close < SmaDL2 = close > Sma4hS2 = close < Sma4hL3 = close CROSSES OVER Sma15mS3 = close CROSSES UNDER Sma15mCondL = L1 and L2 and L3 and Not OnMarketCondS = S1 and S2 and S3 and Not OnMarketIf CondL THENBUY 1 Contract AT MarketElsif CondS THENSELLSHORT 1 Contract AT MarketENDIFset stop pLoss 100set target pProfit 30008/12/2021 at 11:50 AM #175160I forgot to add the trailing stop:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970DEFPARAM CumulateOrders = falseTimeframe(Daily,UpdateOnClose)SmaD = average[100,0](close)//Timeframe(4h,UpdateOnClose)Sma4h = average[100,0](close)//Timeframe(15 Minute,UpdateOnClose)Sma15m = average[100,0](close)//Timeframe(default)L1 = close > SmaDS1 = close < SmaDL2 = close > Sma4hS2 = close < Sma4hL3 = close CROSSES OVER Sma15mS3 = close CROSSES UNDER Sma15mCondL = L1 and L2 and L3 and Not OnMarketCondS = S1 and S2 and S3 and Not OnMarketIf CondL THENBUY 1 Contract AT MarketElsif CondS THENSELLSHORT 1 Contract AT MarketENDIFset stop pLoss 100set target pProfit 300//************************************************************************//trailing stop function////by Nicolas//(https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/)//trailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF08/14/2021 at 7:55 PM #175358Hi thankyou for your quick response. This was the basic idea if my strategy,
I have taken the basic structure of what you posted to adapt to my full strategy
but it did not end up working, there are also a few faults with it i have
tried a few different things to get it working but have typed it out below so you can
see what i’m going for.DEFPARAM CumulateOrders = false
Timeframe(Daily,UpdateOnClose)
sma501d = Average[50](close)
//
sma901d = Average[90](close)
//
sma2001d = Average[200](close)
//
Timeframe(4h,UpdateOnClose)
sma504h = Average[50](close)
//
sma904h = Average[90](close)
//
sma2004h = Average[200](close)
//
Timeframe(15 Minute,UpdateOnClose)
sma5015m = Average[50](close)
//
sma9015m = Average[90](close)
//
sma20015m = Average[200]
//
ema3415m = ExponentialAverage[33](close)
//
ema5515m = ExponentialAverage[55](close)
//
Timeframe(default)
L1 = sma501d > sma901d //I would like to adjust the distances between the moving averages in pips
S1 = sma501d < sma901d L2 = sma901d > sma2001d
S2 = sma901d < sma2001d L3 = sma504h > sma904h
S3 = sma504h < sma904h L4 = sma904h > sma2004h
S4 = sma904h < sma2004h L5 = sma5015m > sma9015m
S5 = sma5015m < sma9015m L6 = sma9015m > sma20015m
S6 = sma9015m < sma20015m L7 = close > sma501d
S7 = close < sma501d L8 = close > sma901d
S8 = close < sma901d L9 = close > sma2001d
S9 = close < sma2001d L10 = close > sma504h
S10 = close < sma504h L11 = close > sma904h
S11 = close < sma904h L12 = close > sma2004h
S12 = close < sma2004h L13 = close > sma9015m
S13 = close < sma9015m L14 = close > sma20015m
S14 = close < sma20015m L15 = close CROSSES OVER ema3415m and ema5515m and sma5015m [Crosses over all in same candle] // I need the trigger candle to have met this criteria within the close of candle on default timeframe S15 = close CROSSES UNDER ema3415m and ema5515m and sma5015m [Crosses over all in same candle] // I need the trigger candle to have met this criteria within the close of candle on default timeframe CondL = L1 and L2 and L3 and L4 and L5 and L6 and L7 and L8 and L9 and L10 and L11 and L12 and L13 and L14 and L15 Not CondS = S1 and S2 and S3 and S4 and S5 and S6 and S7 and S8 and S9 and S10 and S11 and S12 and S13 and S14 and S15 Not If CondL and condM THEN BUY 1 Contract AT Market Elsif CondS and CondT THEN SELLSHORT 1 Contract AT Market ENDIF set stop pLoss 10 set target pProfit 30 The strategy goes as follows: 1 day timeframe: 50 sma > 90sma
90 sma > 200sma
close > 50sma
close > 90sma
close > 200sma4 hour timeframe:
50 sma > 90sma
90 sma > 200sma
close > 50sma
close > 90sma
close > 200sma15 min timeframe
50 sma > 90sma
90 sma > 200sma
close crosses over ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis)Buy 1-3 risk reward.
1 day timeframe:
50 sma < 90sma 90 sma < 200sma close < 50sma close < 90sma close < 200sma 4 hour timeframe: 50 sma < 90sma 90 sma < 200sma close < 50sma close < 90sma close < 200sma 15 min timeframe 50 sma < 90sma 90 sma < 200sma close crosses under ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis) sell risk reward 1-3 I also need a condition putting on there where that if the signal candle exceeds 15 pips, the bot will only take a trade if the price retraces to 50% of this candle on the next candle only. Thankyou for your help kind regards08/14/2021 at 7:59 PM #17535908/15/2021 at 2:22 PM #175389I have attempted to order the programming i have for clearer reading. I hope this works
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172DEFPARAM CumulateOrders = falseTimeframe(Daily,UpdateOnClose)sma501d = Average[50](close)//sma901d = Average[90](close)//sma2001d = Average[200](close)//Timeframe(4h,UpdateOnClose)sma504h = Average[50](close)//sma904h = Average[90](close)//sma2004h = Average[200](close)//Timeframe(15 Minute,UpdateOnClose)sma5015m = Average[50](close)//sma9015m = Average[90](close)//sma20015m = Average[200]//ema3415m = ExponentialAverage[33](close)//ema5515m = ExponentialAverage[55](close)//Timeframe(default)L1 = sma501d > sma901d //I would like to be able to adjust theS1 = sma501d < sma901d distances between the moving averages in pipsL2 = sma901d > sma2001dS2 = sma901d < sma2001dL3 = sma504h > sma904hS3 = sma504h < sma904hL4 = sma904h > sma2004hS4 = sma904h < sma2004hL5 = sma5015m > sma9015mS5 = sma5015m < sma9015mL6 = sma9015m > sma20015mS6 = sma9015m < sma20015mL7 = close > sma501dS7 = close < sma501dL8 = close > sma901dS8 = close < sma901dL9 = close > sma2001dS9 = close < sma2001dL10 = close > sma504hS10 = close < sma504hL11 = close > sma904hS11 = close < sma904hL12 = close > sma2004hS12 = close < sma2004hL13 = close > sma9015mS13 = close < sma9015mL14 = close > sma20015mS14 = close < sma20015mL15 = close CROSSES OVER ema3415m and ema5515m and sma5015m[Crosses over all in same candle on closing basis]// I need the trigger candle to have met this criteria within the close of onecandle on default time frameS15 = close CROSSES UNDER ema3415m and ema5515m and sma5015m[Crosses over all in same candle on closing basis]CondL = L1 and L2 and L3 and L4 and L5 and L6 and L7 and L8 and L9 and L10and L11 and L12 and L13 and L14 and L15 Not OnMarketCondS = S1 and S2 and S3 and S4 and S5 and S6 and S7 and S8 and S9 and S10and S11 and S12 and S13 and S14 and S15 Not OnMarketIf CondL and condM THENBUY 1 Contract AT MarketElsif CondS and CondT THENSELLSHORT 1 Contract AT MarketENDIFset stop pLoss 10set target pProfit 30Then the condition where if the trigger candle exceeds 15 pips (an adjustable value)
the bot will take a trade if the price pulls back to 50% or more of the next candle Only.
Thank you for your support
08/15/2021 at 3:42 PM #175394here is a clear description of the strategy in case above isn’t clear
1 day timeframe:
50 sma > 90sma
90 sma > 200sma
close > 50sma
close > 90sma
close > 200sma4 hour timeframe:
50 sma > 90sma
90 sma > 200sma
close > 50sma
close > 90sma
close > 200sma15 min timeframe
50 sma > 90sma
90 sma > 200sma
close crosses over ema3415m and 5515m and sma5015m (crosses all within same candle on closing basis)Buy 1-3 risk reward.
and the opposite for a sell.
-
AuthorPosts
Find exclusive trading pro-tools on