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
FXCodeBase: Initiate
 
Posts: 106
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: 6
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
FXCodeBase: Initiate
 
Posts: 106
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: 6
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
FXCodeBase: Initiate
 
Posts: 106
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: 6
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
FXCodeBase: Initiate
 
Posts: 106
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 1201 times
PetroIV
 
Posts: 24
Joined: Tue Aug 15, 2017 9:45 am

Re: Questions about strategy writing

Postby maximekaribi » Mon Dec 11, 2017 1:15 pm

HELLO
IS THERE A STRATEGY BASED ON SIMPLE INSIDE BAR AND WHERE IT IS POSSIBLE TO TAKE ONLY INSIDE BAR WITH A NUMBER OF PIPS PREDETERMINED FOR EACH PAIR?
THANK YOU VERY MUCH
maximekaribi
 
Posts: 3
Joined: Mon Sep 19, 2011 2:43 am



Return to General Discussions

Who is online

Users browsing this forum: No registered users and 7 guests