Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 911

 

 if(S1a == S1b && S1a<20.0000 && S1b<20.0000 )

 {OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), Slippage, SL, TP, NULL, 0, 0,clrBlue);

     MyOrderStateB = 1; 

      if(!OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), 3, SL, TP, NULL, 0, 0,clrBlue)) 

   Print("Opening Buy error #", GetLastError());}

   else Sleep(2);

Thank you. Right or wrong, though? The warning still comes up

 
You have the stoploss and takeprofit in absolute values, and you need it in relative values, like Bid - Sl*Point.
 
abeiks:

Hello!

In my Expert Advisor, the previous candlestick is checked and if the conditions allow, the position is opened, if not, it is not opened. The problem is that the position is opened before the previous candle's condition is checked. Then I see the position opening in the log and then I see that it should not be opened. How to fix it?

Thank you, I have it figured out myself. I put the function checking the previous candle above the function opening a position.
 
I apologise for the sloppiness
 
if(S1a == S1b && S1a<20.0000 && S1b<20.0000 )
{OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), Slippage, Bid - SL * Point, Ask + TP * Point, NULL, 0, 0,clrBlue);
MyOrderStateB = 1;
if(!OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), 3, SL, TP, NULL, 0, 0,clrBlue))
Print("Opening Buy error #", GetLastError());}
else Sleep(2);

if(S1a == S1b && S1a>80.0000 && S1b>80.0000 )

{OrderSend(Symbol(), OP_SELL, OrderValue, NormalizeDouble(Bid, Digits), Slippage, Ask + SL * Point, Bid - TP * Point , NULL, 0, 0,clrRed);
MyOrderStateS = 1; }

else Sleep(2);

And with relative it gives out the same thing(

 
Viktorline14:

 if(S1a == S1b && S1a<20.0000 && S1b<20.0000 )

 {OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), Slippage, SL, TP, NULL, 0, 0,clrBlue);

     MyOrderStateB = 1; 

      if(!OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), 3, SL, TP, NULL, 0, 0,clrBlue)) 

   Print("Opening Buy error #", GetLastError());}

   else Sleep(2);

Thank you. Right or wrong, though? The warning still comes up

Wrong, you don't need to call OrderSend twice. And we should calculate SL and TP relative to price, not in pips. And we should normalize not the open Ask and Bid prices, but the result of SL and TP calculations.

In general, "learn, learn and learn again" ))))

 
evillive:

Wrong, no need to call OrderSend twice. And SL and TP should be calculated relative to the price, not in points. And we should normalize not the open Ask and Bid prices, but the result of SL and TP calculations.

In general, "learn, learn and learn again" ))))

Thank you very much))) You have helped me a lot, now everything works:3
 

Thank you very much again!

Now there is one problem, the EA opens several orders in a row, not one as I wanted(

int start()



  { S1a = NormalizeDouble(iStochastic(NULL, 0, S1_period, 3, S1_slowing, MODE_SMA, 1, MODE_MAIN, 1), 0);

   S1b = NormalizeDouble(iStochastic(NULL, 0, S1_period, 3, S1_slowing, MODE_SMA, 1, MODE_SIGNAL, 1), 0);

   

   if(MyOrderStateB == 1)Sleep(300000);

    else MyOrderStateB = 0;

   if(MyOrderStateS == 1)Sleep(300000);

    else MyOrderStateS = 0;

    

 

     

   if(S1a == S1b && S1a<20.0000 && S1b<20.0000 )

 

      if(!OrderSend(Symbol(), OP_BUY, OrderValue, NormalizeDouble(Ask, Digits), Slippage, Bid - SL * Point, Ask + TP * Point, NULL, 0, 0,clrBlue))

   Print("Opening Buy error #", GetLastError());  

     else Sleep(2);

   MyOrderStateB = 1;

  

   


      

   if(S1a == S1b && S1a>80.0000 && S1b>80.0000 )


    

    

       if(!OrderSend(Symbol(), OP_SELL, OrderValue, NormalizeDouble(Bid, Digits), Slippage, Ask + SL * Point, Bid - TP * Point , NULL, 0, 0,clrRed))

       Print("Opening Sell error #", GetLastError()); 

       else Sleep(2);

       MyOrderStateS = 1;

       

      

       

       

       

   return(0);}

 

I have seen some strange behaviour in the strategy tester. My EA sets and trawls pending stop orders. The following happens. The Expert Advisor sets a Buy Stop and Sell Stop at 30 pips from the current price (symbol - GbpUsd. Four digits. Minimal level = 3 pips). After a while it pulls them up following the market, if they didn't trigger. So what I see. the modification is successful, the modification is successful, and then at some point in time slams and error #1 pops up. That is, everything was fine, the EA was doing the same actions and suddenly this error pops up. All prices have been normalized to digits. In general, all values that are passed to the OrderModify() function input are normalized!

What can be the reason for such behavior of the EA in the tester?

 
drknn:

I have seen some strange behaviour in the strategy tester. My EA sets and trawls pending stop orders. The following happens. The Expert Advisor sets a Buy Stop and Sell Stop at 30 pips from the current price (symbol - GbpUsd. Four digits. Minimal level = 3 pips). After a while it pulls them up following the market, if they didn't trigger. So what I see. the modification is successful, the modification is successful, and then at some point in time slams and error #1 pops up. That is, everything was fine, the EA was doing the same actions and suddenly this error pops up. All prices have been normalized to digits. In general, all values that are passed to the OrderModify() function input are normalized!

What can be the reason for such behavior of the Expert Advisor in the tester?

The normalization should be done to check if the modification is necessary. Better compare the modified price difference with zero.

if(NormalizeDouble(цена1 - цена2, _Digits) != 0)


Depending on the condition, it may be better to put < or > zero.