How can I autotrade with a signal only for one entry/exit ?  [SOLVED]

Questions about MultiCharts and user contributed studies.
maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

How can I autotrade with a signal only for one entry/exit ?  [SOLVED]

Postby maxmax68 » 23 Mar 2015

Hi,
I'm stuck with this problem:

I would like to apply a signal for the entry and a signal for the exit into a chart and to start autotrade.
But I would like to have only 1 entry and only 1 exit, not continuous autotrading.
I tried creating some flags to stop signal trading but with no luck.

Has anyone solved this feature and has any code to share ?
Thanks in advance.
Massimo

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How can I autotrade with a signal only for one entry/exi

Postby TJ » 23 Mar 2015

Hi,
I'm stuck with this problem:

I would like to apply a signal for the entry and a signal for the exit into a chart and to start autotrade.
But I would like to have only 1 entry and only 1 exit, not continuous autotrading.
I tried creating some flags to stop signal trading but with no luck.

Has anyone solved this feature and has any code to share ?
Thanks in advance.
Massimo
Please post your flag, we can work from there.

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How can I autotrade with a signal only for one entry/exi

Postby maxmax68 » 28 Mar 2015

This solution should work, I'll test it on monday.

Code: Select all

inputs: LECondition( C > highest(high,20)[1] ) ;
vars: flag(1);

if LastBarOnChart then once flag=0;

if LECondition and flag=0 then begin
Buy ( "LE_Flag=0" ) next bar at market ;
flag=1;
End;

print(flag:0:0," - ", BarNumber:0:0);
Regards
Massimo
Last edited by maxmax68 on 29 Mar 2015, edited 1 time in total.

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: How can I autotrade with a signal only for one entry/exi

Postby tony » 28 Mar 2015

You could use a conditional with positionprofit, so once a trade is taken and exited whether you have a win or loss, there would be a positionprofit. So you could put one of your first lines of code to be

"If PositionProfit <>0 Then Begin;"

Only problem is if you are flat on that first trade then it would allow another entry.

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How can I autotrade with a signal only for one entry/exi

Postby maxmax68 » 29 Mar 2015

Thanks Tony,
but if it works, probably to manage flags is more simple.
Regards
Massimo

escamillo
Posts: 203
Joined: 25 Mar 2011
Has thanked: 23 times
Been thanked: 56 times

Re: How can I autotrade with a signal only for one entry/exi

Postby escamillo » 29 Mar 2015

you might look at EntriesToday(Date) = 0 , which will limit your entries each time you turn strategy automation off to on, such as below:

Code: Select all

If LastBarOnChart and EntriesToday(Date) = 0 and Buy_Condition
then
Buy Size_Entry Contracts Next Bar Your_Price LIMIT ;

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How can I autotrade with a signal only for one entry/exi

Postby maxmax68 » 29 Mar 2015

Thanks escamillo,
I was not aware of this function.
To work the counting of entries should reset every time you start the signal.
I'll try it as soon as possible.
Regards
Massimo

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How can I autotrade with a signal only for one entry/exi

Postby TJ » 29 Mar 2015

You can go to the Wiki and get yourself acquainted with these keyword categories:

Strategy Orders‎ (28)
Strategy Performance‎ (33)
Strategy Position‎ (47)
Strategy Position Synchronization‎ (2)
Strategy Position Trades‎ (29)
Strategy Properties‎ (4)

maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

Re: How can I autotrade with a signal only for one entry/exi

Postby maxmax68 » 29 Mar 2015

TJ,
thanks for yours always precious answers.
I did my homeworks.
Probably you intended functions of Powerlanguage and not Wiki.
Best regards
Massimo

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: How can I autotrade with a signal only for one entry/exi

Postby TJ » 29 Mar 2015

TJ,
thanks for yours always precious answers.
I did my homeworks.
Probably you intended functions of Powerlanguage and not Wiki.
Best regards
Massimo
You don't need to use function...

try

EntryDate

eg.

Code: Select all


if EntryDate(1) <> Date then Begin... // ie. haven't done any trades today yet


Return to “MultiCharts”