[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 22

 
I decided to test all trailing stops and noticed that the simplest one does not work quite correctly, pushing the stops back. I thought it was easy to do it myself. I tried it and it turned out like this:
     RefreshRates();
      if ( Tip==0 && NormalizeDouble(Bid, Digits) > NormalizeDouble(OrderStopLoss()+ TrailingStop, Digits))
       {
        OrderModify(OrderTicket(), OrderOpenPrice(), Bid- TrailingStop*Point, OrderTakeProfit(), 0);
       }
     RefreshRates();
      if ( Tip==1 && NormalizeDouble(Ask, Digits) < NormalizeDouble(OrderStopLoss()- TrailingStop, Digits))
       {
        OrderModify(OrderTicket(), OrderOpenPrice(), Ask+ TrailingStop*Point, OrderTakeProfit(), 0);
       }
But for some reason it does not want to work. Can you tell me what's wrong?
 

Are Tral_Stop and TrailingStop equal to each other?

 
Roger >> :

Are Tral_Stop and TrailingStop equal to each other?

Oops, yes, sorry, unfortunate rookie mistake, two identical variables. Doesn't want to work with one as well.

 
Is it possible to directly extract (from the characteristics of the order) the margin for the open order in the currency of the deposit (the value of the invested funds for the open position in the currency of the deposit)? Let's say the deposit is in Rubles, and yesterday I opened a position with X lots of USDJPY. I may calculate the margin for this position as "Margin = (Contract/Leverage)*USDRUR [at the opening]", but it would not be exact (the exact USDRUR rate at the opening is not always available, especially if the position is old). What to do?
 

I really need help!

How to write a trading criterion for crossing the price with an expotential average in MQL4.

Suppose I set EMA20_Open variable through iMA. I don't know how to set the Price variable to be the current price (!)

Please help me!

 
Dear programmers, does anyone have a script that opens positions when the price reaches the horizontal line set by the user? Or tell me how to recognise the horizontal line on the chart.
 
xruss >> :

I don't know how to set the Price variable to the current price (


Current price is stored in the Ask and Bid variables


If you compare the current price with indicator values, you have to take the Bid, as all indicators and oscillators are only calculated on demand prices.
 
xruss >> :

I really need help!

How to write a trading criterion for crossing the price with an expotential average in MQL4.

Suppose I set EMA20_Open variable through iMA. But I don't know how to set the Price variable to be the current price ( I don't know ).

>> Help!

I can try to do it this way:


double Price = Bid;

if (NormalizeDouble( Price, Digits)==NormalizeDouble( EMA20_Open, Digits))
 {
   //Действие
 }

Exactly the crossing can be done this way:

EMA20_Open=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,1); //Переменная экспотенциальной средней

   if (iOpen(NULL,0,1)>= EMA20_Open&&iClose(NULL,0,1)<= EMA20_Open) //Критерий пересечения (Правда здесь свечи.)
     {
       //Действие 
     }
 

ToReshetov, and


Novice

- special kudos!!!

Thank you very much.



 
To xruss I would be grateful if you could test trailing at your leisure, maybe help with the error. (It's not working for me for some reason).
Reason: