Need Help with Order Send and Cose function

 

Hi All,

I am new to coding (never done this before) but want to realize my own trading strategy.

The system should send a buy order each bar (at open price) for a number of periods that is equal to an moving average used. After this the EA should close the first (oldest) order in the next period ans simultaniously open anthoter one.

Example: Lets say we use a MA(5), now the following should happen:

Period 1  -> send 1 buy order at open price                                        What the EA does instead: send 1 buy order at open price

Period 2  -> send 2 buy order at open price        What the EA does instead: send 2 buy order at open price

Period 3  -> send 3 buy order at open price       What the EA does instead: send 3 buy order at open price

Period 4  -> send 4 buy order at open price       What the EA does instead: send 4 buy order at open price

Period 5  -> send 5 buy order at open price               What the EA does instead: send 5 buy order at open price

Period 6  -> close 1 buy order and open 6 buy order at open price       What the EA does instead: close 1 buy order at open price

Period 7  -> close 2 buy order and open 7 buy order at open price       What the EA does instead: send 6 buy order at open price

Period 8  -> close 3 buy order and open 8 buy order at open price       What the EA does instead: close 2 buy order at open price

Period 9  -> close 4 buy order and open 9 buy order at open price       What the EA does instead: send 7 buy order at open price 

... 

 

Could anybody help me to fix this?? I realy don't understand whats wrong there. Thanks very much in advance for your help guys. I've attachted the EA below 

 

With best regards,

tbm 

Files:
 

using volume to trade the first tick isn't reliable use time instead

Reason: