Need help creating a VERY simple EA - page 2

 
i do this trade on 2hr charts also. would this work on a 2hr offline chart or an avg of the last two 1hr candles?
 
if i change the High[1]-Low[1] to High[2]-Low[2] and place it on the 1hr chart will that give me the trading range of the last two 1hr candles?
 

High[2]-Low[2] wil give the range of candle 2 only.

 
how would i code it to take the avg of the last two candles
 
would it be High[2]Low[2]-High[1]Low[1]
 
crazfoto wrote >>
i see why this is not working. it is cancelling everyorder automatically every half hour in stead of letting the market stop it out or take profit. i see a lot of orders that would have paid out but the robot closed the order. if that can be changed i think the results will be better

Yes it closes a running trade on the opening of a new bar.

To stop it doing this modify the follow line.

From

CloseAllOpenOrders(); //first close any existing trades left over from previous bar
To

//CloseAllOpenOrders(); //first close any existing trades left over from previous bar

It simply rems out the request to close the trade. The trade will then run until stopped out or a profit is take. No new trade will be taken during this period.

As for your question about the 2 hour candle

This should be possible by running against a one hour chart and taking into account the max and min of the last two bar to calculate the range over two hours.

I'll think about it for the moment and get back to you.

Would you still be looking for a 20 point range over the two hours ???????

Regards

Brendan

 
doshur wrote >>

Thanks brendan for the code.

I have yet to test the code but seems that if you activate the EA, will it execute an order immediately if all rules are met even if the current price is like 10pip above the previous bar already.

Well spotted. You are quite right a trade will be executed on open of a bar if all rules are meet. No account is taken for gapping.

 
doshur wrote >>

Thanks brendan for the code.

I have yet to test the code but seems that if you activate the EA, will it execute an order immediately if all rules are met even if the current price is like 10pip above the previous bar already.

Well spotted. You are quite right a trade will be executed on open of a bar if all rules are meet. No account is taken for gapping.

Perhaps crazfoto could tell us how he/she handles gapping in the manual method

Regards

Brendan

 
no on the 2hr trade i just candles that are smaller than 100 or so. that way my stop isn't to crazy just for 5 pips. i never had any gap issues cause i always set pending orders right before the new candle forms and i rarely trade it on fridays. i guess there maybe a trick on when to turn the EA on or hv it place pending orders. what i do for the 2hr trade is place two pending orders right before the new 2hr range starts. when one is activated i delete the other pending order and wait for the activated one to pay out.
 
i will be trying to implement brendan code
Reason: