hi guys,
i want to count the bars – and exit the market after 16 days /bars.
i know there is
if onmarket and barindex-tradeindex > 15 then
sell at market
endif
but i dont like to use barindex – because it depends on when u started a system or on the chart.
so i am looking for another try like
N=summation[15]
if onmarket and n>15 then
sell at market
endif
is this possible? i just want to exit after x days/bars
I do not understand what the issue is with:
if onmarket and barindex-tradeindex > 15 then
….as it works perfectly in all situations for counting how many bars you have been on the market for. When the chart data started is irrelevant as BARINDEX and TRADEINDEX are just a filing system that gives a bar a numerical label.
I guess you could try something like:
if summation[15](countofposition <> 0) = 15 then
sell at market
endif
Not tested and as I say I do not understand why you are trying to re-invent the wheel.
@vonasi – thx for ur quick reply i really thank u!
// Bedingungen zum Ausstieg von Short-Positionen
yy1 = (close < average[10](close)-std[20](close)) // hier ggf. auch + und close[1]
yy2 = (close < close[1])
yy3 = barindex-tradeindex >= 15
yy4 = positionperf <= 0
yy = yy1 and yy2 or yy3 or yy4
if yy then
exitshort at market
endif
i did that at yy3 – but now i get 16 bars – so thats what i meant…. 🙁
The decision to close it is made at the close of the 15th bar but the close does not happen until the open of bar 16 I’m guessing.
hmm thx think thats right – automated trading is at close.. so could be the 16th to exit….
yy4 = positionperf(close[1]) <= -1
do u think thats right? i want to say:
if the profit of the open trade is negative since the bar before, system has to sell this order…
mmo_vienna, your code
N=summation[15]
if onmarket and n>15 then
sell at market
endif
will never be true (also, SUMMATION lacks what it has to SUM) since N will never be > 15, as you wrote 15 within brackets!
yes thats true.. tried some things but dont work :S
if the profit of the open trade is negative since the bar before, system has to sell this order…
yy4 = close[1] > positionprice and close < close[1]
thx for this!
but i get negative results :/
but i get negative results :/
You provide the questions – the answers can not always be guaranteed to be profitable! 🙂
haha yes but shouldn’t the order been closed when i have this code? if profit ist negative then…
Not if on the last bar it was in profit and then on this bar it fell back again into a loss.
so if i want to say if order is negative and stays negative the next bar i have to write it in a loop right?
I’m not certain of what you are trying to achieve. Maybe this?
yy4 = close[1] > positionprice and close < close[1] and close > positionprice
i want to say:
if my open order is negative -€ since 2 bars or more than -100€ the system must sell this order and buy in other direction