How can this be an entry?
Forums › ProRealTime English forum › ProOrder support › How can this be an entry?
- This topic has 20 replies, 5 voices, and was last updated 2 years ago by Mike Boorman.
-
-
12/21/2021 at 10:36 PM #183713
Your help please folks…
The most simple of code is producing a strange result. The cross of the blue SMA 8 and green SMA 20 is the trigger for crossflag to equal 1, and yet when I graph crossflag it says it’s zero.
The entry itself is correct by these simple rules, but it becomes a problem when I add more complicated variables to derive “crossflag”. I can’t trust my system until crossflag becomes 1, -1 or zero when it ought to.
How can this code actually enter when crossflag is graphing at zero? I just can’t understand! And is there a different way of presenting this logic to make crossflag graph at 1 in the bar I’ve highlighted in the screengrab?
Thanks in advance for your help.
12/22/2021 at 12:24 AM #183717Actually where your mouse is sitting no crossover occurred, as Sma8 is below Sma20, while on the right side of your chart there’s been a crossover, which is correctly reported.
12/22/2021 at 2:33 AM #183720But SMA8 is lower than SMA20 to the left of the mouse, and then it is higher one bar to the right of the mouse. How could this happen without there being a crossover?
12/22/2021 at 6:37 AM #183724Yes, right.
I need the code to figure out what’s the cause.
12/22/2021 at 11:28 AM #183739Oh sorry, I forgot to include it! And now I can’t see the “include code” button, so here it is below in plain text.
DEFPARAM CumulateOrders = False
Longcross= Average[8](close) > Average[20](close)
Shortcross= Average[8](close) < Average[20](close)
if longcross and not longcross[1] then
crossflag=1
endifif not onmarket and crossflag=1 then
sl=abs(close-lowest[3](low))+5
tp=sl * VL
Set target profit tp
Set stop loss sl
BUY 1 PERPOINT AT market
crossflag=0
endifif shortcross and not shortcross[1] then
crossflag=-1
endifif not onmarket and crossflag=-1 then
sl= abs(close-highest[3](high))+5
tp=sl * VL
Set target profit tp
Set stop loss sl
Sellshort 1 PERPOINT AT market
crossflag=0
endifgraph crossflag
12/22/2021 at 11:52 AM #183740Hi Mike – allow me to jump in. Assuming that what you showed is the full code :
123if longcross and not longcross[1] thencrossflag=1endifSince this is the only time you set crossflag to 1, the culprit has to be the combined condition which won’t become true.
Besides that, for me it would look odd if two subsequent bars would cross (any signal). Thus there it has to go wrong ?Additionally, this looks a bit odd as well :
12345678if not onmarket and crossflag=-1 thensl= abs(close-highest[3](high))+5tp=sl * VLSet target profit tpSet stop loss slSellshort 1 PERPOINT AT marketcrossflag=0endifFirst off, this suggests that you want to know crossflag at the next call (bar) of your code. Do notice that this would require a
1once crossflag = 0somewhere at the start of your code.
Also, personally I would have the Set Stop Loss (and I think Set Target Profit as well) after the Sellshort. It may be fine, but if I would be the PRT code parser ;-), I would set those only at the next call of the code and then it would not even happen because by that time OnMarket will be True.
Possibly it is fine anyway, but I would not depend on that (the code executes from top to bottom and how to set a SL if there is no position yet).Maybe Roberto has better ideas for you ?
1 user thanked author for this post.
12/22/2021 at 12:30 PM #183741Thanks for the suggestion, Peter. I haven’t quite managed to work out how to use ONCE statements effectively, but I’ll have another look in the manual to see how I could apply it here. The SL code has been fine in previous systems, so I think I’ll just leave that one.
What I’d really like to do is have the flag reset to zero on the flip of the PSAR, and then have the cross creating 1 or -1. Or alternatively have each PSAR flip indicate that it’s going to be a long cross or a short cross. I attempted it with this code but it didn’t work:
PSAR flip variation12345678910111213141516171819202122232425262728293031323334353637383940414243444546DEFPARAM CumulateOrders = FalseAveragecrosslong= Average[8](close) >Average[20](close)Averagecrossshort= Average[8](close) <Average[20](close)if SAR[0.02,0.02,0.2] > SAR[0.02,0.02,0.2][1] thenlongsar=1shortsar=0endifif SAR[0.02,0.02,0.2] < SAR[0.02,0.02,0.2] thenshortsar=1longsar=0endifif longsar=1 and averagecrosslong and not averagecrosslong[1] thencrossflag=1endifif not onmarket and longsar=1 and crossflag=1 thensl=abs(close-lowest[3](low))+5tp=sl * VLSet target profit tpSet stop loss slBUY 1 PERPOINT AT marketcrossflag=0longsar=0endifif averagecrossshort and not averagecrossshort[1] thencrossflag=-1endifif not onmarket and shortsar=1 and crossflag=-1 thensl= abs(close-highest[3](high))+5tp=sl * VLSet target profit tpSet stop loss slSellshort 1 PERPOINT AT marketcrossflag=0shortsar=0endifgraph crossflag12/22/2021 at 1:22 PM #183744or
1234567891011121314151617181920212223242526272829303132333435363738394041424344DEFPARAM CumulateOrders = FalseAveragecrosslong= Average[8](close) CROSSES OVER Average[20](close)Averagecrossshort= Average[8](close) CROSSES under Average[20](close)if SAR[0.02,0.02,0.2] > SAR[0.02,0.02,0.2][1] thenlongsar=1shortsar=0endifif SAR[0.02,0.02,0.2] < SAR[0.02,0.02,0.2] thenshortsar=1longsar=0endifcrossflag=0if longsar=1 and averagecrosslong thencrossflag=1endifif not onmarket and crossflag=1 thensl=abs(close-lowest[3](low))+5tp=sl * VLSet target profit tpSet stop loss slBUY 1 PERPOINT AT marketlongsar=0endifif shortsar=1 and averagecrossshort thencrossflag=-1endifif not onmarket and crossflag=-1 thensl= abs(close-highest[3](high))+5tp=sl * VLSet target profit tpSet stop loss slSellshort 1 PERPOINT AT marketcrossflag=0shortsar=0endifgraph crossflag1 user thanked author for this post.
12/22/2021 at 2:05 PM #183748Simple MA -crossing123456789101112131415161718192021222324252627282930313233343536DEFPARAM CumulateOrders = FalseVL = 1Longcross= Average[8](close) > Average[20](close)Shortcross= Average[8](close) < Average[20](close)//if longcross and not longcross[1] then//crossflag=1//endifif Longcross=1 then//sl=abs(close-lowest[3](low))+5//tp=sl * VL//Set target profit tp//Set stop loss slBUY 1 PERPOINT AT market//crossflag=0endif//if shortcross and not shortcross[1] then//crossflag=-1//endifif Shortcross=1 then//sl= abs(close-highest[3](high))+5//tp=sl * VL//Set target profit tp//Set stop loss slSellshort 1 PERPOINT AT market//crossflag=0endifgraph Longcrossgraph ShortcrossWhen using only Longcross and Shortcross there is no problem…
(SL and TP omitted for a better view)
12/22/2021 at 2:37 PM #183753If you want to use Crossflag then remove from your code:
“not onmarket” (because your always on market)
“crossflag=0”Using Crossflag123456789101112131415161718192021222324252627282930313233DEFPARAM CumulateOrders = FalseLongcross= Average[8](close) > Average[20](close)Shortcross= Average[8](close) < Average[20](close)if longcross and not longcross[1] thencrossflag=1endifif crossflag=1 then//sl=abs(close-lowest[3](low))+5//tp=sl * VL//Set target profit tp//Set stop loss slBUY 1 PERPOINT AT market//crossflag=0endifif shortcross and not shortcross[1] thencrossflag=-1endifif crossflag=-1 then//sl= abs(close-highest[3](high))+5//tp=sl * VL//Set target profit tp//Set stop loss slSellshort 1 PERPOINT AT market//crossflag=0endifgraph crossflag12/22/2021 at 2:40 PM #183755Thanks for the suggestions. If I remove not onmarket, when I have a live trade, won’t it enter in a counter direction when these signals are met?
12/22/2021 at 3:10 PM #183756I haven’t quite managed to work out how to use ONCE statements effectively
1234Once MyCounter = 0 // Cause its value to be known at a next (bar) call.MyCounter = MyCounter + 1Graph MyCounter // Goes up and up and up and ...1234MyCounter = 0MyCounter = MyCounter + 1Graph MyCounter // Always shows 1.Easy ! (and the most useful)
12/22/2021 at 3:17 PM #183757DEFPARAM CumulateOrders = False Averagecrosslong= Average[8](close) CROSSES OVER Average[20](close) Averagecrossshort= Average[8](close) CROSSES under Average[20](close) if SAR[0.02,0.02,0.2] > SAR[0.02,0.02,0.2][1] then longsar=1 shortsar=0 endif if SAR[0.02,0.02,0.2] < SAR[0.02,0.02,0.2] then shortsar=1 longsar=0 endif crossflag=0 if longsar=1 and averagecrosslong then crossflag=1 endif if not onmarket and crossflag=1 then sl=abs(close-lowest[3](low))+5 tp=sl * VL Set target profit tp Set stop loss sl BUY 1 PERPOINT AT market longsar=0 endif if shortsar=1 and averagecrossshort then crossflag=-1 endif if not onmarket and crossflag=-1 then sl= abs(close-highest[3](high))+5 tp=sl * VL Set target profit tp Set stop loss sl Sellshort 1 PERPOINT AT market crossflag=0 shortsar=0 endif graph crossflag
That code was okay for only longs, but it didn’t reset properly when I added in shorts. But I think I’ve solved it with this amended version of your code. I added “crossflag=0” at the very top and removed any instances of “crossflag=0” from the rest of the code.
New code12345678910111213141516171819202122232425262728293031323334353637383940if SAR[0.02,0.02,0.2] > SAR[0.02,0.02,0.2][1] thenlongsar=1shortsar=0endifif SAR[0.02,0.02,0.2] < SAR[0.02,0.02,0.2][1] thenshortsar=1longsar=0endifif longsar=1 and averagecrosslong thencrossflag=1endifif not onmarket and crossflag=1 thensl=abs(close-lowest[3](low))+5tp=sl * VLSet target profit tpSet stop loss slBUY 1 PERPOINT AT marketlongsar=0endifif shortsar=1 and averagecrossshort thencrossflag=-1endifif not onmarket and crossflag=-1 thensl= abs(close-highest[3](high))+5tp=sl * VLSet target profit tpSet stop loss slSellshort 1 PERPOINT AT marketshortsar=0endifgraph crossflag12/22/2021 at 3:35 PM #183758No, it will open only in the direction of “crossflag”
Add Crossflag = 0 at the top of your code and everything works fine 🙂Simple MA -crossing1234567891011121314151617181920212223242526272829303132333435DEFPARAM CumulateOrders = FalseCrossflag = 0VL = 1Longcross= Average[8](close) crosses over Average[20](close)Shortcross= Average[8](close) crosses under Average[20](close)if longcross and not longcross[1] thencrossflag=1endifif crossflag=1 thenBUY 1 PERPOINT AT marketsl=abs(close-lowest[3](low))+5tp=sl * VLSet target profit tpSet stop loss sl//crossflag=0endifif shortcross and not shortcross[1] thencrossflag=-1endifif crossflag=-1 thenSellshort 1 PERPOINT AT marketsl= abs(close-highest[3](high))+5tp=sl * VLSet target profit tpSet stop loss sl//crossflag=0endifgraph crossflag1 user thanked author for this post.
12/22/2021 at 3:36 PM #183760 -
AuthorPosts
Find exclusive trading pro-tools on