Closing based on profit of all open positions
01/19/2017 at 2:33 PM #21679
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?01/19/2017 at 5:55 PM #2172701/19/2017 at 6:01 PM #21728
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 day01/19/2017 at 6:41 PM #2173101/19/2017 at 8:33 PM #2175701/20/2017 at 2:14 PM #21866
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/ )12345678910111213141516171819202122232425262728// ---parametersMaxDailyProfit=100 //Max daily profit allowed (in money)// first time we launch the code, the trading is allowedonce TradeAllowed=1// reset the current state of the strategyprofit each new dayIf intradaybarindex=0 thenMyProfit=STRATEGYPROFITTradeAllowed=1endif// test the current floating profit and close orders if neededfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsif floatingprofit>=MaxDailyProfit thenSELL AT MARKETEXITSHORT AT MARKETendif// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowedIf StrategyProfit>=MyProfit+MaxDailyProfit thenTradeAllowed=0endif// initiate a new BUY orderif TradeAllowed=1 and buyconditions thenbuy 1 lot at marketendif01/23/2017 at 10:55 AM #22115
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?06/11/2017 at 12:26 PM #38051
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?06/12/2017 at 1:04 PM #38144
You can always use the “server” trailing stop which operate between bars: SET STOP PTRAILING 1006/12/2017 at 11:17 PM #38164
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! 🙂06/13/2017 at 8:16 AM #38176