NexusFi: Find Your Edge


Home Menu

 





end of day close


Discussion in MultiCharts

Updated
    1. trending_up 9,264 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582

In regular version of multicharts, what is proper code for close at end of day ?
Will it be based on session time ?

And where are some good study material for multicharts coding ?

thanks


shane


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
White House Drops First Alien Files Today -- Market Says …
Prediction Markets & Event Contracts
South Korea Suspends Bithumb for Six Months Over AML Fai …
Cryptocurrency
Prediction Markets Expiry Day: Trump Eyes War Exit, $230 …
Prediction Markets & Event Contracts
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
UCL Final Kicks Off at Noon ET: PSG at 56.5% as Iran May …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

Shane,

what exactly are you looking for? Code for a signal that closes a trade at the end of the session?

In backtesting you can use "SetExitOnClose". However you need to be aware of it's limitations as it will use the closing price of the session that is market as session end in Quotemanager. In realtime this obviously can't work and it even might skew your backtesting as it will not represent an accurate test (as how often would you get filled at the exact closing tick).

Regards,

ABCTG


Follow me on X Reply With Quote
  #3 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582


Hi

I have not had luck with that code for the reason you stated.

Henry at Multicharts posted the code below at the Multicharts.net forum to overcome the problem and to allow you to set your trading times with a time filter.

I was looking for a similar thing in easylanguage.

thanks

Shane








protected override void CalcBar()
{
double m_Avg = m_AverageFC[0];
if (PublicFunctions.DoubleGreater(Price[0], m_Avg))
{
++m_Counter.Value;
}
else
{
m_Counter.Value = 0;
}
TimeSpan _tStart = new TimeSpan(9, 30, 0);
TimeSpan _tEnd = new TimeSpan(12, 0, 0);

bool _Condition = DateTime.Now.TimeOfDay >= _tStart && DateTime.Now.TimeOfDay <= _tEnd;
if (PublicFunctions.DoubleGreater(Bars.CurrentBar, ConfirmBars)
&& m_Counter.Value == ConfirmBars && _Condition)
{
m_MACrossLE.Send();
}
}



The example above has been provided for Realtime trading:
Code:
bool _Condition = DateTime.Now.TimeOfDay >= _tStart && DateTime.Now.TimeOfDay <= _tEnd;

For Backtesting please use the following code:
Code:
bool _Condition = Bars.TimeValue.TimeOfDay >= _tStart && Bars.TimeValue.TimeOfDay <= _tEnd;


Reply With Quote
  #4 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582

Hi

Nice !
And that has worked for you on both live and backtesting ?

Excellent. Thank you.

That will work on most.

On one of my strategies, I use an indicator for entries into the market. One problem I ran into is that the indicator can get changed with custom session times.
That is why I was hoping to code trading times into the strategy. That way, I can leave the chart on full globex session times so as not to change the indicator.

thanks

shane


Reply With Quote
  #5 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,737 since Jul 2012
Thanks Given: 1,917
Thanks Received: 7,470


shanemcdonald28 View Post
Hi

Nice !
And that has worked for you on both live and backtesting ?

Excellent. Thank you.

That will work on most.

On one of my strategies, I use an indicator for entries into the market. One problem I ran into is that the indicator can get changed with custom session times.
That is why I was hoping to code trading times into the strategy. That way, I can leave the chart on full globex session times so as not to change the indicator.

thanks

shane


Sorry I deleted previous msg, I thought it was off topic...

But setexitonclose, with custom sessions times set to end one minute before actual close, does work in backtest and live.

You are right, having a non-standard session will change your indicators. No easy workaround for that.


Follow me on X Reply With Quote
Thanked by:
  #6 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582

I pasted together some code I found over at Traders Exchange.
Can you guys look it over and see if you see any flaws that may be a problem ?

It seems to work in backtesting, but I hope to get some opinions on it.




inputs: price(Close), jthmaLength( 21), jthmaLength2(84),
startTime(0500), endTime(1600), EnterTradeEndTime(1600),StopTime ( 1500 );
variables: Avg( 0 ), Avg2( 0 ), Avg2Up( false ),
Avg2Dn( false ),MP( 0 ),AvgUp( false ), AvgDn( false );

MP = MarketPosition;
Avg = jthma( price, jthmaLength ) ;
Avg2 = jthma( price, jthmaLength2 );
Avg2Up = Avg2 > Avg2[1];
Avg2Dn = Avg2 < Avg2[1];
AvgUp = Avg[2]> Avg[1] and Avg > Avg[1];
AvgDn = Avg[2]< Avg[1] and Avg < Avg[1];




If Time > startTime and Time < EnterTradeEndTime then begin

if AvgUp and Avg2Up then
Buy ( "jup" ) next bar at market ;

if AvgDn and Avg2Dn then
sell short ( "jdn" ) next bar at market ;
end;


If MP = 1 and AvgDn then sell next bar at market;
If MP = -1 and AvgUp then buy to cover next bar at market;

if time = endtime and MP > 0 then sell this bar on close;
if time = endtime and MP < 0 then buy to cover this bar on close;

If Time > StopTime
Then Sell All Contracts Next Bar At Market


Reply With Quote
  #7 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,737 since Jul 2012
Thanks Given: 1,917
Thanks Received: 7,470


shanemcdonald28 View Post
I pasted together some code I found over at Traders Exchange.
Can you guys look it over and see if you see any flaws that may be a problem ?

It seems to work in backtesting, but I hope to get some opinions on it.




inputs: price(Close), jthmaLength( 21), jthmaLength2(84),
startTime(0500), endTime(1600), EnterTradeEndTime(1600),StopTime ( 1500 );
variables: Avg( 0 ), Avg2( 0 ), Avg2Up( false ),
Avg2Dn( false ),MP( 0 ),AvgUp( false ), AvgDn( false );

MP = MarketPosition;
Avg = jthma( price, jthmaLength ) ;
Avg2 = jthma( price, jthmaLength2 );
Avg2Up = Avg2 > Avg2[1];
Avg2Dn = Avg2 < Avg2[1];
AvgUp = Avg[2]> Avg[1] and Avg > Avg[1];
AvgDn = Avg[2]< Avg[1] and Avg < Avg[1];




If Time > startTime and Time < EnterTradeEndTime then begin

if AvgUp and Avg2Up then
Buy ( "jup" ) next bar at market ;

if AvgDn and Avg2Dn then
sell short ( "jdn" ) next bar at market ;
end;


If MP = 1 and AvgDn then sell next bar at market;
If MP = -1 and AvgUp then buy to cover next bar at market;

if time = endtime and MP > 0 then sell this bar on close;
if time = endtime and MP < 0 then buy to cover this bar on close;

If Time > StopTime
Then Sell All Contracts Next Bar At Market

What instrument, and what size bar are you using?


Follow me on X Reply With Quote
  #8 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582

RB,DAX,TF are the ones it is working good on.
moderate success on GC, CL , NQ , ZB

5, 15, 30 min

as well as .04 % .06 % and .08 % renko bars on 1 min setting

fair success on 10, 15 and 21 point settings

various percent trailing , stop loss, session settings


Reply With Quote
  #9 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,737 since Jul 2012
Thanks Given: 1,917
Thanks Received: 7,470


shanemcdonald28 View Post
RB,DAX,TF are the ones it is working good on.
moderate success on GC, CL , NQ , ZB

5, 15, 30 min

as well as .04 % .06 % and .08 % renko bars on 1 min setting

fair success on 10, 15 and 21 point settings

various percent trailing , stop loss, session settings

The reason I asked: Just be careful that there actually is trading going on after endtime and stoptime. For instance, if last bar of the day is at 1600, then the statement
if time = endtime and MP > 0 then sell this bar on close;

won't work in real time (market will be closed by the time order is sent)...


Follow me on X Reply With Quote
  #10 (permalink)
shanemcdonald28
new york
 
Posts: 355 since Mar 2012
Thanks Given: 665
Thanks Received: 582


Hi

Thanks

I see what you mean.

It does not seem to work on point, range or renko type charts.

I will be using this on futures and want to set close for around 3 pm EST.

For the indexes, I will close around 1 hour before Stock exchange closes , with futures market closing at 5 15 pm for those indexes.

I hope this will get around the problem of closing at session end, which I would like to set separately.

thanks

shane


Reply With Quote




Last Updated on August 31, 2014


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts