Questions about strategy writing

All posts which do not fit into any other sections of the forum.

Moderator: admin

Questions about strategy writing

Postby guangho » Sun Aug 27, 2017 8:16 pm

Hello everyone,I have one questions about strategy writing。。。

The execution command is like this:
function enter(BuySell)
......
valuemap=core.valuemap();
valuemap.Command="CreateOrder";
......
success,msg=terminal:execute(2000,valuemap);
if not(success) then executing=false;
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..msg,instance.bid:date(NOW));
else terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order true"..msg,instance.bid:date(NOW));
end
end

that how to write “function ExtAsyncOperationFinished()”?。。。

First kind:
function ExtAsyncOperationFinished(cookie,success,message)
if cookie==2000 and not(success) then
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..message,instance.bid:date(NOW));
end
end

Second kinds:
function ExtAsyncOperationFinished(id,success,message)
if id==2000 and not(success) then
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..message,instance.bid:date(NOW));
end
end

Questions1:How to write “function ExtAsyncOperationFinished()”?
Questions2:Is the effect of the two writing the same?
Questions3:The “cookie” is Specific time for second?

thank you verymuch!
guangho
 
Posts: 72
Joined: Sat Sep 29, 2012 12:16 pm

Re: Questions about strategy writing

Postby IgorNI » Tue Aug 29, 2017 3:07 am

Hi, guangho

> The “cookie” is Specific time for second?
A cookie is a small string contains user specific data.
A server can send a cookie to a client in HTTP response and gets it from a client in HTTP request.
The cookie allows identifying a user. It can contain any textual information (time, userid or whatever else).

> Is the effect of the two writing the same?
Yes, it is.
Name of function parameters can be changed without any effect.

> How to write “function ExtAsyncOperationFinished()”?
You can find an example here: https://github.com/FXCMAPI/FXCM-API-Off ... rategy.lua
IgorNI
FXCodeBase: Confirmed User
 
Posts: 4
Joined: Tue Aug 08, 2017 10:29 am

Re: Questions about strategy writing

Postby guangho » Wed Aug 30, 2017 4:39 am

IgorNI wrote:Hi, guangho

> The “cookie” is Specific time for second?
A cookie is a small string contains user specific data.
A server can send a cookie to a client in HTTP response and gets it from a client in HTTP request.
The cookie allows identifying a user. It can contain any textual information (time, userid or whatever else).

> Is the effect of the two writing the same?
Yes, it is.
Name of function parameters can be changed without any effect.

> How to write “function ExtAsyncOperationFinished()”?
You can find an example here: https://github.com/FXCMAPI/FXCM-API-Off ... rategy.lua



Thank you for your answer!
I want to add a delay in the “function ExtAsyncOperationFinished()”. How should I write it?
guangho
 
Posts: 72
Joined: Sat Sep 29, 2012 12:16 pm

Re: Questions about strategy writing

Postby IgorNI » Thu Aug 31, 2017 2:34 am

Hi, guangho

> I want to add a delay in the “function ExtAsyncOperationFinished()”
If you do this in the ExtAsyncOperationFinished() then it will freeze thread and UI.
If you need to run some code after a delay, the best option is using a timer.

You can find an example here:
http://www.fxcodebase.com/documents/Ind ... oader.html
IgorNI
FXCodeBase: Confirmed User
 
Posts: 4
Joined: Tue Aug 08, 2017 10:29 am

Re: Questions about strategy writing

Postby guangho » Thu Aug 31, 2017 5:18 am

IgorNI wrote:Hi, guangho

> The “cookie” is Specific time for second?
A cookie is a small string contains user specific data.
A server can send a cookie to a client in HTTP response and gets it from a client in HTTP request.
The cookie allows identifying a user. It can contain any textual information (time, userid or whatever else).

> Is the effect of the two writing the same?
Yes, it is.
Name of function parameters can be changed without any effect.

> How to write “function ExtAsyncOperationFinished()”?
You can find an example here: https://github.com/FXCMAPI/FXCM-API-Off ... rategy.lua


The execution command is like this:
function enter(BuySell)
valuemap=core.valuemap();
valuemap.Command="CreateOrder";
....
success,msg=terminal:execute(2000,valuemap);
if not(success) then executing=false;
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order failed"..msg,instance.bid:date(NOW));
else terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order true"..msg,instance.bid:date(NOW));
end
end

function ExtAsyncOperationFinished(id,success,message)
if id==2000 and not(success) then
executing=false;
enter(BuySell);
terminal:alertMessage(instance.bid:instrument(),instance.bid[NOW],"Open order once again"..message,instance.bid:date(NOW)) end
end

The reply received is attached to the drawings.
I want to do it again when open order failed defeated,but not implemented...
Do you know why?How to write?
Thank you!

QQ截图20170831085148.png

QQ截图20170831085345.png
guangho
 
Posts: 72
Joined: Sat Sep 29, 2012 12:16 pm

Re: Questions about strategy writing

Postby IgorNI » Fri Sep 01, 2017 3:11 am

Hi, guangho

In a simple case, you can use global variables for storing order creation parameters.
Move the order creation code to own function, for example,

function CreateOrder()
(..)

And then call it in the ExtAsyncOperationFinished() function again when open order creation has failed.
IgorNI
FXCodeBase: Confirmed User
 
Posts: 4
Joined: Tue Aug 08, 2017 10:29 am

Re: Questions about strategy writing

Postby guangho » Fri Sep 01, 2017 5:57 am

IgorNI wrote:Hi, guangho

In a simple case, you can use global variables for storing order creation parameters.
Move the order creation code to own function, for example,

function CreateOrder()
(..)

And then call it in the ExtAsyncOperationFinished() function again when open order creation has failed.


Thank you for your reply...
Can you give me an example?
Thank you very much...
guangho
 
Posts: 72
Joined: Sat Sep 29, 2012 12:16 pm

Re: Questions about strategy writing

Postby PetroIV » Fri Sep 08, 2017 9:20 am

Hello,

I have attached a strategy that in the case of error in ExtAsyncOperationFinished, repeated request for the creating order.

Thanks.
Attachments
repeat_orders.lua
Example
(3.91 KiB) Downloaded 28 times
PetroIV
 
Posts: 12
Joined: Tue Aug 15, 2017 9:45 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests

cron