The order execution strategy will bring together the results of the other indicators being programmed by Pedro (Pete). Globalvariable values will be stored in each of these "modules" for calculation of position size, ranking of weak and strong stocks to produce a basket of each and buy/sell signals resulting from MLT cycle analysis.
Here is the start of some code that will ultimately glue the whole lot together and generate orders. This is a strategy that will be inserted into the same 1 min $INDU chart as the TT_ENTRY_POINT code.
There are settings within Tradestation that can be ticked on/off to allow the strategy to generate orders and to send them automatically.
AT THIS STAGE DO NOT USE THIS CODE ON A LIVE SYSTEM. ONLY USE IT AGAINST A SIMULATED ACCOUNT
There is a lot more work to be done on this and there is a dependency upon the global variables being generated by other modules, so it is not currently using the global variables but instead using inputs so that some tests can be performed idendently.
I will continue to work on this code, but I thought you might want to see something at this stage in order to feed into the design. I attach an ELD file but also the text for TS2000i users.
Charlton
{This strategy will ultimately receive signals from TT_ENTRYPOINT , TT_POSITION_SIZE and TT_RATE_WEAK_STRONG indicators
using global variables. For the moment these are represented by inputs}
Inputs:
Trigger(" "), //buy/sell trigger from TT_ENTRYPOINT based on cycle analysis
Basket1("IBM"), //this is the first stock in a basket, that will ultimately comprise say, the 5 weakest and 5 strongest stocks
Basket2("DELL"), //this is the second stock in a basket, that will ultimately comprise say, the 5 weakest and 5 strongest
Stop1(0.5), //this could be used for a fixed monetary stop, but has not been used in this script
pos_size(1),//position size will come from TT_POSITION_SIze via a global variable
ATRLENGTH(14), //this illustrates a stop based on ATRs using 14 periods s default
NUMATRS(1.5); //this illustrates that the stop might be set at 1.5 ATRS
VALUE1 = GETPOSITIONQUANTITY(GETSYMBOLNAME, GETACCOUNTID); //Need to know if we have any position open already for symbol and how current holding
{start of outermost loop to loop through each of the 5 (say) stocks. We will have different inputs or global variables for the strong basket
and the weak basket, so more loops wil probably be applid here}
IF GETSYMBOLNAME = Basket1 or value1 > 0 then //checks if current symbol processed is in first basket member or exists in the current portfolio
BEGIN
{start of trigger loop to process if a buy or sell signal received}
SWITCH (Trigger) BEGIN
CASE "BUY":
IF VALUE1 = 0 THEN BEGIN //if there is no open position for the symbol and we have a buy signal create a buy order together with stop
Buy ("LONG BASKET 1") pos_size Contracts next bar at market; //use position size in global variable from TT_POSTIION_SIZE
Sell ("ATR STOP SELL" ) next bar at Close - AvgTrueRange( ATRLength ) * NumATRs stop ;
END;
IF VALUE1 < 0 THEN //if there is an existing short position for symbol then the buy signal generates a buy to cover using existing position size
Buy ("SHORT COVER") VALUE1 Contracts next bar at market;
CASE "SELL":
IF VALUE1 = 0 THEN //if there is no open position for the symbol and we have a sell signal create a short sell order with stop
BEGIN
SELL ("SELL SHORT 1") pos_size Contracts next bar at market;
BUY ("ATR STOP COVER" ) next bar at Close - AvgTrueRange( ATRLength ) * NumATRs stop ;
END;
IF VALUE1 > 0 THEN //if there is an existing long position for symbol then sell that position size
SELL ("SELL") VALUE1 Contracts next bar at market;
{other items to add are conditions for closing 75% of trade and at same time generation of 25% stop order at breakeven + 2 cents profit.
Also need to consider what order types will be used - for the moment market orders are coded in.
Need to look at partly filled/unfilled orders - consider cancellations after x time/bars/ticks}
END;
END;
Here is the start of some code that will ultimately glue the whole lot together and generate orders. This is a strategy that will be inserted into the same 1 min $INDU chart as the TT_ENTRY_POINT code.
There are settings within Tradestation that can be ticked on/off to allow the strategy to generate orders and to send them automatically.
AT THIS STAGE DO NOT USE THIS CODE ON A LIVE SYSTEM. ONLY USE IT AGAINST A SIMULATED ACCOUNT
There is a lot more work to be done on this and there is a dependency upon the global variables being generated by other modules, so it is not currently using the global variables but instead using inputs so that some tests can be performed idendently.
I will continue to work on this code, but I thought you might want to see something at this stage in order to feed into the design. I attach an ELD file but also the text for TS2000i users.
Charlton
{This strategy will ultimately receive signals from TT_ENTRYPOINT , TT_POSITION_SIZE and TT_RATE_WEAK_STRONG indicators
using global variables. For the moment these are represented by inputs}
Inputs:
Trigger(" "), //buy/sell trigger from TT_ENTRYPOINT based on cycle analysis
Basket1("IBM"), //this is the first stock in a basket, that will ultimately comprise say, the 5 weakest and 5 strongest stocks
Basket2("DELL"), //this is the second stock in a basket, that will ultimately comprise say, the 5 weakest and 5 strongest
Stop1(0.5), //this could be used for a fixed monetary stop, but has not been used in this script
pos_size(1),//position size will come from TT_POSITION_SIze via a global variable
ATRLENGTH(14), //this illustrates a stop based on ATRs using 14 periods s default
NUMATRS(1.5); //this illustrates that the stop might be set at 1.5 ATRS
VALUE1 = GETPOSITIONQUANTITY(GETSYMBOLNAME, GETACCOUNTID); //Need to know if we have any position open already for symbol and how current holding
{start of outermost loop to loop through each of the 5 (say) stocks. We will have different inputs or global variables for the strong basket
and the weak basket, so more loops wil probably be applid here}
IF GETSYMBOLNAME = Basket1 or value1 > 0 then //checks if current symbol processed is in first basket member or exists in the current portfolio
BEGIN
{start of trigger loop to process if a buy or sell signal received}
SWITCH (Trigger) BEGIN
CASE "BUY":
IF VALUE1 = 0 THEN BEGIN //if there is no open position for the symbol and we have a buy signal create a buy order together with stop
Buy ("LONG BASKET 1") pos_size Contracts next bar at market; //use position size in global variable from TT_POSTIION_SIZE
Sell ("ATR STOP SELL" ) next bar at Close - AvgTrueRange( ATRLength ) * NumATRs stop ;
END;
IF VALUE1 < 0 THEN //if there is an existing short position for symbol then the buy signal generates a buy to cover using existing position size
Buy ("SHORT COVER") VALUE1 Contracts next bar at market;
CASE "SELL":
IF VALUE1 = 0 THEN //if there is no open position for the symbol and we have a sell signal create a short sell order with stop
BEGIN
SELL ("SELL SHORT 1") pos_size Contracts next bar at market;
BUY ("ATR STOP COVER" ) next bar at Close - AvgTrueRange( ATRLength ) * NumATRs stop ;
END;
IF VALUE1 > 0 THEN //if there is an existing long position for symbol then sell that position size
SELL ("SELL") VALUE1 Contracts next bar at market;
{other items to add are conditions for closing 75% of trade and at same time generation of 25% stop order at breakeven + 2 cents profit.
Also need to consider what order types will be used - for the moment market orders are coded in.
Need to look at partly filled/unfilled orders - consider cancellations after x time/bars/ticks}
END;
END;