You could probably do something like this and use :
int Tradebar = ibar (NULL,CloseMATimeFrame,OpenTradeTime());
int Current = ibar (NULL,CloseMATimeFrame,timecurrent());
double Open1 = iopen(NULL,CloseMATimeFrame,0)
if (OrderType()==OP_BUY)
{
if ((Tradebar!=Current)&&(Open1<=ma ))
{
orderclose …
Its just to give an idea as Im at work and don`t have mq4 on this computer…
thanks cissou132 for your input
i tried your idea and it compiled fine but still doesnt wait till close…it is being really stubborn…is there a way to use PRICE_CLOSE somewhere in the parentheses? could that work?
if price_close is <=ma or >=ma?
This is what I use to wait for a new bar and to run functions that are not required to run all the time. When a new bar opens, Volume[0] is set to 0 or 1, so that is the indication that the last bars closed.
Does this help you?
Thank you for your reply IdeFX…I inserted that code as well and it compiled but yet again still did not wait for close…maybe I am doing something wrong…but my programming skills are very limited…would you or anyone else be able to code an EA to do this simple function? close an existing trade on the current timeframe when bid price crosses a specified moving average and closes above if the trade was a sell and closes below if the trade was a buy. If i have a code that works then I can compare to try to implement it into my other EA…thank you again for all of your help
Well, looking at your first snippet, there are four triggers that can trigger a closetrade:
sig==“Sell”
(iClose(NULL,CloseMATimeFrame,0)<=ma && shift>0)
trend==“Dn”
(Bid<=exit && exit!=-1)
When each one of these are hit, your trade is closed no matter the close of a bar (Based on what I am seeing here). They are not AND, AND, AND (&&)but OR, OR, OR (||). So if you don’t enclose all four of them with the code I gave, they are run every tick and applied when one of them is triggered, no matter if the bar ended or not.
The way you coded it now equals:
if(sig==“Sell”) CloseTrade();
One question I am having is if you perhaps use different timeframes in your script? I am confident that The Volume[0] snippet works. Based on that it is not working for you, I am afraid that there is something wrong in your script. Most likely that you have four triggers that are not time or Bar-related.
If so, than you can give cissou132 and myself a nice big like…
[QUOTE=IdeFX;430136]Well, looking at your first snippet, there are four triggers that can trigger a closetrade:
sig==“Sell”
(iClose(NULL,CloseMATimeFrame,0)<=ma && shift>0)
trend==“Dn”
(Bid<=exit && exit!=-1)
Wow IdeFX kudos to you cuz you broke it down quite nicely…you helped me understand better what the code was actually doing with your AND and OR explanations…that gave me the idea to eliminate all but the one to see if that would work on its own…and yes it does…one or all of the other 3 triggers were interfering in waiting for candle close…thank you again for helping me realize that…i give both you and cissou132 a great big Like