Hi Nicolas, i am afaid is not what i want. You gave me a clue and i have been trying to find out if there is a way to get what i want but unfortunatelly not.
I give you the code again and i explain what happen:
// Definición de los parámetros del código
DEFPARAM CumulateOrders = True // Acumulación de posiciones activada
// Condiciones para entrada de posiciones largas
c1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)
IF LONGONMARKET=0 THEN
IF c1 THEN
BUY 1000 cash AT MARKET
ENDIF
ELSE
if close<close[Barindex - Tradeindex] then
buy 2000 cash at market
endif
endif
IF close>average[5] then
sell at market
endif
It works as i want but i have unlimited orders and i want a maximum of 4.
Also it buys 1000 in the first order and 2000 in the rest and i want only four entries (1000 eur, 2000 eur, 3000 eur, 4000 eur)( i mean 4 entries if the price goes lower but a trade can be 1,2,3 or 4 buys)
It is a kind of pyramiding buying more when you get lower prices.
i have read this
https://www.prorealcode.com/blog/trading/averaging-techniques-automated-trading/
but i trade cash no contracts and i want to increase the cuantity every time i buy (limited to 4) and was no possible to adapt it.
I also studied this advice
Reply To: Limiting accumulating orders & Fuse
but doesn´t work, maybe because this for intraday and in shares.
I also reached this code. It increase the quantity as i want but it does it in the same day!!
// Definición de los parámetros del código
DEFPARAM CumulateOrders = True // Acumulación de posiciones activada
// Condiciones para entrada de posiciones largas
c1 = close<Average[5](close) and close[1]<average[5] and close>average[200](close)
if not longonmarket then
if c1 then
buy 1000 cash at market
endif
else
if close<close[barindex -Tradeindex] and countofposition buy 2000 cash at market
endif
if close<close[barindex -Tradeindex] and countofposition buy 3000 cash at market
endif
if close<close[barindex -Tradeindex] and countofpositionaverage[5] then
sell at market
endif
I dont want to use positionprice as you suggest, it is not important the midprice. Other thing: What happen with countofposition? if i skip it in the last code remains the same! can not be used with cash?
thanks for your help