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:
If LongOnMarket AND close[1] < (ENTRYPRICE- 15) AND MARKETPRICE < (ENTRYPRICE - 10) THEN
SELL AT MARKET
ENDIF
Thanks
Hello,
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 POSITIONPRICE
Fabrice
Close is the market price at any stage during candle formation.
Close is also the market price at candle close.
What 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.
Hi 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.
emaShort = 9
emaLong = 21
ema200 = 200
avgShort = ExponentialAverage[emaShort](Close)
avgLong = ExponentialAverage[emaLong](Close)
avg200 = ExponentialAverage[ema200](Close)
IF NOT LongOnMarket AND NOT ShortOnMarket THEN
IF avgShort CROSSES OVER avgLong AND Open > avg200 THEN
BUY 1 CONTRACTS AT close+2 STOP
ENDIF
IF avgShort CROSSES UNDER avgLong AND Open < avg200 THEN
SELLSHORT 1 CONTRACTS AT close-2 STOP
moveSL=0
ENDIF
ENDIF
SET STOP pLOSS 20
SET TARGET pPROFIT 30
IF ShortOnMarket THEN
myAlert = PositionPrice-10
myBE = PositionPrice-3
IF close < myAlert THEN
moveSL=1
ENDIF
IF moveSL AND close > myBE THEN
EXITSHORT AT MARKET
ENDIF
ENDIF
The 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.
Use MTF support.
Searching the forum for MTF will return blogs, posts and plenty of code to learn how to use it.
Hi 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:
IF close crosses under 15047 THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
1 second is the smallest one.
Non-time based TFs, like ticks, cannot be used for automated trading.