Get current price and entry price
Forums › ProRealTime English forum › General trading discussions › Get current price and entry price
- This topic has 7 replies, 4 voices, and was last updated 3 years ago by robertogozzi.
-
-
09/20/2021 at 9:50 AM #177941
Hi,
Can anyone please advise who in the code part it is possible to get the market price as I can only see the open, close, high and low price options, but not the market price. Also is it possible to see the entry price? My aim is to do something like this:
Sell if market price is less than 10 points from entry price123If LongOnMarket AND close[1] < (ENTRYPRICE- 15) AND MARKETPRICE < (ENTRYPRICE - 10) THENSELL AT MARKETENDIFThanks
09/20/2021 at 10:30 AM #177945Hello,
I believe strategies are made on close only. To get a market price in between, best would be to lower the timeframe as small as possible (1min etc…)
Regarding entryprice, you have the instruction POSITIONPRICEFabrice
09/20/2021 at 11:26 AM #17795409/20/2021 at 11:33 AM #177955What Swingueur said is correct.
As to the entry price, TRADEPRICE, or TRADEPRICE(1) (they are equivalent), is the correct answer. It is ALWAYS tha last price traded.
After entry, TRADEPRICE will retain the entry price, after exit TRADEPRICE will retain the exit price and the entry price will then be retained by TRADEPRICE(2).
After any operation it is shifted by one place.
1 user thanked author for this post.
09/20/2021 at 1:05 PM #177972Hi GraHal,
When I use Close, the system only takes into account the close value of the bar. In real life automated trading, I would like the system to monitor the current price, e.g. If I enter a trade in DAX and the price moves by 15 points, I would move my Stop Loss to +2 points, so that in the event of price turning against me, and not reaching my target of e.g. 30 points, I would not go into loosing trade, but would exit with only 2 points gain. Where as in the backtesting I am unable to tell the system to behave in this manner. This is the code I came up with, but as you can see in the screenshot it is not doing as I am telling it to do.
12345678910111213141516171819202122232425262728293031emaShort = 9emaLong = 21ema200 = 200avgShort = ExponentialAverage[emaShort](Close)avgLong = ExponentialAverage[emaLong](Close)avg200 = ExponentialAverage[ema200](Close)IF NOT LongOnMarket AND NOT ShortOnMarket THENIF avgShort CROSSES OVER avgLong AND Open > avg200 THENBUY 1 CONTRACTS AT close+2 STOPENDIFIF avgShort CROSSES UNDER avgLong AND Open < avg200 THENSELLSHORT 1 CONTRACTS AT close-2 STOPmoveSL=0ENDIFENDIFSET STOP pLOSS 20SET TARGET pPROFIT 30IF ShortOnMarket THENmyAlert = PositionPrice-10myBE = PositionPrice-3IF close < myAlert THENmoveSL=1ENDIFIF moveSL AND close > myBE THENEXITSHORT AT MARKETENDIFENDIFThe blue line is the entry
Green line is alert level, i.e. when the price has already moved by 10 points
Red line, is where the buyback should occur, i.e. if the price has gone to 10 points my way, and then it reaches the 3 point below my entry then sell.09/20/2021 at 1:24 PM #177974Use MTF support.
Searching the forum for MTF will return blogs, posts and plenty of code to learn how to use it.
09/20/2021 at 4:30 PM #177984Hi robertogozzi,
Do you know what is the smallest time frame possible?
I tried running the following code in 1 tick timeframe but the system would not even enter a trade:
My code123IF close crosses under 15047 THENSELLSHORT 1 CONTRACTS AT MARKETENDIF09/20/2021 at 6:19 PM #1779881 second is the smallest one.
Non-time based TFs, like ticks, cannot be used for automated trading.
-
AuthorPosts
Find exclusive trading pro-tools on