MTF Strategy 2 hrs and 2 min
Forums › ProRealTime English forum › ProOrder support › MTF Strategy 2 hrs and 2 min
- This topic has 13 replies, 3 voices, and was last updated 4 years ago by
robertogozzi.
-
-
08/05/2021 at 11:11 AM #174730
I have created this strategy based on 2 time frames MACD on 2 hrs and Supertrend on 2 mins, its not working with me, I believe it needs to be corrected, could you please help in adjusting it.
// VARIABLES
SL = 4
stepfactor1 = 1
stepfactor2 = 0.25
RR = 2
timeframe(2 hour, updateonclose)
MCD = MACD[12,26,9](close)
timeframe(2 minutes)
DM = DEMA[14](close)
PST = Supertrend[2,10]
// Conditions to enter long positions
IF MCD > 0 AND DM CROSSES OVER PST THEN
BUY 1 CONTRACTS AT MARKET
SET STOP pLOSS SL //5
TP = RR * SL
SET TARGET pPROFIT TP //10
ENDIF
// Conditions to exit long positions
If DM CROSSES UNDER PST THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
IF MCD < 0 AND DM CROSSES UNDER PST THEN
SELLSHORT 1 CONTRACTS AT MARKET
SET STOP pLOSS SL //5
TP = RR * SL
SET TARGET pPROFIT TP //10
ENDIF
// Conditions to exit short positions
IF DM CROSSES OVER PST THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets : Enter your protection stops and profit targets here
//====== Trailing Stop mechanism – start =====
trailingstart = (stepfactor1 * SL ) / pointsize
trailingstep = (stepfactor2 * SL ) / pointsize
//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif
//case LONG order
if longonmarket then
//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
priceexit = tradeprice(1) + trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIF
ENDIF
endif
//case SHORT order
if shortonmarket then
//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
priceexit = tradeprice(1) – trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = priceexit-close >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit – trailingstep*pointsize
ENDIF
ENDIF
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//====== Trailing Stop mechanism – end =====
08/05/2021 at 11:30 AM #17473108/05/2021 at 11:36 AM #17473608/05/2021 at 11:49 AM #174741It’s working for me, as well.
What’s the issue you have detected?
If you post instrument, TF, date and time of one or more incorrect trades, we might be of some help.
1 user thanked author for this post.
08/05/2021 at 1:17 PM #17474808/05/2021 at 1:37 PM #17475108/05/2021 at 2:18 PM #17475208/05/2021 at 3:43 PM #174758For me conditions work fine, as requested (at least for the couple of entries I checked).
08/05/2021 at 5:34 PM #174771ignore the conditions of the 2 hours?!!!
In your code below …
-
- Conditions showing at the END of the 2 hour will be followed.
- Conditions showing DURING the 2 hour bar will be ignored.
Does above help at all?
123timeframe(2 hour, updateonclose)MCD = MACD[12,26,9](close)08/05/2021 at 6:51 PM #174774Yes, UpdateOnClose only sets conditions when a bar closes.
Use default, or nothing, to update conditions every 2 minutes (or any default TF you may want to use),
1 user thanked author for this post.
08/06/2021 at 6:49 AM #174799It is working now, I added another condition to the 2 min which is the DRSI, but still the trailing stop loss system is not working don’t know why??
==============================================================================================================
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// VARIABLES
SL = 2.6
stepfactor1 = 1
stepfactor2 = 0.25
RR = 2
timeframe(2 hour, updateonclose)
MCD = MACD[12,26,9](close)
timeframe(2 minutes)
myPRCDynamicRSI, myPRCDynamicRSI2, myPRCDynamicRSI3, myPRCDynamicRSI4 = CALL “PRC_DynamicRSI”[0.1, 0.1, 14, 60]
DM = DEMA[14](close)
PST = Supertrend[2,10]
// Conditions to enter long positions
IF MCD > 0 AND DM > PST AND myPRCDynamicRSI > myPRCDynamicRSI2 THEN
BUY 1 CONTRACTS AT MARKET
SET STOP pLOSS SL //5
TP = RR * SL
SET TARGET pPROFIT TP //10
ENDIF// Conditions to exit long positions
If DM Crosses under PST THEN
SELL AT MARKET
ENDIF// Conditions to enter short positions
IF MCD < 0 AND DM < PST AND myPRCDynamicRSI < myPRCDynamicRSI2 THEN
SELLSHORT 1 CONTRACTS AT MARKET
SET STOP pLOSS SL //5
TP = RR * SL
SET TARGET pPROFIT TP //10
ENDIF// Conditions to exit short positions
IF DM CROSSES OVER PST THEN
EXITSHORT AT MARKET
ENDIF// Stops and targets: Enter your protection stops and profit targets here
//====== Trailing Stop mechanism – start =====trailingstart = (stepfactor1 * SL ) / pointsize
trailingstep = (stepfactor2 * SL ) / pointsize//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif//case LONG order
if longonmarket then//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THENpriceexit = tradeprice(1) + trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsizeIF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIFENDIF
endif//case SHORT order
if shortonmarket then//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THENpriceexit = tradeprice(1) – trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THENP2 = priceexit-close >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit – trailingstep*pointsize
ENDIFENDIF
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//====== Trailing Stop mechanism – end =====08/06/2021 at 7:59 AM #174805Remove / PointSize from these lines:
12trailingstart = (stepfactor1 * SL ) / pointsizetrailingstep = (stepfactor2 * SL ) / pointsizeI fear your system will be always stopped from autotrading, due to such narrow values for SL, as they seem to be less than those required by IG.
08/06/2021 at 8:44 AM #17481008/06/2021 at 9:18 AM #174811You should optimize it, to fond the best possible one.
-
-
AuthorPosts
Find exclusive trading pro-tools on