Thanks very much for your ideas.
Firstly, I would indeed be very grateful to you if you could submit a request for a breakeven function that would be accessible in Initialize. Along with the other functions or methods (stoploss, etc.) this would enable a non-ATM strategy to be as powerful as an ATM without any special coding.
Secondly, thanks very much for the 'breakeven' code you posted. I've been taking a close look at it and it seems very effective. (Almost all my own script work thus far has been involved with indicator development and I'm just now trying to find the best strategy implementation of these so I'm learning about 'AvgPrice', etc.)
Assume we've set variables: ProfitTrigger and BreakEvenPlus (the amount above the entry price where we wish to put the stop) and there's a bool: BreakEvenSet.
The reason for having a bool (and please correct me, Chelsea, if this isn't necessary) is because, without one, as illustrated below, whenever Close[0] >= Position.AvgPrice + ProfitTrigger * TickSize, a new stop would be entered, whereas we only wish this to happen once.
So this is the code as I've slightly adjusted it:
if (
Position.MarketPosition == MarketPosition.Long
&& Close[0] >= Position.AvgPrice + ProfitTrigger * TickSize
&& BreakEvenSet == false
)
{
SetStopLoss(CalculationMode.Price, (Position.AvgPrice + BreakEvenPlus) * TickSize);
BreakEvenSet = true;
}
Another point is this: the stop level is set, initially, as:
(Position.AvgPrice + BreakEvenPlus) * TickSize
Won't future bars recalculate "Position.AvgPrice" according to the AvgPrice level for that bar? I'm thinking (and of course, I could be wrong here) that it may be an idea to set a variable to take this value, such as:
Variable0 = Position.AvgPrice
so that the value remains constant.
Thanks for letting me have your thoughts on this, Chelsea.
Much obliged.

Comment