Hi brothers, I want to ask another thing, I searched in fóruns already and I didn’t read anything to help me solve my problem.
I have a code simple like this one, but when I run the backtest, the buy entry is always at the close of the previous bar level and not at the high level. And the stop is the same thing, it didn’t stop at the low of the previous bar and close at the low of the actual. Thanks
If not longonmarket and close>=high[1] then
Buy 1 lot at high[1] limit
Set target profit range[1]
Set stop loss low[1]
Endif
If longonmarket (barindex-tradeindex=2) then
Sell at market
Endif
Your buy at a limit (better) price should work as you describe – are you allowing for spread?
SET TARGET and SET STOP expects a distance and not a level or price so your SET TARGET should work (use SET TARGET pPROFIT to look for it in pips) but your SET STOP is unlikely to ever be hit.
You have a typo in line 6 as an AND is missing.
An image would help to show where you think a trade is being opened or closed incorrectly.
Thanks brother, I am starting to understand better now.
But I didn’t understand the spread thing, ig spread is 0,3 so it’s 0.003 right?
In this picture it’s buying on the close of the candle and not at the higher. And it’s not stopping.
In the image it does exactly what you have coded.
[attachment file=83584]
I tough that the spinning top was the high[1] now my brain is bugging…
0,3 spread is 0.00003 (three tenths of a pip), not 0.003!
Set stop loss low[1] is WRONG, as
Vonasi pointed out. It requires a difference in price (such as CLOSE – LOW[1]), not a price. Dax is quoting about 11,200, so it would be 11,200-PIP stop loss and will never get hit (your account would be wiped out long before that).
Thanks guys, sorry for those beginners questions.
I fixed the sell entry but the stop is not changing, no idea how to set the stop to stop at the high of the same candle that the entry was done.
Set Stop Loss (high - close)