Any easy way to make the next trade dependant on previous trades outcome?

 

Hi,

I need to check if say int 'a' is divisible by 5, that is if int 'a' is 5 or 10 or 15 or 20 and so forth. Any easy way to do that? I thought I'd ask before I try to think of some sort more complicated way.

The code will be used with an 'if' statement


Thank you in advance,

Vince

 

The function you are looking for is called MathMod. It returns the remainder of a division operation.

So your call would be something like if (MathMod (a, 5) == 0) { // it's divisible by 5 } else { // it's not divisible by 5 }


Have fun!

Daniel

 
danielpasono:

The function you are looking for is called MathMod. It returns the remainder of a division operation.

So your call would be something like if (MathMod (a, 5) == 0) { // it's divisible by 5 } else { // it's not divisible by 5 }


Have fun!

Daniel

That's exactly what I was looking for. Thank you very much!

 

I know how to make a trade open with a stop loss and take profit, however what I want to do is say that I've got a short trade open, and if it ends up with a loss then at the exact time the short trade is closed a long trade is open. If the short trade goes for a profit then a short trade is open again. In other words, the next trade is dependant on the previous trade's outcome. Any easy way to do that?

I was thinking of something along the lines of, but couldn't get it to work:


double TakeProfit=50, StopLoss=50, StopLossAsk, TakeProfitAsk, StopLossBid, TakeProfitBid;

boolean longtrade=true;

boolean busy=false;


int start()
{
if(longtrade==true && busy==false) //checks if should go long or short (on the first time will always go long), and checks if there are any trades
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point, "Trade 1", 12345, 0, 0); //tries to open the order
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) //checks if an order is open
{
Print("Buy order opened : ",OrderOpenPrice());
StopLossAsk=Ask-StopLoss; //stores the stoploss price
TakeProfitAsk=Ask+TakeProfit; //stores the take profit price
busy=true; //makes it so that the loop does not repeat again because an order is open
}
}
else Print("Error opening BUY order: ",GetLastError());
}
if(StopLossAsk==Ask) //checks if trade is stopped out

{

longtrade=false; //will go short next time

busy=false; //not busy anymore, we have no trades

}

if(TakeProfitAsk==Ask) //checks if we are at take profit

{

longtrade=true; //will go long again

busy=false;

}

//blah blah blah the same with going short

...

...

return(0);

}

Now, please don't laugh, this is one of my first fruits with mql4, and I have done very little programming in the past. So what I want to know is if there is an easier approach to this? I have very limited knowledge of MQL4 so I was trying to see if I'm able to get my ideas working with the most basic stuff. So far I've got little success, and I'm asking for suggestions from fellow internauts.