Welcome to the Traders Laboratory.

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

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

Join Date: Oct 2006
Posts: 4
Ignore this user

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 ;
jmi88 is offline  
Reply With Quote
Old 06-20-2007, 07:34 PM   #2
ant

ant's Avatar

Join Date: Sep 2006
Location: USA
Posts: 424
Ignore this user

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.
ant is offline  
Reply With Quote

Reply

Tags
buytocover, sess1endtime

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to start trading FOREX with $1000? 1time Forex Trading Laboratory 96 02-22-2010 10:27 AM
How did I start my future trade? Weryfalloffdown Beginners Forum 25 01-19-2009 10:40 AM
if you had to start over... darthtrader Beginners Forum 38 12-20-2008 01:22 PM
Newbie looking to start trading creso Beginners Forum 18 09-07-2006 11:56 AM

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