And as a small additional question, which index would be correct to map the other variants, idx or (idx-1)?
Setting the colors made it clear which index refer to the last bar (idx) and what (idx-1) is. But i don't get results for the crossover if i use idx. I do not need to discuss this here, but if there is an easy explanation, that would be nice of course, to know about it.
Back to the topic i would be happy to get a recommandation if the using conditional market order (compared to the limit orders) might be useful somehow. The behaviour in the backtest would be different (i guess), would it use the open instead of the limit that is checked in the code? On the other hand when live trading it should behave like limit order when it is scanned in the quotes and price monitor and would be triggered. I am only thinking if there might be a useful scenario to code it that way.
Unfortunately, I'm in a hurry right now. I hope I have not written nonsense in a hurry and look forward to further feedback.
CODE:
if (!HasOpenPosition(bars, PositionType.Long)) { if(idx < 1) return; bool cross = indicator4.CrossesOver(bars.Close[idx-1], idx); // no results for Close[idx] if(cross && bars.Close[idx] > _ema4[idx] && _ema4[idx] > _ema8[idx] && _ema8[idx] > _ema16[idx]) { PlaceTrade(bars, TransactionType.Buy, OrderType.Market); SetBarColor(bars, idx, WLColor.Blue); SetBarColor(bars, idx-1,WLColor.Silver); } }
Setting the colors made it clear which index refer to the last bar (idx) and what (idx-1) is. But i don't get results for the crossover if i use idx. I do not need to discuss this here, but if there is an easy explanation, that would be nice of course, to know about it.
Back to the topic i would be happy to get a recommandation if the using conditional market order (compared to the limit orders) might be useful somehow. The behaviour in the backtest would be different (i guess), would it use the open instead of the limit that is checked in the code? On the other hand when live trading it should behave like limit order when it is scanned in the quotes and price monitor and would be triggered. I am only thinking if there might be a useful scenario to code it that way.
Unfortunately, I'm in a hurry right now. I hope I have not written nonsense in a hurry and look forward to further feedback.
Rename
CODE:
//bool cross = indicator4.CrossesOver(bars.Close[idx-1], idx); // no results for Close[idx] bool cross = bars.Close.CrossesOver(indicator4[idx], idx);
The CrossOver overload you used checks if "indicator4 crosses over a value, bars.Close[idx-1], on the idx bar".
Notice the difference -
Edit - you may actually be looking for Close crossing over the indicator, like Eugene showed.
Notice the difference -
Edit - you may actually be looking for Close crossing over the indicator, like Eugene showed.
CODE:
// IS: bool cross = indicator4.CrossesOver(bars.Close[idx-1], idx); // no results for Close[idx] // SHOULD BE: (Checks two TimeSeries crossing at idx) bool cross = indicator4.CrossesOver(bars.Close, idx);
QUOTE:Sure it's useful. It's the difference between using "touch stop/limit orders" or exiting after price exceeds a target. In the second case, exiting at market will be a different result - for better or worse.
if the using conditional market order (compared to the limit orders) might be useful somehow.
CODE:
Position p = LastOpenPosition; //exit immediately at 2% profit target ClosePosition(p, OrderType.Limit, p.EntryPrice * 1.02, "PT Touch"); - OR - //exit on the next if the profit target was *achieved* if (bars.High[idx] >= p.EntryPrice * 1.02) ClosePosition(p, OrderType.Market, 0, "PT Close");
Thanks to both of you. It think it is clear now.
What i intended to do is what Eugene code snippet is showing.
The general hint from Cone was very helpful too, of course.
These two implementations should lead to the same result in the example context.
Depending on which data type I have available, in this case both, I can choose appropriate method.
In practice I will often have only one, the Value or the TimeSeries.
What i intended to do is what Eugene code snippet is showing.
The general hint from Cone was very helpful too, of course.
These two implementations should lead to the same result in the example context.
CODE:
// cross_by_val == cross_by_tss bool cross_by_val = indicator4.CrossesOver(indicator8[idx], idx); bool cross_by_tss = indicator4.CrossesOver(indicator8, idx);
Depending on which data type I have available, in this case both, I can choose appropriate method.
In practice I will often have only one, the Value or the TimeSeries.
Your Response
Post
Edit Post
Login is required