ramaParticipant
Senior
I want to stop my strategy if my floating profit >=10 pips
I have tested QUIT function which is not working for floating profit. it is working only realized profit
It will be most useful if we can use this for floating profit
QUIT is the function to stop the strategy. It has nothing to deal with the way you are calculating your profit!
If you have used STRATEGYPROFIT, it is indeed the realized profit.
The floating profit could be calculated as with this snippet:
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
Code is read at bar close, so if your strategy is running on a 5-minutes timeframe and you want it to be read more times during a bar for orders management, use the TIMEFRAME instruction with a lower timeframe and place all your desired functions you want to act faster below it.
ramaParticipant
Senior
DEFPARAM CumulateOrders = False
buy .5 contract at market
set stop loss 50
set target profit 300
ret=.1
//ret1=.1
//ret2=.4
IF Not OnMarket THEN
y = 0
ENDIF
IF LongOnMarket AND close > (TradePrice + (y * pipsize)) THEN
x = (close - tradeprice) / pipsize //convert price to pips
IF x >= 10 and x<=12.5 THEN //go ahead only if 30+ pips
y = max(x * ret, y) //y = 66.6% of max profit
ENDIF
ENDIF
IF y THEN //Place pending LIMIT (not STOP) order when y>0
SELL AT Tradeprice + (y * pipsize) stop //convert pips to price
ENDIF
if x>12 then
quit
endif
I am using the above code stop the system once profit >10 , I have asked the system stop once x>12 , as I am running this code in 1 second. here I am hoping that by the time program reached line 41 system has already moved my stop . Is there any way to stop system only after stop is moved?
I am using the option “when trading system is stopped – Remain open” I want to keep my position when I am in profit
I suppose I’m doing something wrong because the system stops as soon as it detects the quit function in the code. It doesn’t even enter the market, it stops the system right away with the following code as a test run (it’s not my strategy, let’s be clear about that 😀 ):
IF NOT LongOnMarket THEN
BUY 1 CONTRACTS AT MARKET
Elsif longonmarket and barindex - tradeindex > 1 then
sell at market
endif
If strategyprofit < 100 then
quit
endif
I get the following message from PRT: “this trading system has been stopped because of the presence of the quit function in the code.”
How about that?
When the strategy starts STRATEGYPROFIT is zero, so line 7 is immediately TRUE and line 8 executed to stop the strategy.
I suggest modifying line 7 so that it checks the strategy has entered at least one trade:
If strategyprofit < 100 AND strategyprofit[1] <> 0 then
but this will exit immediately if the first trade is a losing one.
I was only testing simple coding lines to get to know the function..