Hi Cosmic,
Please change the line 37 to 45 with this code instead:
if longonmarket then
set stop ploss 40
set target pprofit 25
endif
if shortonmarket then
set stop ploss 30
set target pprofit 25
endif
To test if it’s ok. In your broker orders list, do you see the takeprofit and stoploss values?
Sorry Cosmic1, were too late and didn’t test it, my fault… above code is wrong, here you have it, tested:
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FLATAFTER = 205500
// One Trade Per Day
Once nbTrades = 0
Once tradesPerDay = 1
If Day<>Day[1] then
nbTrades = 0
Else
If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
nbTrades = nbTrades + 1
Endif
Endif
If nbTrades < tradesPerDay then
//End One Trade Per Day Code
cashhigh = highest[180](high)
cashlow = lowest[180](low)
ENDIF
IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
//Enter Longs
BUY 1 PERPOINT AT cashhigh-5 STOP
set stop ploss 40
set target pprofit 25
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
set stop ploss 30
set target profit 25
ENDIF
Cheers
Thank you, I think we are nearly there but this latest version now breaks the one trade per day code 🙁
Separate stops and limits work though 🙂
Actually I can’t see if the separate stops and limits are working as trades are being taken too often…
This should fix the one trade per day issue:
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FLATAFTER = 205500
// One Trade Per Day
Once nbTrades = 0
Once tradesPerDay = 1
If Day<>Day[1] then
nbTrades = 0
Else
If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
nbTrades = nbTrades + 1
Endif
Endif
If nbTrades < tradesPerDay then
//End One Trade Per Day Code
cashhigh = highest[180](high)
cashlow = lowest[180](low)
IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
//Enter Longs
BUY 1 PERPOINT AT cashhigh-5 STOP
set stop ploss 40
set target pprofit 25
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
set stop ploss 30
set target profit 25
ENDIF
ENDIF
Hi, It does and I tried moving the IF’s as you did above but it now doesn’t follow the separate stops and limits. Longs and shorts both get stopped at 20points when using this code.
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FLATAFTER = 205500
// One Trade Per Day
Once nbTrades = 0
Once tradesPerDay = 1
If Day<>Day[1] then
nbTrades = 0
Else
If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
nbTrades = nbTrades + 1
Endif
Endif
If nbTrades < tradesPerDay then
//End One Trade Per Day Code
cashhigh = highest[180](high)
cashlow = lowest[180](low)
IF NOT LONGONMARKET AND Time > 173000 AND Time <= 193000 THEN
//Enter Longs
BUY 1 PERPOINT AT cashhigh-5 STOP
set stop ploss 40
set target pprofit 40
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET AND Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
set stop ploss 20
set target pprofit 20
ENDIF
ENDIF
I should correct the above to say Longs and shorts both have their stops and limits at 20points when using this code. Thanks for all your help 🙂
Could be this ?
IF Time > 173000 AND Time <= 193000 THEN
//Enter Longs
IF NOT LONGONMARKET THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
set stop ploss 40
set target pprofit 40
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET
SELLSHORT 1 PERPOINT at cashlow+5 STOP
set stop ploss 20
set target pprofit 20
ENDIF
ENDIF
Nope still makes no difference 🙁
Ok, how about this?
IF Time > 173000 AND Time <= 193000 THEN
//Enter Longs
IF NOT LONGONMARKET THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
stoplong = cashhigh-45*pipsize
profitlong = cashhigh+55*pipsize
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET
SELLSHORT 1 PERPOINT at cashlow+5 STOP
stopshort = cashlow-15*pipsize
profitshort = cashlow+25*pipsize
ENDIF
ENDIF
IF NOT ONMARKET THEN
stoplong = 0
stopshort = 0
profitlong = 0
profitshort = 0
ENDIF
IF LONGONMARKET THEN
sell at stoplong stop
sell at profitlong limit
ENDIF
IF SHORTONMARKET THEN
exitshort at stopshort stop
exitshort at profitshort limit
ENDIF
Thanks again but not working, no stops or limits work at all… All other code works. All trades close at the FLATAFTER time…
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FLATAFTER = 205500
//One Trade Per Day
Once nbTrades = 0
Once tradesPerDay = 1
If Day<>Day[1] then
nbTrades = 0
Else
If (Not OnMarket[1] and OnMarket) xor (ShortOnMarket[1] and LongOnMarket) xor (LongOnMarket[1] and ShortOnMarket) then
nbTrades = nbTrades + 1
Endif
Endif
If nbTrades < tradesPerDay then
//End One Trade Per Day Code
IF Time = 173000 then
cashhigh = highest[180](high)
cashlow = lowest[180](low)
ENDIF
IF Time > 173000 AND Time <= 193000 THEN
//Enter Longs
IF NOT LONGONMARKET THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
stoplong = cashhigh-40*pipsize
profitlong = cashhigh+40*pipsize
ENDIF
//Enter Shorts
IF NOT SHORTONMARKET THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
stopshort = cashlow-20*pipsize
profitshort = cashlow+20*pipsize
ENDIF
ENDIF
IF LONGONMARKET THEN
sell at stoplong stop
sell at profitlong limit
ENDIF
IF SHORTONMARKET THEN
sell at stopshort stop
sell at profitshort limit
ENDIF
IF NOT ONMARKET THEN
stoplong = 0
stopshort = 0
profitlong = 0
profitshort = 0
ENDIF
ENDIF