Hello!
I want to backtest a few lines I have identified as good r/s levels but am an utter noob when it comes to coding.
Say I want to test 11500 on NQ, when the price comes from above I want to long. doing this with the help of MA14.
But I’m not sure what to use to specify the level, as I understand “close” it needs to actually close on that level, is there anything I can use for a touch?
Don’t know if this makes any sense.
😀
In essence, I want to find out the best SL and TP for trading my levels.
Touch is when either LOW or HIGH reach or break that level, such as:
If low <= 11500 then //touched from above
If high >= 11500 then //touched from below
Thanks Roberto!
This really helped, when it reaches tp for example, it opens a new order the bar after as long as price is above my level, which I understand from the code is correct.
How do I set it to not keep adding while above?
So one buy per touch, if it touches again, buy.
JSParticipant
Senior
If you do not want to open cumulative orders, you must place the following line at the beginning of your code:
DefParam CumulateOrders=False
An alternative is to use:
If High CrossesOver Average[14](Close) then
Buy 1 contract at Market
EndIf
If Low CrossesUnder Average[14](Close) then
SellShort 1 contract at Market
EndIf
With the latter option, you only buy / sell when the price crosses with the average…
Yea sure that could work but I want to be really specific, which I understand is difficult.
high >= “value”
tp = 20
sl = 5
when either of those is hit and price is high >= the algo will keep opening positions. I really just want it to open a position when the line is touched.
attached is a really bad example on s&p, there will be bad trades and these would be 2 of them, I still would like it to work but I can’t figure out how to open exactly on the line, and only then.
Maybe smaller TF and maybe lesser MA.
Any other ideas?
JSParticipant
Senior
You could use Limit orders:
If Close < Resistance then
SellShort 1 contract at Resistance Limit
EndIf
If Close > Support then
Buy 1 contract at Support Limit
EndIf