Only one entry
Forums › ProRealTime English forum › ProOrder support › Only one entry
- This topic has 8 replies, 2 voices, and was last updated 2 years ago by
Vogeltje.
-
-
09/26/2022 at 12:40 PM #201429
Hello. Say I want to go long when a>b AND c>d. When both conditions are true I want only ONE entry which stops when take profit or stoploss is hit (or condition changes).
Problem is: when profit or loss is hit the system goes long AGAIN on the next candle since still a>b AND c>d. I have been suggested to stop this by setting Trend=0 when in position, but I can’t get a code wright for “position means Trend=0”. Also ONMARKET or NOTONMARKET are suggested, but I do not find these in the syntax, I get no results when using these words in the code.
For example, I tried this code but the part “AND Trend=0” is rejected….
(sorry for the Dutch in the code 🙂 )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109// Opstapelen posities gedeactiveerdDEFPARAM CumulateOrders = False// Definitie mijnMACDMMsnel = exponentialAverage[12](close)MMlangzaam = exponentialAverage[26](close)mijnMACD = MMsnel - MMlangzaam//Definitie RSIopwaarts = max(0, close - close[1])neerwaarts = max(0, close[1] - close)mmopwaarts = wilderAverage[14](opwaarts)mmneerwaarts = wilderAverage[14](neerwaarts)RS = mmopwaarts / mmneerwaartsmijnRSI = 100 - 100 / (1 + RS)//Longtrend, shorttrendIF mijnMACD > 0 AND mijnRSI > 50 THENTrend = 1ELSIF mijnMACD < 0 AND mijnRSI < 50 THENTrend = -1ELSETrend = 0ENDIF//Conditiesc1 = Trend = 1c2 = Trend = -1// Condities om long posities te openenIF c1 THENBUY 1 SHARES AT MARKET AND Trend = 0ENDIF// Condities om long posities te sluitenIF c2 THENSELL AT MARKET AND Trend = 0ENDIF// Condities om short posities te openenIF c2 THENSELLSHORT 1 SHARES AT MARKET AND Trend = 0ENDIF// Condities om short posities te sluitenIF c1 THENEXITSHORT AT MARKET AND Trend = 0ENDIF// Stops en targetsSET STOP pLOSS 20SET TARGET pPROFIT 1509/26/2022 at 4:30 PM #201448You cannot use conditions, nor instructuons, on the same line as BUY, SELL, SELLSHORT and EXITSHORT. Wrirte them on a separate line.
Moreover, you do not need to exit an open position for a Stop & Reverse, simply execute the contrary instruction. BUY will close any open short postition, then start a LONG one, the other way round for SELLSHORT.12345678910111213141516171819202122232425262728293031323334353637// Opstapelen posities gedeactiveerdDEFPARAM CumulateOrders = False// Definitie mijnMACDMMsnel = exponentialAverage[12](close)MMlangzaam = exponentialAverage[26](close)mijnMACD = MMsnel - MMlangzaam//Definitie RSIopwaarts = max(0, close - close[1])neerwaarts = max(0, close[1] - close)mmopwaarts = wilderAverage[14](opwaarts)mmneerwaarts = wilderAverage[14](neerwaarts)RS = mmopwaarts / mmneerwaartsmijnRSI = 100 - 100 / (1 + RS)//Longtrend, shorttrendIF mijnMACD > 0 AND mijnRSI > 50 THENTrend = 1ELSIF mijnMACD < 0 AND mijnRSI < 50 THENTrend = -1ELSETrend = 0ENDIF//Conditiesc1 = Trend = 1c2 = Trend = -1// Condities om long posities te openenIF c1 AND Not LongOnMarket THENBUY 1 SHARES AT MARKETTrend = 0ENDIF// Condities om short posities te openenIF c2 THENSELLSHORT 1 SHARES AT MARKETTrend = 0ENDIF// Stops en targetsSET STOP pLOSS 20SET TARGET pPROFIT 1509/26/2022 at 10:35 PM #201464OK Roberto, I understand the exit Long and exit short was not needed. Also I see you just simply put “Trend=0”. To me that is interesting, I was struggeling with conditions etc.
But, sorry, I have to inform you that this solution is not working. The system still trades on EVERY candle. When I leave “Trend=0” out of the code, the result is exactly the same… also on every candle.
09/27/2022 at 11:50 AM #201477When do you want to restart trading AFTER one entry?
09/27/2022 at 3:24 PM #201490Hello Roberto. I want to go long (only once) when RSI >50 AND MACD reaches >50. Then the trade will run until a) RSI <50 OR b) MACD < 0 (this is now not in the code, but is just to give you the whole idea) OR b) stoploss is hit OR c) profit is hit. After this I only want to trade again when there is a NEW situation, a NEW opportunity: RSI<50 and MACD<0 or a NEW situation where RSI>50 and MACD>0 again.
I do not know if it is possible to code such a thing. I think ONMARKET/NOTONMARKET will not work because once the stop or te profit is hit the system will conclude: NOTONMARKET and immediately trade again… Maybe something must de done with Trend = nr a+1 ? Thank you.09/27/2022 at 4:54 PM #201505There you go:
12345678910111213141516171819202122232425262728293031323334353637// Opstapelen posities gedeactiveerdDEFPARAM CumulateOrders = FalseONCE LastTrade = 0// Definitie mijnMACDMMsnel = exponentialAverage[12](close)MMlangzaam = exponentialAverage[26](close)mijnMACD = MMsnel - MMlangzaam//Definitie RSIopwaarts = max(0, close - close[1])neerwaarts = max(0, close[1] - close)mmopwaarts = wilderAverage[14](opwaarts)mmneerwaarts = wilderAverage[14](neerwaarts)RS = mmopwaarts / mmneerwaartsmijnRSI = 100 - 100 / (1 + RS)//Longtrend, shorttrendIF mijnMACD > 0 AND mijnRSI > 50 THENTrend = 1ELSIF mijnMACD < 0 AND mijnRSI < 50 THENTrend = -1ELSETrend = 0ENDIF// Condities om long posities te openenIF Trend = 1 AND Not LongOnMarket AND LastTrade <> 1 THENBUY 1 SHARES AT MARKETLastTrade = 1ENDIF// Condities om short posities te openenIF Trend = -1 AND Not ShortOnMarket AND LastTrade <> 2 THENSELLSHORT 1 SHARES AT MARKETLastTrade = 2ENDIF// Stops en targetsSET STOP pLOSS 20 //120SET TARGET pPROFIT 15 //215////graph LastTrade1 user thanked author for this post.
10/18/2022 at 1:57 PM #202781Thanks Roberto, this is really great!! I was looking for this for a longtime. (Sorry for late reaction, somehow I did not see the email). It is a simple code. I am even able to understand it!
I have only one question: is the variable LastTrade something you made up (can one write Apple instead?) or is it Syntax? If so – it is not in my syntax….
Thanks!10/19/2022 at 5:50 AM #202812It’s not a keyword, so you can name it as best suits you, be itApple, Cat or A3. They cannot start with a digit and cannot have blanks and special characters embedded, though.
10/19/2022 at 12:56 PM #202828 -
AuthorPosts
Find exclusive trading pro-tools on