Dear All
I want to code as when 2 of my conditions met then waiting for another condition to be happened to enter short and if c1 happened exit loop. please confirm below code will do what i need. with thanks.
IF C2 AND C4 THEN
WHILE C6 DO
SELLSHORT 1 CONTRACT AT MARKET
IF C1 THEN
BREAK
ENDIF
WEND
ENDIF
A strategy with this code will either never enter the WHILE loop if C6 is false or never exit that loop if C6 is true, since C6 and C1 are not modified once you are within the loop.
Roberto
can you pls guide me a code that , if c1 happened wait for c2 to happen then enter market and if c3 happened cancel the first if confirmation and exit the loop?
with thanks.
by the way, c1 will not persist. is a crossover
Please post here the complete code of the strategy, not so easy to understand what you want to be coded 🙂
DEFPARAM CUMULATEORDERS=FALSE
TREND = CALL "Pedi's Trend Detector"
K = CALL "STOCH K"
C1= TREND CROSSES OVER 0
C2=K CROSSES OVER K[1]
C3=TREND>0
//NEED TO BE COMPLETED. WHEN C1 HAPPEN WAIT UNTIL C2 HAPPEN WHEN C3 ALSO PERSISTS TO ENTER MARKET.
NEED TO BE COMPLETED. WHEN C1 HAPPEN WAIT UNTIL C2 HAPPEN WHEN C3 ALSO PERSISTS TO ENTER MARKET
Ok Pedi’s! Let’s try with this code. 🙂
You need first to store the fact that C1 has crossed, and there are 2 ways to know it has, first one is a test through the last X bars:
x = 10 //last 10 bars will be tested
testC1 = summation[x](c1)>0 //c1 was true at least one time in the last X bars
or you can store the variable like this (but you’ll need to reset it to 0 when another trigger, but it depends on your strategy… so I do not when you’d like to reset the C1 has crossed)
if c1 then
testc1 = 1
endif
Now that you know your c1 condition is true, let’s check the other conditions and put an order at market:
if testc1 and c2 and c3 then
buy 1 contract at market
endif
Thanks for clarifying advice, Nicolas.