I was wondering if it is possible to use the total profit or loss as a way of deciding to exit the market or not.
For example when the total profit of all open positions equals 100 then close all positions for the day?
I’ve read the blog post about using strategyprofit and graphing an average of that as a variable but as far as I know that only applies to already closed positions, I was wondering if there as a way to track all positions that are currently open?
Do you mean all positions of all running automated strategies or only of the current one?
I mean just for the current strategy.
So for example if the strategy cumulates orders (so there are several positions open at different levels) and the total profit of all positions reaches £100 then the strategy closes for the day
Do the profit must be already banked or it could be floating profit with trades not closed?
I mean the floating profit from unclosed trades
It’s clear now, I have not tested this code snippet, but it should work, tell us if it’s ok: (major part of the code come from the Wing’s code here: https://www.prorealcode.com/blog/learning/max-profit-loss-day-trading-strategy/ )
// ---parameters
MaxDailyProfit=100 //Max daily profit allowed (in money)
// first time we launch the code, the trading is allowed
once TradeAllowed=1
// reset the current state of the strategyprofit each new day
If intradaybarindex=0 then
MyProfit=STRATEGYPROFIT
TradeAllowed=1
endif
// test the current floating profit and close orders if needed
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
if floatingprofit>=MaxDailyProfit then
SELL AT MARKET
EXITSHORT AT MARKET
endif
// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowed
If StrategyProfit>=MyProfit+MaxDailyProfit then
TradeAllowed=0
endif
// initiate a new BUY order
if TradeAllowed=1 and buyconditions then
buy 1 lot at market
endif
Thanks so much Nicolas!
I’m trying to add this to my strategy now, I will let you know how it goes,just one question, the maths there looks like its right, but I am unsure why we divide by pipsize when working out the floating profit. is the calculation the same for CFDs and spread bets etc?
ramaParticipant
Senior
The the problem with pro real time close takes as close at the end of the current bar.
say I have profit 40 gbp or usd sometime during the middle of the of bar
by the time bar closes profit my vanish and go to zero or -40
is there any way to reference current price?
@rama
You can always use the “server” trailing stop which operate between bars: SET STOP PTRAILING 10
https://www.prorealcode.com/blog/learning/kinds-trailing-stop-proorder/
Good question rama!
When we get multi-timeframe (PRT future release) then a conditions to exit with £x profit could run on 1 second TF whereas the main entry and exit conditions can run on, for example, 30 minutes TF … is this how multi-timeframe will work Nicolas … I’m hoping so! 🙂
Yes GraHal, once I’ll be able to test it myself, I will tell you 😉