Oil SL

Back to topics list To post a new topic, please log in or register
avatar
1
kocifilip 2016.06.04 23: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); 
   if(ticket<1)
     {
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return;
     }


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

   return(0);
  }

 


Attached files:
  code.mq4  (0.73 KB)
avatar
Moderator
3423
GumRai 2016.06.04 23: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

avatar
Moderator
3423
GumRai 2016.06.04 23: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


avatar
13009
WHRoeder 2016.06.05 15: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
Back to topics list  

To add comments, please log in or register