No short positions established
Forums › ProRealTime English forum › General trading discussions › No short positions established
- This topic has 5 replies, 2 voices, and was last updated 4 weeks ago by dubbzie.
-
-
11/21/2024 at 10:26 PM #240638
Below is a script I created to go short if the close crosses under EMA10. I’m using a 15-minute chart for Nasdaq100, with a target and stop loss of 100 points. However, no positions are ever being established. Does anyone understand why? Thanks in advance 🙂
DEFPARAM FlatAfter= 215900 // Cancel any pending orders, close any positions and prevent placement of additional orders by the trading system after 16:00:00 in the market time zone
DEFPARAM CUMULATEORDERS=FALSEindicator1 = ExponentialAverage[10](close)
c1 = close < indicator1 and close[1] > indicator1
IF not onmarket and time =1430000 OR (time > 143000 AND time[1] < 143000) and c1 THEN
entry = close
SELLSHORT 1 CONTRACTS AT MARKET
ENDIFindicator10 = ExponentialAverage[10](close)
c10 = close CROSSES OVER indicator10
c11= close <= entry-100
c12 = close >= entry+100if c10 or c11 or c12 THEN
EXITSHORT AT MARKET
ENDIF11/22/2024 at 1:06 AM #24063911/22/2024 at 1:26 AM #240640Because TIME will never reach 1430000, and, it’s AND’ed in the logic condition of the IF statement, the statement will never be TRUE, so no order will be executed.
3 users thanked author for this post.
11/22/2024 at 4:47 PM #24066411/22/2024 at 9:06 PM #240676Being a rookie means you have the greatest potential to learn and improve, exciting!. An expert may be bored of doing the same thing over and over again before something new comes along.
It takes 10% of the time to learn 90% but, 90% of the time to learn the last 10%.
It maybe an idea to set the 143000 as a variable at the top of the code, since its used three times.
Using it as a variable allows you to change the time in all three places from one point, if needed.
Also, if you type the variable name wrong, you will get the unknown variable error to warn you.
There’s a problem on the same line as before, but with the logic.
I think the three time conditions need to be overall enclosed in brackets for the OR operation to work correctly without affecting c1.
The lack of brackets is AND’ing the c1 to the last time condition on one branch of the OR.
If not onmarket and (time = 143000 OR (time > 143000 AND time[1] < 143000)) and c1 then
I think what was happening was, when time = 143000, everything in the other OR branch was irrelevant, and a order was taken regardless of c1.
1 OR 0 = 1
The common factor between different ema setting would be 143000.
Not sure though what your intensions are with the times.
- if time = 143000 then other OR branch ignored…
- if time > 143000(144500) then AND’ed to time[1] <143000 which will be 143000 @15m and hence (1.) 1 AND 0 = 0
This was why order was taken regardless of C1 because of the AND’ing of c1 to the OR branch which never was needed @15m, and if an entry, it would be taken at 143000.
regards
11/23/2024 at 12:31 PM #240691Thank you, druby, love your positive attidude!
I have been working in the finance industry for a lot of years, but just recently started making scripts. Loving the possibility to back test + let the algos do the trading 🙂
My intensions with the time: I saw it coded like this somewhere, thought it was the correct way 🙂
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on