The first time when is crossed above my code makes the calculation and put's a buy limit at the specified value. (current minus 10).
On the next bar (or tick) current price is different and my buy limit order has a different value now. ( the new current price minus 10) .
But i dont want that. I want to make the calculation first time when conditions are met , put my buy order at that value and keep it there with the same value until i say otherwise.
protected override void OnBarUpdate()
{
if(State == State.Historical)
{
return;
}
//Add your custom strategy logic here.
if( Position.MarketPosition == MarketPosition.Flat
&& EMA(12)[1] > EMA(26)[1])
{
LimitPrice = EMA(26)[0]; // or LimitPrice = Close[0] - 10
EnterLongLimit(LimitPrice,"long");
}
Let's take the code above as an example. When the conditions are met and the code executes for the first time the LimitPrice has a value given by the slow EMA. I want to keep this value , the first value that goes into LimitPrice until i say otherwise (until ema fast is below ema slow let's say).
Comment