Hard stop using a candle
Forums › ProRealTime English forum › ProOrder support › Hard stop using a candle
- This topic has 15 replies, 4 voices, and was last updated 7 years ago by Eric.
-
-
01/26/2017 at 7:19 PM #22654
Hi
The attached code works fine except for the “stop” which closes losing trades at the end of the day using the Flatafter condition. My intention is to place the stop 1.1 points above the high of the 8:00 am (GMT) candle. Can anyone suggest how this could be gone please? The “SellPrice” sets itself per the low of the 8:00 am candle -1.1 points correctly.
I can graph c1 which is showing the correct value but cannot seem to work out how to link the value to the “stop”.
Can anyone help please?
1234567891011121314151617181920DEFPARAM FlatAfter = 163000StartingTime = 080500SellPrice = Low[0] - 1.1*pointsize//sell contractif time >= 080500 and time < 081000 thensellshort 1 contract at SellPrice stopendif//stop lossif time = StartingTime thenc1 = (High[0]+1.1*pointsize)endifSET STOP LOSS c1//set limitif time = StartingTime thenc2 = (High[0]-Low[0])*1.5endifSET TARGET PPROFIT c201/26/2017 at 10:58 PM #22693I’ve tried but I can’t get it to reference that first bar either :-/
I was using this link below.
Hopefully Nicholas can give you some idea
123<a href="https://www.prorealcode.com/documentation/category/constants/page/2/">https://www.prorealcode.com/documentation/category/constants/page/2/</a>01/27/2017 at 10:49 AM #22715Hi Big Hug,
Thanks for the info. about range commands and I agree its not the solution to the problem of linking the stop to a candle.
Nikolas may be able to help if he picks up on the problem ,if not, it seems a major restriction in the software.
I’m sure you can use “intradayindex” to identify a particular candle although the write up if not particularly clear as the index number will be continually moving so doesn’t help.
01/27/2017 at 10:53 AM #2271601/27/2017 at 11:02 AM #2271701/27/2017 at 1:53 PM #22746That’s because when using the “stop loss” command, you need to give your code your desired stop “distance” = the number of points between c1 and your entry, not c1 itself which is the stop “level”.
So with “stop loss c1” (c1 = high[0]+1.1*pointsize level), you have pushed your stop far away at “entry + c1” level (so roughly twice current price level), that’s why it’s never touched within the day, hence the defparam flatafter bringing an end to it.
Changing your line “stop loss c1” into “stop loss (c1 – tradeprice)” should result in triggering the stop at the c1 level.
01/27/2017 at 4:09 PM #2276501/27/2017 at 5:14 PM #22766Great Noobywan – thank you . Now I have to understand it 🙂
1234567891011121314151617181920DEFPARAM FlatAfter = 163000StartingTime = 080500SellPrice = Low[0] - 1.1*pointsize//sell contractif time >= 080500 and time < 081000 thensellshort 1 contract at SellPrice stopendif//stop lossif time = StartingTime thenc1 = (C1-tradeprice)endifSET STOP LOSS c1//set limitif time = StartingTime thenc2 = (High[0]-Low[0])*1.5endifSET TARGET PPROFIT c201/27/2017 at 7:40 PM #22784I don’t agree with your line 12 “c1=C1-tradeprice”, there are two ways to do it:
- either you can keep :
1c1 = high[0]+1.1*pointsize
and then the syntax for the stop would be :
1set stop loss (c1 - tradeprice) - or you can say :
1c1 = high[0]+1.1*pointsize - tradeprice
and then you can keep :
1set stop loss c1because you have made of c1 a distance rather than a level
Should also work with “ploss” by the way… (p for points, just like first p of pprofit)
1 user thanked author for this post.
01/28/2017 at 12:02 PM #22830Hi
I’ve substituted your second formula on my original EA and graphed C1 and the value is not what I would expect
reference information using the DAX for 25th January:-
8:00 High 11691.3 Low 11676.5 candle length 14.8.
Trade was actioned on the 8:05 candle (correctly) at 11675.4.
The stop should have been = 11691.3+1.1-11675.4 =17.0 but when I graphed the stop it came out as 179.4.
On test this again closed out at 163000.
1234567891011121314151617181920212223DEFPARAM FlatAfter = 163000StartingTime = 080500SellPrice = Low[0] - 1.1*pointsize//sell contractif time >= 080500 and time < 081000 thensellshort 1 contract at SellPrice stopendif//stop lossif time = StartingTime thenc1 = ((High[0]+1.1*pointsize)-tradeprice)endifSET STOP LOSS c1//set limitif time = StartingTime thenc2 = (High[0]-Low[0])*1.5endifSET TARGET PPROFIT c2graph c1graph tradepriceI thought it might be because we need to reset C1 at the start of day but don’t think its that.
01/28/2017 at 1:32 PM #22835Do you have screen capture? If I look at the IG cfd data I don’t have these values for these times, so I can’t reproduce your backtest. I assume either you’re looking at something else than my ig dax cfd (futures?) or maybe not the 25/01? Also important, what timeframe? 5 minutes? 1 minute? or (x) minutes? Specifying timeframe might be important here because if using the “easy way” tradeprice to recover your entry, this calls the price level of the latest trade, that latest trade could be either the last trade exit if not entered a new trade yet, or the latest entry, and depending on your timeframe the code might have been setting the stop with the price level of the previous exit instead of current entry (it all depends on in what order events happen and lines are read). For example first sugestion to keep c1 like you first did but make “set stop loss c1-tradeprice” would more likely take into account the latest entry rather than last sell, whilst using the other suggestion of taking tradeprice into account when defining c1 inside that if statement with time restriction could be fine for capturing the high, but not for the tradeprice depending on what timeframe is used.
01/28/2017 at 2:16 PM #22840maybe not the best solution (and fastest) but when i do something like this i try to make an indicator first and then use it in the code by call
indicatorlow = ? -1.1
botten = CALL indicatorlow
and the stoploss
Sell at botten stop
but if you can write it without using call its probably better
01/28/2017 at 2:45 PM #22842Hi
I used the IG spreadbet account and the values and timeframe are correct. The reason I took option 2 of your suggestions was because I was going to add “buys” with an “if” statement to identify whether the trade is a “buy” or “Sell” that way I can use one EA instead of two i.e. with 2 definitions of C1.
In fact, tradeprice may be problem with buy and sell in the same EA so may need to keep them separate.
I’ll go and have a further think but thanks for your interest and input.
01/28/2017 at 2:51 PM #22843Thanks for the input Eric. Because I’m trying to identify the low/high of a specific 5 minute candle at 8:00 a.m. UK time not sure how to pinpoint in an indicator the price at 8:00. I can get the code to work if I allow the low/high value to change with each candle.
01/28/2017 at 3:06 PM #22844 - either you can keep :
-
AuthorPosts
Find exclusive trading pro-tools on