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

 
Zolotai:

Yeah, but, you know. I'd have to dig through someone else's code. Which I don't understand, and it takes a lot of time To figure it out.

Start with Tutorial, then Documentation, etc. There's no other way! And you'll be able to understand other people's code and learn a lot from them! Hints don't teach, they corrupt!
 

Question about visualisation.

I create a pending order with a command like this

OrderSend(Symbol(), OP_BUYLIMIT, lot, price, 3, 0, take_profit, 999, 999, 0, Blue);

In the tester, we can see its all path as arrows: pending order ------> buy --------------> take profit sale

However, only the blue arrow appears when placing an order and we can only guess about the buy and take profit in the logs. Is there any way to see the arrows in the real chart the same way as in the tester?

 
Denis111:

Question about visualisation.

I create a pending order by a command of the following type

OrderSend(Symbol(), OP_BUYLIMIT, lot, price, 3, 0, take_profit, 999, 999, 0, Blue);

In the tester, the arrows show its all path: pending order ------> buy --------------> sell at Take Profit

In real life, only the blue arrow appears when an order is placed and we can only guess about the buy and take profit in the logs. Is there any way to see the arrows in the real chart the same way as in the Strategy Tester?


To do this, open without TP, and then specify a colour when modifying too, and you will have a closing triangle with a dotted line from the opening itself!
 

Hello, I wrote a simple script to open pending buy order. The script works successfully on a demo account, but on a real account it generates error: 133, which means trading is not allowed. Could you tell me what is the problem? What may be the reason for this error?


extern int orderSize = 50;
extern int SL = 20;
extern int TP = 20;

int start()
{
double correctPoint = 0.0001;
double priceOpen = iOpen( Symbol(), PERIOD_M5, 0 ); //write the open price of the current five-minute bar in the priceOpen variable

double priceBuy = priceOpen + (double)orderSize * correctPoint; //the price at which the pending order is placed
double priceTP = priceBuy + (double)TP * correctPoint;
double priceSL = priceBuy - (double)SL * correctPoint;

while( !IsTradeAllowed() )
Sleep( 100 );
int codeError = OrderSend( Symbol(), OP_BUYSTOP, 1.5, priceBuy, 100, priceSL, priceTP );
if( codeError == -1 )
Alert ("BuyStop error: ", GetLastError() );

return(0);
}//±
 
And here it turns out there are those who cram half the forum with one question.
 

I want to make a simple owl..... script when placing the 1st order SL and TP gives error 130, and where to insert code with Tralingstop???

//+------------------------------------------------------------------+
//| установка мышкой отложенных ордеров                              |
//|                               Copyright © 2012, Хлыстов Владимир |
//|                                                cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Хлыстов Владимир"
#property link      "cmillion@narod.ru"
#property show_inputs

//--------------------------------------------------------------------
extern int     Stoploss          = 0,     //стоплосс ордеров
               Takeprofit        = 0;     //тейкпрофит ордеров
extern double  Lot               = 0.1;   //лот
extern int     Magic             = 0;     //уникальный номер ордеров этого советника
extern bool    comment           = true;  //выводить информацию на экран
//--------------------------------------------------------------------
int start()
{
   int n;
   double SL,TP;
   double Price = NormalizeDouble(WindowPriceOnDropped(),Digits);
   string txt=StringConcatenate("Скрипт выставления рыночного ордера, старт ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
   while(true)
   {
      RefreshRates();
      if(Price>Ask) 
      {
         if (Takeprofit!=0) TP = NormalizeDouble(Ask + Takeprofit * Point,Digits); else TP=0;
         if (Stoploss!=0)   SL = NormalizeDouble(Ask - Stoploss   * Point,Digits); else SL=0;
         if (OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),0,SL,TP,"StopOrders",Magic,0,CLR_NONE)!=-1)
              {txt = StringConcatenate(txt,"\nВыставлен BUY ",DoubleToStr(Ask,Digits));break;}
         else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," выставления BUY ");
      }
      if(Price<Bid) 
      {
         if (Takeprofit!=0) TP = NormalizeDouble(Bid - Takeprofit * Point,Digits); else TP=0;
         if (Stoploss!=0)   SL = NormalizeDouble(Bid + Stoploss   * Point,Digits); else SL=0;
         if (OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),0,SL,TP,"StopOrders",Magic,0,CLR_NONE)!=-1)
              {txt = StringConcatenate(txt,"\nВыставлен SELL ",DoubleToStr(Bid,Digits));break;}
         else txt = StringConcatenate(txt,"\nОшибка ",GetLastError()," выставления SELL ");
      }
      if (comment) Comment("Попытка ",n," ",txt);
      n++;
      if (n>10) break;
   }
   if (comment) Comment(txt,"\nСкрипт закончил свою работу ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
   return(0);
}
//--------------------------------------------------------------------
 
