Good Evening,
i posted similar question on italian forum, we are working on it but still didn’t work correctly.
Here what i would like to do, for backtest.
Let’s consider for example Spot Eur/Usd, and TF weekly. As in the picture attached.
I would like to set this code:
At the begin of the week, it starts 2 pending orders, with related Stop Loss and Target Price.
1st) Pending Long, from S1 with target Pivot, and SL on S2
2nd) Pending Short, from R1, with target Pivot and SL on R2
additional instructions:
1) I would like to make sure that ONLY ONE order is executed per week, so that if the Long enters first, the Short one is cancelled, and same thing on the contrary.
2) At the end of the period (in this case week), if the order entered is still active (therefore it has not reached either the stop loss or the target price), I would like it to be closed.
…
In this case i considered wS1 – wS2 – wR1 -wR2 – wP, but i would like it works correctly even if i set dS1 – dS2 , so orders would be closed withing a day, and so on.
Here i post a code that im trying to improve thanks to other users support, but still doesn’t work correctly.
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
// Pivot Giornalieri
ONCE dP = Undefined
ONCE dR1 = Undefined
ONCE dS1 = Undefined
ONCE dR2 = Undefined
ONCE dS2 = Undefined
ONCE dR3 = Undefined
ONCE dS3 = Undefined
// Pivot Setgtimanali
ONCE wP = Undefined
ONCE wR1 = Undefined
ONCE wS1 = Undefined
ONCE wR2 = Undefined
ONCE wS2 = Undefined
ONCE wR3 = Undefined
ONCE wS3 = Undefined
// Pivoy Mensili
ONCE mP = Undefined
ONCE mR1 = Undefined
ONCE mS1 = Undefined
ONCE mR2 = Undefined
ONCE mS2 = Undefined
ONCE mR3 = Undefined
ONCE mS3 = Undefined
IF OnMarket THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
dP, dR1, dS1, dR2, dS2, dR3, dS3, wP, wR1, wS1, wR2, wS2, wR3, wS3, mP, mR1, mS1, mR2, mS2, mR3, mS3 = CALL "Pivots D-W-M"
BUY 1 CONTRACT AT dR1 STOP
SELLSHORT 1 CONTRACT AT dS1 STOP
SET TARGET PROFIT dR2 - dR1
SET STOP LOSS dS1
// dummy lines to avoid errors being reported by ProOrder because some variables are not used
// linee inutili e superflue, messe solo per evitare che ProOrder segnali che alcune variabili non sono utilizzate
x = dP + dR1 + dS1 + dR2 + dS2 + dR3 + dS3 + wP + wR1 + wS1 + wR2 + wS2 + wR3 + wS3 + mP + mR1 + mS1 + mR2 + mS2 + mR3 + mS3
IF x < 0 then
buy at market
endif
Thanks to anyone who can help 🙂