I am still in the development phase so I’m just working on the buy side to keep it simple. I only have one condition set (for the buy side), however the nature of the conditions I’ve created means that I can potentially have multiple consecutive signals on consecutive candles. I do NOT use market orders, I always use limit orders set above the high of the setup bar which reduces the chances of having multiple trades open at once, but never the less I do find I get multiple trades at a time.
The multiple trades issue caused me problems setting the initial stop and profit target but I fixed that by adding a counter to signal names. What I want to do is adjust the stop after the first bar (of the open trade) has closed. If the current price is greater than or equal to the entry price, bring the stop up to breakeven. If the current price is less than the entry price, set the profit target to the entry price. So I have:
private int LongCount = 0; // I create a variable that counts trades protected override void OnBarUpdate() //condition set if ( //long conditions) { LongCount++ //increment the trade counter first double InitialRisk = (High[0] + 2*TickSize) - (Low[0]-2*TickSize) // I also create a variable here for initial risk so I can print the value and pass it into the profit target EnterLongLimit(DefaultQuantity, High[0] + 2*TickSize, “LongEntry:”+LongCount); SetStopLoss(“LongEntry:”+LongCount, CalculationMode.Price, Low[0]-2*TickSize,false); SetProfitTarget(“LongEntry:”+LongCount,CalculationMode.Price,High[0]+2*TickSize+(InitialRisk*2)); } if (BarsSinceEntry(“LongEntry:”+LongCount)==1 && Close[0]>=Position.AvgPrice) { SetStopLoss(“LongEntry:”+LongCount, CalculationMode.Price, Position.AvgPrice, false); } else if (BarsSinceEntry(“LongEntry:”+LongCount)==1 && Close[0]<Position.AvgPrice) { SetProfitTarget(“LongEntry:”+LongCount, CalculationMode.Price, Position.AvgPrice); }
Comment