KeepMarcos:
OrdenOpenPrice() is 1.00000
OrdenOpenPrice() is 1.20 (STOPLOSS())
OrderOpenPrice() is 1.50 (STOPLOSS())
- Can't be all three. Your statement is illogical.
SLshell = stnewprice-AutoStop*MyPoint; double SLshell2 = stnewprice-40*MyPoint; if(OrderOpenPrice()-Bid > AutoStop*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell,0,0,clrGreen);
You only are checking against OOP You need to also check against the current SL to avoid Error=1- You have two separate values SLshell and SLshell2. Make up your mind which is the trailing.
double SL = ... if(OrderOpenPrice() > SL // sell order && OrderStopLoss() - SL > _Point // Prevent Error 1 ){ modify = OrderModify(OrderTicket(),OrderOpenPrice(),SL,0,0,clrGreen);
and Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articlesfor(cnt=0;cnt<total;cnt++)
In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
Heey gus!
I'm trying to make a Trailling Stop
Bad, is very large. Is there something I'm missing?
Example:
OrdenOpenPrice() is 1.00000
OrdenOpenPrice() is 1.20 (STOPLOSS())
OrderOpenPrice() is 1.50 (STOPLOSS())
thank you for help.
Look at example. Maybe helps.
extern int TrailingStart =0; extern int TrailingStop = 20; extern int TrailingStep =10; /////////////////////////////////////////////////////////////////////////// void Traling_Stop_f() { for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS)) { if(OrderSymbol() == Symbol()) { if(OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY) { if(Bid>=NormalizeDouble(OrderOpenPrice()+TrailingStart*point+TrailingStop*point,Digits)) { if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep)*point,Digits)) { if(NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Bid-TrailingStop*point,Digits)) { while(IsTradeContextBusy()) Sleep(200); RefreshRates(); if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*point,Digits), OrderTakeProfit(), 0, clrNONE)) continue; } } } } else if(OrderType()==OP_SELL) { if(Ask<=NormalizeDouble(OrderOpenPrice()-TrailingStart*point-TrailingStop*point,Digits)) { if((NormalizeDouble(OrderStopLoss(),Digits)>NormalizeDouble(Ask+(TrailingStop+TrailingStep)*point,Digits)) || OrderStopLoss()==0) { if(NormalizeDouble(OrderStopLoss(),Digits)!=NormalizeDouble(Ask+TrailingStop*point,Digits)) { while(IsTradeContextBusy()) Sleep(200); RefreshRates(); if(OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*point,Digits), OrderTakeProfit(), 0, clrNONE)) continue; } } } } } } } } }
I need to change the stoploss when the price reaches 10 pips for example.
The code below is correct. bad when the price reaches another 10 pips can not change.
:(((((
Help-me people!!!
make 5 days in this code line. I can not change :(((('
*Sorry some error in English.
AutoStop=20; AutoStop2=30; int cnt, total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_SELL) { double stnewprice = OrderOpenPrice(); SLshell = stnewprice-AutoStop*MyPoint; double SLshell2 = stnewprice-40*MyPoint; if(OrderOpenPrice()-Bid > AutoStop*MyPoint) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLshell,0,0,clrGreen);
int cnt, total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) { double stnewprice = OrderOpenPrice(); SLbuy = stnewprice+AutoStop*MyPoint; //if(Ask>SLbuy) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLbuy,0,0,clrGreen); if(stnewprice+20*MyPoint>stnewprice) modify = OrderModify(OrderTicket(),OrderOpenPrice(),SLbuy,0,0,clrGreen); if(stnewprice+40*MyPoint> stnewprice) modify = OrderModify(OrderTicket(),OrderOpenPrice(),stnewprice+40*MyPoint,0,0,clrGreen); }
this screen is my real doubts.
It is in an infinite loop. =(
int cnt, total=OrdersTotal(); for(cnt=0;cnt<total;cnt++)
Why you use construction like this?
Why not
for(int cnt=OrdersTotal()-1;cnt>=0;cnt--)
Maybe like this
double stnewprice = OrderStopLoss(); if( stnewprice<Bid-20*MyPoint)
thank you eevviill.
tank you too WHRoader =)))))
CODE:
int cnt, total=OrdersTotal(); for(cnt=0;cnt<total;cnt++) { if (OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) { double st = OrderStopLoss(); double stnewprice = OrderOpenPrice(); SLbuy = stnewprice+AutoStop*MyPoint; if(Ask+35*MyPoint>st); modify = OrderModify(OrderTicket(),OrderOpenPrice(),st+35*MyPoint,0,0,clrLightGreen); }
thank you eevviill.
tank you too WHRoader =)))))
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Heey gus!
I'm trying to make a Trailling Stop
Bad, is very large. Is there something I'm missing?
Example:
OrdenOpenPrice() is 1.00000
OrdenOpenPrice() is 1.20 (STOPLOSS())
OrderOpenPrice() is 1.50 (STOPLOSS())
thank you for help.