Profile Picture

Open New Position only if Higher than Previous Entry / Exit Price

Posted By ywlee 2 Years Ago

Open New Position only if Higher than Previous Entry / Exit Price

Posted Tuesday May 19 2015

I want to add an additional condition to control the opening of a new position only if the current price is above the Entry Price of the last open / closed position (long position).  This is to avoid the situation where the Stop Loss on the previous position has been hit and the system opens another position because the primary conditions are still valid (eg EMA50  > EMA200).

I'm aware there is an EntryPrice property but how do I call it in NewBar()?

Posted Wednesday May 20 2015
There's various ways to do this.  You need to keep track of the most recent position, or it's entry price.  I'd create a field for the entry price of the most recent position in the symbol script class, and then put the following in the OrderFilled method:

if (trade.TradeType == TradeType.OpenPosition && trade.Order.OrderState == BrokerOrderState.Filled)
    LastEntryPrice = position.EntryPrice.SymbolPrice;

Then you can check to see if the current price is greater than LastEntryPrice in the NewBar() method.  You may also want to have a condition to reset the LastEntryPrice after a certain time or number of bars or something.  Otherwise even if you made a profit on a position, you won't be able to open another one any time the price goes below that entry price.

Posted Thursday May 21 2015
Hi Daniel

Thanks for clarifying the same.

That worked out for me.

Similar Topics

Reading This Topic

2005-2017 © RightEdge Systems