Hello,
I use automatic trading with margin account type. unfortunately the purchases often exceed my capital and in my opinion this is dangerous and should be prevented.
-
Some of the options that I have done are asking my broker (IBKR) to turn off the margin feature but still using a margin account (not a cash account), but that doesn't seem possible (please let me know if this is possible).
-
By preventing purchases from the algo If equity = 0, then don't buy again. Maybe by asking for info by using
ibc.GetAccountValue
, The problem is that things like this have to be done in realtime with money and events that are a bit difficult, So I want to ask input from this forum.
How to insert If equity = 0, then don't buy again with ibc.GetAccountValue
if(LastValue(Buy) AND Position==0 AND transmit==1){
Price = LastValue(C);
Position = Max(round(Posisi_1/Harga_Terupdate),1);
orderid = Panggil_IBController.PlaceOrder( Name(), "BUY", Posisi_1 , "MKT", 0, 0, "GTC", Transmit );
StaticVarSet(Symbol + "Shares", Shares, True);
Posisi_Open1 = 1;
StaticVarSet(Symbol + "Posisi_Open1", 1, True);
Trade = Trade+1;
StaticVarSet(Symbol + "Trade",Trade, True);
price = LastValue(C);
StaticVarSet(Symbol + "buyprice",buyprice, True);
}
Thank you for your attention