I am back testing a strategy where I am buying a commodity in one exchange and selling the same in the other and can physically settle it. Thus, I don’t need to reverse my open positions. How can I do that in Amibroker?
I have created the spread charts between the pricing of the same commodity between the 2 exchanges. Able to generate long and short signals, but stuck on the settlement part as I don’t need to reverse my open positions. The open positions can be closed in a min or sometimes within 15 mins but not more than that. Can there be an option that I can close it in the same candle or the next candle?
Even if I am able to reverse the open positions at 0 price, that will also work. i.e. I buy at 100 but sell at 0. Short at 100 and cover at 0.
@abhaykhanna, I am assuming that your database contains two symbols for each commodity, one for each exchange. The way I would do this would be to open a transaction as usual (either Buy or Short) using the symbol for the first exchange, and then close the transaction using Sell or Cover on the same symbol but with the SellPrice / CoverPrice set to the price from the symbol on the second exchange. You may need to turn off AmiBroker Price Bound Checking for this to work correctly.
Buy Symbol 1, sell Symbol 2 if Symbol1>Symbol2 and netclosedifference >0 (and vice-versa if Symbol2>Symbol1 and netclosediffernce > 0) - Not working for me
If Symbol1 is long and Symbol2 is short then they both should square off at price 0 automatically after 15 mins. I can use ApplyStop( stopTypeNBar, stopModeBars, 15 ) to auto square off after 15 mins but not able to set the price to 0.
_N( Symbol1= ParamStr("Symbol1", "abc") );
SetForeign( Symbol1 ); // Symbol 1 default set to abc
C1 = C;
H1 = H;
L1 = L;
O1 = O;
V1 = V;
RestorePriceArrays();
_N( Symbol2= ParamStr("Symbol2", "xyz") );
SetForeign( Symbol2 ); // Symbol 2 default set to xyz
C2 = C;
H2 = H;
L2 = L;
O2 = O;
V2 = V;
RestorePriceArrays();
Fees1 = Param("Fees1 in $",0.15,0,2,0,0.01); // Default set to $0.15
Fees2 = Param("Fees2 in %",0.2,0,1,0.01); // Default set to 0.2%
Fees3= Param("Fees3 in %",0,0,1,0.01); // Default set to 0%
netCloseDifference [0] = 0;
for (i = 1; i < BarCount; i++)
{
if ((C1[i] > 0) AND (C2[i] > 0) AND (C1[i] > C2[i]))
{
netCloseDifference[i] = Max(((c1[i]-c2[i])- (Fees1/100 * C2[i]) - (Fees2/100 * C1[i]) - (Fees2/100 * C2[i]) - (Fees3/365 * C1[i])),0);
}
else
if ((C1[i] > 0) AND (C2[i] > 0) AND (C2[i] > C1[i]))
{
netCloseDifference[i] = -1 * Max(((c2[i]-c1[i])- (Fees1/100 * C1[i]) - (Fees2/100 * C2[i]) - (Fees2/100 * C1[i]) - (Fees3/365 * C2[i])),0);
}
else
{
netCloseDifference[i] = 0;
}
}
Plot(netCloseDifference,"Net Close Difference",colorAqua, styleThick);
EntrySignal = netCloseDifference > 0;
ShortSignal = netCloseDifference <0;
SellSignal = netCloseDifference == 0;
CoverSignal = netCloseDifference == 0;
if( Name() == Symbol1 )
{
Buy = EntrySignal;
Sell = SellSignal;
Short= ShortSignal;
Cover = CoverSignal;
}
if( Name() == Symbol2 )
{
Short = EntrySignal;
Cover = SellSignal;
Buy = ShortSignal;
Sell = CoverSignal;
}