Hello,
I would love to create a strategy for the ATR Ledge Indicator. Maybe someone is able to help? It is currently not working and I don’t know why..
if time = 010500 then
ATRperiod = 14
// ---
dTR = 0
for i = 0 to ATRperiod
dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
next
avg = dTR/ATRperiod
htr = Dlow(0)+avg[1]
ltr = Dhigh(0)-avg[1]
ab=(htr-ltr)/2*1+ltr
b=(htr-ab)/4*2+ab
c=(htr-ab)/4*1+ab+0.0003
d=(ab-ltr)/4*3+ltr-0.0003
e=(ab-ltr)/4*2+ltr
if not longonmarket and close<c then
buy 1 share at c stop
endif
if not shortonmarket and close>d then
sellshort 1 share at d stop
endif
if longonmarket then
sell at b stop
sell at d limit
elsif shortonmarket then
exitshort at e stop
exitshort at c limit
endif
endif
Thanks a lot!
I did not test your code, but the first thing I can tell you is that your pending orders (STOP and LIMIT ones) are only set at 010500 time and only for 1 bar.
Pending orders only last 1 bar and should be placed at market each new bar.
Hello Nicolas,
is it recommended to place the pending order at market each new bar or is it then generating new entries for every new bar? How would that work?
A market order will executed with the open of the next bar, so this should NOT be repeated every bar. Limit- and stop-orders on the other hand are only valid one bar and have to repeated if this is what you desire.
The only pending orders that do not have to repeated are the once you put with the set command (set stop loss for example).
ok I understand. But I really don’t have a clue how to solve the problem. If I change the code to “buy / sellshort 1 share at market” instead of “stop” it only buys at the particular time and it does ignore the other condition.
I want to buy if it’s over c and set a stop at d. Target would be b. And I want to sell if it’s under d and set stop at c. Target would be e.
I don’t have a clue how to change the stop order to something else.
if close>c then
buy 1 contract at market
elsif close<d then
sellshort 1 contract at market
endif
if longonmarket then
sell at b limit
sell at d stop
elsif shortonmarket then
exitshort at e limit
exitshort at c stop
endif
Here you go.
Thanks a lot for your help but it’s not working
Can you be more specific what is the problem? I assume that you maybe have a mistake in the calculation of the variables. It is easy to get confused with points/pips and price.
If you are not on market, you should placed your pending orders until you get market orders. This is how you should develop the code of your strategy.
The problem is that the code above is not working. I want to use it for Forex. Nicolas said that my pending orders are only set at 010500. I want to change this that ithe system starts when the specific entry points are reached and not a specific time. Your code is looking good for me too but it doesn’t work
I don’t know for which instruments your strategy is, your code seems correct, but you should try to code it into 2 different parts instead: one that calculate the price levels for your pending orders at 010500 and one that continuously put your pending orders until one of them triggered.
Sounds complicated. Any recommendations or is there a guide how I can code it into 2 different parts?
There is a picture of the indicator attached. I want to buy at the first green line in the middle and sell at the second, vice versa sell at the first red line from the middle and target profit at the second red line.
I think you also want the only one position is open until it reaches the goal or the stop again? Would the market move to the first green line in a sideways movement, which could be fatal if strategy X opened positions?
I am quite good at developing strategies myself, but I have no idea of programming myself, I only manage to mend strategies from others.
@Jessar: Just come with your ideas. Maybe there is something I can code for you.
@jessar: exactly it should only open one short or long until it is closed.
Any ideas?