Another hedging question

Forums ProRealTime English forum ProOrder support Another hedging question

Viewing 15 posts - 1 through 15 (of 17 total)
  • #219822
    kt

    Hi Experts,

    I need some help to figure out a hedging coding with a snippet stated below. I reckon the code below should exit with a win, or it’ll never exit the positions “forever…”, but the a backtesting showed losing trades which I couldn’t figure out why.   The closest lead that I suspect is the “positionprice” with respect to the long AND short position has messed thing up? if so, any suggestion to fix the code?  Thanks!!

    // Define a positivegain value, of course this value can be a small loss in real life.  Sensibility aside 🙂   just making it positive here for validating a hedging

    if longonmarket and not shortonmarket then
    positivegain = close – positionprice > pointvalue * 10
    elsif shortonmarket and not longonmarket then
    positivegain = positionprice – close > pointvalue * 10
    elsif shortonmarket and longonmarket then
    positivegain = abs(close – positionprice) > pointsize    // Tried a variation of: positionperf > pointsize, didn’t work
    endif

    // A branch of entry criteria that can buy and sell the position which are omitted here as it doesn’t matter to the inquiry

    // Exit condition

    if longonmarket and shortonmarket then   // — this backtest generated losing trades… 🙁
    if positivegain then
    sell at market
    if shortonmarket then
    exitshort at market
    endif
    endif
    endif

    // This variation #1 did not work either, same backtest result as above

    if longonmarket and shortonmarket then
    if positivegain then
    sell at market
    exitshort at market
    endif
    endif

    // This variation #2 did not work either, same backtest result as above

    if longonmarket and shortonmarket then
    if positivegain then
    sell at market
    endif
    exitshort at market
    endif

     

    // some more codes to show a long Or a short position exit strategy for completeness. Don’t think these codes affected the long And short positions criteria above.

    if longonmarket and not shortonmarket then
    if positivegain then
    sell at market
    endif
    endif

    if not longonmarket and shortonmarket then
    if positivegain then
    exitshort at market
    endif
    endif

    #219837

    If you ask me you can’t be both Long and Short at the same time within one AutoTrading System. And assumed I am correct, now 75% of your code fails.

    That would never be True.

    #219838
    JS

    Hi,

    As far as I know Back testing cannot handle hedging i.e., a long and short position at the same time is not possible in Back testing…

    #219840
    JS

    It is possible in an “Auto Trading System” (Force Opening) but you cannot back test that system…

    #219844

    Hi Jaap – can you show that somehow ? (by screenshots from Live and please not by theories because theories seem never to work out regarding this aspect of ForceOpen).
    Keep in mind, this would be about one and the same instance of a code (because it is about PositionPerf and such).

     

    #219851
    kt

    hi Peter, Aha, so the concurrent long and short trades will never be True in this case. If there are “longpositionperf/long tradeprice/ect and “shortpositionperf” that would be different story..  Thanks.

    I don’t think there are alternatives 🙁  As i researched two systems cannot track each other.

    #219852
    kt

    unless i can figure out a l0ngposition system that “presumes” a losing short exists by looking back at the bars with a Loop. e.g. i split the codes to two systems, one for long without the sellshort and one for short without the buy. and put placeholder for these arbitrary trades. sound crazy but this should work, or not?

    #219854

    Well… it should work, but keep in mind that LIVE trades not always are entered as they do in backtests. So your check cannot be 100% accurate.

     

    #219875

    sound crazy but this should work, or not?

    What Roberto said, but *that* would not be the real problem (I would be more than fine with that). But the Placeholder thing has been something that I never dared to start off with; it would be too complicated plus many things would have to be revamped (for how we think), starting with If OnMarket would need to be If VirtualOnMarket1 (and 2 if you want) and then … systems get killed by environmental circumstances, and you wouldn’t know how to restart all.

    Fact is that with 2 (or a max of 120) systems you could do a few things. It’s a matter of sitting back and think over (be creative) how you can exploit that and achieve what you want after all.

    1 user thanked author for this post.
    #219892
    kt

    Thanks for the guidances and great insight! Robert and Peter

    May I pose another question: Does the auto trading system retain the position state (which could potentially be costly in terms of system architecture), or does it simply run the system repeatedly while querying the currently open positions from the broker? The reason I’m inquiring is that I’ve contemplated running one system for regular trading and another to monitor open positions, ready to step in for hedging when necessary. Of course, I’d need to think through this carefully to ensure that the entry and exit conditions in both systems don’t overlap 

    I recall a previous instance where I ran two systems on a currency pair, and they did influence each other? e.g., both systems had a if OnMarket to trigger condition, i was under the impression that when the 1st system entered the market, the 2nd system picked it up somehow and fulfilled the action based on its own if OnMarket=True action, I halted one of the systems to reduce trading uncertainties due to my lack of understanding (or I did see it wrong?)

    And as I observed, the two systems seemed to generate their own individual gains by looking at the PRT trading board, and I’m puzzled about how exactly they were able to track their positions distinctly if two system queried the position from the broker.

    I hope the inquiry make sense.

    #219898

    Yes, that makes sense !

    I only know this from Interactive Brokers – where hedging is explicitly not allowed with AutoTrading, not even with two different systems – and where your own position is always dealt with first. This is just a broker thing and thinking of it, it makes sense. Regarding this there’s also an important thing to remember : it may happen in short squeezes that you can’t get rid of your Short position while you were obviously so smart to hedge that with a long position. Mind you, with IB this is thus not possible (also not outside of AutoTrading) unless to do it with two of your accounts (that would work for AutoTrading just the same – just saying). However, IB binds your accounts and know it is you in both cases. Now, only if you get rid of your Long, your Short will be allowed to exit (it is too early in the morning here to reason out the flow, but I recall it is all “logic”). Anyway, you provide the pieces for your Short in that situation (this is about Stocks).

     

    Does the auto trading system retain the position state (which could potentially be costly in terms of system architecture), or does it simply run the system repeatedly while querying the currently open positions from the broker?

    The latter;
    Once you know about it, you can see-through many redundancies which PRT keeps tracks of on the side line (this is when observing the charts), which are NOT being dealt with redundantly with AutoTrading. Sorry for the bit of a difficult sentence, but you first need to know about the charts and lists, to know that server-side it does not work like that. Watch out though, because you could be working with PRT’s API for IB (in Australia) and then things are different. But readily you will have the real means at hand : observe all in IB’s TWS and you will see the truth.

    PRT’s charts work like a kind of spreadsheet, with some main figures derived once in a while, the remainder calculated. Good example is Daily Profit. This does not come from Broker’s data but from that “spreadsheet”.  And if one figure is off, the daily profit is also off.

    Server side, the internal API in there (talking to the broker (IB or IG)) queries the current results always. But, don’t ask me whether this is cached by PRT at some level – I don’t think so because it would be too dangerous. In any event the queries exist and they are there to be used (I worked with IB’s API myself – I mean, as a native language element within C++).

     

    And as I observed, the two systems seemed to generate their own individual gains by looking at the PRT trading board, and I’m puzzled about how exactly they were able to track their positions distinctly if two system queried the position from the broker.

    I am sure I did not answer that thoroughly, but I hope you can pose the question/suggestion better now ?

    1 user thanked author for this post.
    #219901
    kt

    Hi Peter, Thank you for shedding light on the intricacies of ‘easy to understand (, quite the opposite instead)” systems that work tirelessly behind the scenes. I was naive enough to believe it was a straightforward systems interaction, but now I realize the complexity involved. I’ll definitely reconsider my approach to multiple systems, as it’s either a path to real trading success or a quick route to financial ruin in pursuit of the elusive holy grail of hedging by experimenting with real trades.

    Fyi, (so that you know I don’t enquire without a reason) I’m currently operating a trend-following system with simplicity through straightforward entry rules (keep it simple). but I have incorporated 5-6 partial/full exit conditions, and am developing a hedging strategy. This includes devising methods to exit positions during sideways trend. (Would be good if you/anyone has came across great ideas on exiting a losing trade with minimal damage while i’m working on it.  (And yes, I didn’t mention hedge anymore .. )

    My primary goal is to maintain a delicate balance between risk and reward. In my trading and just me, the exit codes are more complicated than the entry 🙂

    #219902
    kt

    And this would be my last question (about the sideway exit strategy, if anyone), else I’ll writing a book which I shouldn’t for one post in the forum.

    #219914

    I would urge you to keep on asking. People like me learn from forming the answers (especially in writing them).

    I full-heartedly agree that the Exit is way more difficult than the Entry. 🤣
    My solution for that became this (at least for the past months – more solutions the upcoming months) :

    Make a coherent system of going too long in the wrong direction. Below you see this happening, no matter this trade won (this is from 2 hours ago). N.b.: White and pink is backtest (forward in this case), green and red is Live.

    If you closely watch the white “average” line, you can see that it consistently dropped because the trade decided to Exit – unlike prior slopes which were more bumpy and which were still given a chance. Of course in this case it should have stayed in, but if we knew all in advance … 😉
    This is golden for when being in a loss. So the same mechanism operates there (originally it was made for being in a loss) and it wildly causes the losses to be minimal (for $). Btw this is for Forex and for Futures this would not work out well.

    In the second screenshot you see it at work for being in a loss, knowing that this implied less than half of the SL because the “market” does not allow to let it get there (the drop is too consistent). Of course there too the decision seemed wrong, but in the end not on the longer term (that’s why I show some to the right of the happening). This was last Friday.


    Here’s a strange hint :

    When working with systems which hedge (which in my case happens more coincidentally but also continuously), mentally you always win. You (at least me) will always be happy with the winning trade and don’t care about the losing trade because you also have the winning trade. In the 3rd screenshot you see another kind of example of this happening:
    So the first screenshot showed EUR/USD and it exited and a few minutes later it should make me sad because it had better stayed in. However, the 3rd screenshot shows another account with a slightly different System, but on the same instrument – EUR/USD. That one stayed in, and I am happy hence not sad at all.
    *Because* that system is still in … when things go against that situation, the other – which is not in at this moment, will (or should go) in that other direction (Short in this case). And now all is hedging each other with as a bonus that two systems will be in the winning mood (the 3rd screenshot will go out with profit and the 1st will start in a winning mood).

    You would say this is all coincidence, but this is not really so. It *is* what I meant with “sit back and be creative” (did I say that in this topic ?), because you can really make mechanisms which work out for you, even if half is losing. Key is to have winning systems in the first place or else nothing works out.
    In the end of the day it is about your mood because you always saw things in your favour. The negatives are diminished with that.

    2 users thanked author for this post.
    #219941
    kt

    Thanks! Peter

    I like your hedge approach that aligns with a broader theme of maintaining a positive mindset in trading. The examples with screenshots illustrate how this multiple system concept works in practice that can lead to an overall positive mood and potentially better trading results!

    1 user thanked author for this post.
Viewing 15 posts - 1 through 15 (of 17 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login