As soon as a trade is stopped out MarketPosition =0

Questions about MultiCharts and user contributed studies.
mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 10 Apr 2012

Hi

I am running a strategy using the following instructions:

Code: Select all

[IntrabarOrderGeneration = False]

MP = MarketPosition;

setstopposition;
setstoploss(one_perc_dollars); //$500

if (MP[1]=0  and (Long_Stop=0) and (scale=0) and (stage=0 or stage=1 or stage=2 or stage=3) ) 
then begin           
               Long_Stop = Close[0] * (1 - (vol_perc_long/100));

               Num_Shares_p1 = ((p1_pcent) * (one_perc_dollars/(Close[0]-Long_Stop)) ) ;
          
                     Buy ("LE_1") Num_Shares_p1 shares  this bar on close;
                     //Long_Stop = Close[1] * (1 - (vol_perc_long/100));
                     scale=1;
                     eprice = close;
                   
end;




I am seeing the following behavior in the attached image

As soon as the trade is stopped out it is executing another trade even though I am using "MP[1]=0" i.e telling it to wait one bar before entering the next trade.
It looks like the MarketPosition does not get set to 1 at the close of the previous trade bar hence once the 1st trade is stopped out it is valid then to execute the second trade.

As soon as the trade is filled how can I get MP to be set to 1?

Thanks
Attachments
MP.jpg
MP.jpg (20.35 KiB) Viewed 358 times

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 10 Apr 2012

After printing out some of the variables the MarketPosition, MP and scale are not being set after the close of the previous bar the 5th of April? At the close of the 5th MarketPosition,MP[0] should be 1 and scale too? Any ideas?

Date:Thu_05Apr2012 MP, 0.00 scale 0.00
Date:Mon_09Apr2012 MP, 0.00 scale 0.00


The 2 dates correspond to the last 2 bars on that image

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby escamillo » 10 Apr 2012

If LastBarOnChart AND EntriesToday(Date) = 0 and Buy_Condition
then
Buy ("LE_1") Num_Shares_p1 shares this bar on close;
These users thanked the author escamillo for the post:
mefTrader

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby furytrader » 10 Apr 2012

Is it the case that you can get filled and stopped out of the same bar? Or does that rarely ever happen? Also, is the problem happening when you backtest or when you're trading live?
These users thanked the author furytrader for the post:
mefTrader

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 10 Apr 2012

escamillo and furytrader

- to me it seems to be a difference backtest versus live trading
- will try escamillo's logic to see if fixes my problem.
- will wait for the close of today's candle to see the change on historical data (if any)

thanks

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 10 Apr 2012

escamillo - is the function "EntriesToday(Date)" your own function? Can not find it in the dictionary

thanks

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 10 Apr 2012

okay I can find the function - no problem

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 11 Apr 2012

Added the following line of code to examine this

Code: Select all

Print("Date:",FormatDate("ddd_ddMMMyyyy", ElDateToDateTime(Date))," MP,",MP[0]," scale",scale, "Num Entries,",EntriesToday(Date), "EntryDate,",EntryDate(0));


It is returning the following

Date:Thu_05Apr2012 MP, 0.00 scale 0.00Num Entries, 0.00EntryDate, 0.00
Date:Mon_09Apr2012 MP, 0.00 scale 0.00Num Entries, 0.00EntryDate, 0.00
Date:Tue_10Apr2012 MP, 0.00 scale 0.00Num Entries, 0.00EntryDate, 0.00


But there are clearly 3 entries see attached image

Dont understand why the entries are not being picked up?????
Attachments
SPY_April.PNG
SPY_April.PNG (22.47 KiB) Viewed 352 times

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: As soon as a trade is stopped out MarketPosition =0

Postby JoshM » 11 Apr 2012

mefTrader wrote:Dont understand why the entries are not being picked up?????

Did you place that code segment at the end of the signal? Does it work when you increase the holding period to 2 or more days?

mefTrader
Posts: 141
Joined: 23 Jun 2011
Has thanked: 9 times
Been thanked: 7 times

Re: As soon as a trade is stopped out MarketPosition =0

Postby mefTrader » 11 Apr 2012

Yes the code is placed at the end of the code!


Return to “MultiCharts”