CODE TO CLOSE ALL TRADES BASED ON EQUITY OR PORTFOLIO VALUE

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #191010 quote
    Gibbo04
    Participant
    New

    Hi Everyone,

    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.

    Thanks,

    Andy

    boup09 thanked this post
    #191012 quote
    PeterSt
    Participant
    Master

    Hi Andy, – Sadly No, not possible. But I counted … you just asked the most asked question of all. So if ProRealTime listens …

    Kind regards and welcome !
    Peter

    #191033 quote
    GraHal
    Participant
    Master

    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 …

    https://www.prorealtime.com/en/contact?suggestion=1

    boup09 thanked this post
    #191047 quote
    Gibbo04
    Participant
    New

    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.

    #191050 quote
    PeterSt
    Participant
    Master

    But do notice that the server which runs your strategy, doesn’t know anything about your charts. It doesn’t deal with your portfolio value as well (the broker does).
    In other words : this is not so easy as we hope it could be.

    #191053 quote
    nonetheless
    Participant
    Master

    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.

    Gibbo04 thanked this post
    #191059 quote
    Gibbo04
    Participant
    New

    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??

    #191068 quote
    PeterSt
    Participant
    Master

    I’m no computer programmer,

    That’s the thing – haha.

    So No;
    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. 🙂

    [hr]

    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”.

    #191069 quote
    Gibbo04
    Participant
    New

    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?

    #191071 quote
    Gibbo04
    Participant
    New

    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?

    #191083 quote
    GraHal
    Participant
    Master

    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.

    Gibbo04 thanked this post
    Gibbo.jpg Gibbo.jpg
    #191102 quote
    nonetheless
    Participant
    Master

    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.

    Capital = 10000
    MinSize = 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 occurred
    TradesQtyForSwitch = 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 strategy
     
    Once MoneyManagement = MM1stType
     
    Equity = Capital + StrategyProfit
    maxequity = max(equity,maxequity)
     
    if equity < maxequity * (1 - (DrawdownNeededToSwitch/100)) then
    enoughtrades = 0
    tradecount = 0
    moneymanagement = MM1stType
    endif
     
    if equity < maxequity * (1 - (DrawdownNeededToQuit/100)) then
    quit
    endif
     
    if not EnoughTrades then
    if abs(countofposition) > abs(countofposition[1]) then
    tradecount = tradecount + 1
    endif
    if tradecount > TradesQtyForSwitch and maxequity >= Capital * (1 + (ProfitNeededForSwitch/100)) then
    EnoughTrades = 1
    MoneyManagement = MM2ndType
    endif
    endif
     
    IF MoneyManagement = 1 THEN
    PositionSize = Max(MinSize, Equity * (MinSize/Capital))
    ENDIF
     
    IF MoneyManagement = 2 THEN
    PositionSize = Max(LastSize, Equity * (MinSize/Capital))
    LastSize = PositionSize
    ENDIF
     
    IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
    PositionSize = MinSize
    ENDIF
     
    PositionSize = Round(PositionSize*100)
    PositionSize = PositionSize/100
     
     
    // Size of POSITIONS
    PositionSizeLong = 1 * positionsize
    PositionSizeShort = 1 * positionsize
    GraHal, Midlanddave and Gibbo04 thanked this post
    #191103 quote
    GraHal
    Participant
    Master

    Link to above code added as Log 316 here …

    Snippet Link Library

    #218019 quote
    boup09
    Participant
    New

    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 …

    https://www.prorealtime.com/en/contact?suggestion=1

    IG is also offered in MetaTrader4 where the account equity function is available. So clearly the issue is not from IG side.

    https://docs.mql4.com/account/accountequity

    Being able to set money management and control risk based on overall account equity/balance is VIP.

    I have written to PRT as suggestion but no reply

    GraHal thanked this post
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.

CODE TO CLOSE ALL TRADES BASED ON EQUITY OR PORTFOLIO VALUE


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Gibbo04 @gibbo04 Participant
Summary

This topic contains 13 replies,
has 5 voices, and was last updated by boup09
2 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/01/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...