How can I know what margin is needed before I confirm a trade on ProRealTime?
It is not possible to know this directly in PRT.
IG provide a good description of how to calculate your margin:
https://www.ig.com/uk/learn-to-trade/margin-explained
Although they do not mention there how margin is effected by having stops with your trade.
It should be quite easy to create a simple indicator that calculates your required initial margin and even one that shows your initial margin and maintenance margin as a graph in a back test – I may have a go at doing this later if I find time.
I wrote this indicator that will display current initial margin requirements to open positions with no stop, a non guaranteed stop and a guaranteed stop:
DEFPARAM calculateonlastbars = 1
Size = 1 //Your Trade Size
MarginFactor = 5 //Margin Factor in %
SlippageFactor = 50 //Slippage Factor in %
StopDistance = 100 //Stop Distance in pips
LimitedRiskPremium = 1 //Limited Risk Premium
NoStopMargin =(Size * close) * (MarginFactor / 100)
NoStopMargin = Round(NoStopMargin * 100) / 100
StopMargin = (Min((NoStopMargin * (Slippagefactor / 100)) + (Size * StopDistance),NoStopMargin))
StopMargin = Round(StopMargin * 100) / 100
GStopMargin = (Size * StopDistance) + (Size * LimitedRiskPremium)
GStopMargin = Round(GStopMargin * 100) / 100
DRAWTEXT("No Stop Margin #nostopmargin#",barindex,0,SansSerif,Bold,16)coloured(0,0,255)
DRAWTEXT("Stop Margin #stopmargin#",barindex,-0.5,SansSerif,Bold,16)coloured(0,0,255)
DRAWTEXT("Guaranteed Stop Margin #gstopmargin#",barindex,-1,SansSerif,Bold,16)coloured(0,0,255)
return 0.5,-1.5
The calculations are taken from IG’s information on the charts on their platform.
You will need to put in the correct values for each of the factors involved in the calculation for whichever instrument you apply it to.
I have not found any information yet saying what the values for the Limited Risk Premium used in the guaranteed stops calculation are and IG do not list it in the chart information.
ITF file also attached.
[attachment file=”Margin Calculator.itf”]
[attachment file=78928]
Here is another version. You can enter your buy or sell price of a trade that you have open and your stop price and it will calculate a running margin taking into account any gains or losses (the maintenance margin).
[attachment file=”Total Running Margin.itf”]
DEFPARAM CalculateOnLastBars = 1
BuySell = 1 // 1 = Buy 0 = Sell
Price = 25720 // The Price you bought or sold at
Size = 1 //Quantity bought or sold
StopType = 1 //1 = No Stop 2 = Non G Stop 3 = G Stop
MarginFactor = 5 //Margin Factor in %
SlippageFactor = 50 //Slippage Factor in %
StopPrice = 25800 //Stop Price
LimitedRiskPremium = 1 //Limited Risk Premium
NoStopMargin =(Size * close) * (MarginFactor / 100)
InitialMargin = Round(NoStopMargin * 100) / 100
If StopType = 2 then
StopMargin = (Min((NoStopMargin * (Slippagefactor / 100)) + (Size * (ABS(close - StopPrice))),NoStopMargin))
InitialMargin = Round(StopMargin * 100) / 100
endif
If StopType = 3 then
GStopMargin = (Size * (ABS(close - StopPrice))) + (Size * LimitedRiskPremium)
InitialMargin = Round(GStopMargin * 100) / 100
endif
If BuySell <> 1 then
MaintenanceMargin = (Size * Price) - (Size * close)
else
MaintenanceMargin = (Size * close) - (Size * Price)
endif
TotalMargin = InitialMargin + MaintenanceMargin
DRAWTEXT("Total Running Margin #totalmargin#",barindex,0,SansSerif,Bold,16)coloured(0,0,255)
return 0.5, -0.5
I wrote this snippet that can be added to long only strategies with no stops to graph the maximum margin required in a back test. It could be adapted to short and with stops using the calculations in the indicators but I will let someone else do that as I would never use it!
MarginFactor = 5 //Margin Factor in %
NoStopMargin = (CountOfPosition * low) * (MarginFactor / 100)
InitialMargin = Round(NoStopMargin * 100) / 100
MaintenanceMargin = (CountOfPosition * PositionPrice) - (CountOfPosition * low)
TotalMargin = 0 - (InitialMargin + MaintenanceMargin)
if not onmarket or TotalMargin > 0 then
TotalMargin = 0
endif
Graph TotalMargin
[attachment file=78971]
I think it works correctly but if any one spots a bug or error in it or any of the other codes here then please correct them as none of them have really been tested properly.