Hello Developers
I need to Build an Expert advisor which does hedging using buy stop and sell stop orders on any pairs with respective conditions below.
So this Ea opens order at high and low of candles (green/red any doesn't matter) at any timeframe given to ea.
Assume account size 200 dollar
So for eg Gbpusd 1hr candle has a high of 1.41103 and low of 1.40904
difference in H and L = 199 points.
1. Ea makes Buy stop at 1.41103 and a sell stop 1.40904 after candle closes.
2. For eg market triggers sell stop at 1.40904
so Ea should divide difference of h and l by the number given manually
For eg i give divide by 10 = 199/10 = 19.9 points / 20 point
division should be manual in input settings where i can select divide h and l difference by 5/6/7/8/9...20..
risk per trade plays crucial role here because on that ea selects lot size lets assume i select 0.5% risk per trade so 1 dollar max risk on a single trade.
so 199/10 = 20 points + broker commission + spreads = 20*0.03 + 0.05*3(commission of 0.01lot is 0.05 could vary according to broker pair) + 2*3 ( 2point is spread can vary from pair to pair)
EA should recognise the Commission and average spread of that pair.
Total points = 20+5+2 ( difference/10 + commission points + spread points) = 27
risk per trade = 0.5% or 1 dollar
so 27*0.03(lot) = 0.81 nearest below. ( 0.03 lot selected because of being nearest to risk per trade )
imp - lot size can vary depending on points which calculates risk per trade.
So now continuing the process when sell stop at 1.40904 trigger with 1.40931 as stop-loss there must be a buy stop at 1.40931 as this is hedging concept. (1.40904+27=1.40931)
and , tp = 199 points / size of the candle * 1
tp should be manual given size of candle * 1 so 199 points if i select *2 = 199*2 = 398 points if i select more * likewise multiplying the size of candle.
So for buy stop at 1.40931 tp is 1.41130 and for sell stop at 1.40904 target price is 1.40705 (selected size of candle * 1 )
opening of sell stop and buy stop must be in loop till it target gets hit
means if sell stop hits sl buy stop opens if buy stop hits sl, sell stop opens and so on continuing till it target gets hit.
When target gets hit for eg buy stop at 1.40931 hits it target at 1.41130 its corresponded sell stop pending order at 1.40904 should also close automatically like a pair it should close once target hits.
This process must start/carry out at every candles high and low appearing depending upon the timeframe after ea starts.
Manual - TF = 15m/30m/1hr/2hr/3hr....
Division of candle size = (5/6/7....)
Risk per Trade = (0.1%/0.2%....)
Tp = Size of candle * (1/2/3...)