MyTHblu:

i want to make a simple owl..... script when placing 1st order SL and TP gives error 130, and where to insert code with Tralingstop???


130 - stops are wrong. Carefully read the terms of your brokerage company again and then re-read them regularly so you don't forget. Why do you all like Alpari so much, it's like honey...


The code of trawl can be copied into the start, or you can use a separate function, again, from the start.

 
evillive:

130 - the stops are wrong. Read the trading conditions of your broker once again and then reread them regularly so that you don't forget. Why do you all like Alpari so much, it's like honeydew...


The code of trawl can be copied into the start, or you can use a separate function, again, from the start.


As he took this owl from CodeBase, he can also choose another one with trawl. And in Alps, you have to open without SL and TP and immediately modify the order by placing them. Why don't they bother to read the broker's terms and conditions, the forum rules, the MT4 help and the information written and discussed a hundred times here on the site, use the search here and on Google? Before asking basic questions?
 

how to connect codes....there's a trading stop... I have not inserted it anywhere, maybe it has an error, when compiling it says 'if' - expressions are not allowed on a global scop, it seems to mean an error before if.... right?

extern bool UseTrailing = true;
extern int lMinProfit = 30;
extern int sMinProfit = 30;
extern int lTrailingStop = 15;
extern int sTrailingStop = 15;
extern int lTrailingStep = 5;
extern int sTrailingStep = 5;
//-----

if (UseTrailing) TrailingPositions();  

void TrailingPositions() 
{
  int cnt = OrdersTotal();

  for (int i=0; i<cnt; i++) {
        if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
        if (OrderSymbol() != Symbol()) continue;                

        if (OrderType() == OP_BUY) {
        if (Bid-OrderOpenPrice() > lMinProfit*Point) {
                if (OrderStopLoss() < Bid-(lTrailingStop+lTrailingStep-1)*Point) {
                OrderModify(OrderTicket(), OrderOpenPrice(), Bid-lTrailingStop*Point, OrderTakeProfit(), 0, Blue);
                }
        }
        }

        if (OrderType() == OP_SELL) {
        if (OrderOpenPrice()-Ask > sMinProfit*Point) {
                if (OrderStopLoss() > Ask+(sTrailingStop+sTrailingStep-1)*Point || OrderStopLoss() == 0) {
                OrderModify(OrderTicket(), OrderOpenPrice(), Ask+sTrailingStop*Point, OrderTakeProfit(), 0, Blue);
                }
        }
        }
  }
  
}
 
MyTHblu:

how to connect codes....there's a trading stop... I have not inserted it anywhere, maybe it has an error, when compiling it says 'if' - expressions are not allowed on a global scop, it seems to mean that the error is before if.... right?

The if condition is not allowed on a global scop. Turn it into a robot, like this:

extern bool UseTrailing = true;
extern int lMinProfit = 30;
extern int sMinProfit = 30;
extern int lTrailingStop = 15;
extern int sTrailingStop = 15;
extern int lTrailingStep = 5;
extern int sTrailingStep = 5;
//--------------------------------------------------------------- 2 --
int start()
  {
   if (UseTrailing) TrailingPositions();     
//--------------------------------------------------------------- 9 --
   return;                                      // Выход из start()
  }
//-------------------------------------------------------------- 10 --
void TrailingPositions() 
{
  int cnt = OrdersTotal();

  for (int i=0; i<cnt; i++) {
        if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
        if (OrderSymbol() != Symbol()) continue;                

        if (OrderType() == OP_BUY) {
        if (Bid-OrderOpenPrice() > lMinProfit*Point) {
                if (OrderStopLoss() < Bid-(lTrailingStop+lTrailingStep-1)*Point) {
                OrderModify(OrderTicket(), OrderOpenPrice(), Bid-lTrailingStop*Point, OrderTakeProfit(), 0, Blue);
                }
        }
        }

        if (OrderType() == OP_SELL) {
        if (OrderOpenPrice()-Ask > sMinProfit*Point) {
                if (OrderStopLoss() > Ask+(sTrailingStop+sTrailingStep-1)*Point || OrderStopLoss() == 0) {
                OrderModify(OrderTicket(), OrderOpenPrice(), Ask+sTrailingStop*Point, OrderTakeProfit(), 0, Blue);
                }
        }
        }
  }
  
}