Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

smurf77

How to Code Time Between to Trade?

Recommended Posts

Hi,

 

For backtesting, I would like to set up a minimum number of days (5 day) between two trades:

I tried that:

barssinceexit(1) > 5, it didn't work... I tried a few other possibilities too. Didn't work!

 

Thanks for your help,

 

Smurf

Share this post


Link to post
Share on other sites
Hi,

 

For backtesting, I would like to set up a minimum number of days (5 day) between two trades:

I tried that:

barssinceexit(1) > 5, it didn't work... I tried a few other possibilities too. Didn't work!

 

Thanks for your help,

 

Smurf

 

have you read the manual on how to use "barssinceexit" ?

Share this post


Link to post
Share on other sites

yes, I read this manual again and again and look on internet. I am actually not sure it's the right command for what I a want to do but I can not think about something else... any suggestion?

Share this post


Link to post
Share on other sites

HI smurf77,

 

If you need Time Gap between the trades, then you can use Bassinceexit(1) > 5 then...as you have used.

 

But you have to make sure that you have a condition in the entry

If Maarketposition = 0 then Buy.....
If MarketPosition = 0 then SellShort.....

 

The Bolded words are important, as this will make sure that your entries are neither a stop&Reverse, Not enter immediately.

 

Hope that will help...

 

EasyTrader_I

Edited by EasyTrader_I
typo

Share this post


Link to post
Share on other sites

Hi,

 

Thank you for your answer but it doesn't work.

 

Here is the piece of code:

-------------------------------------------------------------------------------------------

condition1 = Average(close,8) crosses over Average(close,12) ;

condition2 = barssinceentry(1) > 5;

condition3 = marketposition=0;

 

IF condition1 and condition2 and condition3 THEN BUY 1 share next bar AT MARKET;

----------------------------------------------------------------------------------------------

 

What do you think?

 

Thanks

Share this post


Link to post
Share on other sites

oh yes, sorry (bad copy and paste), in the code it's actually barssinceexit(1)>5 but it doesn't work.

here is all the code:

 

condition1 = Average(close,8) crosses over Average(close,12) ;

condition2 = close > average (close,300) ;

condition3 = barssinceexit(1)>5;

condition4 = marketposition=0;

 

IF condition1 and condition2 and condition3 and condition4 THEN BUY 1 share next bar AT MARKET;

 

//SELL SIGNAL

if marketposition=1 then sell next bar at(entryprice+10)limit;

setstoploss(20);

if currentbar - barssinceentry(0)= 22 then sell next bar at market;

 

Any ideas?

 

Thanks a lot!

Share this post


Link to post
Share on other sites

Hi smurf77,

 

In your code condition3 will always be False, as you are applying the condition for the very first trades where you don't have Exit. Hope you understand my Point.

 

Please try the following code..

condition1 = Average(close,8) crosses over Average(close,12) ;
condition2 = close > average (close,300) ;
condition3 = barssinceexit(1)>5;
condition4 = marketposition=0;

IF condition1 and condition2 and (condition3 or Totaltrades < 1) and condition4 THEN BUY 1 share next bar AT MARKET;

//Print(D, T, Condition1, Condition2, Condition3, Condition4);
//SELL SIGNAL
if marketposition=1 then sell next bar at(entryprice+10)limit;
setstoploss(20);
if currentbar - barssinceentry(0)= 22 then sell next bar at market;

 

I have added an (Or) condition.

 

Good Luck.

EasyTrader_I

Edited by EasyTrader_I
coment added

Share this post


Link to post
Share on other sites

One more thing that I forget to post here is your Barssinceentry.

 

BarsSinceEntry(Num)

Where Num is a whole number (up to a maximum 10) representing positions ago.

 

Hope it cannot have 0. Unless you are working with the Intrabar Order Generation.

 

Good Luck.

EasyTrader_I

Edited by EasyTrader_I
IOG

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.