[Coding Issues] Order immediately closes after placing

 

Hello all,

 I was trying to make a scalping EA, but I can't figure this thing out: It immediately closes all it's positions. Been looking over it for hours now, hope one of you can see it. I guess it has to do with the TP/SL. The reason I don't use the OrderSend function for that, is because my broker doesn't support it :/ So I thought to deal with it this way, but didn't worked out. Any questions? Shoot'em! Thanks in advance! 

 Obvious, my meaning is to open an order when desired Stochastic level is reached, and then work with a SL/TP goal. 

Files:
mql4forum.mq4  9 kb
 
 extern int   StopLoss_S = 10;   // Stop Loss in points
 :
         if(Ask<=OpenPrice-((StopLoss_L)/100000))
           {
            Print("Stoploss long");
            OrderClose(Ticket,LotSize(),Bid,Slippage,Red);
            return(0);                   
           }
Your code assumes a 5 digit broker, so you close the order at a 1 pip drop.
 

Thanks for the quick reply.

I work with a 5-digit broker though(Armada Markets), any other thoughts?

 

WHRoeder is right. 10 Points = 1 pip and hence if spread is more than 1 pip the trade will be immediately closed. There are few other issues in the code mostly due to confusing integer and floating point variables/calculations. Also, you close buy for Bid price and a sell for a Ask price. Attached corrected code.

Files:
 
Superthanks! I'm still quite new to MQL, so still strugling with a lot of things, including when to use Ask when to use Bid although it might sound silly.

Edit: Cool it works, very glad I can continue working on it, thanks again. 
 

No prob. BTW: to convert points to correct decimal number instead of "StopLoss_L/100000.0" you can use "StopLoss_L*Point".

A general note on your EA idea: ticks in mt4 tester are randomly generated so your scalping EA's backtest performance should be ignored unless you base your EA on at least completed M1 bars or you feed the tester fxt file with correct ticks and achieve 99% tick modelling quality. Google "Birt 99%" to learn how to do it.

 
Cool that's a lot to read, didn't knew about it so good you mention it!
Reason: