My First Strategy Attempt

How to create strategies and indicators
Message
Author
patronus
Posts: 8
Joined: Tue Apr 15, 2008 4:31 pm
Location: Sacramento CA

My First Strategy Attempt

#1 Postby patronus » Sat May 03, 2008 10:32 am

I've created a couple of indicators by plagerizing existing indicators. I would like to create a strategy that would only be run at close of a bar let's say for the hour or 15min chart. Specifically I'm looking to play off of the weekend gap to trigger my trade. What if statement would I need to make sure my code only runs at the close of a bar?

Thanks...Dave

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

Re: My First Strategy Attempt

#2 Postby Terranin » Sat May 03, 2008 2:08 pm

patronus wrote:I've created a couple of indicators by plagerizing existing indicators. I would like to create a strategy that would only be run at close of a bar let's say for the hour or 15min chart. Specifically I'm looking to play off of the weekend gap to trigger my trade. What if statement would I need to make sure my code only runs at the close of a bar?

Thanks...Dave


You need to set timeframe first

SetCurrencyAndTimeframe('EURUSD', PERIOD_M15);

also you need to have some global variable that will keep your previous time

var
PrevTime: TDateTime;

do not forget to initialize it in ResetStrategy procedure
then you need to write some code:

Code: Select all

if Time(0) <> PrevTime then
  begin
    PrevTime := Time(0);
    ... // here it is new bar appears
  end;


Here we caught the event when new bar just appears with different time mark. So if you want to work with a bar that was closed you should use index = 1.
Hasta la vista
Mike

patronus
Posts: 8
Joined: Tue Apr 15, 2008 4:31 pm
Location: Sacramento CA

#3 Postby patronus » Sun May 04, 2008 10:33 pm

Thanks for all the help you're great!


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 10 guests