How to effectively program the bot to reconize reversals in the market while in a bad trade?

 

Greetings fellow programmers;

I recently have coded a bot to trade XAUUSD and it has a 90% win rate but the few bad trades it does get itself into it seems to hold on to them far too long and it is causing major draw down. How can i effectively show the bot that it is in a bad trade and either either cut the trade loose or possibly hedge(perhaps a martingale system?) it to soften the blow? I really don't know where to being to even start coding the hedging system without it auto destructing the demo account into oblivion. Also it has a trail stop and most trades never actually reach the TP I have set but if i lower the TP anymore it'll make the trail stop useless, I'd like to be able to signal the bot to recognize that it is better to cut the trade while ahead rather than being drawn down to the point where it gets stopped out by the trail stop. Mind you i also don't want the bot cutting the better trades short and not getting decent profits, it's really a double edged sword. Any help would be greatly appreciated.

Thanks

Best regards;

-Colin

Files:
 
  1. Win percentage is only half the equation. Win/loss ratio is the other. Expected profit = W% × $W – L% × $L If you change your stop loss ($L) you change both.

  2. Control your risk. Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk. Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.
    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum 2017.10.10
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum 2018.02.11
                Lot value calculation off by a factor of 100 - MQL5 programming forum 2019.07.19
    4. You must normalize lots properly and check against min and max.
    5. You must also check FreeMargin to avoid stop out

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

  3. Hedging, Same as Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
              Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum 2015.02.11

    Why it won't work: Calculate Loss from Lot Pips - MQL5 programming forum 2017.07.11

 

<Deleted>

Coding 2 bots for well over 12 hours has left me extremely irritated so i suppose i will leave this for another time when i'm not feeling so burnt out and mentally exhausted

<Deleted>
 
Haha... you sound like a .... attacking someone who is actually trying to help you.. based on your screen-shot showing just 20 trades and only 60% modelling quality... you results are worthless
 
Colin Lundrigan:

<Deleted>

Coding 2 bots for well over 12 hours has left me extremely irritated so i suppose i will leave this for another time when i'm not feeling so burnt out and mentally exhausted

<Deleted>

Oh that's what we do everyday and 18 hours is no exception.

I have to buy a new keyboard every other Month because the key's just fall off from the constant banging and then the mouse also becomes jumpy and the scroll wheel starts to go funky i mean you can expect all kind of weird things. 

Welcome to our world.

Reason: