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

 
Ekburg:

put OrderStopLoss() instead of sl


didn't work...

void VirtualTral(int Dist_Tral,int Start_Tral,int Magic,int SL)
{

double dist=Dist_Tral;
double start=Start_Tral;
double priceopen=OrderOpenPrice();
double sl=OrderStopLoss();
 
if(OrdersTotal()<=0)
ObjectDelete("Stop"); 

int i, k=OrdersTotal();

  for (i=k-1; i>=0; i--) 
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {  

       if ((NormalizeDouble(priceopen+start*Point,Digits)<=Bid)&&(NormalizeDouble(Bid-sl*Point,Digits)>NormalizeDouble(dist*Point,Digits)))
         {                    
                sl=NormalizeDouble(Bid-dist*Point,Digits);
                Print(+sl);
                ObjectCreate("Stop",OBJ_HLINE,0,D'2013.02.20 12:30',sl);                                                         
                ObjectSet("Stop",OBJPROP_STYLE,1);                                                                                         
                ObjectMove("Stop",0,D'2013.02.20 12:30',sl);                                                                                                 
                if (NormalizeDouble(sl*Point,Digits) >=Bid)
             {
                Print("Закрываем");
                OrderClose(OrderTicket(),OrderLots(),Bid,50,Blue);
             }
         }               
      }
   }
}

It seems to work, but something is not accounted for...

 
alexey1979621:
Yes, now it does, but it opens a whole bunch of trades, and I need only two trades to open on given pairs, say for EURAUD and AUDUSD.

The algorithm is simpler than a felt-tree:

1. If there are no positions on the EuroAudi, open a position,

2. If there is no position on AudiBucks - open a position.

 
vadynik:


Didn't work...

seems like it should work, but something's not accounted for...

Shouldn't priceopen be taken in the loop already after the order has been selected?
 
artmedia70:

The algorithm is simpler than a felt-tree:

1. If there are no positions on the EuroAudi, open a position,

2. If there is no position on AudiBucks - open a position.


No, Artemis, it doesn't work that way in my situation.
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(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:
No, Artemida, it doesn't work for my situation.


In the loop, recalculate positions depending on the symbol and magician.

And what's this: OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,0);


P.S.: Artemida not Artemida a

Artmedia

 
evillive:


In the loop, recalculate positions depending on the symbol and magician.

And what's this: OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,0);


P.S.: Artemida is not Artemida a

Artmedia


Come on, I'm used to everyone calling me names ... whatever ...

Actually, the closing price in this function used to work fine. The compiler would cram the necessary price in by itself. Someone here recently had this cause an error.

 
artmedia70:

Come on, I'm used to everyone calling me names ... whatever...

Time to change your nickname?
 
alexey1979621:
No, Artemis, it doesn't work that way in my situation.


Yeah, well... In your situation, when it's so crooked, normal proposals don't really work...
 
Zhunko:
Time to change your nickname?

This nickname is 300 years old... I've grown fond of it.
 
artmedia70:

Yeah... In your situation, when everything is so crooked, normal offers are definitely not an option...

Artmedi,

My hands are being attacked again. I've already written that I'm just learning. Since I have no system knowledge, I write as best I can. I think that such an experienced person like you could show me a master class on the example of my owl (more interested in your style of EA writing). It's not too difficult, I think, it will take you 5-10 minutes to write it. How to suggest....