CODE TO CLOSE ALL TRADES BASED ON EQUITY OR PORTFOLIO VALUE
04/01/2022 at 9:44 PM #191010
Very much enjoying Prorealtime and have only been using it for a couple of weeks through IG, very much a beginner here, previously using MT4. I’ve managed to code my few strategies on here, reading and experimenting with the code library, i’m learning slowly!
My question is, is there any code relating to being able to stop all ProOrder trading based on portfolio value (account balance)? I run my strategy on 3 or 4 non-correlating FX pairs (charts) running simultaneously (same strategy with different conditions). I would like to be able to somehow stop all trading on all charts based on the profit/loss of my overall account balance. Is this at all possible? My strategy has profit target on each different chart banking small profits and slowly growing equity. Through extensive back-testing I know i’m just missing the something that says STOP ALL TRADING on all ProOrder strategies once a certain balance is met. Any help/ advice gratefully appreciated.
Andy04/01/2022 at 11:31 PM #19101204/02/2022 at 9:43 AM #191033
you just asked the most asked question of all. So if ProRealTime listens …
Sounds like Gibbo needs to submit a Suggestion direct to PRT, referring to this Topic, using the Form on the link below …04/02/2022 at 2:07 PM #191047
Thanks for the feedback. I will definitely write to PRT to suggest, really frustrating as every chart has your balance displayed, the stoploss and take profit obviously work on the value of the latent gain so surely a very simple addition. I really am loving the program, but this an absolute basic function required to auto trade. Finger’s crossed PRT listen.04/02/2022 at 2:57 PM #19105004/02/2022 at 3:32 PM #191053
It can be coded using a starting level of equity +/- the strategy profit … but only for that strategy, it won’t know what you’ve gained or lost elsewhere.
There’s a money management snippet somewhere that has a quit function after x% drawdown that might help, I’ll post it when I find it.04/02/2022 at 4:33 PM #191059
Not sure I understand you? ProOrder runs 4 of my strategies simultaneously and on the Auto-trading window each running system shows Total Gain. It would need to also show latent gain just like it does on every chart with open orders. I’m no computer programmer, but surely its easy to display the sum total of all running systems of the latent and total gain somewhere in that window, its just another indicator. PRT (api) has all the information it needs. It maybe i’m missing something, but if there was a 2 boxes on the auto-trading window one adding up the total gain and one the latent gain (theses values is on the top of every chart with open positions and just need adding together). Box 1, syntax = (TotLatGain) Box 2, syntax = (TotGain) then on every strategy code under stops and targets would read If (TotLatGain = (pick a number) then close all orders and STOP trading, same with total gain. Happy to be corrected, and you would need to factor in slippage etc. Hopefully someone from PRT will read the thread which I’ve attached the feedback form and comment as to why this isn’t possible. As far as I can see its just a simple indicator that doesn’t exist at the moment??04/02/2022 at 4:58 PM #191068
I’m no computer programmer,
That’s the thing – haha.
You must see PRT – the charts you are looking at, as a derived spreadsheet. All you see in there, is data from the broker. 100% all. And indeed, if you’d add up all the different columns of that spreadsheet, you have derived new data. Put it in a new tab (new chart etc.) and you have another base for a next base etc. Exactly as you propose it …
But it is a server which runs your strategy. Not your screen or your PC. That server knows nothing of your charts (hence derived data from the broker). It only has that strategy code as how you gave it. And it runs it … It does nothing else.
ALL you see on your screen is derived data. FYI : it contains 1000s (I am serious) of flaws and miscalculations, because that data is redundant indeed. It may tell you that you are losing 20K instead of breaking even (want to have some screenshots of that ? haha, better not). This is all because the broker systems (which rule) are a. quite complex and b. unknown to PRT development. Development can only think logically and guess how situations will be.
FYI again : your Statement (be that from IG or IB or elsewhere) comes from them (thus the broker) indeed. This is because PRT does not know this. No database for that.
By the time you start to believe me, let me know. 🙂
What would be possible, is doing / achieving what you want in backtest or forward testing. Why ? well, because at that moment your charts are open. Indeed your portfolio data can be read from the screen. But once you hand the Strategy to the server, nothing will communicate with your screens any more.
Btw, I am not saying it can’t be made. But forget the “being easy”.04/02/2022 at 5:01 PM #191069
Apologies, just realised my initial post simply talked about account balance. I’m basically looking for a tool that will stop all systems based on equity gain or loss for the trading period I have my systems set to trade. Maybe my the above explains better?04/02/2022 at 5:12 PM #191071
Fair enough, and thank you for the feedback. I’m just a bit perplexed having used a few EA’s on MT4 that do what I’m describing, different syntax and code, but running off the same broker server? So you would not rely on total sum of latent gains on running systems to be used as a tool to stop trading, bank profit or stop loss?04/02/2022 at 8:03 PM #191083
So you would not rely on total sum of latent gains
I do what you describe above by keepng an eye on attached, both when I am near my screen and via the IG mobile App when I away from home etc.
I know you want all above automatic via code, but thought I’d mention it anyway.
You must be logged in to access attached files.04/03/2022 at 12:07 PM #191102
this is the code i mentioned. Can be used to stop the system if it falls a certain % from max equity. Here it’s set to 35% but can be anything you want.
To my mind this makes more sense, as it seems unlikely that all your systems will fail at the same time, so maybe better to only stop the ones that are losing.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354Capital = 10000MinSize = 1 //The minimum position size allowed for the instrument.MM1stType = 0 //Starting type of moneymanagement. Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.MM2ndType = 1 //Type of money management to switch to after TradesQtyForSwitch number of trades and ProfitNeededForSwitch profit has occurredTradesQtyForSwitch = 50 //Quantity of trades required before switching to second money management choice.ProfitNeededForSwitch = 3 //% profit needed before allowing a money management type change to MM2ndType.DrawdownNeededToSwitch = 10 //% draw down from max equity needed before money management type is changed back to MM1stType.DrawdownNeededToQuit = 35 //% draw down from max equity needed to stop strategyOnce MoneyManagement = MM1stTypeEquity = Capital + StrategyProfitmaxequity = max(equity,maxequity)if equity < maxequity * (1 - (DrawdownNeededToSwitch/100)) thenenoughtrades = 0tradecount = 0moneymanagement = MM1stTypeendifif equity < maxequity * (1 - (DrawdownNeededToQuit/100)) thenquitendifif not EnoughTrades thenif abs(countofposition) > abs(countofposition) thentradecount = tradecount + 1endifif tradecount > TradesQtyForSwitch and maxequity >= Capital * (1 + (ProfitNeededForSwitch/100)) thenEnoughTrades = 1MoneyManagement = MM2ndTypeendifendifIF MoneyManagement = 1 THENPositionSize = Max(MinSize, Equity * (MinSize/Capital))ENDIFIF MoneyManagement = 2 THENPositionSize = Max(LastSize, Equity * (MinSize/Capital))LastSize = PositionSizeENDIFIF MoneyManagement <> 1 and MoneyManagement <> 2 THENPositionSize = MinSizeENDIFPositionSize = Round(PositionSize*100)PositionSize = PositionSize/100// Size of POSITIONSPositionSizeLong = 1 * positionsizePositionSizeShort = 1 * positionsize04/03/2022 at 12:27 PM #191103