Download MetaTrader 5

Oil SL

To add comments, please log in or register
kocifilip 2016.06.04 21:17 

Hi guys! I´m asking you for little help :) I´am newbie in MQL4 and have issue with my simply code for trading on Oil. It just open two position and i need SL always 10 cents for both position. Can anyone please advise me with this trivial issue? Or show example of code? I was spending a lot of time with that and couldn´t find any solve...thank you for everything :)

#include <stdlib.mqh>
#include <WinUser32.mqh>

int start()
   double alt_bid ;
   double alt_ask ;
   alt_bid = MarketInfo(Symbol(),MODE_BID);
   alt_ask = MarketInfo(Symbol(),MODE_ASK);
   int ticket=OrderSend(Symbol(),OP_BUYSTOP,1.0,alt_ask+5*Point,3,0,0,"expert comment",255,0,CLR_NONE); 
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));

   int ticket1=OrderSend(Symbol(),OP_SELLSTOP,1.0,alt_bid-5*Point,3,0,0,"expert comment",255,0,CLR_NONE); 
      int error1=GetLastError();
      Print("Error = ",ErrorDescription(error1));

code.mq4 1 kb
Keith Watford
Keith Watford 2016.06.04 21:39  

For such a small amount of code, please use the SRC button and paste your code into your post

I have done it for you this time

Keith Watford
Keith Watford 2016.06.04 21:45  
   double sl=//Calculate your stoploss here
   int ticket=OrderSend(Symbol(),OP_BUYSTOP,1.0,alt_ask+5*Point,3,sl,0,"expert comment",255,0,CLR_NONE); 

calculate your stoploss the same as you would when placing a manual order

whroeder1 2016.06.05 13:13  
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
  • Do NOT use TickValue by itself - DeltaPerlot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out
To add comments, please log in or register