1-day trading strategy close out before close of market

Questions about MultiCharts and user contributed studies.
geoff1983
Posts: 12
Joined: 21 Feb 2016
Has thanked: 2 times

1-day trading strategy close out before close of market

Postby geoff1983 » 21 Feb 2016

Hi,

I am currently running a 1-day strategy that enters and exits based on momentum at the end of the trading day. The challenge is the order goes in when the market closes. Hence, volumes are down and pricing deteriorates so the bid / ask spread is horrible.

I would like to have the strategy run at 3:45pm instead so the order is filled during regular trading hours. Is there an easy way to do this? I can change the indicator charts (data 3 and data 4) to 15min bars, but I only want the strategy to look at 3:45pm every. Hence, I would need to cancel / not have the other data used for the indicator so I can back test at 3:45pm daily.

Below is the code.

Thanks a ton for the help!


inputs:
PriceN( Close data3),
PriceD( Close data4),
Opening_Momentum (0),
Closing_Momentum (0),
LengthF( 1 );

variables:
var0( 0 ),
var1( 0 ),
varN( 0 ),
varD( 0 ),
varF( 0 ),
tradesize(0);

tradesize = (10000 / close);
tradesize = tradesize +(Netprofit/close);

varN = Average( PriceN, LengthF );
varD = Average( PriceD, LengthF );
varF = varN / varD ;


var0 = Momentum( varF, LengthF ) ;
var1 = Momentum( var0, 1 ) ;

condition1 = var0 > Opening_Momentum and var1 > Opening_Momentum ;
condition2 = var0 < Closing_Momentum and var1 < Closing_Momentum ;

if condition1 then
Buy ( "BUY" ) tradesize shares This bar at Close ;

if condition2 then
Sell ( "SELL" ) This bar at Close;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: 1-day trading strategy close out before close of market

Postby TJ » 21 Feb 2016


User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: 1-day trading strategy close out before close of market

Postby TJ » 21 Feb 2016

see post #6, second example
viewtopic.php?f=16&t=10811

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: 1-day trading strategy close out before close of market

Postby tony » 21 Feb 2016

I don't fully understand your question but you can add the following at the start of your script

Code: Select all


If TIME = 1545

Then Begin
This way the script will only run when the bar = 1545, no sooner, no later. Obviously 1345 is based on using 15 minute bars and needs to be converted to the time zone of the instrument traded and your machine. Backtests would only be based on this bar, nothing prior each day.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: 1-day trading strategy close out before close of market

Postby TJ » 21 Feb 2016

I don't fully understand your question ...
Hi,

I am currently running a 1-day strategy...

geoff1983
Posts: 12
Joined: 21 Feb 2016
Has thanked: 2 times

Re: 1-day trading strategy close out before close of market

Postby geoff1983 » 21 Feb 2016

I'll try to clarify. The strategy has a couple steps:

Step 1: Take the average price of data 3 and divide by the average price for data 4. This gives you the "indicator ratio." This happens daily.

Step 2: Take the momentum for the current indicator ratio and compare it to the previous indicator ratio.

Step 3: If the momentum is greater than the "input - opening momentum" (let's call it 0 so it's just negative and positive), then you buy.

Ratio at Monday: -.01 = Hold / no action
Ratio at Tuesday: -.06 = Hold / no action
Ratio at Wednesday: +.04 = Buy ...crosses from negative to posative
Ratio at Thursday: +.02 = Hold
Ratio at Friday: -.01 = Sell ...crosses positve to negative

The tricky part (for me) is that I only want to look at the indicator ratio at 3:45pm for the current day versus the previous ratio at 3:45pm (or close if possible). Based on this, you would buy, sell or hold the Target security (data 1) based off the momentum of the current and previous ratio (ie signal is sent at 3:45 today). The actual market transaction (buy or sell Target security) would happen at the next bar period / next 15 minute period (3:45 to 4:00) or before market close.

Also, per previous advice I added in some descriptive language that hopefully makes the code easier to understand. Thanks again for the help.

Code: Select all

inputs:
PriceN( Close data3), //Price for Numerator
PriceD( Close data4), //Price for Denominator
LengthF( 1 ), //Average Period
Opening_Momentum (0), //Buy Signal
Closing_Momentum (0); //Sell Signal

variables:
var_Numerator( 0 ), //Averege Numerator Price
var_Denominator( 0 ), //Averege Denominator Price
var_Ratio( 0 ), //Indicator Ratio
var_Ratio_Momentum( 0 ), //Indicator Momentum
tradesize(0);


tradesize = (10000 / close);
tradesize = tradesize +(Netprofit/close);


var_Numerator = Average( PriceN, LengthF ) ;
var_Denominator = Average( PriceD, LengthF ) ;
var_Ratio = var_Numerator / var_Denominator ;
var_Ratio_Momentum = Momentum( var_Ratio, LengthF ) ;


condition1 = var_Ratio_Momentum > Opening_Momentum ;
condition2 = var_Ratio_Momentum < Closing_Momentum ;


if condition1 then
Buy ( "BUY" ) tradesize shares next bar at Open ;

if condition2 then
Sell ( "SELL" ) next bar at Open;

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: 1-day trading strategy close out before close of market

Postby tony » 22 Feb 2016

You need to do two things. First, add the line I mentioned prior

Code: Select all

If time = 1545

then begin
This will only calculate at the time you want. Second you need to hold the value each day so you can calculate your ratio.

geoff1983
Posts: 12
Joined: 21 Feb 2016
Has thanked: 2 times

Re: 1-day trading strategy close out before close of market

Postby geoff1983 » 02 Mar 2016

Thanks Tony!


Return to “MultiCharts”