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!!!
Lesson 3 Multiple orders questions
- neHcioHep
- Posts: 18
- Joined: Sat Nov 21, 2009 5:49 pm
- Contact:
Re: Lesson 3 Multiple orders questions
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.
-
- Posts: 3
- Joined: Tue May 13, 2014 11:53 pm
Re: Lesson 3 Multiple orders questions
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?
Do you know what sort of rule I could add? Is there a way to say only open 1 position at 8:00?
- neHcioHep
- Posts: 18
- Joined: Sat Nov 21, 2009 5:49 pm
- Contact:
Re: Lesson 3 Multiple orders questions
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
-
- Posts: 3
- Joined: Tue May 13, 2014 11:53 pm
Re: Lesson 3 Multiple orders questions
Thank you so much!!!
Return to “Programming lessons”
Who is online
Users browsing this forum: No registered users and 18 guests