Wait for Price over/under code help!
Forums › ProRealTime English forum › ProOrder support › Wait for Price over/under code help!
- This topic has 10 replies, 3 voices, and was last updated 7 years ago by
MattyJ.
-
-
10/02/2017 at 12:06 PM #47990
Hi Guys,
I just wanted to ask for a little bit of help adding something to my SMA system.
Here is my current system –
123456789101112131415161718192021222324252627282930313233343536373839REM Money ManagementCapital = 2000 // initial capital at launch of the strategyRisk = 0.05 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))indicator1 = Average[MA1](close)indicator2 = Average[MA2](close)indicator3 = Average[MA3](close)c1 = (indicator1 CROSSES OVER indicator2)c2 = (indicator1 CROSSES UNDER indicator3)if c1 and ControlBuy =0 thenControlBuy=1ControlSell=0BUY maxrisk-0.5 PERPOINT AT MARKETelsif c2 and ControlSell=0 thenControlSell=1ControlBuy=0SELLSHORT maxrisk-0.5 PERPOINT AT MARKETEndifSET STOP LOSS SLI am hoping to add the following to this.
When c1 occurs then wait x number of bars and if the price is above the price at the SMA crossover then buy, if price is under then no trade. And likewise for C2.
Basically, waiting to see if a trend becomes established by waiting x number of bars and cutting down the number of losing trades.
I hope that makes sense.
10/02/2017 at 1:04 PM #48003Automatic trading support go to ProOrder support… and please add code within the <> code button please! 😐
Ok, so firstly we save the BARINDEX of the bar that saw the moving averages cross. Before buying or selling, we verify if the trend if still the right one (no contrarian cross over have occurred since) and if we have sufficient bar elapsed since the cross over/under. You can adapt this bar quantity with the ‘barquantity’ variable in the code.
123456789101112131415161718192021222324252627282930313233343536373839barquantity=5 //how many bars to wait after a signal to open a new orderREM Money ManagementCapital = 2000 // initial capital at launch of the strategyRisk = 0.05 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))indicator1 = Average[MA1](close)indicator2 = Average[MA2](close)indicator3 = Average[MA3](close)c1 = (indicator1 CROSSES OVER indicator2)c2 = (indicator1 CROSSES UNDER indicator3)if c1 thenbuybar=barindexendifif c2 thensellbar=barindexendifstillbullish = buybar>sellbarstillbearish = sellbar>buybarif stillbullish and barindex-buybar>=barquantity thenbuy 1 contract at marketendifif stillbearish and barindex-sellbar>=barquantity thensellshort 1 contract at marketendifSET STOP LOSS SLI did not test the code, please make your own tests and make feedback here.
I did not test it, please make your own tests and give feedback.
10/02/2017 at 3:44 PM #48023Hi Nicolas,
Thanks so much for coming back to me, oh no sorry was this in the wrong place? and I am sorry I will add the code using the button next time. I am still very much a newbie.
I will do some testing on the code and let you know. Thanks.
Matt
10/02/2017 at 4:00 PM #48025SMA with Wait123456789101112131415161718192021222324252627282930313233343536373839barquantity=5 //how many bars to wait after a signal to open a new orderREM Money ManagementCapital = 2000 // initial capital at launch of the strategyRisk = 0.05 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))indicator1 = Average[25](close)indicator2 = Average[250](close)indicator3 = Average[15](close)c1 = (indicator1 CROSSES OVER indicator2)c2 = (indicator1 CROSSES UNDER indicator3)if c1 thenbuybar=barindexendifif c2 thensellbar=barindexendifstillbullish = buybar>sellbarstillbearish = sellbar>buybarif stillbullish and barindex-buybar>=barquantity thenbuy maxrisk -0.5 perpoint at marketendifif stillbearish and barindex-sellbar>=barquantity thensellshort maxrisk-0.5 perpoint at marketendifSET STOP LOSS 30Hi Nicolas,
Thanks again, I had a go with the above and it’s not quite right. It’s taking a trade on every single bar!?
10/02/2017 at 4:20 PM #4802810/02/2017 at 5:46 PM #4803910/02/2017 at 10:40 PM #48070If you restrict the length of each trade it is not so strange that the number of trades increases. Sometimes the new version with restriction takes a new trade when the old version is still on market with the first trade. Think about it.
10/03/2017 at 7:14 AM #4808110/03/2017 at 8:17 AM #48089Ok thank again for the response.
On my original code there would only be one trade taken for any MA cross over. Either C1 or C2. Why is it now launching more than one trade?
Maybe i’ve not explained it correctly. I don’t want to restrict the length of the trade.
I’ll explain again more clearly. When a cross over occurs I want to wait x number of candles sticks to see if the price is above the price it was when the cross over occurred. If it is then the system should take the trade at that moment, if it isn’t then don’t take a trade and wait for the next cross over to occur. Other than that I don’t want anything else to change to the system, if a trade is taken it should then continue until either my stop loss is hit or the exit condition is met.
10/03/2017 at 1:04 PM #48121On my original code there would only be one trade taken for any MA cross over. Either C1 or C2. Why is it now launching more than one trade?
Because code has changed a bit to reflect your strategy..
So, in this new version, I added only one trade per cross and if the Close is above / below the cross price when all other conditions are ok.
123456789101112131415161718192021222324252627282930313233343536373839404142434445defparam cumulateorders=falsebarquantity=5 //how many bars to wait after a signal to open a new orderREM Money ManagementCapital = 2000 // initial capital at launch of the strategyRisk = 0.05 // risk in percentREM Calculate contractsequity = Capital + StrategyProfitmaxrisk = round(equity*(Risk/100))indicator1 = Average[25](close)indicator2 = Average[250](close)indicator3 = Average[15](close)c1 = (indicator1 CROSSES OVER indicator2)c2 = (indicator1 CROSSES UNDER indicator3)if c1 thenbuybar=barindexbuyprice=closeendifif c2 thensellbar=barindexsellprice=closeendifstillbullish = buybar>sellbarstillbearish = sellbar>buybarif stillbullish and barindex-buybar>=barquantity and gobuy<>buybar and close>buyprice thenbuy maxrisk -0.5 perpoint at marketgobuy=buybarendifif stillbearish and barindex-sellbar>=barquantity and gosell<>sellbar and close<sellprice thensellshort maxrisk-0.5 perpoint at marketgosell=sellbarendifSET STOP pLOSS 30Please note that in this version, orders are still exited by contrarian condition (a SELLSHORT is exited if new BUY conditions are met).
10/11/2017 at 1:31 PM #49033 -
AuthorPosts
Find exclusive trading pro-tools on