placing an order when predefined levels achieved.
Forums › ProRealTime English forum › ProScreener support › placing an order when predefined levels achieved.
- This topic has 19 replies, 2 voices, and was last updated 3 years ago by Slowlyslowly.
-
-
05/07/2021 at 9:16 AM #169015
Hi
If you look at the attached I need to know how to code this example.
lets assume CURRENT price is ABOVE level A and B.
Price needs to achieve a price less than A but not less than B (a -10 pips) , then place an order to BUY when the 9 EMA crosses 26 EMA .
If price achieves level B (a -10 pips) then no order is placed for the EMA cross over .
Is this possible?
Obviously if you could elaborate on the reverse example , i.e placing a code when the current price is lower than a fictions level A and B (which are higher levels) and the code would place a sell order for a EMA cross under.
Many thanks.
05/07/2021 at 11:57 AM #169030There you go:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970DEFPARAM CumulateOrders = FALSEONCE P = 4ONCE Pips = 10 * PipSizeONCE LongA = 0ONCE ShortA = 0//clear data each new dayIF Day <> Day[1] THENLongA = 0ShortA = 0ENDIF//set entry conditions, if not previously setIF LongA = 0 THENLongA = lowest[P](low)LongB = LongA - PipsEntryLong = 0ENDIFIF ShortA = 0 THENShortA = highest[P](high)ShortB = ShortA + PipsEntryShort = 0ENDIF//clear entry data when on marketIF OnMarket THENEntryLong = 0EntryShort = 0IF LongOnMarket THENLongA = 0LongB = 0ENDIFIF ShortOnMarket THENShortA = 0ShortB = 0ENDIFENDIF//calculate averagesEma9 = average[9,1](close)Ema26 = average[26,1](close)//LONGIF close <= LongB THENEntryLong = 0ELSIF close < LongA THENEntryLong = 1ENDIFIF EntryLong AND Not LongOnMarket AND Ema9 CROSSES OVER Ema26 THENBuy 1 Contract at MarketENDIF//SHORTIF close >= ShortB THENEntryShort = 0ELSIF close > ShortA THENEntryShort = 1ENDIFIF EntryShort AND Not ShortOnMarket AND Ema9 CROSSES UNDER Ema26 THENSellshort 1 Contract at MarketENDIF// TP & SLSET Target pProfit 100SET Stop pLoss 50//monitor some data//graphonprice LongA coloured(0,128,0,150)//graphonprice LongB coloured(0,128,0,150)//graphonprice ShortA coloured(0,0,0,255)//graphonprice ShortB coloured(0,0,0,255)05/07/2021 at 12:01 PM #169031At lines 15 and 20 you can change the way to calculate the A-B range. I used the lowest and the highest prices within the last P bars.
05/07/2021 at 4:40 PM #169055Thank you Roberto ,
so just to clarify if i wanted a level broken below for a buy at 2100 i would amend line 15 to :
Long A = 2100
and if I wanted a level broken above for a sell at 3800 i would amend line 20 to :
Short A = 3800.
so would i still need line 2 P= 4 ? As not sure how that relates…..
and assuming a long trade ie trigger level is 2100 (market is dropping and looking for reversal) ( but not 10 pips lower ) and entry is a 9/26 cross over , if the 926 cross over happens outside the range of 2100-2090 which is very likely the entry will still work as 2100 was achieved 2090 was not (which invalidates the trade) – it then retraces to more than 2100 to cross over 926 (ie reversal happened) for example 2120 and then enters the trade as the 926 crosses over for a buy ?
The code will cope with this ?
Many thanks for clarification.
05/07/2021 at 5:12 PM #169056You don’t need line 2 anymore as it was only used by HIGHEST and LOWEST.
As to your question “and assuming a long trade ie trigger level is 2100 (market is dropping and looking for reversal) ( but not 10 pips lower ) and entry is a 9/26 cross over , if the 926 cross over happens outside the range of 2100-2090 which is very likely the entry will still work as 2100 was achieved 2090 was not (which invalidates the trade) – it then retraces to more than 2100 to cross over 926 (ie reversal happened) for example 2120 and then enters the trade as the 926 crosses over for a buy ?“, it already entered a LONG trade, do you want to accumulate another position if the same 2100 level is crossed over again?
05/07/2021 at 6:09 PM #169057Hi roberto
No did not want to enter again – was just clarifying that once it hits the initial trigger of 2100 it places an order for a 926 cross over , and even if this 926 does not happen for a while it will maintain that order until its complete or becomes invalid if subsequently price crosses line B (+-10 depending on direction ) ?
05/07/2021 at 11:05 PM #169073Yes, that’s exactly what it’s doing now.
It is either triggered or invalidated.
05/10/2021 at 11:09 AM #169254Hi Roberto
Code looks fantastic but a problem …..
I ran the code this morning on the FTSE – so i amended line 20 to read SHORT A = 7154 removed the line 2 P reference and just set LONG A = 0
I loaded the code up at 0900 am and it triggered on the 926 cross under (2 minutes) but it should not have as SHORT A was never reached at 7154.
It had previously hit 7154 earlier but even if this is the error and it noted the level was hit before the code was activated it should have been an invalid trade as it breached 10 pips higher at 7164 ?
Am i missing something ?
attached screen shot and actual code used on the FTSE this morning on 2 minutes timeframe .
05/10/2021 at 11:42 AM #169260Ok, I modified it so that it starts ONLY when you run it, ignoring whatever happened before:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273DEFPARAM CumulateOrders = FALSEDEFPARAM PreLoadBars = 0//ONCE P = 4ONCE Pips = 10 * PipSizeONCE LongA = 0ONCE ShortA = 0ONCE MyTime = Time//clear data each new dayIF Day <> Day[1] THENLongA = 0ShortA = 0ENDIFIF BarIndex >= 26 AND (Time >= MyTime) then//set entry conditions, if not previously setIF LongA = 0 THENLongA = 0//lowest[P](low)LongB = LongA - PipsEntryLong = 0ENDIFIF ShortA = 0 THENShortA = 7154//highest[P](high)ShortB = ShortA + PipsEntryShort = 0ENDIF//clear entry data when on marketIF OnMarket THENEntryLong = 0EntryShort = 0IF LongOnMarket THENLongA = 0LongB = 0ENDIFIF ShortOnMarket THENShortA = 0ShortB = 0ENDIFENDIF//calculate averagesEma9 = average[9,1](close)Ema26 = average[26,1](close)//LONGIF close <= LongB THENEntryLong = 0ELSIF close < LongA THENEntryLong = 1ENDIFIF EntryLong AND Not LongOnMarket AND Ema9 CROSSES OVER Ema26 THENBuy 1 Contract at MarketENDIF//SHORTIF close >= ShortB THENEntryShort = 0ELSIF close > ShortA THENEntryShort = 1ENDIFIF EntryShort AND Not ShortOnMarket AND Ema9 CROSSES UNDER Ema26 THENSellshort 1 Contract at MarketENDIF// TP & SLSET Target pProfit 100SET Stop pLoss 50ENDIF//monitor some data//graphonprice LongA coloured(0,128,0,150)//graphonprice LongB coloured(0,128,0,150)//graphonprice ShortA coloured(0,0,0,255)//graphonprice ShortB coloured(0,0,0,255)// Stops and targets : Enter your protection stops and profit targets here05/11/2021 at 8:14 AM #169361Hi Roberto
great seems to have fixed that , but code seems to be ignoring line 4 ONCE PIPS = 5 x PIPSIZE, and line 35 LONGB = LONG A – PIPS
so long A is trigger point to look for a 926 cross over on 2 minutes , but if LONG B is hit no trade should action for the day .
In the attached example it entered at the 926 cross over great ! but it ignored the fact LINE B was breached by a lot , and as I read the code line B was 5 pips below line A as soon as this is hit no 926 should be looked for and trade is invalid for the day ?
attached is a back test but it performed exactly the same in real time yesterday ?
attached code which has a flag statement added but that’s it. what am I missing ?
Thanks for your help.
05/11/2021 at 5:20 PM #169422It’s not ignoring any lines.
It enters AFTER a crossover has occurred at the closing of the candle (and prior to that, price had sit in the range a-B).
05/11/2021 at 9:13 PM #169432Hi Roberto
maybe I didn’t explain it correctly .
level A triggers looking for an EMA cross over .
if BEFORE this cross over occurs it breaches level B Then the trade is invalid and no trade must occur .
you can clearly see from the screen shot that code is placed live then level A is hit then level B is breached before an EMA cross over so no trade should happen .
You are correct the cross over is in the range a-b but that should be irrelevant – the cross over CAN occur even above level A if price retraces after hitting level A as long as level B is not breached before the ema cross over.
The key is AFTER the code is activated – the first action is level A must be hit – this activates looking for the ema cross over .
if level b is breached BEFORE the ema cross over the trade is cancelled for the day . this is very important as it can retrace which is what it did in the screen shot – but the trade is no longer valid .
you will see from the screen shot – level B was breached after level A was hit and before the ema cross over therefore it should not trade .
In the screenshot it did subsequently retrace and crossed over on the ema and traded but it should not as level B was breached before the ema cross over so it must cancel the trade / deactivate the code . Once level B is breached it should stop looking for a trade or any ema cross over .
it’s probably easier to look at the possible options
…………………………………………………………..,,
The possible option are ONLY 2 .price is falling so this is the sequence of events in order :
OPTION 1
1.level A is hit
2.it starts to look for ema cross over
3.ema cross over happens a trade is placed – this cross over can be at ANY level below A OR above A but NOT below B ( note the cross over can happen at ANY level >B and <or > A AFTER level A is activated FIRST triggering it looking for this ema cross over – which is step 1 above )
(B)
1. level A hit
2.it starts to look for ema cross over
3.no ema cross over happens
4.level B hit so trade/code cancelled . It no longer looks for any cross over or any trade the breach of level B basically turns the code off .
obviously the reverse for a sell.
does that help explain it better by looking at the only 2 possible sequences of events ?
05/12/2021 at 9:52 AM #169452I could find the glitch.
I had forgotten to disable trading for the day on a levelB breach. Now as breach occurs, trading will be disabled (for the chosen direction) for the day and willbe resumed at the start of the new day (when IntraDayBarIndex = 0).
I also added comments where you can replace CLOSE with LOW (for Long trades) or HIGH (for Short trades), if you want to use, as price trigger before the crossover, just a “touch” of the price, rather than the closing price.
1 user thanked author for this post.
05/12/2021 at 9:53 AM #169455You may have seen an email about a post that I almost immediately deleted because it was not a working correction.
05/12/2021 at 10:30 AM #169462Many many thanks Roberto , I will test it today.
-
AuthorPosts
Find exclusive trading pro-tools on