I would like to ask for you help.
I am seeking a way,how to set up stoploss or profit taking orders on previous bar price(high, or low, or else). Specifically in this case, I want set up a stoploss on Low[0] - that is signal bar low price.
When I tried to define it like this in the State== State.Configure area, nothing happened and the script didnt even run in analyzer.
SetProfitTarget("", CalculationMode.Percent, 0.01);
SetStopLoss("", CalculationMode.Price,(Low[0]), false);
I guess it has to do something with the logical order of things,when you put it into this area and set it to some price of candle zero like Low [0].
So I tried to put it in the OnBarUpdate() section like this:
if (
Open[0]<Close[0] &&
Math.Abs(Close[0]-Open[0]) <= Math.Abs((Open[0]-Low[0])*0.5)
)
{
EnterLong(Convert.ToInt32(DefaultQuantity),"");
SetProfitTarget("", CalculationMode.Percent, 0,01);
SetStopLoss("", CalculationMode.Price,(Low[0]), false);
}
That kind of works, but not always it seems, its strange. One of the problems seems that if one signal occurs(a Candle defined like mentioned above) and then, before any of the S/L or P/T order for this signal is executed, apperas another signal (Candle) ---the orders for the first candle re-set for values on the second candle- so the S/L for the first signal is set on Low price for the second candle ,rather than the Low of the first signal candle as was meant to be.
So my question would be how to properly set up S/L or P/T orders, when you intent to put it as price of some specific previous bar, in this case the signal bar [0] - but I guess[1],[2],[3] bars should be the same.. And stay at that level until the order triggers and not to move on to another candles as the time passes or similar signal appears.
Thank you very much for you help.
Comment