once function combined with a stop
Forums › ProRealTime English forum › ProOrder support › once function combined with a stop
- This topic has 12 replies, 3 voices, and was last updated 3 years ago by Albaran.
-
-
03/04/2021 at 5:41 PM #163141
Hi there,
Having trouble to understand why below code doesn’t behave like I would have it:
12345678c1 = barindex - tradeindex <= 45Once c11 = (close or high) >= (tradeindex + 14)If not onmarket thenbuy 5 contract at marketelsif countoflongshares = 5 and c1 and c11 thensell at Fulllongstop stopendifProblem with above is that the stop doesn’t seem to kick in as soon as c1 and c11 are satisfied.
C11 needs to be read only once as the stop should remain active even if c11 isn’t valid anymore. The stop needs to remain active once it has kicked in..
Thanks for getting back to me,
cheers.
03/04/2021 at 7:49 PM #163147ONCE means that whatever follows on the same line is evaluated only when the strategy is first executed, not next bars.
At that time TRADEINDEX is 0.
Next, you assign c11 a logical value of a price compared to another logical value.
c11 will ALWAYS be false if used on most currency pairs and will ALWAYS be false with indices. That’s why the SELL pending order can’t be placed when you want to.
What do you want to achieve with the first two lines?
03/05/2021 at 11:54 AM #163195Well, the problem I’m having right now is that the STOP that I want to put in place seems to come and go without the “assumed wrong idea of of the ONCE function above”. That’s why I thought I’d give the “assumed wrong idea above” a try.
The idea behind the first two lines is the following:
1c1 = barindex - tradeindex <= 45The first condition is there because I have different STOP levels in mind. See it as an inactivity, if TARGET PRICE is not reached within the next 45 bars then another type of STOP sets in.
1Once c11 = (close or high) >= (tradeindex + 14)With the second (wrong) condition I wanted to prevent that the stop comes and go (which is the case without the c11 idea). I didn’t put the whole code on display in my first post but you can assume that, because of various reasons, the stop comes and goes.
See the condition as the TRAILINGSTART part. As soon as the POSITIONPRICE + TARGET PROFIT is reached, I want the stop to kick in.
So the second condition only needs to be satisfied once and shouldn’t be recalculated bar after bar.
My mistake here is that I thought that the ONCE function could be used for trading strategies as well and not only for indicators (or maybe it can be but from the explanation that you gave me, I understand it can’t be used in that way?)
03/05/2021 at 12:04 PM #163197c1 should be written as:
1c1 = OnMarket AND (barindex - tradeindex <= 45)to make sure it’s not always evaluated.
I still can’t understand what your goal is with:
1Once c11 = (close or high) >= (tradeindex + 14)let’s replace it the real values (for both DAX and EUR/GBP):
1234//Once c11 = (close or high) >= (tradeindex + 14) becomesOnce c11 = 13950 >= 14 //DAX (always TRUE)Once c11 = 0.8650 >= 14 //EUR/GBP (always FALSE)03/05/2021 at 12:09 PM #16319803/05/2021 at 3:32 PM #163209Your code,line 7, will only be executed when c11 is TRUE, which can be at some bar,but cannot be the following bar.
When it’s true for the first time, you need to keep placing the stoip order, even later when the porice drops down (that’s what it’s made for).
So you should use a flag (a variable, no matter the name, that is ised to signal something). This flag should be rest to 0 when not on market, then set to 1 whenever c11 is true.
Then you can place the stop order while this flag os true:
1234567891011121314if not OnMarket thenFlag = 0endifc1 = OnMarket and (barindex - tradeindex <= 45)IF Flag = 0 thenc11 = close >= (tradeprice + 14*pipsize) //you may use HIGH instead of CLOSE, PIPSIZES makes your code portableFlag = 1endifIf not onmarket thenbuy 5 contract at marketendifif Flag thensell at Fulllongstop stopendif1 user thanked author for this post.
03/05/2021 at 6:30 PM #163229I don’t really understand the lines 5 to 7 (what is the trigger in your example that changes flag into = 1?); shouldn’t it be like below?
12345IF Flag = 0 thenIf c11 = close >= (tradeprice + 14*pipsize) then //you may use HIGH instead of CLOSE, PIPSIZES makes your code portableFlag = 1EndifEndifBut I get the overall idea of the flag!
I’ll give it a try and let you know if I still got any questions 🙂
03/05/2021 at 6:48 PM #163230Yes, well spotted.
I forgot to embed that within IF…ENDIF.
03/08/2021 at 4:04 PM #163469Works great!
I got another (very silly) question though and I don’t know if there’s already a post covering this but here it goes…
When is the cost of a guaranteed stop loss triggered? I would assume every time you use the stop function?
Or is it only triggered when using the below kind of command:
1Set stop loss xand not when using this kind of command
1Sell at FullLongStop Stop?
03/08/2021 at 4:26 PM #163475This is something I cannot answer. I would guess when a STOP order yields a loss, not a profit, but I am not aware of it.
I suggest that you post this question at https://www.prorealcode.com/forum/prorealtime-english-forum/prorealtime-support/, since it’s a PRT monitored forum and someone will surely reply asap.
03/08/2021 at 4:30 PM #163476Not so silly after all then (I thought it would be)!
I’ll do that and keep you updated with the publication of a link in this topic then!
1 user thanked author for this post.
03/08/2021 at 4:31 PM #163479IG only deduct their guaranteed stops fee when a stop is hit so if you have an order on a market attached to a position to close it at a worse price than the entry price and that order is hit you will get charged the fee.
This is only my assumption as I don’t use guaranteed stops.
03/08/2021 at 5:16 PM #163498There its is:
https://www.prorealcode.com/topic/cost-trigger-of-a-guaranteed-stoploss/#post-163496
It’s triggered in both cases!
-
AuthorPosts
Find exclusive trading pro-tools on