crossing higher than previous crossing
Forums › ProRealTime English forum › ProBuilder support › crossing higher than previous crossing
- This topic has 13 replies, 3 voices, and was last updated 2 years ago by Vogeltje.
-
-
08/07/2022 at 5:02 PM #198716
I have an indicator that has two MA-lines (line p and q), just like the MACD-line and its signal-line. I want to build a system that goes long when p crosses over q AND when this crossing is higher than the previous crossing (because then there is the change of nice rising pattern). Similar: go short when p crosses under q AND this crossing is lower than the previous crossing.
My knowlegde of programming is not enough. I tried this code but it is not working:IF p CROSSES OVER q THEN
a = p
ENDIF
IF p CROSSES UNDER q THEN
b = p
ENDIF//Conditions for long
c1 = (p CROSSES OVER q)
IF c1 AND a > a[1] THEN
BUY 1 SHARES AT MARKET
ENDIFWho can help? Thanks!
08/08/2022 at 8:47 AM #198726Hi @Vogeltje
I have a comment about the “previous crossing”
For example, if the “FastMA crosses over SlowMA” then the “previous crossing” must always be “FastMA crosses under SlowMA”.
The “previous crossing” can therefore never be a confirmation of the current crossing but is always the opposite.
(A “Crosses Under” is always followed by a “Crosses Over” and this is always followed by a “Crosses Under”, and so on)
1 user thanked author for this post.
08/08/2022 at 10:00 AM #198731Not tested:
1234567891011121314ONCE PrevOVER = 0ONCE PrevUNDER = 99999999//Conditions for longc1 = (p CROSSES OVER q)IF c1 AND high > PrevOVER THENBUY 1 SHARES AT MARKETPrevOVER = highENDIF//Conditions for shortc2 = (p CROSSES UNDER q)IF c2 AND low < PrevUNDER THENSELLSHORT 1 SHARES AT MARKETPrevUNDER = lowENDIF1 user thanked author for this post.
08/08/2022 at 11:42 AM #198734Same previous crossing TS1234567891011121314151617181920212223242526272829303132333435363738DefParam CumulateOrders = FalseLongCrossingPrice = 0LongPrevCrossingPrice = 0ShortCrossingPrice = 0ShortPrevCrossingPrice = 0FastMA = Average[10](Close)SlowMA = Average[20](Close)If FastMA Crosses Over SlowMA thenLongCrossingPrice = CloseFor i = 1 to BarIndex[1]If FastMA[i] Crosses Over SlowMA[i] thenLongPrevCrossingPrice = Close[i]BreakEndIfNextEndIfIf LongCrossingPrice > LongPrevCrossingPrice thenBuy 1 contract at MarketEndIfIf FastMA Crosses Under SlowMA thenShortCrossingPrice = CloseFor i = 1 to BarIndex[1]If FastMA[i] Crosses Under SlowMA[i] thenShortPrevCrossingPrice = Close[i]BreakEndIfNextEndIfIf ShortCrossingPrice < ShortPrevCrossingPrice thenSellShort 1 contract at MarketEndIfThis system is based on two of the same crossings so for example the last crossing was a “LONG crossing” (crosses over) and when this LONG crossing takes place higher than the previous “LONG crossing” then the system goes LONG and vice versa for SHORT…
1 user thanked author for this post.
08/08/2022 at 3:02 PM #19875308/23/2022 at 11:18 AM #19945508/23/2022 at 11:26 AM #199456Thanks a lot JS this code is working. But, there is a “but”. And that is that on every new day this systems acts on the very first crossing. By the start of a new day the system does not look at the previous crossing, which should be higher or lower. I have studied your code and I can understand a lot of it (I could not have figured it ou my self).
Is it possible that this mistake has to do with:
For i = 1 to BarIndex[1] ?
Does that start every day new? And can this be fixed?
Thanks!
08/23/2022 at 11:54 AM #199458Hi @Vogeltje
Nice that the code works…
How do you use this system?
Do you stop it every night or does it continue automatically?
Do you (manually) close positions?
Is the market you trade on a 24-hour market, or does it have a limited opening?
08/23/2022 at 12:37 PM #199460Previous Crossing V212345678910111213141516171819202122232425262728293031DefParam PreLoadBars = 1000DefParam CumulateOrders = FalseFastMA = Average[10](Close)SlowMA = Average[20](Close)If FastMA Crosses Over SlowMA thenLongCrossingPrice = CloseFor i = 1 to BarIndex[1]If FastMA[i] Crosses Over SlowMA[i] thenLongPrevCrossingPrice = Close[i]BreakEndIfNextIf LongCrossingPrice > LongPrevCrossingPrice thenBuy 1 contract at MarketEndIfEndIfIf FastMA Crosses Under SlowMA thenShortCrossingPrice = CloseFor i = 1 to BarIndex[1]If FastMA[i] Crosses Under SlowMA[i] thenShortPrevCrossingPrice = Close[i]BreakEndIfNextIf ShortCrossingPrice < ShortPrevCrossingPrice thenSellShort 1 contract at MarketEndIfEndIfI think this will solve the problem…
08/23/2022 at 2:32 PM #199466Hi JS,
I use this only in backtesting at the moment. I try different intraday-timeframes like 15 min, 30 min, 1 hour.
I backtest over longer periods like 3 months.
I test on futures like miniDAX (closes 22.00 – 08.00) or miniNasdaq (closes 23.00 -00.00).
Thank you.
Does the new system replace the one before? I guess so and will try.
08/23/2022 at 3:02 PM #199469Hi @Vogeltje
Yes, the “new” system (V2) replaces the previous system…
I have removed the lines that set the “CrossingPrice” to zero.
I have made sure that there are always enough bars present for the calculation (PreLoadBars = 1000)I think this is going to solve the problem…
08/23/2022 at 6:46 PM #199485Yes JS I think tis is working….. but the results are much worse 🙂 🙂 But that is not your mistake…..
Few simple questions:
- why is good to remove the lines that set previous cross to zero?
- you write: FOR….. Break in the tutorial I see For… Else… Break I added Else but it makes no difference ( 🙂 )
- You end “”Break .. Endif… Next… Endif” is there a reason for this extra Next.. Endif?
08/23/2022 at 8:34 PM #199494Hi @Vogeltje
You just must assume that the results are always bad … 😉
- The code is executed at the close of each bar, so after each bar the “CrossingPrice” and “PrevCrossingPrice” are set to zero.This is not desirable because when you compare them, one can still be at zero and then the comparison is always true.
- You can use “else” when you want to set a variable to zero or one, for example:
If ….then
Variable = 1
Else
Variable = 0
EndIf
- You are looking for the previous crossing with “For i=1 to BarIndex[1]”, when the “If … then” is not true then you end up after the “EndIf” and that is “Next”
When the “If… then” is true then you end up at “Break” and the “For … to” ended.
Hopefully a little clear.
09/02/2022 at 9:27 AM #200043 -
AuthorPosts
Find exclusive trading pro-tools on