DEFPARAMCumulateOrders=False// Acumulación de posiciones desactivada
DEFPARAMFlatBefore=090000
DEFPARAMFlatAfter=220000
//Variables
sl=20// Stop Loss
xx=30// Periodos WeightedAverage
wma=WeightedAverage[xx](close)
// Condiciones para entrada de posiciones largas
IFcloseCROSSES OVERwmaTHEN
BUY1CONTRACTATMARKET
ENDIF
// Condiciones de salida de posiciones largas
IFcloseCROSSES UNDERwmaTHEN
SELLATMARKET
ENDIF
// Condiciones de entrada de posiciones cortas
IFcloseCROSSES UNDERwmaTHEN
SELLSHORT1CONTRACTATMARKET
ENDIF
// Condiciones de salida de posiciones cortas
IFcloseCROSSES OVERwmaTHEN
EXITSHORTATMARKET
ENDIF
// Stops y objetivos
SET STOPpLOSSsl
If I start this code in ProOrder, the order will start on the open of the next candle where the price crosses over the weighted moving average, and not in the exact moment than the prices crosses over this WMA. And the next candle can be too late, or, at least, I can lose the difference between crossing and close.
The problem is that I don’t know the instruction to change “close” to for example “price” in the code
“IF close CROSSES OVER wma THEN”
I also tried with for example “typical price” instead of “close”. It changes a little, but is not what desired.
Is there any instruction to lose this problem, or which would be the way?
Please, see the photo hereby for more understanding.
I see 2 reasons for this. Firstly a crossover is valid only when the current period is already closed. Secondly, you may already know that code are only read once per bar, so test is made at bar close then trade is launched at the open of the next one.
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue