Page 1 of 1

Lesson 3 Multiple orders questions

Posted: Wed May 14, 2014 12:02 am
by Randalmi
I am working with lesson 3 using Delphi and I am wondering how to open a order every day at 8:00 weather a previous position from a prior day is still open or not . It will not do this because of line:

(OrdersTotal = 0)

I tried changing it to (OrdersTotal < 100), or (OrdersTotal >1), but then at 8:00 it opens 30 orders for some reason as if for every tick or minute it continues to open a order until the 8:00 hour is over.

Any help is greatly appreciated!!!

Re: Lesson 3 Multiple orders questions

Posted: Wed May 14, 2014 10:10 am
by neHcioHep
Randalmi wrote:I am working with lesson 3 using Delphi and I am wondering how to open a order every day at 8:00 weather a previous position from a prior day is still open or not . It will not do this because of line:

(OrdersTotal = 0)

I tried changing it to (OrdersTotal < 100), or (OrdersTotal >1), but then at 8:00 it opens 30 orders for some reason as if for every tick or minute it continues to open a order until the 8:00 hour is over.

Any help is greatly appreciated!!!


Hello Randalmi,

if you want to change rule for opening orders you also need to change this rule in code, in your case you need remove rule based on orderstotal and add new rule based on last day of opened order.
You can do this in some ways, for example you can remember last day of opened order at once after opening new order.

Re: Lesson 3 Multiple orders questions

Posted: Wed May 14, 2014 10:35 am
by Randalmi
Thanks neHcioHep,

Do you know what sort of rule I could add? Is there a way to say only open 1 position at 8:00?

Re: Lesson 3 Multiple orders questions

Posted: Wed May 14, 2014 3:10 pm
by neHcioHep
Randalmi wrote:Thanks neHcioHep,

Do you know what sort of rule I could add? Is there a way to say only open 1 position at 8:00?


If I understand you correctly then you need to open one trade every day at 8:00.

Please see the modefied example from lesson 3

Code: Select all

library DemoStrategy1;

uses
  SysUtils, DateUtils, StrategyInterfaceUnit, TechnicalFunctions;

var
  lastOpenedOrdersDayOfTheYear : integer;
  Currency: PAnsiChar;

procedure InitStrategy; stdcall;
begin
  StrategyShortName('8 hour orders');
  StrategyDescription('Strategy opens orders at 8 a.m.');

  lastOpenedOrdersDayOfTheYear := 0;
  RegOption('Currency', ot_Currency, Currency);
end;

procedure DoneStrategy; stdcall;
begin
  FreeMem(Currency);
end;

procedure ResetStrategy; stdcall;
begin

end;

procedure GetSingleTick; stdcall;
var
  time: TDateTime;
  OrderHandle: integer;
begin
  if Symbol <> Currency then
    exit;

  time := iTime(Symbol, PERIOD_M1, 0);
  if (HourOf(time) = 8) and  (DayOfTheYear(time) <> lastOpenedOrdersDayOfTheYear) then
    begin
      SendInstantOrder(Symbol, op_Buy, 0.1, Ask - 100*Point, Ask + 50*Point, '', 0, OrderHandle);
      lastOpenedOrdersDayOfTheYear := DayOfTheYear(time);
    end;
end;

exports
  InitStrategy,
  DoneStrategy,
  ResetStrategy,
  GetSingleTick;

end.


In code from lesson was added global variable

Code: Select all

lastOpenedOrdersDayOfTheYear : integer;

also was added checking current day of the year with day of the year from last opened order

Code: Select all

DayOfTheYear(time) <> lastOpenedOrdersDayOfTheYear

also we need set new value to lastOpenedOrdersDayOfTheYear after every opening trade

Re: Lesson 3 Multiple orders questions

Posted: Thu May 15, 2014 11:27 pm
by Randalmi
Thank you so much!!!