code inside bar-trade
Forums › ProRealTime English forum › ProOrder support › code inside bar-trade
- This topic has 7 replies, 3 voices, and was last updated 11 months ago by kimmen.
-
-
12/03/2023 at 9:15 PM #224779
Hello.
I am trying to code a trading system based on inside bar. I have created an own indicator that gives 1 when an inside bar appears within my margins. With this code it is only taking trades for the upside. If the inside-bar indicator gives 1 i want to set an stop order att the high of the mother-bar and a stoploss at the low of the mother-bar.
Question 1
When i probacktest, it is not taking a trade every time, only sometimes. And i dont understand why?
Question 2
If i want it to make pending-orders both at the uppside and downside until one will be activated, can i do it with two tradingsystems? I guess i just can put one order at once in one trading-system.
12/03/2023 at 9:21 PM #224781123456789101112131415161718192021222324//status of the indicatorindicatoractive = CALL "kims inside bar"[80, 11, 4]//Pending-order, pendingorder=1 make the order active more than 1 bar, until it become zeroIf indicatoractive=1 and pendingorder=0 and not ONMARKET thenpendingorder=1pipsloose=(high[1]-low[1])*10000entry=high[1]pipsgain=(high[1]-low[1])*10000elsif pendingorder=1 and not onmarket thenbuy 16 contracts at entry stopSET STOP pLOSS pipslooseSET TARGET pPROFIT pipsgainloose=low[1]elsif pendingorder=1 and high[0]>=entry or pendingorder=1 and low[0] <=loose or onmarket thenpendingorder=0endif12/04/2023 at 10:20 AM #224795You should port the indicator as well, to be able to test the code.
In line 15, you are using a STOP order which means that the current price is LOWER than the entry price, is that always the case?
12/05/2023 at 9:22 PM #224906as it is an inside bar trade, the daughter bar must be lower than the mother bar that sets the stop order level and then the price is always below my stop order. But you are right, a gap can appear between bars. I could enter that stop order is placed for example 1 pips above the mother bar high to cover this. Do you have any better suggestions?
12/05/2023 at 9:27 PM #224907here comes the indicator for the trade123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657//Definition of motherbar and doughterbar as high and lowMotherbarhigh = high [1]Motherbarlow = low [1]Doughterbarhigh = highDoughterbarlow = low//Difinition of the motherbar opening and closingMotherbaropen = open [1]Motherbarclose = close [1]//sizemotherbody is a limit on how big the body in the bar should be set in percentage units.sizemotherbody=80//max limit on how big the motherbar can be and should be set in pipsmaxmotherbar=11//min-limit is set on how small the motherbar can be and should be set in pipsminmotherbar=4//motherbody up and down are the bodies percent of the bar in decimal form.motherbodyup = (motherbarclose - motherbaropen)/(motherbarhigh-motherbarlow)motherbodydown = (motherbaropen - motherbarclose)/ (motherbarhigh-motherbarlow)//if statement where validity if the body of the motherbar is large enough is determinedif motherbodyup>sizemotherbody/100 or motherbodydown>sizemotherbody/100 thenbodyvaild=1elsebodyvaild=0endif//if statement where a max limit is set on how big the motherbar can be.if motherbarhigh-motherbarlow<maxmotherbar/10000 thenmaxbarvaild = 1elsemaxbarvaild=0endif//if statement where min-limit is set on how small the motherbar can be.if motherbarhigh-motherbarlow>minmotherbar/10000 thenminbarvaild = 1elseminbarvaild=0endif//if the motherbar is greater than the doughterbar and the body in the motherbar is greater than the limit value bodyvaild and the bar is not greater than the limit value maxbarvaild and the bar is not less than the limit value minbarvaild, becomes results=1If Motherbarhigh > Doughterbarhigh and Motherbarlow < Doughterbarlow and bodyvaild=1 and maxbarvaild=1 and minbarvaild=1 Thenresults = 1elseresults=0Endif//sending the results to the indicatorreturn results12/05/2023 at 9:31 PM #22490812/06/2023 at 12:44 AM #224910Hi @kimmen
Try this one:
Kims Inside Bar System12345678910111213141516171819202122//status of the indicatorIndicatorActive = CALL "kims inside bar"[80,11,4]//Pending-order, pendingorder=1 make the order active more than 1 bar, until it become zeroIf IndicatorActive=1 and not ONMARKET thenPendingOrder=1pipsLoose=(high[1]-low[1])*10000Entry=high[1]Loose=low[1]pipsGain=(high[1]-low[1])*10000EndIfIf PendingOrder=1 and not onmarket thenbuy 16 contracts at entry stopSET STOP pLOSS pipsLooseSET TARGET pPROFIT pipsGainEndIfIf PendingOrder=1 and High[0]>=Entry or PendingOrder=1 and Low[0]<=Loose or OnMarket thenPendingOrder=0EndIf2 users thanked author for this post.
12/07/2023 at 12:37 PM #224989Thanks for the help. Now it works much better. However, I don’t understand why it sometimes skips trades. For example as in the picture I am attaching, EUR/USD 5 min chart, 2023-12-07 at 09:30 and 10:25. The indicator shows 1 but it only trades on the first opportunity and skips the second.
The changes you made that I can see is that you removed pendingorder=0 in my first if statement where I wrote: If indicatoractive=1 and pendingorder=0 and not ONMARKET then pending order=1. Now it works better, but this probably means that pipsLoose,Entry,Loose,pipsGain changes every bar when the indicator is active until the price passes the stop order and a deal is made. Or is “onmarket” counted already when the stop order is placed on the market? The indicator can show 1 for several bars but I want the pipsLoose,Entry,Loose,pipsGain levels to be set only after the first time. How can i fix this issue?
thanks again for the help
-
AuthorPosts
Find exclusive trading pro-tools on