indicator1 = close
c1 = (indicator1>25)
indicator2 = close
c2 = (indicator2<25)
IF SHORTONMARKET AND C1 OR C2 THEN
EXITSHORT AT MARKET
ENDIF
Hmm i’m not sure what you want to do with this code. You are trying to close a short trade if the price is > to 25 and also if price is < 25 , so obviously your conditions are always met.
What is the exact question please?
Sorry Nicolas, still learning.
I want to close the trade if it either hits 25 points profit or 25 points loss from the entry price.
Ok, don’t be sorry, there is no stupid question 🙂
So, just add these instructions to your code:
SET STOP PLOSS 25
SET TARGET PPROFIT 25
You can have a look at all the Probacktest/ProOrder instruction here in the prorealtime documentation: http://www.prorealcode.com/documentation/category/probacktest/ , if you need more assistance to program your trading strategy, or just ask!
Thanks but I want to exit long positions at different targets and stops to short ones. What I’m after would come in handy for many strategy’s I’m testing.
Ok so test if you are in long or short conditions and then set your different values like this:
if longonmarket then
SET STOP PLOSS 25
SET TARGET PPROFIT 25
endif
if shortonmarket then
SET STOP PLOSS 35
SET TARGET PPROFIT 42
endif
Aha so simple when you know how 🙂 Will test soon.
Still no dice?
IF Time = 173000 then
cashhigh = highest[180](high)
cashlow = lowest[180](low)
ENDIF
//Enter Longs
IF Time > 173000 AND Time <= 193000 THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
ENDIF
//Enter Shorts
IF Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
ENDIF
if longonmarket then
SET STOP PLOSS 40
SET TARGET PPROFIT 25
endif
if shortonmarket then
SET STOP PLOSS 30
SET TARGET PPROFIT 25
endif
I’m sorry? On what instrument do you test this automated strategy?
The major indices and it only takes one trade per day, sorry didn’t include that bit. Basically everything works the way I want it apart from the fact I can’t adjust the long and short, stop and limit separately.
I could of course separate the code in to long and short positions but would be nice to have it in one code.
So you want to only let the current order go to profit or loss and avoid another one to initiate?
Sorry I have not been clear, been too long at the screen.
This is working the way I want it, just need to achieve separate stops and limits for long and short positions.
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
//Enter Longs
IF Time > 173000 AND Time <= 193000 THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
ENDIF
//Enter Shorts
IF Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
ENDIF
set stop ploss 25
set target pprofit 50
//ENDIF below is to finish off the one trades per day code at the start.
ENDIF
Been playing around with this today but still no joy, any help appreciated 🙂
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
//Enter Longs
IF Time > 173000 AND Time <= 193000 THEN
BUY 1 PERPOINT AT cashhigh-5 STOP
ENDIF
//Enter Shorts
IF Time > 173000 AND Time <= 193000 THEN
SELLSHORT 1 PERPOINT at cashlow+5 STOP
ENDIF
if longonmarket then
set stop ploss 40
set target pprofit 25
endif
if shortonmarket then
set stop ploss 30
set target profit 25
endif
//ENDIF below is to finish off the one trades per day code at the start.
ENDIF
Hi,
Thanks for the reply but it doesn’t work unfortunately. Did it work for you? The results never come to any stop or limit on any trade when I test it.