[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 88

 

All right. Let's not. We both don't seem to have enough knowledge. The author of the question asked how to change StopLoss. I don't think he's going to get into the depths.

Try to assign it after the OrderSend function

 
MaxZ:

What is the number "12" in the OrderSend function? :(

And you misunderstood me about the selection of orders... That's how it should be:

Hi!

Thank you very much!!! for your replies!!!

I must not have expressed it correctly: the idea is this:

A sell trade is made at 1.4545... the price goes against the trend - 1.4585... and THEN - a pending order should be placed at 1.4565.

my code is not working correctly:

void otlogka (int order)
{  
   int a, k=OrdersTotal();
   for (a=k-1; a>=0; a--){
         if (OrderSelect(a, SELECT_BY_POS, MODE_TRADES)){
            if (OrderType()==OP_BUY){
               if (Bid*Point-OrderOpenPrice()>40)
               RefreshRates();
               if (k>1){
                  {
                     order=OrderSend(Symbol(),OP_SELLLIMIT,0.02,OrderOpenPrice()+20*Point,1,SL,0,"Otlogka",mn,5,0);
                  }}}}}
    
           if (OrderType()==OP_SELL){
               if (Ask*Point-OrderOpenPrice()<40)
                  RefreshRates();
                  if (k>1){
                {
                  order=OrderSend(Symbol(),OP_BUYLIMIT,0.02,OrderOpenPrice()-20*Point,1,SL,0,"Otlogka",mn,5,0);
                }}}

}

Please help!!!

 
FOReignEXchange:

I told you that while the OrderSend function is running, the price may change. So you must assign it afterwards, when it has already changed.

You can do it that way:

if (Opn_B)
{
   Alert("Попытка открыть ордер Buy...");
   RefreshRates();
   Ticket = OrderSend(Symb, OP_BUY , Lots, Ask, Slippage, 0, 0, NULL, MAGIC, 0, Blue);
   if (Ticket > 0)
   {
      if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES))
      if (OrderCloseTime() == 0)
      {
         Alert("Открыт ордер Buy ", Ticket, ".");
         Opn_B = False;
         SL = OrderOpenPrice()-StopLoss*Point;
         TP = OrderOpenPrice()+TakeProfit*Point;
         
         Alert("Попытка модифицировать ордер Buy ", Ticket, "...");
         if (OrderModify(Ticket, OrderOpenPrice(), SL, TP, 0, Blue))
            Alert("Ордер Buy ", Ticket, " модифицирован.");
         else
            Alert("Ошибка: ", GetLastError());
      }
      else
         Alert("Да ну нафиг!?");
   }
   else
      Alert("Ошибка: ", GetLastError());
}
There are pros and cons to each approach.
 
smartemiy:

Hi!

Thank you very much!!! for the replies!!!

I must have mispronounced it: the idea is this:

There is a sell trade at 1.4545... price goes against the trend - 1.4585... and THEN - a pending order should be placed at 1.4565.

my code is not working correctly:

Please help!!!

Bid and Ask should not be multiplied by Point. It caught my eye right away.

The conditions should be constructed differently:

if (Bid-OrderOpenPrice() > 40*Point)
{...}
if (OrderOpenPrice()-Ask > 40*Point)
{...}

I'm also not clear what variable you have SL? What value does it have? Where is it calculated?

And this

           if (OrderType()==OP_SELL){
               if (Ask*Point-OrderOpenPrice()<40)
                  RefreshRates();
                  if (k>1){
                {
                  order=OrderSend(Symbol(),OP_BUYLIMIT,0.02,OrderOpenPrice()-20*Point,1,SL,0,"Otlogka",mn,5,0);
                }}}

You should put it in a loop. A loop with order search should be common for BUY and SELL orders.

You must be really bad at programming. I advise you to reread the textbook again and look at examples, which are given in it for writing a simple Expert Advisor, order calculation and trading functions.


Also your mistake: RefreshRates() should be put before you want to use predefined variables or time-series arrays, not after...

 
MaxZ:

Bid and Ask do not need to be multiplied by Point. It immediately caught my eye...

The conditions should be constructed differently:


Don't you have to put brackets?

if ((Bid-OrderOpenPrice()) > 40*Point)
{...}
if ((Ask-OrderOpenPrice()) < 40*Point)
 
MaxZ:

Bid and Ask do not need to be multiplied by Point. It immediately caught my eye...

The conditions should be constructed differently:

I'm also not sure what variable you have SL? What value does it have? Where is it calculated?

And this

You have to put it into a loop...

You are really bad at programming... I advise you to reread the tutorial again and look at examples of writing a simple Expert Advisor, calculating orders and trading functions.

This is the normal Stop Loss = SL
 
FOReignEXchange:


Don't you have to use brackets?

Not necessarily. It'll work without the brackets! :)

It depends on how you like it. Handwriting! :D

 
smartemiy:
This is a regular Stop Loss = SL.
How is it calculated? And why is it common for BUY and SELL?

smartemiy:

there is a sell trade at 1.4545... the price goes against the trend - 1.4585... and THEN - a pending order should be placed at 1.4565.

By the way, if it is against the trend, the conditions should be negative:

if (Bid-OrderOpenPrice() < -40*Point)
{...}
if (OrderOpenPrice()-Ask < -40*Point)
{...}

Usually from the expressions

 ProfitBUY  = Bid-OrderOpenPrice();
ProfitSELL = OrderOpenPrice()-Ask;

We can find the profit of the corresponding trade in pips. If the profit is negative, it is already a loss. Here we check if the loss is more than 40 pips, we need to place a pending order.

 
MaxZ:
How is it calculated? And why is it common for BUY and SELL?

Stop loss is not that important, now...

the code, in theory, will it work?? with your adjustments

 
smartemiy:

Stop loss is not that important, now...

The code, in theory, will it work?? With your corrections

It may work, but will it work correctly?

Again, from your problem:

Smartemiy:

"A sell trade is made at 1.4545... price goes against the trend - 1.4585... and THEN - a pending order should be placed at 1.4565."

An SELL order has been opened. OrderOpenPrice() will return 1.4545.

The price goes against the trend. Ask = 1.4585. Condition:

if (OrderOpenPrice()-Ask <= -40*Point)

Will work (put a "<=" sign).

Let us analyze the following code:

order=OrderSend(Symbol(),OP_BUYLIMIT,0.02,OrderOpenPrice()-20*Point,1,SL,0,"Otlogka",mn,5,0);

A pending BUYLIMITorder is set at the price of 1.4545-20*Point = 1.4525. It must be 1.4565.


But before you do that, try to rewrite the entire code. There are a lot of errors, and some fragments look as if you don't understand what you're writing.

Reason: