Welcome to the Traders Laboratory.

 Coding Forum Collaborate, receive help, or discuss indicators and other coding-related topics

06-20-2007, 10:05 AM   #1

Join Date: Oct 2006
Posts: 4

Thanks: 0
Thanked 1 Time in 1 Post

Start and End Timing?

Im trying to test a system and have it start trading at 8:00am and close any postion at end of day...For example this simple MA cross, how would I put in 'dont take a signal till after 8am' and then 'exit any postion at the close'?

Thanks for any help

Code:
```inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: FastAvg( 0 ), SlowAvg( 0 ) ;

FastAvg = AverageFC( Price, FastLength ) ;
SlowAvg = AverageFC( Price, SlowLength ) ;

if CurrentBar > 1 and FastAvg crosses over SlowAvg then

Buy ( "MA2CrossLE" ) next bar at market ;

if CurrentBar > 1 and FastAvg crosses under SlowAvg then

Sell Short ( "MA2CrossSE" ) next bar at market ;```

06-20-2007, 07:34 PM   #2

Join Date: Sep 2006
Location: USA
Posts: 424

Thanks: 22
Thanked 318 Times in 82 Posts

Re: Start and End Timing?

jmi88, see if this works for you...

Code:
```inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: FastAvg( 0 ), SlowAvg( 0 ) ;

FastAvg = AverageFC( Price, FastLength ) ;
SlowAvg = AverageFC( Price, SlowLength ) ;

if MarketPosition = 0 and Time > 800 and CurrentBar > 1 and FastAvg crosses over SlowAvg then

Buy ( "MA2CrossLE" ) next bar at market ;

if MarketPosition = 0 and Time > 800 and CurrentBar > 1 and FastAvg crosses under SlowAvg then

Sell Short ( "MA2CrossSE" ) next bar at market ;

if MarketPosition > 0 and Time = Sess1EndTime then

Sell ( "MA2CrossLX" ) this bar at close ;

if MarketPosition < 0 and Time = Sess1EndTime then

BuyToCover ( "MA2CrossSX" ) this bar at close ;```
I added the check for MarketPosition so that you only have one position open at a time. You can also hardcode the time instead of using Sess1EndTime.

 Thread Tools Display Modes Help Others By Rating This Thread Linear Mode Help Others By Rating This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 ∧ Similar Threads Thread Thread Starter Forum Replies Last Post 1time Forex Trading Laboratory 96 02-22-2010 10:27 AM Weryfalloffdown Beginners Forum 25 01-19-2009 10:40 AM darthtrader Beginners Forum 38 12-20-2008 01:22 PM creso Beginners Forum 18 09-07-2006 11:56 AM

### Website Terms

All times are GMT -4. The time now is 02:15 PM.
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer