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

 

Buf0[i]=iMA(NULL,0,8,0,MODE_EMA,PRICE_OPEN,i-1)-iMA(NULL,0,8,1,MODE_SMA,PRICE_OPEN,i);

for a yem in infinity you will be thrown when calculating -1 bar when i=0

it's better this way:

Buf0[i]=iMA(NULL,0,8,0,MODE_EMA,PRICE_OPEN,i)-iMA(NULL,0,8,1,MODE_SMA,PRICE_OPEN,i+1);

and if you need a shift as in the variant you cited by 1-n bar to the right, better implement it explicitly in the init via SetIndexShift(0,1);

 
ALXIMIKS:

Buf0[i]=iMA(NULL,0,8,0,MODE_EMA,PRICE_OPEN,i-1)-iMA(NULL,0,8,1,MODE_SMA,PRICE_OPEN,i);

for the yem to be infinite you will be thrown when calculating -1 bar when i=0

it's better this way:

Buf0[i]=iMA(NULL,0,8,0,MODE_EMA,PRICE_OPEN,i)-iMA(NULL,0,8,1,MODE_SMA,PRICE_OPEN,i+1);

and if you need a shift as in the variant you cited by 1-n bar to the right, better implement it explicitly in the init via SetIndexShift(0,1);



Thank you very much, but I understand it all perfectly, but why is it ok with iCCI and not with iMA?
 
       if ((NormalizeDouble(priceopen+start*Point,Digits)<=Bid)&&(NormalizeDouble(Bid-sl*Point,Digits)>NormalizeDouble(dist*Point,Digits)))
         {   
                sl=NormalizeDouble(Bid-dist*Point,Digits); 
Ekburg
:


you are calculating the distance from the price to the order placement price, and you need from the price to the current stop!)

If a short is standing, then it is directed to the first block, if a long is standing, then it is directed to the second block, and then the trailing stops.

If shorts are good, then they go to the first block, if long, then to the second, after that the calculations, checks and the trailing stops.


i still can't do it... I only try long, I've tried so many things, I can't remember what I've done))
 
clubsmi:


Thank you very much, but I understand it all perfectly, but why does it work with iCCI and not with iMA?


There were mistakes there and there, it's just that with iCCI it's not obvious, because of the peculiarities of calculations,

and the application of MAs, in particular EMAs, I think leads to their visibility.

 
vadynik:

still nothing comes out... I'm only trying long, I've tried so many things, I don't remember what I've done))

put OrderStopLoss() instead of sl
 
Vinin:

Are you going to live on tips?
Until I'm an expert at this.
You don't need tips now, do you? :)
 

There is a program that opens two orders to buy or sell, say for EURAUD and AUDUSD. The programme works only if there are no open orders in the terminal for these or other pairs. If at least one order is present in the terminal, trades will not open. My question is, how to programme the opening of orders whether there are open orders in the terminal or not? I thank you in advance for your reply.

extern double lotAU=1.3;
extern double lotEA=1.0;
extern double Profit=30;
extern int Operation=0;
extern string Сomment           = "KVAZ";
extern int Magic                = 1111;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

double prof;
double bidEA = MarketInfo("EURAUD",MODE_BID);
double askEA = MarketInfo("EURAUD",MODE_ASK);
double bidAU = MarketInfo("AUDUSD",MODE_BID);
double askAU = MarketInfo("AUDUSD",MODE_ASK);

string symEA = "EURAUD";
string symAU = "AUDUSD";

for(int i=OrdersTotal()-1; i>=0; i--)
{
 OrderSelect(i,SELECT_BY_POS);
 prof=prof+OrderProfit();
 Print("Profit="+prof);
}
if(prof>=Profit)
{
 for(i=OrdersTotal()-1; i>=0; i--)
 {
  OrderSelect(i,SELECT_BY_POS);
  {
  if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,0);
  }
 }
}
if(OrdersTotal()==0)
{
 if(Operation==0)
 {
  OrderSend(symEA,OP_BUY,lotEA,askEA,3,0,0,"KVAZ",Magic,0,Blue);
  OrderSend(symAU,OP_BUY,lotAU,askAU,3,0,0,"KVAZ",Magic,0,Blue); 
 }
 if(Operation==1)
 {
  OrderSend(symEA,OP_SELL,lotEA,bidEA,3,0,0,"KVAZ",Magic,0,Red);
  OrderSend(symAU,OP_SELL,lotAU,bidAU,3,0,0,"KVAZ",Magic,0,Red);
 }
}  
   return(0);
  }
 
alexey1979621:

There is a program that opens two buy or sell orders, say for EURAUD and AUDUSD. The programme works only if there are no open orders in the terminal for these or other pairs. If at least one order is present in the terminal, trades will not open. My question is, how to programme the opening of orders whether there are open orders in the terminal or not? I thank you in advance for your reply.


Remove check
if(OrdersTotal()==0)
 
evillive:

Remove the check
Yes, now it does, but it opens a whole bunch of trades, while I need only two trades to open on the specified pairs, say for EURAUD and AUDUSD.
 
okidoki543:
If anyone wants to help me (see above), I am open to collaboration.
On a commercial basis, no problem, there will be a queue of people who want to help. Otherwise... start writing yourself and help will come.
Reason: