Need help with GetOrderInfo

Examples step by step how to make your own automated strategy or user indicator
Message
Author
Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Need help with GetOrderInfo

#1 Postby Lonesome » Sun Apr 16, 2017 8:01 am

Below is a simple EA that executes a buy order when none exist with a user defined stop loss and take profit.
In this EA I build in a GetOrderInfo function to get the OpenPrice of the placed order.
Subsequently the OpenPrice will be displayed in a popup window.
This EA is only for figuring out how to script the GetOrderFunction.

Is this EA I get the error message: [dcc32 Error] Test.dpr(77): E2033 Types of actual and formal var parameters must be identical.
Clearly the GetOrderInfo function is not set up properly.
Please somebody help with implementing the GetOrderInfo function correctly.

Code: Select all

library Test;

uses
  SysUtils,
  StrategyInterfaceUnit,
  DateUtils,
  Windows,
  Math;

var
  LastTime: TDateTime;
  Timeframe: integer;
  OrderHandle: integer;
  SymbolName: PAnsiChar = nil;
  lot: double = 1;
  TakeProfit: integer = 10000;
  StopLoss: integer = 2650;
  x:integer = 0;

  OpenPrice:integer;
  Oprice: double;

{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
  // set strategy name and description
  StrategyShortName('GetOrderInfo check');
  StrategyDescription('EA to figure out how to script GetOrderInfo');

  // register parameters
  AddSeparator('Trade settings');
  RegOption('Symbol', ot_Currency, SymbolName);
  ReplaceStr(SymbolName, 'USDJPY');
  RegOption('Lot', lot, 1, 0.1, 10);
  RegOption('Take Profit', TakeProfit, 1, 100000);
  RegOption('Stop Loss', StopLoss, 1, 100000);
  RegOption('Timeframe', ot_TimeFrame, Timeframe);
  Timeframe := PERIOD_H4;

end;

{-----Done strategy---------------------------------------------------------}
procedure DoneStrategy; stdcall;

begin
  FreeMem(SymbolName);
end;

{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;

begin
  LastTime := 0;    // reset options before new test
end;

{-----Code Testing Popup Window--------------------------------------------}
procedure TestWindow;
begin
  if (x = 0) then
    begin
      x := x + 1;
      MessageBox(0, PChar('Open price: '+FloatToStr(Oprice)),PChar('Test Window'), MB_OK);
    end;
end;

{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
begin

  SetCurrencyAndTimeFrame(SymbolName, Timeframe);

  if (OrdersTotal = 0) then
    begin
      SendInstantOrder(SymbolName, op_Buy, Lot, Ask - StopLoss*Point, Ask + TakeProfit*Point, '', 1, OrderHandle);
    end;

  GetOrderInfo(OrderHandle, OpenPrice);
  Oprice := OpenPrice;
  TestWindow;

end;

exports

      InitStrategy,
      DoneStrategy,
      ResetStrategy,
      GetSingleTick;

Begin

end.
Last edited by Lonesome on Fri Apr 21, 2017 7:03 pm, edited 2 times in total.

User avatar
neHcioHep
Posts: 18
Joined: Sat Nov 21, 2009 5:49 pm
Contact:

Re: Need help with GetOrderInfo

#2 Postby neHcioHep » Fri Apr 28, 2017 2:42 am

To GetOrderInfo you should set a variable with type TTradePosition, and then you can get info about the order.
That how you can do this in your case

Code: Select all

procedure GetSingleTick; stdcall;
var orderInfo : TTradePosition;
begin

  SetCurrencyAndTimeFrame(SymbolName, Timeframe);

  if (OrdersTotal = 0) then
    begin
      SendInstantOrder(SymbolName, op_Buy, Lot, Ask - StopLoss*Point, Ask + TakeProfit*Point, '', 1, OrderHandle);
    end;

  GetOrderInfo(OrderHandle, orderInfo);
  Oprice := orderInfo.OpenPrice;
  TestWindow;

end;

Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Re: Need help with GetOrderInfo

#3 Postby Lonesome » Sun Apr 30, 2017 11:12 pm

aha, understood. Thank you for the explanation.


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 11 guests