I m totally New, need help for Stop Lost

 

Hi all, I m totally new to EA, and I just copy the code from website but i didnt know how to add in the stop lost for my open order..

Here is the code looks like

input int SmallSMA=20;

input int BigSMA=50;



void OnTick()

{

  



   // We create a string variable for the signal

   string signal ="";

   

   // We calculate the small moving average

   double SmallMovingAverage1 = iMA(_Symbol, _Period, SmallSMA, 0, MODE_SMA, PRICE_CLOSE, 1);

   

   // We calculate the big moving average

   double BigMovingAverage1 = iMA(_Symbol, _Period, BigSMA, 0, MODE_SMA, PRICE_CLOSE, 1);

   

   // We calculate the small moving average

   double SmallMovingAverage2 = iMA(_Symbol, _Period, SmallSMA, 0, MODE_SMA, PRICE_CLOSE, 2);

   

   // We calculate the big moving average

   double BigMovingAverage2 = iMA(_Symbol,_Period, BigSMA, 0, MODE_SMA, PRICE_CLOSE, 2);

   

   // If BigMovingAverage > SmallMovingAverage

   if (BigMovingAverage1 > SmallMovingAverage1)

   

   // If BigMovingAverage < SmallMovingAverage before

   if (BigMovingAverage2 < SmallMovingAverage2)

   

   {

      //Set the signal variable to sell

      signal="sell";

   }

   

   // If BigMovingAverage < SmallMovingAverage

   if (BigMovingAverage1 < SmallMovingAverage1)

   

   // If BigMovingAverage > SmallMovingAverage

   if (BigMovingAverage2 > SmallMovingAverage2)

   

   {

      // Set the signal variable to buy

      signal="buy";

   }

   

   // Buy 10 Microlot

   if (signal=="buy" && OrdersTotal()==0)

   OrderSend (_Symbol,OP_BUY,0.03,Ask,3,0,Ask+150*_Point,NULL,0,0,Green);

   

   // Sell 10 Microlot

   if (signal=="sell" && OrdersTotal()==0)

   OrderSend (_Symbol,OP_SELL,0.03,Bid,3,0,Bid-150*_Point,NULL,0,0,Red);

   

   // Chart output for the signal

   Comment ("The current signal is: ",signal);

     

}

Anyone could help? Very appreciated on this, I found EA is wonderful thing but I have zero knowledge in coding  :(

 
up*
 
Ong Kean:
up*

You up your post 20 minutes after posting????!!!!!

You do that again and I will delete your topic altogether.


Please edit your post and

use the code button (Alt+S) when pasting code

 

Why not pump this knowledge up ? :)

There's tons of MQL4 tutorials on youtube which can pump you up from zero to hero!

To answer your question:

https://docs.mql4.com/trading/ordersend


int  OrderSend(
   string   symbol,              // symbol
   int      cmd,                 // operation
   double   volume,              // volume
   double   price,               // price
   int      slippage,            // slippage
   double   stoploss,            // stop loss
   double   takeprofit,          // take profit
   string   comment=NULL,        // comment
   int      magic=0,             // magic number
   datetime expiration=0,        // pending order expiration
   color    arrow_color=clrNONE  // color
   );
Meaning that:

// Buy 10 Microlot

   if (signal=="buy" && OrdersTotal()==0)

   OrderSend (_Symbol,OP_BUY,0.03,Ask,3,0,Ask+150*_Point,NULL,0,0,Green);

   

   // Sell 10 Microlot

   if (signal=="sell" && OrdersTotal()==0)

   OrderSend (_Symbol,OP_SELL,0.03,Bid,3,0,Bid-150*_Point,NULL,0,0,Red);
these are your stop losses :)

Congratulations! You did set them up! ;)

(0 meaning no stop loss set up btw)
OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function. At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a...
 

Wow! U r awesome mate! I tried figure out where to is the stoplost omg.. 

Thanks alot~ this is a new language for me.. is interesting though  :D



Sorry Moderator, I didnt mean to do it, I thought my post is lost so I tried "up" it, then realize is in another section in the forum. My apology  :)

Reason: