This system Buy 2 contracts when today's close is greater than yesterday's close. If given the opposite condition sold 2 contracts.
has 3 buttons that are configured Start Trading, Trading and Close End Open positions.
Copy and paste in the Formula Editor window
StaticVarGet Autotrading = ("Autotrading");
if (IsNull (Autotrading)) StaticVarSet (Autotrading ", 0);
ATonTrigger = ParamTrigger (" Start Trading Machine "," START ") ;
ParamTrigger AToffTrigger = ("Weekend Trading Machine", "STOP");
if (ATonTrigger) StaticVarSet (Autotrading ", 1);
else if (AToffTrigger) StaticVarSet (Autotrading", 0);
Autotrading = StaticVarGet ("Autotrading");
/ / terms of purchase
Buy = Ref (C, -1)> Ref (C, -2) AND (Autotrading)
if (LastValue (Buy)) {
Avulsion
GetTradingInterface ibc = ("IB");
/ / check that
ok if (ibc.IsConnected ()) {
/ / comrobamos no
positions if (ibc.GetPositionSize (Name ()) {< 0 )
/ / / / retrieve orderID from previous run, will be empty if no order WAS Placed Before StaticVarGetText
OrderID = ("OrderID" + Name ());
/ / launched a market order and transmit
ibc.ModifyOrder OrderID = ( OrderID, Name (), "Buy", 2, "MKT", 0, 0, "Day", True);
StaticVarSetText ("OrderID" + Name (), OrderID);
}}
} / / terms of sale
Sell = Ref (C, -1) < Ref( C, -2 ) AND (AutoTrading);
if (LastValue (Sell)) {
Avulsion GetTradingInterface
ibc = ("IB");
/ / check if this ok
(ibc.IsConnected ()) {
/ / Check that there is an open position
if (ibc.GetPositionSize (Name ())> 0)
{/ / / / retrieve orderID from previous run, will be empty if no order WAS Placed Before StaticVarGetText
OrderID = ("OrderID" + Name ());
/ / launched a market order and transmit
OrderID = ibc.ModifyOrder (OrderID, Name (), "Sell", 2, "MKT", 0, 0, "Day", True);
StaticVarSetText ("OrderID" + Name (), OrderID);
}}}
CerrarTodo = ParamTrigger ("Close all positions "," CLOSE ALL ");
if (CerrarTodo AND autotrading) {
ibc.CloseAllOpenPositions ();
StaticVarSetText (" OrderID}
",""); / / Draw arrows
Plot (Close, "Close", 1, 128);
PlotShapes (IIf (Buy, shapeUpArrow, shapeNone) 5.0, L, -20);
PlotShapes (IIf (Sell, shapeDownArrow, shapeNone), 4.0, H, - 20);
/ / notice if trading is active or not
Title = "\\ n" +
"MODE OF TRADING:" + WriteIf (Autotrading, "ON", "OFF");
IMPORTANT: To make the system work the first order is to launch at market manually.
This system had run for an hour without any problem, this is the capture of all orders made:
Once the system is working to stop and cancel the press position Right-click on the graphic that is inserted the system (in this case below) go to Settings / Cancel All positions.
0 comments:
Post a Comment