how to have a time exit regardless the number of entrys  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

how to have a time exit regardless the number of entrys

Postby scarecrow » 13 Sep 2012

Hello all,
I wrote a super easy correlation strategy that looks to hold for 7 days after entry. uses daily bars.
the problem I'm having is if I'm currently in a position and i get another signal the second entry will exit the same time as the first.
how do i exit 7 days after each entry?
so that each individual entry is held for 7 bars regardless if another entry is initiated.

barssinceentry does not seem to work. it liquidates all entries after the initial ones 7 day mark.
Attachments
Capture2.png
(107.76 KiB) Downloaded 870 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: how to have a time exit regardless the number of entrys

Postby Henry MultiСharts » 14 Sep 2012

scarecrow, please provide a sample code you are using for entry and exit orders.
Have you tried "sell from entry" command?

User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

Re: how to have a time exit regardless the number of entrys

Postby scarecrow » 14 Sep 2012

scarecrow, please provide a sample code you are using for entry and exit orders.
Have you tried "sell from entry" command?
I tried sell from entry. but that only seems to work at a maximum of 2 entries.
example: if a 3rd buy signal is initiated within the seven days of the 2nd, that 3rd buy signal is treated as another 2nd buy signal, instead of a 3rd. therefore the 3rd and any subsequent entries within the 7 day time frame exit the same as the second entry. I feel like i'm missing something easy. i would just like to be able to enter the market and hold for seven days no matter what other entries occur. i.e. if i buy separately on monday then tuesday then wednesday, mondays entry will sell next monday, tuesday entry will sell next tuesday etc...
very first and basic entry and exit code i have been messing with. the one from the chart

Code: Select all

//Longs
If marketposition <> -1 and (MyVolit < VltFilter )
and (close < Open) and (close data2 < open data2)
and ((Close - close[1]) / close[1] < (close data2 - close[1] data2) / close[1] data2)
{and ((Close - close[1]) / close[1] < PctChange)}
then
Begin
alert ("Buy This Bar or Tomorrow Open");
buy this bar close;

end;



//long exits
if marketposition <> 0 then
begin
if barssinceentry = BarToExitOn then
sell next bar at market;

end;

setstopshare;
if MarketPosition = 1 then
SetStopLoss( EntryPrice * StopLossPct )
else
Sell ( "PctStopLX-eb" ) next bar at Close * ( 1 - StopLossPct ) stop ;

KhaosTrader
Posts: 186
Joined: 10 May 2012
Has thanked: 14 times
Been thanked: 11 times

Re: how to have a time exit regardless the number of entrys

Postby KhaosTrader » 14 Sep 2012

Here is the easy way...

Code: Select all

ForceCloseTime = 15:50;

if MarketPosition = 1 then

If Time < ForceCloseTime then begin

// put your normal share handling code here that works before your ForceTimeClose

end
else begin // code below here executes after ForceCloseTime
Sell ( "PctStopLX-eb" ) next bar at Market;
end;

User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

Re: how to have a time exit regardless the number of entrys

Postby scarecrow » 15 Sep 2012

I don't see how this code would apply with a daily bar chart...? i'll work with it tomorrow and try to understand it more. But could you elaborate how this would work?
Thanks KT
Here is the easy way...


Code: Select all

ForceCloseTime = 15:50;

if MarketPosition = 1 then

If Time < ForceCloseTime then begin

// put your normal share handling code here that works before your ForceTimeClose

end
else begin // code below here executes after ForceCloseTime
Sell ( "PctStopLX-eb" ) next bar at Market;
end;

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: how to have a time exit regardless the number of entrys

Postby Henry MultiСharts » 18 Sep 2012

Scarecrow, barssinceentry works as expected. Please try your script without exit price orders or put them under barssinceentry condition as well.

User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

Re: how to have a time exit regardless the number of entrys

Postby scarecrow » 18 Sep 2012

Hi Henry,
Not sure i follow.
Scarecrow, barssinceentry works as expected. Please try your script without exit price orders or put them under barssinceentry condition as well.
Barssenseentry does work, unless i have multiple orders. then they all exit after 7 days of the initial entry.
I feel like i'm missing something easy. i would just like to be able to enter the market and hold for seven days no matter what other entries occur. i.e. if i buy separately on monday then tuesday then wednesday, mondays entry will sell next monday, tuesday entry will sell next tuesday etc... in this example barssensentry would have all the orders exit on the next monday.

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

Re: how to have a time exit regardless the number of entrys

Postby escamillo » 19 Sep 2012

you have the option to Exit a part of you position by using the syntax:

Code: Select all

Sell ("STOP_1") Size_Exit Contracts Next Bar STOP_1 STOP ;
where Size_Exit is a number that you Input or calculate as a Variable; and STOP_1 is a Variable that has been calculated.
Last edited by escamillo on 20 Sep 2012, edited 1 time in total.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: how to have a time exit regardless the number of entrys

Postby SUPER » 20 Sep 2012

Hi Henry,
Not sure i follow.
Scarecrow, barssinceentry works as expected. Please try your script without exit price orders or put them under barssinceentry condition as well.
Barssenseentry does work, unless i have multiple orders. then they all exit after 7 days of the initial entry.
I feel like i'm missing something easy. i would just like to be able to enter the market and hold for seven days no matter what other entries occur. i.e. if i buy separately on monday then tuesday then wednesday, mondays entry will sell next monday, tuesday entry will sell next tuesday etc... in this example barssensentry would have all the orders exit on the next monday.

scarecrow,

Have a look at following tutorial to help you with your code.

http://markplex.com/free-tutorials/tuto ... id-trades/

User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

Re: how to have a time exit regardless the number of entrys

Postby scarecrow » 20 Sep 2012

Hi Henry,
Not sure i follow.
Scarecrow, barssinceentry works as expected. Please try your script without exit price orders or put them under barssinceentry condition as well.
Barssenseentry does work, unless i have multiple orders. then they all exit after 7 days of the initial entry.
I feel like i'm missing something easy. i would just like to be able to enter the market and hold for seven days no matter what other entries occur. i.e. if i buy separately on monday then tuesday then wednesday, mondays entry will sell next monday, tuesday entry will sell next tuesday etc... in this example barssensentry would have all the orders exit on the next monday.

scarecrow,

Have a look at following tutorial to help you with your code.

http://markplex.com/free-tutorials/tuto ... id-trades/
thanks super, i love markplex. i'll check it out.

User avatar
scarecrow
Posts: 50
Joined: 12 Apr 2012
Has thanked: 14 times
Been thanked: 3 times

Re: how to have a time exit regardless the number of entrys  [SOLVED]

Postby scarecrow » 25 Sep 2012

Yep that did it!!!!! thanks again SUPER


Return to “MultiCharts”