setting stop and target at bar high and low
Forums › ProRealTime English forum › ProOrder support › setting stop and target at bar high and low
- This topic has 6 replies, 4 voices, and was last updated 6 years ago by
Jaldidee.
-
-
06/05/2019 at 8:20 PM #100010
Hello everybody,
I am fairly new at programming my own trading codes. I recently finished the advanced programming course and i am starting to program my first (simple) codes.
I have run into a problem with setting my stop and target at de previous bar and low.
What I want to achieve is that when a insidebar appears in a strong trend a order is put in.
The entrypoint is the previous bar high(high[1] (this i already accomplished!)
The stoploss is at the previous bar low (low[1]). (this also now works in the following code thanks to this forum)
The target I want to set at two times the difference between the bar high and bar low so I get a R:R of 1:2.
1234567891011121314151617once mystop = 1//once mytarget = 1var1 = ExponentialAverage[20](close)>= ExponentialAverage[100](close)var2 = High[0] < High[1]var3 = Low[0] > Low[1]// Conditions to enter long positionsIF var1 AND var2 AND var3 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT HIGH[1] STOPmystop = low[1]//mytarget = high[1] + (2*(high[1]-low[1]))ENDIFsell at mystopbull stop//sell at mytarget stopHope someone can help me.
Kind Regards,
Jaldidee
06/08/2019 at 6:52 PM #100227Change the last line from STOP to LIMIT
123456789101112131415161718var1 = ExponentialAverage[20](close)>= ExponentialAverage[100](close)var2 = High[0] < High[1]var3 = Low[0] > Low[1]// Conditions to enter long positionsIF not onmarket and var1 AND var2 AND var3 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT HIGH[1] STOPmystop = low[1]mytarget = high[1] + (2*(high[1]-low[1]))sell at mystopbull stopsell at mytarget limitENDIFif onmarket thensell at mystopbull stopsell at mytarget limitendifI’ve added a IF NOT ONMARKET condition as otherwise the stop and limit values could change after you have opened a position. This does however mean that you can not have cumulating positions.
06/09/2019 at 9:58 AM #100246Above code added to here
06/09/2019 at 12:38 PM #10025106/09/2019 at 4:09 PM #10025506/09/2019 at 6:44 PM #100266Yeah I noted that … it needs below as Line 9?
Vonasi must not have had his coffees! 🙂
Oh no it was 6:52 PM … he must have started on the beers early … well it is Sunday and he had been travelling for days! 🙂
19 mystopbull = low[1]06/09/2019 at 7:45 PM #100267Hello Guys,
Grahal is right. The inconsistency was in difference between mystop and mystopbull (has to be the same offcourse!).
Underneath I complemented the code now with also the conditions for short positions.
1234567891011121314151617181920212223242526272829var1 = ExponentialAverage[20](close)>= ExponentialAverage[100](close)var2 = High[0] < High[1]var3 = Low[0] > Low[1]var4 = ExponentialAverage[20](close)<= ExponentialAverage[100](close)// Conditions to enter long positionsIF not onmarket and var1 AND var2 AND var3 AND not daysForbiddenEntry THENBUY 1 CONTRACT AT HIGH[1] STOPmystoplong = low[1]mytargetlong = high[1] + (2*(high[1]-low[1]))ENDIFif onmarket thensell at mystoplong stopsell at mytargetlong limitendif//conditions to enter short positionsIF not onmarket and var4 AND var2 AND var3 AND not daysForbiddenEntry THENSELLSHORT 1 CONTRACT AT LOW[1] STOPmystopshort = high[1]mytargetshort = low[1]-(2*(high[1]-low[1]))ENDIFif onmarket thenexitshort at mystopshort stopexitshort at mytargetshort limitendif -
AuthorPosts
Find exclusive trading pro-tools on