Wait for specific event before placing a new Buy Stop
Forums › ProRealTime English forum › ProOrder support › Wait for specific event before placing a new Buy Stop
- This topic has 10 replies, 4 voices, and was last updated 1 year ago by
ZeroCafeine.
-
-
05/10/2023 at 10:57 AM #214454
Hello,
I have a hard time finding how to write what I want, simply put let’s say we have a
Simple Moving Average 20 Period
and aSimple Moving Average 50 Period
.How could I do so when the SMA20 > SMA50 and close < SMA50 a
BUY x SHARES AT SMA50 STOP
is placed on the SMA50 and if the buy stop is reached and the shares bought, then wait for SMA20 to go below SMA50 then come back above before placing a new buying stop on SMA50? So if SMA20 > SMA50 and close keep going above and below SMA50, only the first time close was below SMA50 the buy stop was placedIt’s the waiting part once a buy stop has been reached that is causing me an issue 😕 If I enter and exit on the same candle I can’t just call
IF LongOnMarket
and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe05/10/2023 at 11:34 AM #214456If I enter and exit on the same candle I can’t just call IF LongOnMarket and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe
The solution comprises two parts (pseudo code) :
12345678910111213141516171819202122Once PutLimit = 0NewOrderGoodToGo = 0If PutLimit then // Check whether order was filled.If StrategyProfit <> StrategyProfit[1] then // Somehthing changed ?// This either tells you're OnMarket now, or that you're foo already again.If Not OnMarket then// Prepare condition for new Order.NewOrderGoodToGo = 1endifendifPutLimit = 0 // Reset.endif[...]If NewOrderGoodToGo and MySMAConditions thenBuy At MyPrice LimitPutLimit = 1endifNewOrderGoodToGo = 0 // Reset.This is a quick and dirty of course, but I assume sufficient for you to fully work out.
Checking for having been OnMarket within a candle is always a hassle and depending on whether you applied other stuff, my example must be adjusted.
N.b.: IMO it is an omission that PRT does not provide a simple “HasTraded” as a Boolean telling you that a trade occurred in the last bar.Hint : keep on checking your Ticks in the Optimization Result window. Each count in there implies a “too positive” result, as in-bar multiple trades can not be tracked correctly by PRT. At least always cause the Ticks to be on as per the Editor window checkbox, and ALWAYS backtest from within the button on that window (or else results are erroneous).
1 user thanked author for this post.
05/10/2023 at 11:47 AM #214459PRT does not provide a simple “HasTraded” as a Boolean
12LongTriggered[N]ShortTriggered[N]2 users thanked author for this post.
05/10/2023 at 5:47 PM #214478Yes, but that would be the same as an If OnMarket which was not true the previous call, right ?
So it remains a kind of a hassle to know whether two events happened (even three can occur) within the bar. An Enter followed by an Exit would not be unambiguously covered with anything.
05/12/2023 at 7:05 PM #2146311
2
LongTriggered[N]
ShortTriggered[N]no good Snippet link about this fonction LongTriggered ?
05/12/2023 at 8:10 PM #2146331
2
LongTriggered[N]
ShortTriggered[N]
no good Snippet link about this fonction LongTriggered ?
That is quite easy to use :
LongTriggered
is True if we entered long on the current candle (otherwise False)LongTriggered[1]
is True if we entered long on the last candle (otherwise False)- etc
So one way to use it could be
123456//If we entered Long on the last candle//Then put a Stop Loss 1 pip below the last candleIF LongTriggered[1] THENSET STOP Price low[1] - 1*PointSizeENDIFJust an example, it would be dangerous to use that if the last candle was finally bearish and the SL was put too late
1 user thanked author for this post.
05/12/2023 at 10:22 PM #214635@aldtrading tks you,
I want somethink maybe more complicated 😊
05/13/2023 at 8:15 AM #214636Are there no
SellTriggered
andExitShortTriggered
variables so I can know when instructions likeSELL x SHARES AT y STOP
(to exit partially from a position) have been triggered and act accordingly?05/13/2023 at 9:33 AM #214638you can use CountOfPosition of the current candle and the previous candle to compare the size of the position maybe 😊
1 user thanked author for this post.
05/13/2023 at 9:36 AM #214639Yep I came up with something like this too, just making sure because I found it funny we have the implementation for when entering the positions but not for when exiting them 😁
05/13/2023 at 10:56 PM #214659don’t forget to use ABS when Short :
1abs(COUNTOFPOSITION)1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on