[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 218

 
what's wrong for (f=1;f<Bars;f++)
{
Price1 =(iClose(Symbol_1,0,0) - iClose(Symbol_1,0,f)) / MarketInfo(Symbol_1, MODE_POINT)
Price2 = K*(iClose(Symbol_2,0,0) - iClose(Symbol_2,0,f)) / MarketInfo(Symbol_2, MODE_POINT);
Spread = Price1 - Price2;
Print ("Price1="+Price1, " Price2="+Price2);
if (Spread==0){t=f; break;}
}
Price12 = (iClose(Symbol_1,0,0) - iClose(Symbol_1,0,t)) / MarketInfo(Symbol_1, MODE_POINT);
Price22 = K*(iClose(Symbol_2,0,0) - iClose(Symbol_2,0,t)) / MarketInfo(Symbol_2, MODE_POINT);
Spread2 = Price12 - Price22;


if (MathAbs(Spread2) >= razdvizka && Spread2 < 0) { open trade }


I want to fix the bar where the spread was equal to zero and control the spread from it

 
DanLett:

Please advise what to do if:

In the tester is working fine, all according to plan, but on the realsk does not open the transaction.

P.S. Really need some help, it's a matter of life or death

Are advisors allowed to trade?
 
DanLett:

Please advise what to do if:

In the tester is working fine, all according to plan, but on the realsk does not open the transaction.

P.S. Really need some help, it's a matter of life or death


I'm not an expert, maybe there is a problem?

ОrderSelect(i,SELECT_BY_POS,MODE_TRADES)
has been replaced by MODE_TRADES?
 

What's wrong with my maths?

int modOrder()
{
double currentPrice = Bid;
double currentStoploss = OrderStopLoss();
double profitLine=profitLine();
if (currentPrice >= profitLine)
  {
  OrderModify(getTicket(),0,currentStoploss+1*Point,0,0,Blue);
  }
  Alert("profit line ", profitLine);
  return (0);
}

My currentPrice >= profitLine means that if profitLine == or >, right?

But it works for me if > by at least one point.

 
Comparing real numbers (double) to strict equality is not the best thing to do with them. It is more correct to compare their difference to the maximum allowed value.
 
olis: What's wrong with my maths?
Have you looked atthe FAQ?
 

Yeah, well... didn't think of that. Thank you. (chuckles)
 
Gek34:

Dear experts, the question about the indicator is removed, the solution came quite unexpectedly, I duplicated the calculations, and oops.... Everything is working.

But I have another one, how it worked, I would like to understand. The code is attached:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

extern int PerMa = 5;
extern int Shift = 0;
extern int Step = 15;

double ABuf45[],ABuf[],ABuf5[],ABuf15[];//,Stark[];
double Stark;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{ Stark=0;
//---- indicators
// IndicatorBuffers(4);

SetIndexBuffer(0,ABuf);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i,n;

//----
i=Bars-counted_bars-1;

while(i>=0)
{ RefreshRates();
//----
double Ma15=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,i);
double Ma45=iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,i);
double Ma=iMA(NULL,0,PerMa,0,MODE_EMA,PRICE_CLOSE,i);
//double Ma1=iMA(NULL,0,PerMa,Shift,MODE_EMA,PRICE_CLOSE,i+1);
if(Ma>Stark+Step*Point&&Ma15>Ma45){Stark=Ma;}
if(Ma<Stark-Step*Point&&Ma15<Ma45){Stark=Ma;}//else{Stark=Stark;}
ABuf[i+Shift]=Stark;Comment(Stark);
if(Ma>Stark+Step*Point&&Ma15>Ma45){Stark=Ma;}//else{Stark=Stark;}
if(Ma<Stark-Step*Point&&Ma15<Ma45){Stark=Ma;}//else{Stark=Stark;}
ABuf[i+Shift]=Stark;//Comment(Stark);

//----
i--;
}
return(0);
}


Withdrawn. I made up all kinds of nonsense. It turned out to be much simpler. I took the Stark variable out of the start function, so it wouldn't reset on every tick.
 

sig1"signal is given , BUY command is triggered and SELLSTOP pending order is placed below BUY order.

When the BUY position is closed, the SELLSTOP is also deleted.

But what happens when this BUY is not closed, and the next BUY, etc. is opened.

This SELLSTOP which is set first has to be somehow figured out in order to close it after the first BUY has been closed.

In addition, if the price breaks through the pending one and then it closes without a loss, the pending one has been set in the same place as its predecessor.

-----------------------------------

thiswill not solve the problem because after the sell is closed, a new sell with a different masterwill open and it will be deleted.

After closing the buy I don't know how.

 int i, k=OrdersTotal(),ti;
    for (i=0; i<k; i++){
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
    if(OrderType()== OP_SELLSTOP){
    ti = OrderMagicNumber();  }
    if(OrderType()== OP_BUY)
    if(OrderTicket()==ti) что дальше не пойму, как узнать о наличии ордера бай с нужным тикетом?

 
Top2n:

sig1"signal is given , BUY command is triggered and SELLSTOP pending order is placed below BUY order.

When the BUY position is closed, the SELLSTOP is also deleted.

But what happens when this BUY is not closed, and the next BUY, etc. is opened.

This SELLSTOP which is set first has to be somehow figured out in order to close it after the first BUY has been closed.

In addition, if the price breaks through the pending one and then it closes without a loss, the pending one has been set in the same place as its predecessor.

-----------------------------------

thiswill not solve the problem because after the sell is closed, a new sell with a different masterwill open and it will be deleted.

after the buy is closed, I don't know how.


Well... you use the same Select to check...

int i, k=OrdersTotal(), ti, tid;

for (i=0; i<k; i++){
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
       if (OrderType()== OP_SELLSTOP) {
          tid = OrderTicket(); // запомним тикет ордера селлстоп - если его придётся удалить...
          ti = OrderMagicNumber();  
          //  ищем ордер по тикету
          if (OrderSelect(ti, SELECT_BY_TICKET)==true) {
             // проверяем Закрылся ли этот ордер - это твоя Байка
             if (OrderCloseTime() > 0) {
                //  удаляем ордер Селлстоп - если связанная с ним байка Закрылась...
                OrderDelete(tid);
             }
          } 
       }
    }
}