How can i limit the code to only do one trade per trend? Lets say im following supertrend and after take profit or loss i want to stay flat till next direction on supertrend.
BR. Lasse
To take an order only when the Supertrend turn from green to red or red to green, use that code snippet:
st=supertrend[3,10]
if close crosses over st then
buy at market
endif
if close crosses under st then
sellshort at market
endif
I moved the topic from ProBuilder to ProOrder support, as it deals with a strategy.
Please make sure you have carefully read the rules highlighted below (in yellow) in order to correctly use this forum. Thank you 🙂
Hi Nicolas
I attach the code for better understanding. For an example i want to the sell 25-jan 11:00 then take profit 13:37. Then i want the system to stay flat til 25-jan 22:10 when the upptrend starts and after stopploss 26-jan 02:25 stay flat again til next downtrend.
I only want one trade per trend (trend =30min supertrend 3:10)
Open itf in 1minute 5k units and Wall street cash.
Many Thanks.
This is what the code I prodived is doing 🙂
Please copy/paste your code and by using the ‘insert prt code’ button. Better than attaching the itf file, thank you.
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
timeframe(30 minutes,updateonclose)
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = SuperTrend[3,10]
c1 = (indicator1 > indicator2)
timeframe(1 minutes,updateonclose)
indicator3 = Average[1](close)
indicator4 = Average[5](close)
c2 = (indicator3 crosses over indicator4)
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
timeframe(30 minutes,updateonclose)
// Conditions to exit long positions
indicator5 = Average[5](close)
indicator6 = SuperTrend[3,10]
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
timeframe(30 minutes,updateonclose)
indicator7 = Average[5](close)
indicator8 = SuperTrend[3,10]
c4 = (indicator7 < indicator8)
timeframe(1 minutes,updateonclose)
indicator9 = Average[1](close)
indicator10 = Average[5](close)
c5 = (indicator9 crosses under indicator10)
IF c4 AND c5 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
timeframe(30 minutes,updateonclose)
indicator11 = Average[5](close)
indicator12 = SuperTrend[3,10]
c6 = (indicator11 > indicator12)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 100
SET TARGET pPROFIT 100
You need to set a flag every time you send an entry order to market and not reset that flag until the trend changes direction. The flag not being set is a condition for allowing entry.
sounds right, but i don’t know how to do it. flag?
flag = just a variable that you set to 1 or 0. If it is 1 then you have already opened a trade. If it is zero then no trade has been opened since the last change in supertrend direction. I don’t have time to amend your code for you right now.
OK please help me when you have time.
Thanks.
Something like this (not tested and coded after a couple of glasses of wine!):
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
timeframe(30 minutes,updateonclose)
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = SuperTrend[3,10]
c1 = (indicator1 > indicator2)
newtrend = (SuperTrend[3,10] > SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) < SuperTrend[3,10](close[2])) or (SuperTrend[3,10] < SuperTrend[3,10](close[1]) and SuperTrend[3,10](close[1]) > SuperTrend[3,10](close[2]))
if newtrend then
flag = 0
endif
timeframe(1 minutes,updateonclose)
indicator3 = Average[1](close)
indicator4 = Average[5](close)
c2 = (indicator3 crosses over indicator4)
IF c1 AND c2 and not flag THEN
BUY 1 CONTRACT AT MARKET
flag = 1
ENDIF
timeframe(30 minutes,updateonclose)
// Conditions to exit long positions
indicator5 = Average[5](close)
indicator6 = SuperTrend[3,10]
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
timeframe(30 minutes,updateonclose)
indicator7 = Average[5](close)
indicator8 = SuperTrend[3,10]
c4 = (indicator7 < indicator8)
timeframe(1 minutes,updateonclose)
indicator9 = Average[1](close)
indicator10 = Average[5](close)
c5 = (indicator9 crosses under indicator10)
IF c4 AND c5 and not flag THEN
SELLSHORT 1 CONTRACT AT MARKET
flag = 1
ENDIF
// Conditions to exit short positions
timeframe(30 minutes,updateonclose)
indicator11 = Average[5](close)
indicator12 = SuperTrend[3,10]
c6 = (indicator11 > indicator12)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 100
SET TARGET pPROFIT 100
Something is wrong in line 11, im not able to fix it 🙂
Try this:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
timeframe(30 minutes,updateonclose)
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = SuperTrend[3,10]
c1 = (indicator1 > indicator2)
newtrend = (indicator2 > indicator2[1] and indicator2[1] < indicator2[2]) or (indicator2 < indicator2[1] and indicator2[1] > indicator2[2])
if newtrend then
flag = 0
endif
timeframe(default)
indicator3 = Average[1](close)
indicator4 = Average[5](close)
c2 = (indicator3 crosses over indicator4)
if flag = 0 then
myflag = 0
endif
IF c1 AND c2 and not myflag THEN
BUY 1 CONTRACT AT MARKET
myflag = 1
ENDIF
timeframe(30 minutes,updateonclose)
// Conditions to exit long positions
indicator5 = Average[5](close)
indicator6 = SuperTrend[3,10]
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
timeframe(30 minutes,updateonclose)
indicator7 = Average[5](close)
indicator8 = SuperTrend[3,10]
c4 = (indicator7 < indicator8)
timeframe(default)
indicator9 = Average[1](close)
indicator10 = Average[5](close)
c5 = (indicator9 crosses under indicator10)
IF c4 AND c5 and not myflag THEN
SELLSHORT 1 CONTRACT AT MARKET
myflag = 1
ENDIF
// Conditions to exit short positions
timeframe(30 minutes,updateonclose)
indicator11 = Average[5](close)
indicator12 = SuperTrend[3,10]
c6 = (indicator11 > indicator12)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 100
SET TARGET pPROFIT 100
Hi Robertogozzi
Can you help me fix a flag or trade limiter i the code, i only want one trade /supertrend timeframe ( 30min)
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
timeframe(30 minutes,updateonclose)
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = SuperTrend[3,10]
c1 = (indicator1 > indicator2)
timeframe(1 minutes,updateonclose)
indicator3 = Average[1](close)
indicator4 = Average[5](close)
c2 = (indicator3 crosses over indicator4)
IF c1 AND c2 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
timeframe(30 minutes,updateonclose)
// Conditions to exit long positions
indicator5 = Average[5](close)
indicator6 = SuperTrend[3,10]
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
timeframe(30 minutes,updateonclose)
indicator7 = Average[5](close)
indicator8 = SuperTrend[3,10]
c4 = (indicator7 < indicator8)
timeframe(1 minutes,updateonclose)
indicator9 = Average[1](close)
indicator10 = Average[5](close)
c5 = (indicator9 crosses under indicator10)
IF c4 AND c5 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
timeframe(30 minutes,updateonclose)
indicator11 = Average[5](close)
indicator12 = SuperTrend[3,10]
c6 = (indicator11 > indicator12)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 200
SET TARGET pPROFIT 100
Try this (not tested):
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
timeframe(30 minutes,updateonclose)
BarIndex30 = BarIndex
// Conditions to enter long positions
indicator1 = Average[5](close)
indicator2 = SuperTrend[3,10]
c1 = (indicator1 > indicator2)
timeframe(1 minutes,updateonclose)
ONCE MyBar = 0
indicator3 = Average[1](close)
indicator4 = Average[5](close)
c2 = (indicator3 crosses over indicator4)
IF c1 AND c2 AND (MyBar <> BarIndex30) AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
MyBar = BarIndex30
ENDIF
timeframe(30 minutes,updateonclose)
// Conditions to exit long positions
indicator5 = Average[5](close)
indicator6 = SuperTrend[3,10]
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
timeframe(30 minutes,updateonclose)
indicator7 = Average[5](close)
indicator8 = SuperTrend[3,10]
c4 = (indicator7 < indicator8)
timeframe(1 minutes,updateonclose)
indicator9 = Average[1](close)
indicator10 = Average[5](close)
c5 = (indicator9 crosses under indicator10)
IF c4 AND c5 THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
timeframe(30 minutes,updateonclose)
indicator11 = Average[5](close)
indicator12 = SuperTrend[3,10]
c6 = (indicator11 > indicator12)
IF c6 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pLOSS 200
SET TARGET pPROFIT 100