I could use some help getting my “scale in” logic to work correctly. I’ve taken a look at the example code usually referenced for this sort of problem and I think I still don’t understand everything correctly.
I do have this working correctly for getting in/out with one entry and need help getting it to work with more than one entry using the “Entries per direction” property.
“Entry handling” is set to “AllEntries”.
What is supposed to happen (and what I have working correctly) is an entry after conditions are met and an immediate placement of a profit target order. Exit occurs upon either hitting the profit target or at the market if conditions indicate.
The part I don’t have working correctly is: If the next bar is against the trade and the market is below the fill price (for a long), then scale into the position.
I’ve tried to ‘cut and paste’ to isolate the code handling orders as much as possible! The problem is that it doesn’t seem to matter what I set the Entries per direction property to - I don’t seem to be getting any additional entries.
Thanks so much for your help!
Here’s some example logic of what I have so far:
private IOrder entryOrder = null;
protected override void OnExecution(IExecution execution)
{
if (entryOrder != null && entryOrder.Token == execution.Order.Token) {
// we have an execution to process!
lastEntryPrice = execution.Order.AvgFillPrice;
}
}
In method OnBarUpdate():
if (exitlong) {
ExitLong(signalname);
entryOrder = null;
lastEntryPrice = 0.0;
}
if (enterlong) {
signalname = “EntryA”;
entryOrder = EnterLongLimit(limitprice), signalname);
lastEntryPrice = 0.0;
if (!Historical) {
SetProfitTarget(signalname, CalculationMode.Percent, ptargetpercent);
}
}
else if (Position.MarketPosition == MarketPosition.Long) {
if(lastEntryPrice > 0.0 && lastEntryPrice > Closes[0][0]-.02) {
entryOrder = EnterLong(signalname);
lastEntryPrice = 0.0;
}
Comment