Executing order only after the first signal has occurred

 

Hi all,

 

This is my first post and I did search for the answer extensively over the last week.

 

The problem is, my EA when attached to a chart will execute a buy/sell order almost immediately, because its buy/sell condition has been met. However, this could be halway through or at the end of the trend. The EA doesn't discriminate. What I need is an algorithm/code that stops the EA from doing that and instead wait for the signal to occur for the first (second?) time. Is there any such code or solution to this problem?

 

Thank you in advance all. 

 
Simple solution= set a Saving_Variable to True when [Condition_Is_Met  &&  Saving_Variable==false]. That variable can be Static | GlobalVariableSet() | File. While that variable is True, don't place anymore orders. When [Condition_Is_No_Longer_Met  &&  Saving_Variable==true], set the Saving_Variable to False.
 
Thank you. I will try to implement the code. As I am a noob, hopefully I won't have to come back next week to ask for further help with that. Thanks again ubzen.
 
SilverKaiser: What I need is an algorithm/code that stops the EA from doing that and instead wait for the signal to occur for the first (second?) time. 
Do exactly that. Wait for no signal, and then a signal. something like:
bool isWaiting; init(){ isWaiting = false; }
int start(){
    bool wasWaiting = isWaiting;
    isWaiting = false; // Assume no signal, not ok, etc.
    :
    if (MyTimeFilter())      return; // not ok
    if (MyOrderCount() != 0) return; // etc.
    :
    // Ok to open
    isWaiting = !MySignal(); // Wait if no signal.
    if (!wasWaiting) return; // Previously triggered.
    if (  isWaiting) return; // No signal yet.
    // Open now.
 

No need for long stuff isWaiting, isEating just a simple variable can do the job like below

string Trend; // declared globally so as not to lose value after every execution

int start()
{

if(/* Buying criteria */) bool buysignal=true;
if(/* Selling criteria */) bool sellsignal=true;

if(buysignal==true&&Trend!="buying trend")
{
 OrderSend... // send a buying order first then update trend below
 Trend="buying trend";
}

if(sellsignal==true&&Trend!="selling trend")
{
 OrderSend... // send a selling order first then update trend below
 Trend="selling trend";
}

//-----------------------------------------------------------------------------------------------------------------------------------------------------
// Looking at the above, when trend changes the ea trades once then updates the trend so other trades are not opened until the trend changes again
//-----------------------------------------------------------------------------------------------------------------------------------------------------
return(0);
}
 
tonny: No need for long stuff isWaiting, isEating just a simple variable can do the job like below
You code does NOT work for the OP's problem:
its buy/sell condition has been met. However, this could be halway through or at the end of the trend.
You do NOT prevent a signal at the end of the trend.
 

Thats an example on the "only trade once per signal" i dont have to show order closing or one trade at a time or similar scripts. Im just showing how adding a simple variable can be used to achieve his requirement. Playing with the statement in the indicator condition that sets buysignal or sellsignal or adding another variable can achieve your argument. Most clients usually want it such that when the ea is attached, a trade opens even if trend is halfway then continues that way. If i can explain the script a little more:

- When ea is attached whichever signal buy or sell(depending on how indicator is) will open since variable trend has no value

- Lets assume at attaching buysignal(say maybe MA has crossed upwards) is true and variable trend is not set the condition trend!="buying trend" will be met so a buy will be opened then afterwards trend value is set to buying trend

-On the next ticks trend value will be buying trend while buysignal is still true but no trade will open since trend!="buying trend" changed in the previous tick right after trade opened

-At this moment no trade opens until sellsignal becomes true

-When sell signal becomes true the variable trend(remember globally declared variables act like static variables) will still have value "buying trend" so condition sellsignal==true&&trend!="selling trend" will be met and a sell trade will open(and maybe close the other if he adds such a code) then immediately variable trend will now be updated to "selling trend" again blocking other sell trades since in the next ticks trend!=''selling trend" wont be true. The cycle will then continue that way.

If he wishes he can add other codes to satisfy other things like maybe not close on reverse signal and not open oposite trade on reverse signal if a trade is opened etc etc

 
Hi can anyone help
I want to open new order after certain amount of pips but it opens unlimited orders at that point it shud open one
 
Zubair Sharif:
Hi can anyone help
I want to open new order after certain amount of pips but it opens unlimited orders at that point it shud open one

Code it to open just one.

 
I have the same problem.. did you solved this
Reason: